Пример #1
0
        public void SuperComplexQuery()
        {
            SimpleClass[] someItems =
            {
                new SimpleClass {
                    Name = "Jason Jarett", Age = 25, FavoriteColor = Color.Aqua
                },
                new SimpleClass {
                    Name = "Aaron Erickson", Age = 37, FavoriteColor = Color.Green
                },
                new SimpleClass {
                    Name = "Erin Erickson", Age = 34, FavoriteColor = Color.Green
                },
                new SimpleClass {
                    Name = "Adriana Erickson", Age = 13, FavoriteColor = Color.Aqua
                },
            };
            var indexSpec = IndexSpecification <SimpleClass> .Build()
                            .With(person => person.FavoriteColor)
                            .And(person => person.Age)
                            .And(person => person.Name);

            var theIndexSet = new IndexSet <SimpleClass>(someItems, indexSpec);
            var oneResult   =
                from item in theIndexSet
                where
                (
                    (item.FavoriteColor == Color.Green && item.Age == 37) ||
                    (item.Name == "Adriana Erickson" && item.Age == 13) ||
                    (item.Name == "Jason Jarett" && item.Age == 25)
                ) && item.Name == "Aaron Erickson"
                select item;

            Assert.AreEqual(1, oneResult.Count());
        }
Пример #2
0
    /*
     *  1) get all relevant CareAbouts for each index's
     *  IndexFillSpecification at each index that is not set
     *  2) for all non-set indices, get all targeted complex entities
     *  3) for all non-set indices, assign id of the complex entity with highest score
     */
    public static void SetIndiciesByCareAbout(
        BaseSimpleEntity beingFilled,
        SimpleEntitySharedData beingFilledSharedData,
        Collective c)
    {
        int numOfFillSpecs = beingFilledSharedData.aboutSpecs.Count;

        for (int i = 0; i < numOfFillSpecs; i++)
        {
            // the specification for how to fill the associated
            // index with a complex entity id
            IndexSpecification spec = beingFilledSharedData.aboutSpecs[i];

            // negative value in "about" indicates no set index
            if (spec.fillType <= INDEX_FILL_TYPE.CARE_ABOUT_FIRST &&
                beingFilled.about[i] < 0)
            {
                List <CareAbout> temp = new List <CareAbout>();

                for (int j = 0; j < c.controllingCharacters.Count; j++)
                {
                    var character = c.controllingCharacters[j];

                    // all CareAbouts that have any of the specified IDs
                    temp.AddRange(GetRelevantCareAbouts(character, spec));
                }

                beingFilled.about[i] = GetHighestScoringComplexEntityID(temp);
            }
        }
    }
Пример #3
0
        public void ComplexQuery()
        {
            SimpleClass[] someItems =
            {
                new SimpleClass {
                    Name = "Jason", Age = 25
                },
                new SimpleClass {
                    Name = "Aaron", Age = 37, FavoriteColor = Color.Green
                },
                new SimpleClass {
                    Name = "Erin", Age = 34
                },
                new SimpleClass {
                    Name = "Adriana", Age = 13
                },
            };
            var indexSpec = IndexSpecification <SimpleClass> .Build()
                            .With(person => person.FavoriteColor)
                            .And(person => person.Age);

            var theIndexSet = new IndexSet <SimpleClass>(someItems, indexSpec);
            var twoResults  =
                from item in theIndexSet
                where item.FavoriteColor == Color.Green || item.Age == 13 && item.Name == "Adriana"
                select item;

            Assert.AreEqual(2, twoResults.Count());
        }
    // assembles a list of all CareAbouts relevant to the specification
    static List <CareAbout> GetRelevantCareAbouts(Character c, IndexSpecification spec)
    {
        // all CareAbouts with any of the specified IDs
        var relevantCareAbouts = new List <CareAbout>();

        for (int j = 0; j < c.situations.Count; j++)
        {
            // the CareAbouts for this specific situation
            var careAboutsAtSituation = c.situations[j].sharedData.careAbouts;

            // check all the CareAbouts of the situation
            for (int k = 0; k < careAboutsAtSituation.Count; k++)
            {
                int targetIndex = careAboutsAtSituation[k].targetAboutIndex;

                // gets the target type at the current situation for the specified index
                var typeAtSituation = c.situations[j].sharedData.aboutSpecs[targetIndex].targetType;

                // is the type from the situation the same as the one I'm looking for?
                if (spec.targetType == typeAtSituation)
                {
                    // is this one of the CareAbouts we're looking for?
                    if (spec.careAboutGroupIDs.Contains(careAboutsAtSituation[k].groupID))
                    {
                        relevantCareAbouts.Add(careAboutsAtSituation[k]);
                    }
                }
            }
        }

        return(relevantCareAbouts);
    }
 protected override void Init_internal()
 {
     IndexedLINQCellTree      = new ObservableCollection <Cell>();
     IndexedLINQCellTreeIndex = new IndexSet <Cell>(IndexedLINQCellTree, IndexSpecification <Cell> .Build()
                                                    .With(cell => cell.MinX)
                                                    .And(cell => cell.MaxX)
                                                    .And(cell => cell.MinY)
                                                    .And(cell => cell.MaxY));
 }
