Beispiel #1
0
 public void hashCodeComparerStringTest()
 {
   Oid id;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Placement place = new Placement(223, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     session.Compact();
     session.BeginUpdate();
     HashCodeComparer<string> hashCodeComparer = new HashCodeComparer<string>();
     BTreeSet<string> bTree = new BTreeSet<string>(hashCodeComparer, session);
     bTree.Persist(place, session);
     id = bTree.Oid;
     for (int i = 0; i < 100000; i++)
     {
       bTree.Add(i.ToString());
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     BTreeSet<string> bTree= (BTreeSet<string>)session.Open(id);
     int count = 0;
     foreach (string str in bTree)
     {
       count++;
     }
     Assert.True(100000 == count);
     session.Commit();
   }
 }
 public void CompareDateTime()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         AllSupported obj;
         CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("dateTime", session);
         BTreeSet <AllSupported>       sortedSet      = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(long), true);
         for (int i = 0; i < 20000; i++)
         {
             obj          = new AllSupported(1);
             obj.dateTime = DateTime.FromBinary(randGen.Next(Int32.MinValue, Int32.MaxValue) * randGen.Next());
             sortedSet.Add(obj);
         }
         int          ct    = 0;
         AllSupported prior = null;
         foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet)
         {
             if (prior != null)
             {
                 Assert.Less(prior.dateTime, currentObj.dateTime);
             }
             prior = currentObj;
             ct++;
         }
         session.Commit();
     }
 }
        public void CompareInt32DescendingComparisonArray()
        {
#if DEBUG
            Assert.Throws <NotImplementedException>(() =>
            {
                using (SessionNoServer session = new SessionNoServer(systemDir))
                {
                    session.BeginUpdate();
                    AllSupported obj = new AllSupported(2);
                    CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int32", session, false, false, false);
                    BTreeSet <AllSupported> sortedSet            = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(Int32), true);
                    for (int i = 0; i < 100000; i++)
                    {
                        obj       = new AllSupported(1);
                        obj.int32 = randGen.Next(Int32.MinValue, Int32.MaxValue);
                        sortedSet.Add(obj);
                    }
                    int ct             = 0;
                    AllSupported prior = null;
                    foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet)
                    {
                        if (prior != null)
                        {
                            Assert.Greater(prior.int32, currentObj.int32);
                        }
                        prior = currentObj;
                        ct++;
                    }
                    session.Commit();
                }
            });
#endif
        }
Beispiel #4
0
 public CustomerContact(string company, string firstName, string lastName, string email, string address,
                        string addressLine2, string city, string zipCode, string state, string country, string countryCode, string phone, string fax,
                        string mobile, string skypeName, string webSite, string userName, string password, string howFoundOther, int howFoundChoice,
                        SessionBase session)
 {
     this.company            = company;
     this.firstName          = firstName;
     this.lastName           = lastName;
     this.email              = email;
     this.address            = address;
     this.addressLine2       = addressLine2;
     this.city               = city;
     this.zipCode            = zipCode;
     this.state              = state;
     this.country            = country;
     this.countryCode        = countryCode;
     this.phone              = phone;
     this.fax                = fax;
     this.mobile             = mobile;
     this.skypeName          = skypeName;
     this.webSite            = webSite;
     this.userName           = userName;
     this.password           = password;
     this.howFoundOther      = howFoundOther;
     this.howFoundVelocityDb = (HowFound)howFoundChoice;
     priorVerifiedEmailSet   = new SortedSetAny <string>();
     licenseSet              = new BTreeSet <License>(null, session);
     licenseRequestSet       = new BTreeSet <LicenseRequest>(null, session);
     licenseUnpaidSet        = new BTreeSet <License>(null, session);
     licenseUnpaidRequestSet = new BTreeSet <LicenseRequest>(null, session);
     licensePaymentSet       = new BTreeSet <LicensePayment>(null, session);
     CompareByField <VisitEvent> comparator = new CompareByField <VisitEvent>("eventTime", session);
     //visitEvents = new BTreeSet<VisitEvent>(comparator, session, 10000, sizeof(long), true);
 }
 public void CompareInt16()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         AllSupported obj = new AllSupported(1);
         CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int16", session);
         BTreeSet <AllSupported>       sortedSet      = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(Int16), true);
         for (int i = 0; i < 100000; i++)
         {
             obj       = new AllSupported(1);
             obj.int16 = (Int16)randGen.Next(Int16.MinValue, Int16.MaxValue);
             sortedSet.Add(obj);
         }
         int          ct    = 0;
         AllSupported prior = null;
         foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet)
         {
             if (prior != null)
             {
                 Assert.Less(prior.int16, currentObj.int16);
             }
             prior = currentObj;
             ct++;
         }
         session.Commit();
     }
 }
Beispiel #6
0
 /// <summary>
 /// Internally sets a property value
 /// </summary>
 /// <param name="element">element id</param>
 /// <param name="aValue">value</param>
 virtual protected void SetPropertyValueX(ElementId element, T aValue)
 {
     Update();
     m_propertyValue[element] = aValue;
     if (m_valueIndex != null)
     {
         BTreeSet <ElementId> oidArray;
         if (!m_valueIndex.TryGetKey(aValue, ref aValue))
         {
             oidArray = new BTreeSet <ElementId>(null, Session);
             oidArray.Add(element);
             m_valueIndex.AddFast(aValue, oidArray);
         }
         else
         {
             oidArray = m_valueIndex[aValue];
             oidArray.Add(element);
             m_valueIndex[aValue] = oidArray;
         }
     }
     else if (m_valueIndexUnique != null)
     {
         m_valueIndexUnique.AddFast(aValue, element);
     }
 }
