Ejemplo n.º 1
0
 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();
     }
 }
Ejemplo n.º 2
0
 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();
   }
 }
Ejemplo n.º 3
0
        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
        }
Ejemplo n.º 4
0
 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();
   }
 }
Ejemplo n.º 5
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);
     }
 }
Ejemplo n.º 6
0
 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();
     }
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
0
 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();
     }
 }
Ejemplo n.º 9
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();
            }
        }
Ejemplo n.º 10
0
 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();
     }
 }
Ejemplo n.º 11
0
        static bool GreaterThanOrEqualUseIndex <Key>(BTreeBase <Key, Key> sourceCollection, BinaryExpression binExp)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            SessionBase          session  = sourceCollection.Session;
            CompareByField <Key> comparer = sourceCollection.Comparer as CompareByField <Key>;

            Expression leftSide   = binExp.Left;
            Expression rightSide  = binExp.Right;
            object     rightValue = GetRightValue(leftSide, rightSide);

            if (leftSide.NodeType == ExpressionType.Parameter)
            {
                Key key = (Key)rightValue;
                if (key != null)
                {
                    if (session.TraceIndexUsage)
                    {
                        Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff") + " Index used with " + sourceCollection.ToString());
                    }
                    return(true);
                }
            }
            else
            {
                if (comparer != null)
                {
                    //if we were able to create a hash from the right side (likely)
                    MemberExpression returnedEx = null;
                    if (comparer.FieldsToCompare == null)
                    {
                        comparer.SetupFieldsToCompare();
                    }
                    DataMember dataMember = comparer.FieldsToCompare[0];
                    if (rightValue != null && HasIndexablePropertyOnLeft <Key>(leftSide, sourceCollection, dataMember, out returnedEx))
                    {
                        if (session.TraceIndexUsage)
                        {
                            Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff") + " Index used with " + sourceCollection.ToString());
                        }
                        return(true);
                    }
                    else if (leftSide.NodeType == ExpressionType.Call)
                    {
                        // don't know yet how to handle TODO

                        /*MethodCallExpression expression = leftSide as MethodCallExpression;
                         * Trace.Out.WriteLine("Method: " + expression.Method.Name);
                         * Trace.Out.WriteLine("Args: ");
                         * foreach (var exp in expression.Arguments)
                         * sourceCollection where */
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 12
0
        static IEnumerable <Key> Equal <Key>(BTreeBase <Key, Key> sourceCollection, BinaryExpression binExp)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            SessionBase          session   = sourceCollection.Session;
            CompareByField <Key> comparer  = sourceCollection.Comparer as CompareByField <Key>;
            Expression           leftSide  = binExp.Left;
            Expression           rightSide = binExp.Right;
            object rightValue = GetRightValue(leftSide, rightSide);

            if (leftSide.NodeType == ExpressionType.Parameter)
            {
                Key key = (Key)rightValue;
                if (key != null)
                {
                    BTreeSetIterator <Key> itr = sourceCollection.Iterator();
                    itr.GoTo(key);
                    while (sourceCollection.Comparer.Compare(itr.Current(), key) == 0)
                    {
                        yield return(itr.Next());
                    }
                }
            }
            else
            {
                if (comparer != null)
                {
                    MemberExpression returnedEx = null;
#if WINDOWS_PHONE || WINDOWS_UWP
                    Key key = (Key)Activator.CreateInstance(typeof(Key));
#else
                    Key key = (Key)FormatterServices.GetUninitializedObject(typeof(Key));
#endif
                    if (comparer.FieldsToCompare == null)
                    {
                        comparer.SetupFieldsToCompare();
                    }
                    DataMember dataMember = comparer.FieldsToCompare[0];
                    if (rightValue != null && HasIndexablePropertyOnLeft <Key>(leftSide, sourceCollection, dataMember, out returnedEx))
                    {
                        MemberExpression propExp  = (MemberExpression)returnedEx;
                        MemberInfo       property = propExp.Member;
                        dataMember.SetMemberValueWithPossibleConvert(key, rightValue);
                        BTreeSetIterator <Key> itr = sourceCollection.Iterator();
                        itr.GoTo(key);
                        Key current = itr.Current();
                        while (current != null && comparer.CompareField(dataMember, key, current, 0) == 0)
                        {
                            yield return(current);

                            current = itr.Next();
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
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);
   }
 }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
0
        public IssueTracker(int capacity, SessionBase session)
        {
            issueSetById = new SortedSetAny <Issue>(capacity);
            CompareByField <Issue> descriptionCompare = new CompareByField <Issue>("description", session, true);

            issueSetByDescription = new SortedSetAny <Issue>(descriptionCompare);
            ComparePriority priorityCompare = new ComparePriority();

            issueSetByPriority = new SortedSetAny <Issue>(priorityCompare);
            CompareByField <Issue> dateTimeCreatedCompare = new CompareByField <Issue>("dateTimeCreated", session, true);

            issueSetByDateTimeCreated = new SortedSetAny <Issue>(dateTimeCreatedCompare);
            CompareByField <Issue> dateTimeUpdatedCompare = new CompareByField <Issue>("dateTimeLastUpdated", session, true);

            issueSetByDateTimeUpdated = new SortedSetAny <Issue>(dateTimeCreatedCompare);
            CompareByField <Issue> compareStatus = new CompareByField <Issue>("status", session, true);

            issueSetByStatus = new SortedSetAny <Issue>(compareStatus);
            CompareSummary compareSummary = new CompareSummary();

            issueSetBySummary = new SortedSetAny <Issue>(compareSummary);
            CompareByField <Issue> compareProject = new CompareByField <Issue>("project", session, true);

            issueSetByProject = new SortedSetAny <Issue>(compareProject);
            CompareCategory compareCategory = new CompareCategory();

            issueSetByCategory = new SortedSetAny <Issue>(compareCategory);
            CompareReportedBy compareReportedBy = new CompareReportedBy();

            issueSetByReportedBy = new SortedSetAny <Issue>(compareReportedBy);
            CompareLastUpdatedBy compareLastUpdatedBy = new CompareLastUpdatedBy();

            issueSetByLastUpdatedBy = new SortedSetAny <Issue>(compareLastUpdatedBy);
            CompareAssignedTo compareAssignedTo = new CompareAssignedTo();

            issueSetByAssignedTo = new SortedSetAny <Issue>(compareAssignedTo);
            CompareByField <Issue> compareByDueDate = new CompareByField <Issue>("dueDate", session, true);

            issueSetByDueDate = new SortedSetAny <Issue>(compareByDueDate);
            CompareByVersion compareByVersion = new CompareByVersion();

            issueSetByVersion = new SortedSetAny <Issue>(compareByVersion);
            componentSet      = new SortedSetAny <Component>(capacity);
            userSet           = new SortedSetAny <User>(capacity);
            projectSet        = new SortedSetAny <Project>(capacity);
            versionSet        = new SortedSetAny <ProductVersion>(capacity);
            organizationSet   = new SortedSetAny <Organization>(capacity);
            permissions       = null;
        }
Ejemplo n.º 16
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);
            }
        }
Ejemplo n.º 17
0
        static bool GreaterThanUseIndex <Key>(BTreeBase <Key, Key> sourceCollection, BinaryExpression binExp)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            SessionBase          session   = sourceCollection.GetSession();
            CompareByField <Key> comparer  = sourceCollection.Comparer as CompareByField <Key>;
            Expression           leftSide  = binExp.Left;
            Expression           rightSide = binExp.Right;
            object rightValue = GetRightValue(leftSide, rightSide);

            if (leftSide.NodeType == ExpressionType.Parameter)
            {
                Key key = (Key)rightValue;
                if (key != null)
                {
                    if (session.TraceIndexUsage)
                    {
                        Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff") + " Index used with " + sourceCollection.ToString());
                    }
                    return(true);
                }
            }
            else
            {
                if (comparer != null)
                {
                    //if we were able to create a hash from the right side (likely)
                    MemberExpression returnedEx = null;
                    if (comparer.FieldsToCompare == null)
                    {
                        comparer.SetupFieldsToCompare();
                    }
                    DataMember dataMember = comparer.FieldsToCompare[0];
                    if (rightValue != null && HasIndexablePropertyOnLeft <Key>(leftSide, sourceCollection, dataMember, out returnedEx))
                    {
                        if (session.TraceIndexUsage)
                        {
                            Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff") + " Index used with " + sourceCollection.ToString());
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 18
0
        public void SortedObjectsSample()
        {
            Oid bTreeId;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                const UInt32 numberOfPersons              = 100000;
                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;
                VelocityDbSchema.Samples.AllSupportedSample.Person person;
                session.BeginUpdate();
                //mySession.SetTraceAllDbActivity();
                CompareByField <VelocityDbSchema.Samples.AllSupportedSample.Person> compareByField = new CompareByField <VelocityDbSchema.Samples.AllSupportedSample.Person>("m_idNumber", session, addIdCompareIfEqual);
                BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person>       bTree          = new BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.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 VelocityDbSchema.Samples.AllSupportedSample.Person();
                    session.Persist(person);
                    bTree.Add(person);
                }
                bTreeId = bTree.Oid;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person> bTree = (BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person>)session.Open(bTreeId);
                foreach (VelocityDbSchema.Samples.AllSupportedSample.Person person in (IEnumerable <VelocityDbSchema.Samples.AllSupportedSample.Person>)bTree)
                {
                    if (person.IdNumber > 196988888791402)
                    {
                        Console.WriteLine(person);
                        break;
                    }
                }
                session.Commit();
                session.BeginRead();
                // 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();
            }
        }
Ejemplo n.º 19
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();
   }
 }
Ejemplo n.º 20
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();
     }
 }
