public InsertSearchIndex(IndexInfo indexInfo, ITable table, IEnumerable <long> rows) : base(indexInfo, table) { comparer = new IndexComparer(this); list = new SortedCollection <IndexKey, long>(); if (rows != null) { foreach (var row in rows) { list.Add(row); } } }
void PopulateIndex(ISortedCollection <Name, Person> list, int count) { Person firstPerson = null; foreach (var key in Tests.KeySeq(count)) { Person p = new Person(key); if (null == firstPerson) { firstPerson = p; } list.Add(p); } list.Add(firstPerson); }
protected SortedCollectionBase(ISortedCollection <TKey, TValue> collection) : this() { if (collection is SortedCollectionBase <TKey, TValue> ) { // Optimization for when the input list is a BlockIntegerList var blockIndex = (SortedCollectionBase <TKey, TValue>)collection; var inBlocks = blockIndex.Blocks; var inBlocksCount = inBlocks.Count; // For each block in 'blockIndex' for (int i = 0; i < inBlocksCount; ++i) { // get the block. var block = inBlocks[i]; // Insert a new block in this object. var destBlock = InsertBlock(i, NewBlock()); // Copy the contents of the source block to the new destination block. block.CopyTo(destBlock); } // Set the size of the list Count = blockIndex.Count; //count; } else { // The case when IIntegerList type is not known using (var i = collection.GetEnumerator()) { while (i.MoveNext()) { Add(i.Current); } } } // If the given list is immutable then set this list to immutable if (collection.IsReadOnly) { IsReadOnly = true; } }
/// <inheritdoc/> public SortedCollection(ISortedCollection <TKey, TValue> collection) : base(collection) { }
public void Run(TestConfig config) { int i; int count = config.Count; var res = new TestTtreeResult(); DateTime start = DateTime.Now; IDatabase db = config.GetDatabase(); PersonList root = (PersonList)db.Root; Tests.Assert(root == null); root = new PersonList(); root.list = db.CreateSortedCollection <Name, Person>(new NameComparator(), IndexType.Unique); db.Root = root; ISortedCollection <Name, Person> list = root.list; Tests.Assert(!list.IsReadOnly); Tests.Assert(!list.RecursiveLoading()); PopulateIndex(list, count); db.Commit(); res.InsertTime = DateTime.Now - start; start = DateTime.Now; foreach (var key in Tests.KeySeq(count)) { Name name = new Name(key); int age = (int)key % 100; Person p = list[name]; Tests.Assert(p != null); Tests.Assert(list.Contains(p)); Tests.Assert(p.age == age); } res.IndexSearchTime = DateTime.Now - start; start = DateTime.Now; Name nm = new Name(); nm.first = nm.last = ""; PersistentComparator <Name, Person> comparator = list.GetComparator(); i = 0; foreach (Person p in list) { Tests.Assert(comparator.CompareMemberWithKey(p, nm) > 0); nm.first = p.first; nm.last = p.last; Tests.Assert(list.Remove(p)); i += 1; } Tests.Assert(i == count); res.RemoveTime = DateTime.Now - start; Tests.Assert(list.Count == 0); PopulateIndex(list, count); Person[] els = list.ToArray(); Tests.Assert(els.Length == list.Count); Name firstKey = new Name(els[0]); Name lastKey = new Name(els[els.Length - 1]); Name midKey = new Name(els[els.Length / 2]); Person[] els2 = list[firstKey, lastKey]; Tests.Assert(els.Length == els2.Length); var e = list.Range(firstKey, midKey).GetEnumerator(); TestEnumerator(e); e = list.GetEnumerator(midKey, lastKey); TestEnumerator(e); foreach (var key in Tests.KeySeq(count)) { var p = RemoveEl(els, key); Tests.Assert(list.Contains(p)); Tests.Assert(list.Remove(p)); Tests.Assert(!list.Contains(p)); } Tests.Assert(null == list.Get(firstKey)); Tests.Assert(null == list.Get(new Name(-123345))); db.Commit(); PopulateIndex(list, 20); Tests.Assert(20 == list.Count); Tests.Assert(null == list.Get(new Name(-123456))); var arr = list.ToArray(); Tests.Assert(20 == arr.Length); Person pTmp = arr[0]; list.Clear(); Tests.Assert(!list.Remove(pTmp)); list.Deallocate(); db.Commit(); db.Close(); }
public void Run(TestConfig config) { int i; int count = config.Count; var res = new TestIndex2Result(); config.Result = res; var start = DateTime.Now; IDatabase db = config.GetDatabase(); Root root = (Root)db.Root; Tests.Assert(root == null); root = new Root(); root.strIndex = db.CreateSortedCollection <string, Record>(new StrRecordComparator(), IndexType.Unique); root.intIndex = db.CreateSortedCollection <long, Record>(new IntRecordComparator(), IndexType.Unique); db.Root = root; ISortedCollection <long, Record> intIndex = root.intIndex; ISortedCollection <string, Record> strIndex = root.strIndex; foreach (var key in Tests.KeySeq(count)) { Record rec = new Record(); rec.intKey = key; rec.strKey = System.Convert.ToString(key); intIndex.Add(rec); strIndex.Add(rec); } db.Commit(); res.InsertTime = DateTime.Now - start; start = System.DateTime.Now; foreach (var key in Tests.KeySeq(count)) { Record rec1 = intIndex[key]; Record rec2 = strIndex[Convert.ToString(key)]; } res.IndexSearch = DateTime.Now - start; start = System.DateTime.Now; var k = Int64.MinValue; i = 0; foreach (Record rec in intIndex) { Tests.Assert(rec.intKey >= k); k = rec.intKey; i += 1; } Tests.Assert(i == count); i = 0; String strKey = ""; foreach (Record rec in strIndex) { Tests.Assert(rec.strKey.CompareTo(strKey) >= 0); strKey = rec.strKey; i += 1; } Tests.Assert(i == count); res.IterationTime = DateTime.Now - start; start = DateTime.Now; res.MemoryUsage = db.GetMemoryUsage().Values; start = System.DateTime.Now; foreach (var key in Tests.KeySeq(count)) { Record rec = intIndex[key]; intIndex.Remove(rec); strIndex.Remove(rec); rec.Deallocate(); } res.RemoveTime = DateTime.Now - start; db.Close(); //Tests.DumpMemoryUsage(res.TypeMemoryUsage); }