Beispiel #7
0
 bool RemovePropertyValueT(ElementId oid, out T pv)
 {
     if (m_propertyValue.TryGetValue(oid, out pv))
     {
         m_propertyValue.Remove(oid);
         if (m_valueIndex != null)
         {
             if (m_valueIndex.TryGetKey(pv, ref pv))
             {
                 BTreeSet <ElementId> oidArray = m_valueIndex[pv];
                 if (oidArray.Count > 1)
                 {
                     oidArray.Remove(oid);
                 }
                 else
                 {
                     oidArray.Unpersist(Session);
                     m_valueIndex.Remove(pv);
                 }
             }
         }
         else if (m_valueIndexUnique != null)
         {
             m_valueIndexUnique.Remove(pv);
         }
         return(true);
     }
     return(false);
 }
Beispiel #8
0
 public ImdbRoot(SessionBase session)
 {
     actorSet        = new BTreeSet <Actor>(null, session);
     actressSet      = new BTreeSet <Actress>(null, session);
     actingByNameSet = new BTreeSet <ActingPerson>(actingByNameComparer, session);
     movieSet        = new BTreeSet <Movie>(movieNameHashComparer, session, 10000, sizeof(Int32));
 }
Beispiel #9
0
 void SetPropertyValueX(ElementId element, T aValue)
 {
     Update();
     propertyValue[element] = aValue;
     if (valueIndex != null)
     {
         BTreeSet <ElementId> oidArray;
         if (!valueIndex.TryGetKey(aValue, ref aValue))
         {
             oidArray = new BTreeSet <ElementId>(null, graph.Session);
             oidArray.Add(element);
             valueIndex.AddFast(aValue, oidArray);
         }
         else
         {
             oidArray = valueIndex[aValue];
             oidArray.Add(element);
             valueIndex[aValue] = oidArray;
         }
     }
     else if (valueIndexUnique != null)
     {
         valueIndexUnique.AddFast(aValue, element);
     }
 }
Beispiel #10
0
        static void CreateData()
        {
            using (SessionNoServer session = new SessionNoServer(s_systemDir))
            {
                bool dirExist = Directory.Exists(session.SystemDirectory);
                if (dirExist)
                {
                    return;

                    Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
                }
                Directory.CreateDirectory(session.SystemDirectory);
                File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
                SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4;
                session.BeginUpdate();
                CompareGeoObj comparer = new CompareGeoObj();
                var           btreeSet = new BTreeSet <GeoObj>(comparer, session, 1000);
                for (int i = 0; i < s_numberOfSamples; i++)
                {
                    var g = new GeoObj();
                    btreeSet.Add(g);
                }
                session.Persist(btreeSet);
                session.Commit();
                Console.Out.WriteLine($@"Done creating {s_numberOfSamples} GeoHashSample GeoObj ");
            }
        }
Beispiel #11
0
 static void createTopLevelInvertedIndex()
 {
     Console.WriteLine(DateTime.Now.ToString() + ", start creating top level inverted index");
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
         Placement wordPlacement = new Placement(Lexicon.PlaceInDatabase, 2, 1, 1000, 50000, true, false, UInt32.MaxValue, false);
         session.BeginUpdate();
         IndexRoot indexRoot                 = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));
         BTreeSetOidShort <Word> wordSet     = indexRoot.lexicon.WordSet;
         BTreeSet <Document>     documentSet = indexRoot.repository.documentSet;
         Word existingWord = null;
         foreach (Document doc in documentSet)
         {
             foreach (Word word in doc.WordSet)
             {
                 WordHit wordHit = doc.WordHit[word];
                 if (wordSet.TryGetKey(word, ref existingWord))
                 {
                     existingWord.GlobalCount = existingWord.GlobalCount + (uint)wordHit.Count;
                 }
                 else
                 {
                     existingWord = new WordGlobal(word.aWord, session, (uint)wordHit.Count);
                     existingWord.Persist(wordPlacement, session);
                     indexRoot.lexicon.WordSet.Add(existingWord);
                 }
                 existingWord.DocumentHit.AddFast(doc);
             }
             doc.Indexed = true;
         }
         session.Commit();
         Console.WriteLine(DateTime.Now.ToString() + ", done creating top level inverted index");
     }
 }
Beispiel #12
0
        public void Bug2Test()
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                const ushort nodeMaxSize                  = 5000;
                const ushort comparisonByteArraySize      = sizeof(Int32); // enough room to hold entire idNumber of a Person
                const bool   comparisonArrayIsCompleteKey = true;
                const bool   addIdCompareIfEqual          = false;
                session.BeginUpdate();
                //mySession.SetTraceAllDbActivity();
                CompareByField <Entity> compareByField = new CompareByField <Entity>("idNumber", session, addIdCompareIfEqual);
                BTreeSet <Entity>       bTree          = new BTreeSet <Entity>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey);
                Placement place = new Placement(40);
                bTree.Persist(place, session);
                for (int i = 0; i < 5; i++)
                {
                    var x = new Entity();
                    x.idNumber   = 250000;
                    x.UserID     = 100116;
                    x.FirstName  = "Bill";
                    x.LastName   = "Martin";
                    x.MiddleName = "Bob";

                    if (!bTree.Contains(x))
                    {
                        x.Persist(place, session);
                        bTree.Add(x);
                    }
                }
                Assert.IsTrue(bTree.Count == 1);
                session.Commit();
            }
        }
