public void BTreeMap1Populate() { int sessionId = 0; SessionBase session = null; try { session = SessionManager.SessionPool.GetSession(out sessionId); session.BeginUpdate(); var bTreeMap = new BTreeMapOwner(); _id = session.Persist(bTreeMap); for (int i = 0; i < numberOfZipCodes; i++) { string str = i.ToString(); var bTree = new BTreeSet <LocationWithinUSA>(); for (int j = 0; j < Math.Min(i, 1000); j++) { var loc = new LocationWithinUSA(); session.Persist(loc); bTree.AddFast(loc); } bTreeMap.LocationByZipCode.AddFast(str, bTree); } session.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } finally { SessionManager.SessionPool.FreeSession(sessionId, session); } }
public void CreateCompareFields(int numberOfLoops, int comparisonByteArraySize) { GCLatencyMode gcLatencyMode = GCSettings.LatencyMode; Person.s_randGen = new Random(5); try { using (SessionNoServer session = new SessionNoServer(systemDir)) { //session.ClientCache.MinimumAvailableMegaBytes = 1100; //session.SetTraceAllDbActivity(); Man aMan; Woman aWoman; session.BeginUpdate(); CompareByField <Person> compareByField = new CompareByField <Person>("m_firstName", session, false); compareByField.AddFieldToCompare("m_lastName"); compareByField.AddFieldToCompare("m_age"); BTreeSet <Person> bTree = new BTreeSet <Person>(compareByField, session, 2000, (ushort)comparisonByteArraySize); Placement place = new Placement((UInt32)numberOfLoops); bTree.Persist(place, session); for (int i = 0; i < numberOfLoops; i++) { aMan = new Man(); aWoman = new Woman(); bTree.AddFast(aMan); bTree.AddFast(aWoman); if (i % 5000 == 0) { bTree.FlushTransients(); } } session.Commit(); } } finally { GCSettings.LatencyMode = gcLatencyMode; } }
private void Button_Click(object sender, RoutedEventArgs e) { using (SessionNoServer session = new SessionNoServer(systemDir)) { Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); const UInt32 numberOfPersons = 10000; const ushort nodeMaxSize = 5000; const ushort comparisonByteArraySize = sizeof(UInt64); // enough room to hold entire idNumber of a Person const bool comparisonArrayIsCompleteKey = true; const bool addIdCompareIfEqual = false; Person person; session.BeginUpdate(); session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None; //mySession.SetTraceAllDbActivity(); BTreeSet <string> stringSet = new BTreeSet <string>(null, session); BTreeSetOidShort <string> stringSetShort = new BTreeSetOidShort <string>(null, session); BTreeMap <string, string> stringMap = new BTreeMap <string, string>(null, session); BTreeMapOidShort <string, string> stringMapShort = new BTreeMapOidShort <string, string>(null, session); CompareByField <Person> compareByField = new CompareByField <Person>("idNumber", session, addIdCompareIfEqual); BTreeSet <Person> bTree = new BTreeSet <Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey); session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low for (int i = 0; i < numberOfPersons; i++) { person = new Person(); // session.Persist(person); bTree.AddFast(person); } session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.UseExternalStorageApi = true; session.BeginRead(); BTreeSet <Person> bTree = session.AllObjects <BTreeSet <Person> >().First(); foreach (Person person in (IEnumerable <Person>)bTree) { if (person.IdNumber > 196988888791402) { Console.WriteLine(person); break; } } session.Commit(); } }
private void Button_Click(object sender, RoutedEventArgs e) { using (SessionNoServer session = new SessionNoServer(systemDir)) { Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); const UInt32 numberOfPersons = 10000; const ushort nodeMaxSize = 5000; const ushort comparisonByteArraySize = sizeof(UInt64); // enough room to hold entire idNumber of a Person const bool comparisonArrayIsCompleteKey = true; const bool addIdCompareIfEqual = false; Person person; session.BeginUpdate(); session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None; //mySession.SetTraceAllDbActivity(); BTreeSet<string> stringSet = new BTreeSet<string>(null, session); BTreeSetOidShort<string> stringSetShort = new BTreeSetOidShort<string>(null, session); BTreeMap<string, string> stringMap = new BTreeMap<string, string>(null, session); BTreeMapOidShort<string, string> stringMapShort = new BTreeMapOidShort<string, string>(null, session); CompareByField<Person> compareByField = new CompareByField<Person>("idNumber", session, addIdCompareIfEqual); BTreeSet<Person> bTree = new BTreeSet<Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey); session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low for (int i = 0; i < numberOfPersons; i++) { person = new Person(); // session.Persist(person); bTree.AddFast(person); } session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.UseExternalStorageApi = true; session.BeginRead(); BTreeSet<Person> bTree = session.AllObjects<BTreeSet<Person>>().First(); foreach (Person person in (IEnumerable<Person>)bTree) { if (person.IdNumber > 196988888791402) { Console.WriteLine(person); break; } } session.Commit(); } }
public void CompareString(int compArraySize) { using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); AllSupported obj = new AllSupported(1, session); CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("aString", session); BTreeSet <AllSupported> sortedSet = new BTreeSet <AllSupported>(compareByField, session, 1000, (ushort)compArraySize); session.Persist(sortedSet); for (int i = 0; i < 11000; i++) { obj = new AllSupported(1, session); obj.aString = RandomString(10); sortedSet.AddFast(obj); } obj = new AllSupported(1, session); obj.aString = null; session.Persist(obj); sortedSet.Add(obj); int ct = 0; AllSupported prior = null; foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet) { if (prior != null) { if (prior.aString != null) { if (currentObj.aString == null) { Assert.Fail("Null is < than a non NULL"); } else { Assert.Less(prior.aString, currentObj.aString); } } } prior = currentObj; ct++; } session.Commit(); } }
public void CreateCompareFields(int numberOfLoops, int comparisonByteArraySize) { GCLatencyMode gcLatencyMode = GCSettings.LatencyMode; Person.s_randGen = new Random(5); try { using (SessionNoServer session = new SessionNoServer(systemDir)) { //session.ClientCache.MinimumAvailableMegaBytes = 1100; //session.SetTraceAllDbActivity(); Man aMan; Woman aWoman; session.BeginUpdate(); CompareByField<Person> compareByField = new CompareByField<Person>("m_firstName", session, false); compareByField.AddFieldToCompare("m_lastName"); compareByField.AddFieldToCompare("m_age"); BTreeSet<Person> bTree = new BTreeSet<Person>(compareByField, session, 2000, (ushort)comparisonByteArraySize); Placement place = new Placement((UInt32)numberOfLoops); bTree.Persist(place, session); for (int i = 0; i < numberOfLoops; i++) { aMan = new Man(); aWoman = new Woman(); bTree.AddFast(aMan); bTree.AddFast(aWoman); if (i % 5000 == 0) bTree.FlushTransients(); } session.Commit(); } } finally { GCSettings.LatencyMode = gcLatencyMode; } }
static readonly string s_systemDir = "SortedObjects"; // appended to SessionBase.BaseDatabasePath for a full path static void Main(string[] args) { try { Oid bTreeId; bool createOnly = args.Length > 0; UInt64 someRandomPersonsIdNumber = 0; using (SessionNoServer session = new SessionNoServer(s_systemDir)) { Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); const UInt32 numberOfPersons = 1000000; const ushort nodeMaxSize = 5000; const ushort comparisonByteArraySize = sizeof(UInt64); // enough room to hold entire idNumber of a Person const bool comparisonArrayIsCompleteKey = true; const bool addIdCompareIfEqual = false; Person person; session.BeginUpdate(); CompareByField <Person> compareByField = new CompareByField <Person>("idNumber", session, addIdCompareIfEqual); BTreeSet <Person> bTree = new BTreeSet <Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey); session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low for (int i = 0; i < numberOfPersons; i++) { person = new Person(); if (i % 1000 == 0) { someRandomPersonsIdNumber = person.IdNumber; } bTree.AddFast(person); } bTreeId = bTree.Oid; session.Commit(); } if (!createOnly) { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); BTreeSet <Person> bTree = session.Open <BTreeSet <Person> >(bTreeId); foreach (Person person in (IEnumerable <Person>)bTree) { if (person.IdNumber > 196988888791402) { Console.WriteLine(person); break; } } session.Commit(); session.BeginRead(); Person lookupPerson = new Person(someRandomPersonsIdNumber); UInt64 id = bTree.GetKeyId(lookupPerson); // lookup without opening object having the key field value of someRandomPersonsIdNumber Person lookedUpPerson = null; bTree.TryGetKey(lookupPerson, ref lookedUpPerson); if (id != lookedUpPerson.Id) { throw new UnexpectedException("Should match"); } // this LINQ statement will trigger a binary search lookup (not a linear serach) of the matching Person objects in the BTreeSet Console.WriteLine((from person in bTree where person.IdNumber > 196988888791402 select person).First()); session.Commit(); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
static readonly string s_systemDir = "SortedObjects"; // appended to SessionBase.BaseDatabasePath for a full path static void Main(string[] args) { try { Oid bTreeId; bool createOnly = args.Length > 0; UInt64 someRandomPersonsIdNumber = 0; using (SessionNoServer session = new SessionNoServer(s_systemDir)) { Console.WriteLine("Running with databases in directory: " + session.SystemDirectory); const UInt32 numberOfPersons = 1000000; const ushort nodeMaxSize = 5000; const ushort comparisonByteArraySize = sizeof(UInt64); // enough room to hold entire idNumber of a Person const bool comparisonArrayIsCompleteKey = true; const bool addIdCompareIfEqual = false; Person person; session.BeginUpdate(); CompareByField<Person> compareByField = new CompareByField<Person>("idNumber", session, addIdCompareIfEqual); BTreeSet<Person> bTree = new BTreeSet<Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey); session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low for (int i = 0; i < numberOfPersons; i++) { person = new Person(); if (i % 1000 == 0) someRandomPersonsIdNumber = person.IdNumber; bTree.AddFast(person); } bTreeId = bTree.Oid; session.Commit(); } if (!createOnly) using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); BTreeSet<Person> bTree = (BTreeSet<Person>)session.Open(bTreeId); foreach (Person person in (IEnumerable<Person>)bTree) { if (person.IdNumber > 196988888791402) { Console.WriteLine(person); break; } } session.Commit(); session.BeginRead(); Person lookupPerson = new Person(someRandomPersonsIdNumber); UInt64 id = bTree.GetKeyId(lookupPerson); // lookup without opening object having the key field value of someRandomPersonsIdNumber Person lookedUpPerson = null; bTree.TryGetKey(lookupPerson, ref lookedUpPerson); if (id != lookedUpPerson.Id) throw new UnexpectedException("Should match"); // this LINQ statement will trigger a binary search lookup (not a linear serach) of the matching Person objects in the BTreeSet Console.WriteLine((from person in bTree where person.IdNumber > 196988888791402 select person).First()); session.Commit(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void AddRelation(Relation <Folder, Folder> relation) { m_folders.AddFast(relation.RelationFrom); }
public void AddRelation(Relation <FileInDb, Folder> relation) { m_files.AddFast(relation.RelationFrom); }