Ejemplo n.º 21
0
 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();
     }
 }
Ejemplo n.º 22
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;
            }
        }
Ejemplo n.º 23
0
 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();
     }
 }
Ejemplo n.º 24
0
        static IEnumerable <Key> And <Key>(BTreeBase <Key, Key> sourceCollection, BinaryExpression binExp)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            CompareByField <Key> comparer = sourceCollection.Comparer as CompareByField <Key>;
            int indexNumberOfFields       = comparer.FieldsToCompare.Length;

#if WINDOWS_PHONE || WINDOWS_UWP
            Key key = (Key)Activator.CreateInstance(typeof(Key));
#else
            Key key = (Key)FormatterServices.GetUninitializedObject(typeof(Key));
#endif
            while (binExp.NodeType == ExpressionType.AndAlso)
            {
                BinaryExpression leftExpr   = (BinaryExpression)binExp.Left;
                BinaryExpression rightExpr  = (BinaryExpression)binExp.Right;
                DataMember       dataMember = comparer.FieldsToCompare[--indexNumberOfFields];
                object           rightValue = GetRightValue(rightExpr.Left, rightExpr.Right);
                dataMember.SetMemberValueWithPossibleConvert(key, rightValue);
                binExp = leftExpr;
                if (binExp.NodeType == ExpressionType.Equal)
                {
                    dataMember = comparer.FieldsToCompare[--indexNumberOfFields];
                    rightValue = GetRightValue(binExp.Left, binExp.Right);
                    dataMember.SetMemberValueWithPossibleConvert(key, rightValue);
                }
            }
            BTreeSetIterator <Key> itr = sourceCollection.Iterator();
            itr.GoTo(key);
            Key current = itr.Current();
            while (current != null && comparer.Compare(key, current) == 0)
            {
                yield return(current);

                current = itr.Next();
            }
        }