Beispiel #13
0
 public ImdbRoot(SessionBase session)
 {   
   actorSet = new BTreeSet<Actor>(null, session);
   actressSet = new BTreeSet<Actress>(null, session);
   actingByNameSet = new BTreeSet<ActingPerson>(actingByNameComparer, session);
   movieSet = new BTreeSet<Movie>(movieNameHashComparer, session, 10000, sizeof(Int32));
 }
 public void CompareInt16()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     AllSupported obj = new AllSupported(1);
     CompareByField<AllSupported> compareByField = new CompareByField<AllSupported>("int16", session);
     BTreeSet<AllSupported> sortedSet = new BTreeSet<AllSupported>(compareByField, session, 1000, sizeof(Int16), true);
     for (int i = 0; i < 100000; i++)
     {
       obj = new AllSupported(1);
       obj.int16 = (Int16) randGen.Next(Int16.MinValue, Int16.MaxValue);
       sortedSet.Add(obj);
     }
     int ct = 0;
     AllSupported prior = null;
     foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet)
     {
       if (prior != null)
         Assert.Less(prior.int16, currentObj.int16);
       prior = currentObj;
       ct++;
     }
     session.Commit();
   }
 }
Beispiel #15
0
 static void createInvertedIndex()
 {
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
         session.BeginUpdate();
         session.EnableAutoPageFlush = false; // so that threads don't stomb on each other
         Console.WriteLine(DateTime.Now.ToString() + ", start creating inverted index");
         ParallelOptions pOptions = new ParallelOptions();
         pOptions.MaxDegreeOfParallelism = 2; // set to what is appropriate for your computer (cores & memory size)
         //pOptions.MaxDegreeOfParallelism = 1; // appears to work best with only 16GB of memory
         IndexRoot           indexRoot   = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));
         BTreeSet <Document> documentSet = indexRoot.repository.documentSet;
         List <Database>     dbs         = session.OpenAllDatabases(true);
         Parallel.ForEach <Database>(dbs, pOptions,
                                     (Database db, ParallelLoopState loop) => // method invoked by the loop on each iteration
         {
             if (db.DatabaseNumber >= Document.PlaceInDatabase)
             {
                 createDocumentInvertedIndex(session, db, documentSet);
             }
         });
         session.Commit();
         Console.WriteLine(DateTime.Now.ToString() + ", done creating inverted index");
     }
 }
Beispiel #16
0
        public void hashCodeComparerStringTest()
        {
            Oid id;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                Placement place = new Placement(223, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
                session.Compact();
                session.BeginUpdate();
                HashCodeComparer <string> hashCodeComparer = new HashCodeComparer <string>();
                BTreeSet <string>         bTree            = new BTreeSet <string>(hashCodeComparer, session);
                bTree.Persist(place, session);
                id = bTree.Oid;
                for (int i = 0; i < 100000; i++)
                {
                    bTree.Add(i.ToString());
                }
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                BTreeSet <string> bTree = (BTreeSet <string>)session.Open(id);
                int count = 0;
                foreach (string str in bTree)
                {
                    count++;
                }
                Assert.True(100000 == count);
                session.Commit();
            }
        }
Beispiel #17
0
        public UInt32 PossiblyAddToken(T token, Document doc)
        {
            UInt32 id;
            BTreeSet <Document> docSet;

            if (!ValueToId.TryGetValue(token, out id))
            {
                Update();
                id = ++_nextId;
                _IdToValue.AddFast(id, token);
                _valueToId.Add(token, id);
                docSet = new BTreeSet <Document>();
                _tokenMap.AddFast(id, docSet);
            }
            else
            {
                docSet = _tokenMap[id];
            }
            UInt32 wordHit;

            if (!doc.WordHit.TryGetValue(id, out wordHit))
            {
                docSet.AddFast(doc);
                doc.WordHit.Add(id, 1);
            }
            else
            {
                doc.WordHit[id] = ++wordHit;
            }
            AddToGlobalCount(id, 1);
            return(id);
        }
Beispiel #18
0
 public void LookupCompareFields(int bTreeDatabaseNumber)
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         Person personPrior = null, person;
         session.BeginRead();
         BTreeSet <Person>         bTree = (BTreeSet <Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
         BTreeSetIterator <Person> itr   = bTree.Iterator();
         int ct = 0;
         while ((person = itr.Next()) != null)
         {
             if (personPrior != null)
             {
                 Assert.LessOrEqual(personPrior.FirstName, person.FirstName);
             }
             ct++;
             personPrior = person;
         }
         int ct2 = 0;
         personPrior = null;
         foreach (Person pers in (IEnumerable <Person>)bTree)
         {
             if (personPrior != null)
             {
                 Assert.LessOrEqual(personPrior.FirstName, pers.FirstName);
             }
             ct2++;
             personPrior = pers;
         }
         session.Commit();
         Assert.AreEqual(ct, ct2);
     }
 }
Beispiel #19
0
 public void UnpersistCompareFields(int bTreeDatabaseNumber)
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         BTreeSet <Person>         bTree = (BTreeSet <Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
         BTreeSetIterator <Person> itr   = bTree.Iterator();
         itr.GoToLast();
         itr.Remove();
         session.Abort();
         session.BeginUpdate();
         bTree = (BTreeSet <Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
         bTree.Unpersist(session);
         session.Commit();
         session.BeginRead();
         Database db = session.OpenDatabase((uint)bTreeDatabaseNumber, false);
         foreach (Page page in db)
         {
             foreach (OptimizedPersistable obj in page)
             {
                 if (obj.PageNumber > 0)
                 {
                     Assert.Fail("No objects should remain in this database");
                 }
             }
         }
         session.Commit();
     }
 }
