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); }
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); }
static public void Main(String[] args) { Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testtree.dbs", pagePoolSize); PersonList root = (PersonList)db.Root; if (root == null) { root = new PersonList(); root.list = db.CreateSortedCollection(new NameComparator(), true); db.Root = root; } SortedCollection list = root.list; long key = 1999; int i; DateTime start = DateTime.Now; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; String str = Convert.ToString(key); int m = str.Length / 2; String firstName = str.Substring(0, m); String lastName = str.Substring(m); int age = (int)key % 100; Person p = new Person(firstName, lastName, age); list.Add(p); } db.Commit(); Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start) + " milliseconds"); start = DateTime.Now; key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; String str = Convert.ToString(key); int m = str.Length / 2; Name name = new Name(); int age = (int)key % 100; name.first = str.Substring(0, m); name.last = str.Substring(m); Person p = (Person)list[name]; Debug.Assert(p != null); Debug.Assert(list.Contains(p)); Debug.Assert(p.age == age); } Console.WriteLine("Elapsed time for performing " + nRecords + " index searches: " + (DateTime.Now - start) + " milliseconds"); start = DateTime.Now; Name nm = new Name(); nm.first = nm.last = ""; PersistentComparator comparator = list.GetComparator(); i = 0; foreach (Person p in list) { Debug.Assert(comparator.CompareMemberWithKey(p, nm) > 0); nm.first = p.firstName; nm.last = p.lastName; list.Remove(p); i += 1; } Debug.Assert(i == nRecords); Console.WriteLine("Elapsed time for removing " + nRecords + " records: " + (DateTime.Now - start) + " milliseconds"); Debug.Assert(list.Count == 0); db.Close(); }