Ejemplo n.º 25
0
 public IssueTracker(int capacity, SessionBase session)
 {
   issueSetById = new SortedSetAny<Issue>(capacity);
   CompareByField<Issue> descriptionCompare = new CompareByField<Issue>("description", session, true);
   issueSetByDescription = new SortedSetAny<Issue>(descriptionCompare); 
   ComparePriority priorityCompare = new ComparePriority();
   issueSetByPriority = new SortedSetAny<Issue>(priorityCompare);
   CompareByField<Issue> dateTimeCreatedCompare = new CompareByField<Issue>("dateTimeCreated", session, true);
   issueSetByDateTimeCreated = new SortedSetAny<Issue>(dateTimeCreatedCompare);
   CompareByField<Issue> dateTimeUpdatedCompare = new CompareByField<Issue>("dateTimeLastUpdated", session, true);
   issueSetByDateTimeUpdated = new SortedSetAny<Issue>(dateTimeCreatedCompare);
   CompareByField<Issue> compareStatus = new CompareByField<Issue>("status", session, true);
   issueSetByStatus = new SortedSetAny<Issue>(compareStatus);
   CompareSummary compareSummary = new CompareSummary();
   issueSetBySummary = new SortedSetAny<Issue>(compareSummary);
   CompareByField<Issue> compareProject = new CompareByField<Issue>("project", session, true);
   issueSetByProject = new SortedSetAny<Issue>(compareProject);
   CompareCategory compareCategory = new CompareCategory();
   issueSetByCategory = new SortedSetAny<Issue>(compareCategory);
   CompareReportedBy compareReportedBy = new CompareReportedBy();
   issueSetByReportedBy = new SortedSetAny<Issue>(compareReportedBy);
   CompareLastUpdatedBy compareLastUpdatedBy = new CompareLastUpdatedBy();
   issueSetByLastUpdatedBy = new SortedSetAny<Issue>(compareLastUpdatedBy);
   CompareAssignedTo compareAssignedTo = new CompareAssignedTo();
   issueSetByAssignedTo = new SortedSetAny<Issue>(compareAssignedTo);
   CompareByField<Issue> compareByDueDate = new CompareByField<Issue>("dueDate", session, true);
   issueSetByDueDate = new SortedSetAny<Issue>(compareByDueDate);
   CompareByVersion compareByVersion = new CompareByVersion();
   issueSetByVersion = new SortedSetAny<Issue>(compareByVersion);
   componentSet = new SortedSetAny<Component>(capacity);
   userSet = new SortedSetAny<User>(capacity);
   projectSet = new SortedSetAny<Project>(capacity);
   versionSet = new SortedSetAny<ProductVersion>(capacity);
   organizationSet = new SortedSetAny<Organization>(capacity);
   permissions = null;
 }