Beispiel #20
0
 IEnumerable <Node> GetNodesFromArtifactsUids(BTreeSet <Node> source, IEnumerable <ulong> uids)
 {
     foreach (var uid in uids)
     {
         yield return(source.Where(x => x.ArtifactUid == uid).SingleOrDefault());
     }
 }
Beispiel #21
0
 public void CreateTicksCompareFields(int numberOfTicks, int nodeSize)
 {
     using (SessionNoServer session = new SessionNoServer(systemDir, 2000, false))
     {
         //session.SetTraceAllDbActivity();
         session.BeginUpdate();
         CompareByField <Tick> compareByField = new CompareByField <Tick>("<Bid>k__BackingField", session, true);
         //compareByField.AddFieldToCompare("<Timestamp>k__BackingField");
         BTreeSet <Tick> bTree      = new BTreeSet <Tick>(compareByField, session, (UInt16)nodeSize, sizeof(double) + sizeof(UInt64), true);
         Placement       place      = new Placement((UInt32)numberOfTicks, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
         Placement       ticksPlace = new Placement((UInt32)numberOfTicks, 10000, 1, UInt16.MaxValue, UInt16.MaxValue);
         bTree.Persist(place, session);
         int i          = 0;
         int dublicates = 0;
         foreach (var record in Tick.GenerateRandom((ulong)numberOfTicks))
         {
             session.Persist(record, ticksPlace);
             if (bTree.Add(record))
             {
                 i++;
             }
             else
             {
                 dublicates++;
             }
         }
         session.Commit();
         Console.WriteLine("Done creating and sorting with BTreeSet<Tick> " + i + " Tick objects by Bid value. Number of dublicates (not added to BTreeSet): " + dublicates);
     }
 }
Beispiel #22
0
 static void CreateData()
 {
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     bool dirExist = Directory.Exists(session.SystemDirectory);
     if (dirExist)
     {
       return;
       Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
     }
     Directory.CreateDirectory(session.SystemDirectory);
     File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
     SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4;
     session.BeginUpdate();
     CompareGeoObj comparer = new CompareGeoObj();
     var btreeSet = new BTreeSet<GeoObj>(comparer, session, 1000);
     for (int i = 0; i < s_numberOfSamples; i++)
     {
       var g = new GeoObj();
       btreeSet.Add(g);
     }
     session.Persist(btreeSet);
     session.Commit();
     Console.Out.WriteLine($@"Done creating {s_numberOfSamples} GeoHashSample GeoObj ");
   }
 }
 public void CompareInt32Descending()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         AllSupported obj = new AllSupported(2, session);
         CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int32", session, false, false, false);
         BTreeSet <AllSupported>       sortedSet      = new BTreeSet <AllSupported>(compareByField, session, 1000);
         for (int i = 0; i < 100000; i++)
         {
             obj       = new AllSupported(1, session);
             obj.int32 = randGen.Next(Int32.MinValue, Int32.MaxValue);
             sortedSet.Add(obj);
         }
         int          ct    = 0;
         AllSupported prior = null;
         foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet)
         {
             if (prior != null)
             {
                 Assert.Greater(prior.int32, currentObj.int32);
             }
             prior = currentObj;
             ct++;
         }
         session.Commit();
     }
 }
 public void CompareInt64()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         AllSupported obj = new AllSupported(2, session);
         CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int64", session);
         BTreeSet <AllSupported>       sortedSet      = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(Int64), true);
         for (int i = 0; i < 100000; i++)
         {
             obj       = new AllSupported(1, session);
             obj.int64 = randGen.Next(Int32.MinValue, Int32.MaxValue) * randGen.Next();
             sortedSet.Add(obj);
         }
         int ct = 0;
         //foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet)
         // {
         //  Console.WriteLine(currentObj.int32);
         //   ct++;
         // }
         AllSupported prior = null;
         ct = 0;
         foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet)
         {
             if (prior != null)
             {
                 Assert.Less(prior.int64, currentObj.int64);
             }
             prior = currentObj;
             ct++;
         }
         session.Commit();
     }
 }
Beispiel #25
0
        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);
            }
        }
Beispiel #26
0
        public void createGlobalInvertedIndex(IndexRoot indexRoot)
        {
            Placement wordPlacement         = new Placement(Lexicon.PlaceInDatabase, 2);
            BTreeSetOidShort <Word> wordSet = indexRoot.lexicon.WordSet;
            BTreeSet <Document>     docSet  = indexRoot.repository.documentSet;
            Word existingWord = null;

            foreach (Document doc in docSet)
            {
                if (doc.Indexed == false)
                {
                    foreach (Word word in doc.WordSet)
                    {
                        WordHit wordHit = doc.WordHit[word];
                        if (wordSet.TryGetKey(word, ref existingWord))
                        {
                            existingWord.GlobalCount = existingWord.GlobalCount + (uint)wordHit.Count;
                        }
                        else
                        {
                            existingWord = new WordGlobal(word.aWord, session, (uint)wordHit.Count);
                            existingWord.Persist(wordPlacement, session);
                            wordSet.Add(existingWord);
                        }
                        existingWord.DocumentHit.AddFast(doc);
                    }
                    doc.Indexed = true;
                }
            }
        }
 public void CompareString(int compArraySize)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     AllSupported obj = new AllSupported(1);
     CompareByField<AllSupported> compareByField = new CompareByField<AllSupported>("aString", session);
     BTreeSet<AllSupported> sortedSet = new BTreeSet<AllSupported>(compareByField, session, 1000, (ushort) compArraySize);
     for (int i = 0; i < 10000; i++)
     {
       obj = new AllSupported(1);
       obj.aString = RandomString(10);
       sortedSet.Add(obj);
     }
     obj = new AllSupported(1);
     obj.aString = null;
     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();
   }
 }
