public void Insert(int i, object o) #endif { if (small != null) { if (small.Count == BtreeThreshold) { #if USE_GENERICS large = Storage.CreateList <T>(); foreach (T obj in small) { large.Add(obj); } #else large = Storage.CreateList(); foreach (object obj in small) { large.Add(obj); } #endif large.Insert(i, o); Modify(); small = null; } else { #if USE_GENERICS small.Insert(i, o); #else small.Insert(i, o); #endif } } else { large.Insert(i, o); } }
static public void Main(string[] args) { int i; Storage db = StorageFactory.Instance.CreateStorage(); db.Open("testlist2.dbs", pagePoolSize); #if USE_GENERICS IPersistentList <Record> root = (IPersistentList <Record>)db.Root; if (root == null) { root = db.CreateList <Record>(); db.Root = root; } #else IPersistentList root = (IPersistentList)db.Root; if (root == null) { root = db.CreateList(); db.Root = root; } #endif DateTime start = DateTime.Now; for (i = 0; i < nRecords / 2; i++) { Record rec = new Record(); rec.i = i * 2; root.Add(rec); } for (i = 1; i < nRecords; i += 2) { Record rec = new Record(); rec.i = i; root.Insert(i, rec); } db.Commit(); Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; for (i = 0; i < nRecords; i++) { #if USE_GENERICS Record rec = root[i]; #else Record rec = (Record)root[i]; #endif Debug.Assert(rec.i == i); } Console.WriteLine("Elapsed time for performing " + nRecords + " gets: " + (DateTime.Now - start)); start = DateTime.Now; i = 0; foreach (Record rec in root) { Debug.Assert(rec.i == i); i += 1; } Debug.Assert(i == nRecords); Console.WriteLine("Elapsed time for iteration through " + nRecords + " records: " + (DateTime.Now - start)); start = DateTime.Now; for (i = 0; i < nRecords; i++) { #if USE_GENERICS Record rec = root[0]; #else Record rec = (Record)root[0]; #endif Debug.Assert(rec.i == i); root.RemoveAt(0); rec.Deallocate(); } Debug.Assert(!root.GetEnumerator().MoveNext()); Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start)); db.Close(); }