Exemplo n.º 1
0
        /// <summary>
        /// 通过[武魂ID]二分快速查表
        /// </summary>
        /// <param name="id">武魂ID</param>
        /// <returns></returns>
        public static IEnumerable <WeaponSoulUpgradeDataBase> Query(this List <WeaponSoulUpgradeDataBase> sorted, uint id)
        {
            var key = new WeaponSoulUpgradeDataBase()
            {
                id = id
            };
            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 + 等级]二分快速查表
        /// </summary>
        /// <param name="id">武魂ID</param>
        /// <param name="level">等级</param>
        /// <returns></returns>
        public static WeaponSoulUpgradeDataBase Query(this List <WeaponSoulUpgradeDataBase> sorted, uint id, uint level)
        {
            var key = new WeaponSoulUpgradeDataBase()
            {
                id = id, level = level
            };
            var comparer = new Comparer2();
            var index    = sorted.BinarySearch(key, comparer);

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