Beispiel #28
0
 public Root(SessionBase session, ushort maxEntriesPerNode)
 { 
   CompareCustomerEmail compareCustomerEmail = new CompareCustomerEmail();
   CompareCustomerUserName compareCustomerUserName = new CompareCustomerUserName();
   customersByEmail = new BTreeSet<CustomerContact>(compareCustomerEmail, session, maxEntriesPerNode);
   customersByUserName = new BTreeSet<CustomerContact>(compareCustomerUserName, session, maxEntriesPerNode);
   lastCustomerIdNumber = 0;     
 }
Beispiel #29
0
 public AspNetIdentity(SessionBase session)
 {
   m_adapterMap = new BTreeMap<string, UserLoginInfoAdapter>(null, session);
   m_userSet = new BTreeSet<IdentityUser>(null, session);
   m_roleSet = new BTreeSet<IdentityRole>(null, session);
   m_emailToId = new BTreeMap<string, ulong>(null, session);
   m_userNameToId = new BTreeMap<string, ulong>(null, session);
 }
Beispiel #30
0
        public TokenStoreHit(SessionBase session)
        {
            var tree = new BTreeSet <Oid>();

            session.Persist(tree);
            session.Persist(this);
            m_tokenInProduct = new WeakIOptimizedPersistableReference <BTreeSet <Oid> >(tree);
        }
Beispiel #31
0
 public AspNetIdentity(SessionBase session)
 {
     m_adapterMap   = new BTreeMap <string, UserLoginInfoAdapter>(null, session);
     m_userSet      = new BTreeSet <IdentityUser>(null, session);
     m_roleSet      = new BTreeSet <IdentityRole>(null, session);
     m_emailToId    = new BTreeMap <string, ulong>(null, session);
     m_userNameToId = new BTreeMap <string, ulong>(null, session);
 }
Beispiel #32
0
        public Root(SessionBase session, ushort maxEntriesPerNode)
        {
            CompareCustomerEmail    compareCustomerEmail    = new CompareCustomerEmail();
            CompareCustomerUserName compareCustomerUserName = new CompareCustomerUserName();

            customersByEmail     = new BTreeSet <CustomerContact>(compareCustomerEmail, session, maxEntriesPerNode);
            customersByUserName  = new BTreeSet <CustomerContact>(compareCustomerUserName, session, maxEntriesPerNode);
            lastCustomerIdNumber = 0;
        }
Beispiel #33
0
 public void AddInteraction(Interaction interaction)
 {
   if (m_interactions == null)
     m_interactions = new BTreeSet<Interaction>();
   if (m_interactions.Add(interaction))
   {
     var reference = new Reference(m_interactions, "m_interactions");
     interaction.References.AddFast(reference); // may be possible to automatize setting reference
   }
 }
Beispiel #34
0
 public Folder(string name, Folder parentFolder, SessionBase session) : base(name)
 {
   CompareByField<FileInDb> comparerByFileName = new CompareByField<FileInDb>("m_name", session, false, true);
   m_files = new BTreeSet<FileInDb>(comparerByFileName, session, 10000, CommonTypes.s_sizeOfUInt32);
   CompareByField<Folder> comparerByFolderName = new CompareByField<Folder>("m_name", session, false, true);
   m_subFolders = new BTreeSet<Folder>(comparerByFolderName, session, 10000, CommonTypes.s_sizeOfUInt32);
   if (parentFolder != null)
   {
     m_parentFolder = parentFolder;
     m_parentFolder.Folders.AddFast(this);
   }
 }
Beispiel #35
0
 public void AddInteraction(Interaction interaction)
 {
     if (m_interactions == null)
     {
         m_interactions = new BTreeSet <Interaction>();
     }
     if (m_interactions.Add(interaction))
     {
         var reference = new Reference(m_interactions, "m_interactions");
         interaction.References.AddFast(reference); // may be possible to automatize setting reference
     }
 }
Beispiel #36
0
        static void createDocumentInvertedIndex(SessionBase session, Database db, BTreeSet <Document> documentSet)
        {
            UInt32    dbNum            = db.DatabaseNumber;
            Document  doc              = null;
            Document  inputDoc         = new Document(db.Id);
            Placement wordPlacement    = new Placement(inputDoc.DatabaseNumber, 20000, 1, 25000, 65000, true, false, 1, false);
            Placement wordHitPlacement = new Placement(inputDoc.DatabaseNumber, 40000, 1, 25000, 65500, true, false, 1, false);
            //session.SetTraceDbActivity(db.DatabaseNumber);
            BTreeSetIterator <Document> iterator = documentSet.Iterator();

            iterator.GoTo(inputDoc);
            inputDoc = iterator.Current();
            while (inputDoc != null && inputDoc.Page.Database.DatabaseNumber == dbNum)
            {
                doc = (Document)session.Open(inputDoc.Page.Database, inputDoc.Id); // if matching database is availeble, use it to speed up lookup
                DocumentText    docText    = doc.Content;
                string          text       = docText.Text.ToLower();
                MatchCollection tagMatches = Regex.Matches(text, "[a-z][a-z.$]+");
                UInt64          wordCt     = 0;
                WordHit         wordHit;
                Word            word;
                if (++s_docCountIndexed % 50000 == 0)
                {
                    Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed);
                }
                BTreeSetOidShort <Word> wordSet = doc.WordSet;
                foreach (Match m in tagMatches)
                {
                    word = new Word(m.Value);
                    if (wordSet.TryGetKey(word, ref word))
                    {
                        //wordHit = doc.WordHit[word]; // to costly to add tight now - figure out a better way ?
                        //wordHit.Add(wordCt);
                    }
                    else
                    {
                        word = new Word(m.Value);
                        word.Persist(wordPlacement, session);
                        wordSet.Add(word);
                        wordHit = new WordHit(doc, wordCt++, session);
                        //wordHit.Persist(wordHitPlacement, session);
                        doc.WordHit.ValuePlacement = wordHitPlacement;
                        doc.WordHit.AddFast(word, wordHit);
                    }
                }
                inputDoc = iterator.Next();
            }
            session.FlushUpdates(db);
            session.ClearCachedObjects(db); // free up memory for objects we no longer need to have cached
            Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed + " Database: " + dbNum + " is completed.");
        }
