public IPersistent Get(object key) { if (root != null) { ArrayList list = new ArrayList(); root.find(comparator, key, key, list); if (list.Count > 1) { throw new StorageError(StorageError.ErrorCode.KEY_NOT_UNIQUE); } else if (list.Count == 0) { return(null); } else { return((IPersistent)list[0]); } } return(null); }
internal bool find(PersistentComparator comparator, object minValue, BoundaryKind minBoundary, object maxValue, BoundaryKind maxBoundary, ArrayList selection) #endif { 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); }
internal bool find(PersistentComparator comparator, Object minValue, Object maxValue, ArrayList selection) { int l, r, m, n; Load(); n = nItems; if (minValue != null) { if (comparator.CompareMemberWithKey(loadItem(0), minValue) < 0) { if (comparator.CompareMemberWithKey(loadItem(n - 1), maxValue) < 0) { if (right != null) { return(right.find(comparator, minValue, maxValue, selection)); } return(true); } for (l = 0, r = n; l < r;) { m = (l + r) >> 1; if (comparator.CompareMemberWithKey(loadItem(m), minValue) < 0) { l = m + 1; } else { r = m; } } while (r < n) { if (maxValue != null && comparator.CompareMemberWithKey(loadItem(r), maxValue) > 0) { return(false); } selection.Add(loadItem(r)); r += 1; } if (right != null) { return(right.find(comparator, minValue, maxValue, selection)); } return(true); } } if (left != null) { if (!left.find(comparator, minValue, maxValue, selection)) { return(false); } } for (l = 0; l < n; l++) { if (maxValue != null && comparator.CompareMemberWithKey(loadItem(l), maxValue) > 0) { return(false); } selection.Add(loadItem(l)); } if (right != null) { return(right.find(comparator, minValue, maxValue, selection)); } return(true); }