public V Get(K key) { if (null == root) { return(null); } List <V> list = new List <V>(); root.find(comparator, key, BoundaryKind.Inclusive, key, BoundaryKind.Inclusive, list); if (list.Count > 1) { throw new DatabaseException(DatabaseException.ErrorCode.KEY_NOT_UNIQUE); } if (list.Count > 0) { return(list[0]); } return(null); }
internal bool find(PersistentComparator <K, V> comparator, K minValue, BoundaryKind minBoundary, K maxValue, BoundaryKind maxBoundary, List <V> selection) { int l, r, m, n; Load(); n = nItems; if (minBoundary != BoundaryKind.None) { if (-comparator.CompareMemberWithKey(loadItem(0), minValue) >= (int)minBoundary) { if (-comparator.CompareMemberWithKey(loadItem(n - 1), minValue) >= (int)minBoundary) { if (right != null) { return(right.find(comparator, minValue, minBoundary, maxValue, maxBoundary, selection)); } return(true); } for (l = 0, r = n; l < r;) { m = (l + r) >> 1; if (-comparator.CompareMemberWithKey(loadItem(m), minValue) >= (int)minBoundary) { l = m + 1; } else { r = m; } } while (r < n) { if (maxBoundary != BoundaryKind.None && comparator.CompareMemberWithKey(loadItem(r), maxValue) >= (int)maxBoundary) { return(false); } selection.Add(loadItem(r)); r += 1; } if (right != null) { return(right.find(comparator, minValue, minBoundary, maxValue, maxBoundary, selection)); } return(true); } } if (left != null) { if (!left.find(comparator, minValue, minBoundary, maxValue, maxBoundary, selection)) { return(false); } } for (l = 0; l < n; l++) { if (maxBoundary != BoundaryKind.None && comparator.CompareMemberWithKey(loadItem(l), maxValue) >= (int)maxBoundary) { return(false); } selection.Add(loadItem(l)); } if (right != null) { return(right.find(comparator, minValue, minBoundary, maxValue, maxBoundary, selection)); } return(true); }