Beispiel #37
0
        public Folder(string name, Folder parentFolder, SessionBase session) : base(name)
        {
            CompareByField <FileInDb> comparerByFileName = new CompareByField <FileInDb>("m_name", session, false, true);

            m_files = new BTreeSet <FileInDb>(comparerByFileName, session, 10000, CommonTypes.s_sizeOfUInt32);
            CompareByField <Folder> comparerByFolderName = new CompareByField <Folder>("m_name", session, false, true);

            m_subFolders = new BTreeSet <Folder>(comparerByFolderName, session, 10000, CommonTypes.s_sizeOfUInt32);
            if (parentFolder != null)
            {
                m_parentFolder = parentFolder;
                m_parentFolder.Folders.AddFast(this);
            }
        }
Beispiel #38
0
 internal VertexType(TypeId aTypeId, string aTypeName, VertexType baseType, Graph graph)
 {
   this.graph = graph;
   this.baseType = baseType;
   subType = new VelocityDbList<VertexType>();
   if (baseType != null)
     baseType.subType.Add(this);
   typeId = (TypeId)aTypeId;
   typeName = aTypeName;
   vertecis = new VelocityDbList<Range<VertexId>>();
   stringToPropertyType = new BTreeMap<string, PropertyType>(null, graph.Session);
   edgeTypes = new BTreeSet<EdgeType>(null, graph.Session);
   tailToHeadEdges = new BTreeMap<EdgeType, BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>>(null, graph.Session);
   headToTailEdges = new BTreeMap<EdgeType, BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>>(null, graph.Session);
 }
Beispiel #39
0
        public Folder(string name, Folder parentFolder, SessionBase session) : base(name)
        {
            CompareByField <FileInDb> comparerByFileName = new CompareByField <FileInDb>("m_name", session, false, true);

            m_files = new BTreeSet <FileInDb>(comparerByFileName, session, 10000, CommonTypes.s_sizeOfUInt32);
            CompareByField <Folder> comparerByFolderName = new CompareByField <Folder>("m_name", session, false, true);

            m_folders = new BTreeSet <Folder>(comparerByFolderName, session, 10000, CommonTypes.s_sizeOfUInt32);
            session.Persist(this);
            if (parentFolder != null)
            {
                Update();
                m_folderRelation = new Relation <Folder, Folder>(this, parentFolder);
            }
        }
Beispiel #40
0
        public void fullShiftRightTest()
        {
            Oid id;
            int ct = 0;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                BTreeSet <int> bTree = new BTreeSet <int>(null, session, 9);
                session.Persist(bTree);
                id = bTree.Oid;
                for (int i = 65; i >= 0; i -= 5)
                {
                    bTree.Add(i);
                    ct++;
                }
                bTree.Remove(65);
                ct--;
                bTree.Remove(60);
                ct--;
                bTree.Remove(55);
                ct--;
                bTree.Remove(50);
                ct--;
                bTree.Add(1);
                ct++;
                bTree.Add(2);
                ct++;
                bTree.Add(3);
                ct++;
                bTree.Add(4);
                ct++;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                BTreeSet <int> bTree = (BTreeSet <int>)session.Open(id);
                int            count = 0;
                foreach (int num in bTree)
                {
                    count++;
                }
                Assert.True(ct == bTree.Count);
                Assert.True(ct == bTree.Count());
                session.Commit();
            }
        }
Beispiel #41
0
 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();
   }
 }
Beispiel #42
0
 internal VertexType(TypeId aTypeId, string aTypeName, VertexType baseType, Graph graph)
 {
   m_graph = new WeakIOptimizedPersistableReference<Graph>(graph);
   m_baseType = baseType;
   m_subTypes = new List<VertexType>();
   if (baseType != null)
   {
     baseType.Update();
     baseType.m_subTypes.Add(this);
   }
   m_typeId = (TypeId)aTypeId;
   m_typeName = aTypeName;
   var vertices = new VelocityDbList<Range<VertexId>>();
   graph.Session.Persist(vertices);
   m_vertices = new WeakIOptimizedPersistableReference<VelocityDbList<Range<VertexId>>>(vertices);
   m_stringToPropertyType = new BTreeMap<string, PropertyType>(null, graph.Session);
   m_edgeTypes = new BTreeSet<EdgeType>(null, graph.Session);
   m_tailToHeadEdges = new BTreeMap<EdgeType, BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>>(null, graph.Session);
   m_headToTailEdges = new BTreeMap<EdgeType, BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>>(null, graph.Session);
   graph.Session.Persist(this);
 }
 public void CompareDateTime()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     AllSupported obj;
     CompareByField<AllSupported> compareByField = new CompareByField<AllSupported>("dateTime", session);
     BTreeSet<AllSupported> sortedSet = new BTreeSet<AllSupported>(compareByField, session, 1000, sizeof(long), true);
     for (int i = 0; i < 20000; i++)
     {
       obj = new AllSupported(1);
       obj.dateTime = DateTime.FromBinary(randGen.Next(Int32.MinValue, Int32.MaxValue) * randGen.Next());
       sortedSet.Add(obj);
     }
     int ct = 0;
     AllSupported prior = null;
     foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet)
     {
       if (prior != null)
         Assert.Less(prior.dateTime, currentObj.dateTime);
       prior = currentObj;
       ct++;
     }
     session.Commit();
   }
 }
    public void CompareInt32DescendingComparisonArray()
    {
#if DEBUG
      Assert.Throws<NotImplementedException>(() =>
      {
        using (SessionNoServer session = new SessionNoServer(systemDir))
        {
          session.BeginUpdate();
          AllSupported obj = new AllSupported(2);
          CompareByField<AllSupported> compareByField = new CompareByField<AllSupported>("int32", session, false, false, false);
          BTreeSet<AllSupported> sortedSet = new BTreeSet<AllSupported>(compareByField, session, 1000, sizeof(Int32), true);
          for (int i = 0; i < 100000; i++)
          {
            obj = new AllSupported(1);
            obj.int32 = randGen.Next(Int32.MinValue, Int32.MaxValue);
            sortedSet.Add(obj);
          }
          int ct = 0;
          AllSupported prior = null;
          foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet)
          {
            if (prior != null)
              Assert.Greater(prior.int32, currentObj.int32);
            prior = currentObj;
            ct++;
          }
          session.Commit();
        }
      });
