Пример #1
0
        internal bool Find(PersistentComparator comparator, object minValue, int minInclusive, object maxValue, int maxInclusive, ArrayList selection)
        {
            int l, r, m, n;
            Load();
            n = nItems;
            if (minValue != null)
            {
                if (-comparator.CompareMemberWithKey(LoadItem(0), minValue) >= minInclusive)
                {
                    if (-comparator.CompareMemberWithKey(LoadItem(n - 1), minValue) >= minInclusive)
                    {
                        if (right != null)
                        {
                            return right.Find(comparator, minValue, minInclusive, maxValue, maxInclusive, selection);
                        }
                        return true;
                    }

                    for (l = 0, r = n; l < r; )
                    {
                        m = (l + r) >> 1;
                        if (-comparator.CompareMemberWithKey(LoadItem(m), minValue) >= minInclusive)
                        {
                            l = m + 1;
                        }
                        else
                        {
                            r = m;
                        }
                    }

                    while (r < n)
                    {
                        if (maxValue != null && comparator.CompareMemberWithKey(LoadItem(r), maxValue) >= maxInclusive)
                        {
                            return false;
                        }
                        selection.Add(LoadItem(r));
                        r += 1;
                    }

                    if (right != null)
                    {
                        return right.Find(comparator, minValue, minInclusive, maxValue, maxInclusive, selection);
                    }
                    return true;
                }
            }

            if (left != null)
            {
                if (!left.Find(comparator, minValue, minInclusive, maxValue, maxInclusive, selection))
                {
                    return false;
                }
            }

            for (l = 0; l < n; l++)
            {
                if (maxValue != null && comparator.CompareMemberWithKey(LoadItem(l), maxValue) >= maxInclusive)
                {
                    return false;
                }
                selection.Add(LoadItem(l));
            }

            if (right != null)
            {
                return right.Find(comparator, minValue, minInclusive, maxValue, maxInclusive, selection);
            }

            return true;
        }