Exemple #1
0
        /// <summary>
        /// 通过[职业]二分快速查表
        /// </summary>
        /// <param name="dwJob">职业</param>
        /// <returns></returns>
        public static IEnumerable <RobotDataBase> Query(this List <RobotDataBase> sorted, uint dwJob)
        {
            var key = new RobotDataBase()
            {
                dwJob = dwJob
            };
            var comparer = new Comparer1();
            var from     = sorted.BinarySearch(key, comparer);

            if (from < 0)
            {
                yield break;
            }
            var to = from + 1;

            while (from > 0 && comparer.Compare(key, sorted[from - 1]) == 0)
            {
                from--;
            }
            while (to < sorted.Count && comparer.Compare(key, sorted[to]) == 0)
            {
                to++;
            }
            for (var i = from; i < to; i++)
            {
                yield return(sorted[i]);
            }
        }
Exemple #2
0
        /// <summary>
        /// 通过[职业 + 等级]二分快速查表
        /// </summary>
        /// <param name="dwJob">职业</param>
        /// <param name="dwLevel">等级</param>
        /// <returns></returns>
        public static RobotDataBase Query(this List <RobotDataBase> sorted, uint dwJob, uint dwLevel)
        {
            var key = new RobotDataBase()
            {
                dwJob = dwJob, dwLevel = dwLevel
            };
            var comparer = new Comparer2();
            var index    = sorted.BinarySearch(key, comparer);

            return(index >= 0 ? sorted[index] : default(RobotDataBase));
        }