Ejemplo n.º 26
0
 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();
   }
 }
Ejemplo n.º 27
0
    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
    }
Ejemplo n.º 28
0
    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());
      }
    }
Ejemplo n.º 29
0
        static bool canUseIndex <Key>(BTreeBase <Key, Key> sourceCollection, BinaryExpression binExp, CompareByField <Key> comparer)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            if (comparer.FieldsToCompare == null)
            {
                comparer.SetupFieldsToCompare();
            }
            int indexNumberOfFields = comparer.FieldsToCompare.Length;

            while (binExp.NodeType == ExpressionType.AndAlso)
            {
                BinaryExpression leftExpr   = (BinaryExpression)binExp.Left;
                BinaryExpression rightExpr  = (BinaryExpression)binExp.Right;
                MemberExpression returnedEx = null;
                if (indexNumberOfFields == 0 || !HasIndexablePropertyOnLeft(rightExpr.Left, sourceCollection, comparer.FieldsToCompare[--indexNumberOfFields], out returnedEx))
                {
                    return(false);
                }
                binExp = leftExpr;
            }
            return(true);
        }
Ejemplo n.º 30
0
        static public IEnumerable <Key> Where <Key>(this BTreeBase <Key, Key> sourceCollection, Expression <Func <Key, bool> > expr)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            if (sourceCollection != null)
            {
                bool                 noIndex  = true;
                SessionBase          session  = sourceCollection.Session;
                CompareByField <Key> comparer = sourceCollection.Comparer as CompareByField <Key>;
                BinaryExpression     binExp   = expr.Body as BinaryExpression;
                if (binExp != null && canUseIndex <Key>(sourceCollection, binExp, comparer))
                {
                    session.WaitForIndexUpdates();
                    switch (expr.Body.NodeType)
                    {
                    case ExpressionType.AndAlso:
                    {
                        noIndex = AndUseIndex(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in And <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                        else
                        {
                            BinaryExpression leftExpr = (BinaryExpression)binExp.Left;
                            binExp = leftExpr;
                            switch (binExp.NodeType)
                            {
                            case ExpressionType.Equal:
                            {
                                noIndex = EqualUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> equal  = Equal <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result = equal.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.LessThan:
                            {
                                noIndex = LessThanUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> lessThan = LessThan <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result   = lessThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.LessThanOrEqual:
                            {
                                noIndex = LessThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> lessThan = LessThanOrEqual <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result   = lessThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.GreaterThan:
                            {
                                noIndex = GreaterThanUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> greaterThan = GreaterThan <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result      = greaterThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.GreaterThanOrEqual:
                            {
                                noIndex = GreaterThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> greaterThan = GreaterThanOrEqual <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result      = greaterThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }
                            }
                            ;
                        }
                    }
                    break;

                    case ExpressionType.Equal:
                    {
                        noIndex = EqualUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in Equal <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.GreaterThan:
                    {
                        noIndex = GreaterThanUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in GreaterThan <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.GreaterThanOrEqual:
                    {
                        noIndex = GreaterThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in GreaterThanOrEqual <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.LessThan:
                    {
                        noIndex = LessThanUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in LessThan <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.LessThanOrEqual:
                    {
                        noIndex = LessThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in LessThanOrEqual <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;
                    }
                }
                if (noIndex) //no index?  just do it the normal slow way then...
                {
                    IEnumerable <Key> sourceEnum;
                    if (sourceCollection.UsesOidShort)
                    {
                        BTreeSetOidShort <Key> c = (BTreeSetOidShort <Key>)sourceCollection;
                        sourceEnum = c.AsEnumerable <Key>();
                    }
                    else
                    {
                        BTreeSet <Key> c = (BTreeSet <Key>)sourceCollection;
                        sourceEnum = c.AsEnumerable <Key>();
                    }
                    IEnumerable <Key> result = sourceEnum.Where <Key>(expr.Compile());
                    foreach (Key resultItem in result)
                    {
                        yield return(resultItem);
                    }
                }
            }
        }
Ejemplo n.º 31
0
        public override int GetHashCode()
        {
            string t = m_token as string;

            return(t != null ? CompareByField <T> .GetHashCode32(t) : m_token.GetHashCode());
        }
Ejemplo n.º 32
0
        static IEnumerable <Key> LessThan <Key>(BTreeBase <Key, Key> sourceCollection, BinaryExpression binExp)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            SessionBase          session    = sourceCollection.Session;
            Expression           leftSide   = binExp.Left;
            Expression           rightSide  = binExp.Right;
            object               rightValue = GetRightValue(leftSide, rightSide);
            CompareByField <Key> comparer   = sourceCollection.Comparer as CompareByField <Key>;

            if (leftSide.NodeType == ExpressionType.Parameter)
            {
                Key key = (Key)rightValue;
                if (key != null)
                {
                    BTreeSetIterator <Key> itr = sourceCollection.Iterator();
                    if (itr.GoTo(key))
                    {
                        while (itr.Previous() != null)
                        {
                            yield return(itr.Current());
                        }
                    }
                }
            }
            else
            {
                if (comparer != null)
                {
                    //if we were able to create a hash from the right side (likely)
                    MemberExpression returnedEx = null;
#if WINDOWS_PHONE || WINDOWS_UWP
                    Key key = (Key)Activator.CreateInstance(typeof(Key));
#else
                    Key key = (Key)FormatterServices.GetUninitializedObject(typeof(Key));
#endif
                    if (comparer.FieldsToCompare == null)
                    {
                        comparer.SetupFieldsToCompare();
                    }
                    DataMember dataMember = comparer.FieldsToCompare[0];
                    if (rightValue != null && HasIndexablePropertyOnLeft <Key>(leftSide, sourceCollection, dataMember, out returnedEx))
                    {
                        //cast to MemberExpression - it allows us to get the property
                        MemberExpression propExp  = (MemberExpression)returnedEx;
                        MemberInfo       property = propExp.Member;
                        foreach (DataMember member in comparer.FieldsToCompare.Skip(1))
                        {
                            if (member.GetTypeCode == TypeCode.String)
                            {
                                member.SetMemberValue(key, "");
                            }
                        }
                        dataMember.SetMemberValueWithPossibleConvert(key, rightValue);
                        BTreeSetIterator <Key> itr = sourceCollection.Iterator();
                        itr.GoTo(key);
                        var v = itr.Current();
                        if (v == null)
                        {
                            v = itr.Previous();
                        }
                        while (v != null && comparer.CompareField(dataMember, key, v, 0) == 0)
                        {
                            v = itr.Previous();
                        }
                        while (v != null)
                        {
                            yield return(v);

                            v = itr.Previous();
                        }
                    }
                    else if (leftSide.NodeType == ExpressionType.Call)
                    {
                        // don't know yet how to handle TODO

                        /*MethodCallExpression expression = leftSide as MethodCallExpression;
                         * Trace.Out.WriteLine("Method: " + expression.Method.Name);
                         * Trace.Out.WriteLine("Args: ");
                         * foreach (var exp in expression.Arguments)
                         * sourceCollection where */
                    }
                }
            }
        }
Ejemplo n.º 33
0
        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());
            }
        }
Ejemplo n.º 34
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;
   }
 }
Ejemplo n.º 35
0
 public void CreateTicksCompareFieldsOidShort(int numberOfTicks, int nodeSize)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     session.Open(10, 1, 1, false);
     session.Open(10, 1, 2, false);
     session.Open(10, 2, 1, false);
     session.Open(10, 2, 2, false);
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir, 2000, false))
   {
     //session.SetTraceAllDbActivity();
     //session.ClientCache.MinimumAvailableMegaBytes = 1100;
     session.BeginUpdate();
     CompareByField<Tick> compareByField = new CompareByField<Tick>("<Bid>k__BackingField", session, true);
     //compareByField.AddFieldToCompare("<Timestamp>k__BackingField");
     BTreeSetOidShort<Tick> bTree = new BTreeSetOidShort<Tick>(compareByField, session, (UInt16) nodeSize, sizeof(double), 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 BTreeSetOidShort<Tick>" + i + " Tick objects by Bid value. Number of dublicates (not added to BTreeSet): " + dublicates);
   }
 }
Ejemplo n.º 36
0
 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();
   }
 }