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(); }
public virtual IBTreeRange CreateIncludingRange(Db4objects.Db4o.Internal.Btree.BTreeNodeSearchResult end) { BTreePointer firstPointer = FirstValidPointer(); BTreePointer endPointer = end._foundMatch ? end._pointer.Next() : end.FirstValidPointer (); return(new BTreeRangeSingle(_transaction, _btree, firstPointer, endPointer)); }
public virtual BTreeNodeSearchResult SearchLeaf(Transaction trans, IPreparedComparison preparedComparison, SearchTarget target) { EnsureActive(trans); BTreeNodeSearchResult result = _root.SearchLeaf(trans, preparedComparison, target ); ConvertCacheEvictedNodesToReadMode(); return(result); }
public virtual IBTreeRange CreateIncludingRange(BTreeNodeSearchResult end) { var firstPointer = FirstValidPointer(); var endPointer = end._foundMatch ? end._pointer.Next() : end.FirstValidPointer (); return new BTreeRangeSingle(_transaction, _btree, firstPointer, endPointer); }
public virtual IBTreeRange CreateIncludingRange(BTreeNodeSearchResult end) { var firstPointer = FirstValidPointer(); var endPointer = end._foundMatch ? end._pointer.Next() : end.FirstValidPointer (); return(new BTreeRangeSingle(_transaction, _btree, firstPointer, endPointer)); }
private IBTreeRange SearchRange(Transaction trans, IPreparedComparison preparedComparison ) { EnsureActive(trans); // TODO: Optimize the following. // Part of the search operates against the same nodes. // As long as the bounds are on one node, the search // should walk the nodes in one go. BTreeNodeSearchResult start = SearchLeaf(trans, preparedComparison, SearchTarget. Lowest); BTreeNodeSearchResult end = SearchLeaf(trans, preparedComparison, SearchTarget.Highest ); IBTreeRange range = start.CreateIncludingRange(end); ConvertCacheEvictedNodesToReadMode(); return(range); }
private BTreePointer FirstBTreePointer() { // We don't want nulls included so we have to search for null and use the resulting pointer if we find one. IIndexable4 keyHandler = Btree().KeyHandler(); if (keyHandler is ICanExcludeNullInQueries) { ICanExcludeNullInQueries canExcludeNullInQueries = (ICanExcludeNullInQueries)keyHandler; if (canExcludeNullInQueries.ExcludeNull()) { BTreeNodeSearchResult searchLeaf = Btree().SearchLeafByObject(Transaction(), null , SearchTarget.Highest); BTreePointer pointer = searchLeaf.FirstValidPointer(); if (pointer != null) { return(pointer); } } } return(Btree().FirstPointer(Transaction())); }
private BTreeNodeSearchResult FindLowestLeafMatch(Transaction trans, IPreparedComparison preparedComparison, ByteArrayBuffer reader, int index) { if (index >= 0) { if (!CompareEquals(preparedComparison, trans, reader, index)) { return(null); } if (index > 0) { BTreeNodeSearchResult res = FindLowestLeafMatch(trans, preparedComparison, reader , index - 1); if (res != null) { return(res); } return(CreateMatchingSearchResult(trans, reader, index)); } } Db4objects.Db4o.Internal.Btree.BTreeNode node = PreviousNode(); if (node != null) { ByteArrayBuffer nodeReader = node.PrepareRead(trans); BTreeNodeSearchResult res = node.FindLowestLeafMatch(trans, preparedComparison, nodeReader , node.LastIndex()); if (res != null) { return(res); } } if (index < 0) { return(null); } return(CreateMatchingSearchResult(trans, reader, index)); }
public virtual BTreePointer SearchPointer(Transaction trans, object key) { EnsureActive(trans); KeyCantBeNull(key); IPreparedComparison preparedComparison = KeyHandler().PrepareComparison(trans.Context (), key); BTreeNodeSearchResult start = SearchLeaf(trans, preparedComparison, SearchTarget. Lowest); BTreePointer bTreePointer = start.FirstValidPointer(); if (bTreePointer == null) { ConvertCacheEvictedNodesToReadMode(); return(null); } object found = bTreePointer.Key(); ConvertCacheEvictedNodesToReadMode(); if (preparedComparison.CompareTo(found) == 0) { return(bTreePointer); } return(null); }