Пример #6
0
    // Method that deletes all documents from a DB XML container that match a given
    // XQuery.
    private static void deleteIndex(Manager mgr, Container container,
                                    string URI, string nodeName, string indexType, Transaction txn)
    {
        System.Console.WriteLine("Deleting index type '" + indexType +
                                 "' from node '" + nodeName + "'.");

        // Retrieve the index specification from the container
        using (IndexSpecification idxSpec = container.GetIndexSpecification(txn))
        {
            // See what indexes exist on the container
            int count = 0;
            System.Console.WriteLine("Before the delete, the following indexes are maintained for the container:");
            // Loop over the indexes and report what's there.
            while (idxSpec.MoveNext())
            {
                System.Console.WriteLine("\tFor node '" + idxSpec.Current.Name +
                                         "', found index: '" + idxSpec.Current.Index + "'.");
                ++count;
            }
            System.Console.WriteLine(count + " indexes found.");

            // Delete the indexes from the specification.
            idxSpec.DeleteIndex(
                new IndexSpecification.Entry(URI, nodeName, indexType));

            // Get an update context.
            using (UpdateContext updateContext = mgr.CreateUpdateContext())
            {
                // Set the specification back to the container
                container.SetIndexSpecification(txn, idxSpec, updateContext);
            }
        }

        // Retrieve the index specification from the container
        using (IndexSpecification idxSpec = container.GetIndexSpecification(txn))
        {
            // Look at the indexes again to make sure our deletion took.
            int count = 0;
            System.Console.WriteLine("After the delete, the following indexes are maintained for the container:");
            while (idxSpec.MoveNext())
            {
                System.Console.WriteLine("\tFor node '" + idxSpec.Current.Name +
                                         "', found index: '" + idxSpec.Current.Index + "'.");
                ++count;
            }
            System.Console.WriteLine(count + " indexes found.");
        }
    }
Пример #7
0
    private static void addIndex(Container container, string uri, string name,
                                 string index, Transaction txn, UpdateContext uc)
    {
        System.Console.WriteLine("Adding index type '" + index +
                                 "' to node '" + name + "'.");

        // Retrieve the index specification from the container
        using (IndexSpecification idxSpec = container.GetIndexSpecification(txn))
        {
            // See what indexes exist on the container
            int count = 0;
            System.Console.WriteLine("Before index add.");
            while (idxSpec.MoveNext())
            {
                System.Console.WriteLine("\tFor node '" + idxSpec.Current.Name +
                                         "', found index: '" + idxSpec.Current.Index +
                                         "'.");
                ++count;
            }

            System.Console.WriteLine(count + " indexes found.");

            // Add the index to the specification.
            // If it already exists, then this does nothing.
            idxSpec.AddIndex(new IndexSpecification.Entry(uri, name, index));

            // Set the specification back to the container
            container.SetIndexSpecification(txn, idxSpec, uc);
        }

        // Retrieve the index specification from the container
        using (IndexSpecification idxSpec = container.GetIndexSpecification(txn))
        {
            // Look at the indexes again to make sure our replacement took.
            int count = 0;
            System.Console.WriteLine("After index add.");
            while (idxSpec.MoveNext())
            {
                System.Console.WriteLine("\tFor node '" + idxSpec.Current.Name +
                                         "', found index: '" + idxSpec.Current.Index +
                                         "'.");
                ++count;
            }

            System.Console.WriteLine(count + " indexes found.");
        }
    }
