コード例 #1
0
        public void LessOrEqual(RbKey key, out int count, out error err)
        {
            count = 0;
            err   = null;
            if (key == null)
            {
                err = ErrorDef.ArgumentNilError("key");
                return;
            }

            RbTree tree;

            this.checkStateAndGetTree(out tree, out err);
            if (err != null)
            {
                return;
            }

            try
            {
                this.walkLessOrEqual(tree.root, key);
                count = this.CurrentCount();
            }
            finally
            {
                Interlocked.CompareExchange(ref this.state, (long)IterationState.iteratorReady,
                                            (long)IterationState.iteratorWalking);
            }
        }
コード例 #2
0
        public void Between(RbKey loKey, RbKey hiKey, out int count, out error err)
        {
            count = 0;
            err   = null;
            if (loKey == null)
            {
                err = ErrorDef.ArgumentNilError("loKey");
                return;
            }
            if (hiKey == null)
            {
                err = ErrorDef.ArgumentNilError("hiKey");
                return;
            }

            RbTree tree;

            this.checkStateAndGetTree(out tree, out err);
            if (err != null)
            {
                return;
            }

            try
            {
                var cmp = loKey.ComparedTo(hiKey);
                switch (cmp)
                {
                case KeyComparison.KeysAreEqual:
                    var node = tree.find(loKey);
                    if (node != null)
                    {
                        count = 1;
                        this.callback(this, node.key, node.value);
                        return;
                    }
                    return;

                case KeyComparison.KeyIsGreater:
                    var tmp = loKey;
                    loKey = hiKey;
                    hiKey = tmp;
                    break;
                }

                this.walkBetween(tree.root, loKey, hiKey);
                count = this.CurrentCount();
            }
            finally
            {
                Interlocked.CompareExchange(ref this.state, (long)IterationState.iteratorReady,
                                            (long)IterationState.iteratorWalking);
            }
        }
コード例 #3
0
        // NewRbIterator creates a new iterator for the given RbTree
        public RbIterator NewRbIterator(RbIterationCallback callback, out error err)
        {
            err = null;
            if (callback == null)
            {
                err = ErrorDef.ArgumentNilError("callback");
                return(null);
            }

            return(new rbIterationContext {
                tree = this,
                callback = callback,
                state = (long)IterationState.iteratorReady,
            });
        }