#endif
    }
Beispiel #45
0
 public void CreateTicksCompareFields(int numberOfTicks, int nodeSize)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir, 2000, false))
   {
     //session.SetTraceAllDbActivity();
     session.BeginUpdate();
     CompareByField<Tick> compareByField = new CompareByField<Tick>("<Bid>k__BackingField", session, true);
     //compareByField.AddFieldToCompare("<Timestamp>k__BackingField");
     BTreeSet<Tick> bTree = new BTreeSet<Tick>(compareByField, session, (UInt16) nodeSize, sizeof(double) + sizeof(UInt64), true);
     Placement place = new Placement((UInt32)numberOfTicks, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     Placement ticksPlace = new Placement((UInt32)numberOfTicks, 10000, 1, UInt16.MaxValue, UInt16.MaxValue);
     bTree.Persist(place, session);
     int i = 0;
     int dublicates = 0;
     foreach (var record in Tick.GenerateRandom((ulong) numberOfTicks))
     {
       session.Persist(record, ticksPlace);
       if (bTree.Add(record))
         i++;
       else
         dublicates++;
     }
     session.Commit();
     Console.WriteLine("Done creating and sorting with BTreeSet<Tick> " + i + " Tick objects by Bid value. Number of dublicates (not added to BTreeSet): " + dublicates);
   }
 }
Beispiel #46
0
 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;
   }
 }
Beispiel #47
0
 static void createDocumentInvertedIndex(SessionBase session, Database db, BTreeSet<Document> documentSet)
 {
   UInt32 dbNum = db.DatabaseNumber;
   Document doc = null;
   Document inputDoc = new Document(db.Id);
   Placement wordPlacement = new Placement(inputDoc.DatabaseNumber, 20000, 1, 25000, 65000, true, false, 1, false);
   Placement wordHitPlacement = new Placement(inputDoc.DatabaseNumber, 40000, 1, 25000, 65500, true, false, 1, false);
   //session.SetTraceDbActivity(db.DatabaseNumber);
   BTreeSetIterator<Document> iterator = documentSet.Iterator();
   iterator.GoTo(inputDoc);
   inputDoc = iterator.Current();
   while (inputDoc != null && inputDoc.Page.Database.DatabaseNumber == dbNum)
   {
     doc = (Document)session.Open(inputDoc.Page.Database, inputDoc.Id); // if matching database is availeble, use it to speed up lookup
     DocumentText docText = doc.Content;
     string text = docText.Text.ToLower();
     MatchCollection tagMatches = Regex.Matches(text, "[a-z][a-z.$]+");
     UInt64 wordCt = 0;
     WordHit wordHit;
     Word word;
     if (++s_docCountIndexed % 50000 == 0)
       Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed);
     BTreeSetOidShort<Word> wordSet = doc.WordSet;
     foreach (Match m in tagMatches)
     {
       word = new Word(m.Value);
       if (wordSet.TryGetKey(word, ref word))
       {
         //wordHit = doc.WordHit[word]; // to costly to add tight now - figure out a better way ?
         //wordHit.Add(wordCt);
       }
       else
       {
         word = new Word(m.Value);
         word.Persist(wordPlacement, session);
         wordSet.Add(word);
         wordHit = new WordHit(doc, wordCt++, session);
         //wordHit.Persist(wordHitPlacement, session);
         doc.WordHit.ValuePlacement = wordHitPlacement;
         doc.WordHit.AddFast(word, wordHit);
       }
     }
     inputDoc = iterator.Next();
   }
   session.FlushUpdates(db);
   session.ClearCachedObjects(db); // free up memory for objects we no longer need to have cached
   Console.WriteLine(DateTime.Now.ToString() + ", done indexing article: " + s_docCountIndexed + " Database: " + dbNum + " is completed.");
 }