Пример #8
0
        public void IndexRecognizesChangeInAChildProperty()
        {
            var someObservableObject = new ObservableObject {
                SomeMutable = 6
            };
            var someCollection = new ObservableCollection <ObservableObject>(
                new List <ObservableObject> {
                someObservableObject
            });
            var indexSpec = IndexSpecification <ObservableObject> .Build()
                            .With(child => child.SomeMutable);

            var someIndex = IndexBuilder.BuildIndicesFor(someCollection, indexSpec);

            someObservableObject.SomeMutable = 3;
            Assert.AreEqual((from v in someIndex where v.SomeMutable == 3 select v).Count(), 1);
        }
    /*
     *  1) get all relevant CareAbouts for each index's
     *  IndexFillSpecification at each index that is not set
     *  2) for all non-set indices, get all targeted complex entities
     *  3) for all non-set indices, assign id of the complex entity with highest score
     */
    public static void SetIndiciesByCareAbout(
        BaseSimpleEntity beingFilled,
        SimpleEntitySharedData beingFilledSharedData,
        Character c)
    {
        int numOfFillSpecs = beingFilledSharedData.aboutSpecs.Count;

        for (int i = 0; i < numOfFillSpecs; i++)
        {
            // the specification for how to fill the associated
            // index with a complex entity id
            IndexSpecification spec = beingFilledSharedData.aboutSpecs[i];

            // negative value in "about" indicates no set index
            if (spec.fillType <= INDEX_FILL_TYPE.CARE_ABOUT_FIRST &&
                beingFilled.about[i] < 0)
            {
                // all CareAbouts that have any of the specified IDs
                var temp = GetRelevantCareAbouts(c, spec);

                beingFilled.about[i] = GetHighestScoringComplexEntityID(temp);
            }
        }
    }
Пример #10
0
 public TestIndexableCollection(IEnumerable <T> items, IndexSpecification <T> indexSpecification)
     : base(items, indexSpecification)
 {
 }
Пример #11
0
        public void PerformanceComparisonTest()
        {
            Stopwatch globalSw = new Stopwatch();

            globalSw.Start();
            List <SimpleClass> someItems = new List <SimpleClass> {
                new SimpleClass {
                    Name = "Jason Jarett", Age = 25, FavoriteColor = Color.Aqua
                },
                new SimpleClass {
                    Name = "Aaron Erickson", Age = 37, FavoriteColor = Color.Green
                },
                new SimpleClass {
                    Name = "Erin Erickson", Age = 34, FavoriteColor = Color.Green
                },
                new SimpleClass {
                    Name = "Adriana Erickson", Age = 13, FavoriteColor = Color.Aqua
                },
            };

            var rnd = new Random();

            var moreItems = Enumerable.Range(1, 100000).Select(r => new SimpleClass()
            {
                Name = "AdrBla" + rnd.NextDouble(), Age = rnd.Next(0, 100), FavoriteColor = new Color(rnd.Next(0, 0xFFFFFF))
            });

            someItems.AddRange(moreItems);

            someItems = someItems.OrderBy(r => rnd.Next()).ToList(); // Shuffle items

            Assert.AreEqual(100004, someItems.Count());

            Console.WriteLine("Arrange test list : " + globalSw.ElapsedMilliseconds);

            globalSw.Reset();

            var indexSpec = IndexSpecification <SimpleClass> .Build()
                            .With(person => person.Name)
                            .With(person => person.Age);

            var theIndexSet = new IndexSet <SimpleClass>(someItems, indexSpec);

            theIndexSet.UnableToUseIndex += (e, args) =>
            {
                throw new Exception(args.Message);
            };

            Console.WriteLine("Define index : " + globalSw.ElapsedMilliseconds);

            globalSw.Reset();

            Stopwatch sw = new Stopwatch();

            // Search a 1000 times in index

            globalSw.Start();
            for (int i = 0; i < 1000; i++)
            {
                sw.Start();

                var inIndexSearch = theIndexSet.Where(item => item.Age == 13 && item.Name == "Adriana Erickson");
                Assert.AreEqual(1, inIndexSearch.Count());

                sw.Stop();

                if (i == 0)
                {
                    Console.WriteLine("In index (first iteration) : " + sw.ElapsedMilliseconds);
                }

                if (i == 1)
                {
                    Console.WriteLine("In index (second iteration) : " + sw.ElapsedMilliseconds);
                }

                //Console.WriteLine("In index : " + sw.ElapsedMilliseconds);

                sw.Reset();
            }

            Console.WriteLine("In index global time : " + globalSw.ElapsedMilliseconds);

            globalSw.Reset();

            sw.Reset();

            // Search a 1000 times in list

            globalSw.Start();
            for (int i = 0; i < 1000; i++)
            {
                sw.Start();
                var inListSearch = someItems.Where(item => item.Age == 13 && item.Name == "Adriana Erickson");
                Assert.AreEqual(1, inListSearch.Count());

                sw.Stop();
                //Console.WriteLine("In list : " + sw.ElapsedMilliseconds);
                sw.Reset();
            }

            Console.WriteLine("In list global time : " + globalSw.ElapsedMilliseconds);
        }