Exemplo n.º 1
0
        internal BTreeNodeSearchResult SearchLeaf(Transaction trans, IPreparedComparison
                                                  preparedComparison, SearchTarget target)
        {
            ByteArrayBuffer reader = PrepareRead(trans);
            Searcher        s      = Search(trans, preparedComparison, reader, target);

            if (!_isLeaf)
            {
                return(Child(reader, s.Cursor()).SearchLeaf(trans, preparedComparison, target));
            }
            if (!s.FoundMatch() || target == SearchTarget.Any || target == SearchTarget.Highest)
            {
                return(new BTreeNodeSearchResult(trans, reader, Btree(), s, this));
            }
            if (target == SearchTarget.Lowest)
            {
                BTreeNodeSearchResult res = FindLowestLeafMatch(trans, preparedComparison, s.Cursor
                                                                    () - 1);
                if (res != null)
                {
                    return(res);
                }
                return(CreateMatchingSearchResult(trans, reader, s.Cursor()));
            }
            throw new InvalidOperationException();
        }
Exemplo n.º 2
0
        private bool WasRemoved(Transaction trans, Searcher s)
        {
            if (!s.FoundMatch())
            {
                return(false);
            }
            BTreePatch patch = KeyPatch(trans, s.Cursor());

            return(patch != null && patch.IsRemove());
        }
Exemplo n.º 3
0
        private Searcher Search(Transaction trans, IPreparedComparison preparedComparison
                                , ByteArrayBuffer reader, SearchTarget target)
        {
            Searcher s = new Searcher(target, _count);

            if (CanWrite())
            {
                while (s.Incomplete())
                {
                    s.ResultIs(CompareInWriteMode(preparedComparison, s.Cursor()));
                }
            }
            else
            {
                while (s.Incomplete())
                {
                    s.ResultIs(CompareInReadMode(trans, preparedComparison, reader, s.Cursor()));
                }
            }
            return(s);
        }
Exemplo n.º 4
0
        /// <returns>
        /// the split node if this node is split
        /// or this if the first key has changed
        /// </returns>
        public Db4objects.Db4o.Internal.Btree.BTreeNode Add(Transaction trans, IPreparedComparison
                                                            preparedComparison, object obj)
        {
            ByteArrayBuffer reader = PrepareRead(trans);
            Searcher        s      = Search(trans, preparedComparison, reader);

            if (_isLeaf)
            {
                PrepareWrite(trans);
                SetStateDirty();
                if (WasRemoved(trans, s))
                {
                    CancelRemoval(trans, obj, s.Cursor());
                    return(null);
                }
                if (s.Count() > 0 && !s.BeforeFirst())
                {
                    s.MoveForward();
                }
                PrepareInsert(s.Cursor());
                _keys[s.Cursor()] = ApplyNewAddPatch(trans, obj);
            }
            else
            {
                Db4objects.Db4o.Internal.Btree.BTreeNode childNode        = Child(reader, s.Cursor());
                Db4objects.Db4o.Internal.Btree.BTreeNode childNodeOrSplit = childNode.Add(trans,
                                                                                          preparedComparison, obj);
                if (childNodeOrSplit == null)
                {
                    return(null);
                }
                PrepareWrite(trans);
                SetStateDirty();
                _keys[s.Cursor()] = childNode._keys[0];
                if (childNode != childNodeOrSplit)
                {
                    int splitCursor = s.Cursor() + 1;
                    PrepareInsert(splitCursor);
                    _keys[splitCursor]     = childNodeOrSplit._keys[0];
                    _children[splitCursor] = childNodeOrSplit;
                }
            }
            if (MustSplit())
            {
                return(Split(trans));
            }
            if (s.Cursor() == 0)
            {
                return(this);
            }
            return(null);
        }
Exemplo n.º 5
0
 private int Search(int[] values, int value)
 {
     _searcher = new Searcher(SearchTarget.Any, values.Length);
     while (_searcher.Incomplete())
     {
         _searcher.ResultIs(values[_searcher.Cursor()] - value);
     }
     return _searcher.Cursor();
 }
		internal BTreeNodeSearchResult(Transaction trans, ByteArrayBuffer nodeReader, BTree
			 btree, Searcher searcher, BTreeNode node) : this(trans, btree, NextPointerIf(PointerOrNull
			(trans, nodeReader, node, searcher.Cursor()), searcher.IsGreater()), searcher.FoundMatch
			())
		{
		}
Exemplo n.º 7
0
 public virtual void TestEmptySet()
 {
     _searcher = new Searcher(SearchTarget.Any, 0);
     if (_searcher.Incomplete())
     {
         Assert.Fail();
     }
     Assert.AreEqual(0, _searcher.Cursor());
 }
		private int Search(int[] values, SearchTarget target)
		{
			_searcher = new Searcher(target, values.Length);
			while (_searcher.Incomplete())
			{
				_searcher.ResultIs(values[_searcher.Cursor()] - SearchFor);
			}
			return _searcher.Cursor();
		}
Exemplo n.º 9
0
		private Searcher Search(Transaction trans, IPreparedComparison preparedComparison
			, ByteArrayBuffer reader, SearchTarget target)
		{
			Searcher s = new Searcher(target, _count);
			if (CanWrite())
			{
				while (s.Incomplete())
				{
					s.ResultIs(CompareInWriteMode(preparedComparison, s.Cursor()));
				}
			}
			else
			{
				while (s.Incomplete())
				{
					s.ResultIs(CompareInReadMode(trans, preparedComparison, reader, s.Cursor()));
				}
			}
			return s;
		}
Exemplo n.º 10
0
		private bool WasRemoved(Transaction trans, Searcher s)
		{
			if (!s.FoundMatch())
			{
				return false;
			}
			BTreePatch patch = KeyPatch(trans, s.Cursor());
			return patch != null && patch.IsRemove();
		}
 internal BTreeNodeSearchResult(Transaction trans, ByteArrayBuffer nodeReader, BTree
                                btree, Searcher searcher, BTreeNode node) : this(trans, btree, NextPointerIf(PointerOrNull
                                                                                                                 (trans, nodeReader, node, searcher.Cursor()), searcher.IsGreater()), searcher.FoundMatch
                                                                                     ())
 {
 }