Beispiel #48
0
 internal void NewTailToHeadEdge(EdgeType edgeType, Edge edge, Vertex tail, Vertex head, SessionBase session)
 {
   BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>> map;
   BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>> innerMap;
   BTreeSet<EdgeIdVertexId> set;
   //lock (tailToHeadEdges)
   {
     if (!m_tailToHeadEdges.TryGetValue(edgeType, out map))
     {
       map = new BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>(null, session);
       innerMap = new BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>(null, session);
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       //if (IsPersistent)
       //{
       //  session.Persist(set, 1000);
       //  session.Persist(innerMap, 1000);
       //  session.Persist(map, 1000);
       //}
       innerMap.AddFast(tail.VertexId, set);
       map.AddFast(head.VertexType, innerMap);
       m_tailToHeadEdges.AddFast(edgeType, map);
       m_edgeTypes.AddFast(edgeType);
     }
     else if (!map.TryGetValue(head.VertexType, out innerMap))
     {
       innerMap = new BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>(null, session);
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       //if (IsPersistent)
       //{
       //  session.Persist(set, 1000);
       //  session.Persist(innerMap, 1000);
       //}
       innerMap.AddFast(tail.VertexId, set);
       map.AddFast(head.VertexType, innerMap);
     }
     else if (!innerMap.TryGetValue(tail.VertexId, out set))
     {
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       //if (IsPersistent)
       //{
       //  session.Persist(set, 1000);
       //}
       innerMap.AddFast(tail.VertexId, set);
     }
     set.AddFast(edgeVertexId(edge, head.VertexId));
   }
 }
Beispiel #49
0
 internal void NewHeadToTailEdge(EdgeType edgeType, Edge edge, Vertex tail, Vertex head, SessionBase session)
 {
   BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>> map;
   BTreeMap<EdgeId, BTreeSet<EdgeIdVertexId>> innerMap;
   BTreeSet<EdgeIdVertexId> set;
   //lock (headToTailEdges)
   {
     if (!m_headToTailEdges.TryGetValue(edgeType, out map))
     {
       map = new BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>(null, session);
       innerMap = new BTreeMap<EdgeId, BTreeSet<EdgeIdVertexId>>(null, session);
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       innerMap.AddFast(head.VertexId, set);
       map.AddFast(tail.VertexType, innerMap);
       m_headToTailEdges.AddFast(edgeType, map);
       m_edgeTypes.AddFast(edgeType);
     }
     else if (!map.TryGetValue(tail.VertexType, out innerMap))
     {
       innerMap = new BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>(null, session);
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       innerMap.AddFast(head.VertexId, set);
       map.AddFast(tail.VertexType, innerMap);
     }
     else if (!innerMap.TryGetValue(head.VertexId, out set))
     {
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       innerMap.AddFast(head.VertexId, set);
     }
     set.AddFast(edgeVertexId(edge, tail.VertexId));
   }
 }
Beispiel #50
0
 public Repository(ushort nodeSize, SessionBase session)   
 {
   documentSet = new BTreeSet<Document>(null, session, nodeSize);
 }
Beispiel #51
0
 public WordGlobal(string word, SessionBase session, UInt32 count):base(word)
 {
     m_globalCount = count;
     documentHit = new BTreeSet<Document>(null, session, 10000);
 }
Beispiel #52
0
 public Person(string name, SessionBase session)
 {
   Name = name;
   inMovieAs = new BTreeSet<InMovieAs>(null, session);
 }
    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());
      }
    }
Beispiel #54
0
 public void CreateDefaultCompareFailException()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Man aMan;
     Woman aWoman;
     session.BeginUpdate();
     BTreeSet<Person> bTree = new BTreeSet<Person>(null, session);
     for (int i = 0; i < 1000000; i++)
     {
       aMan = new Man();
       aWoman = new Woman();
       bTree.Add(aMan);
       bTree.Add(aWoman);
     }
     session.Commit();
   }
 }
Beispiel #55
0
 public Movie(string title, SessionBase session)
 {
   cast = new BTreeSet<Person>(null, session);
   Title = title;
 }
Beispiel #56
0
 public void CreateDefaultCompare()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Man aMan = new Man();
     Woman aWoman = new Woman();
     session.BeginUpdate();
     BTreeSet<Person> bTree = new BTreeSet<Person>(null, session);
     session.Persist(bTree);
     for (int i = 0; i < 50000; i++)
     {
       aMan = new Man();
       aMan.Persist(session, aMan);
       aWoman = new Woman();
       aWoman.Persist(session, aWoman);
       bTree.Add(aMan);
       Assert.AreEqual(bTree.GetKeyId(aMan), aMan.Id);
       bTree.Add(aWoman);
     }
     session.Commit();
   }
 }
Beispiel #57
0
 public Movie(string title, Int16 year, SessionBase session)
 {
   m_cast = new BTreeSet<ActingPerson>(null, session);
   m_title = title;
   m_year = year;
 }
 public void CompareDouble(bool completeKey)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     AllSupported obj = new AllSupported(1);
     CompareByField<AllSupported> compareByField = new CompareByField<AllSupported>("aDouble", session);
     BTreeSet<AllSupported> sortedSet = new BTreeSet<AllSupported>(compareByField, session, 1000, sizeof(double), completeKey);
     List<AllSupported> toRemove = new List<AllSupported>();
     for (int i = 0; i < 100000; i++)
     {
       obj = new AllSupported(1);
       obj.aDouble = (randGen.NextDouble() - randGen.NextDouble()) * randGen.Next(UInt16.MinValue, UInt16.MaxValue);
       if (i % 3500 == 0)
         toRemove.Add(obj);
       sortedSet.Add(obj);
     }
     session.Commit();
     session.BeginUpdate();
     foreach (AllSupported r in toRemove)
       sortedSet.Remove(r);
     int ct = 0;
     AllSupported prior = null;
     foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet)
     {
       if (prior != null)
         Assert.Less(prior.aDouble, currentObj.aDouble);
       prior = currentObj;
       ct++;
     }
     session.Commit();
   }
 }