Ejemplo n.º 1
0
        /// <summary>
        /// Returns the count within a range.
        /// </summary>
        /// <returns></returns>
        public int CountInRange(
            Bound <TK> start,
            Bound <TK> end)
        {
            var tailIndex = GetTailIndex(end);

            if (tailIndex != -1)
            {
                if (tailIndex >= _itemList.Count)
                {
                    tailIndex = _itemList.Count - 1;
                }

                while (tailIndex >= 0 && !BoundExtensions.IsLessThan(end, _itemList[tailIndex].Key, _itemComparer.KeyComparer))
                {
                    tailIndex--;
                }

                if (tailIndex == -1)
                {
                    return(0);
                }

                var headIndex = AdvanceIntoRange(GetHeadIndex(start), start);
                return(Math.Max(tailIndex - headIndex + 1, 0));
            }

            return(0);
        }
Ejemplo n.º 2
0
        public IEnumerable <KeyValuePair <TK, TV> > EnumerateRange(
            Bound <TK> start,
            Bound <TK> end)
        {
            var headIndex = AdvanceIntoRange(GetHeadIndex(start), start);

            for (var ii = headIndex; ii < _itemList.Count && BoundExtensions.IsLessThan(end, _itemList[ii].Key, _itemComparer.KeyComparer); ii++)
            {
                yield return(_itemList[ii]);
            }
        }