Exemplo n.º 1
0
        /// <summary>
        /// 通过[主类ID]二分快速查表
        /// </summary>
        /// <param name="mainID">主类ID</param>
        /// <returns></returns>
        public static IEnumerable <RankTypeDataBase> Query(this List <RankTypeDataBase> sorted, uint mainID)
        {
            var key = new RankTypeDataBase()
            {
                mainID = mainID
            };
            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]);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 通过[主类ID + 子类ID]二分快速查表
        /// </summary>
        /// <param name="mainID">主类ID</param>
        /// <param name="childID">子类ID</param>
        /// <returns></returns>
        public static RankTypeDataBase Query(this List <RankTypeDataBase> sorted, uint mainID, uint childID)
        {
            var key = new RankTypeDataBase()
            {
                mainID = mainID, childID = childID
            };
            var comparer = new Comparer2();
            var index    = sorted.BinarySearch(key, comparer);

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