Ejemplo n.º 1
0
        public void Clear()
        {
            IIndex         sut     = GetIndex();
            IInMemoryIndex imIndex = sut as IInMemoryIndex;

            IDocument doc = MockDocument("Doc", "Document", "ptdoc", DateTime.Now);

            if (imIndex != null)
            {
                imIndex.IndexChanged += AutoHandlerForDocumentStorage;
            }
            sut.StoreDocument(doc, null, PlainTextDocumentContent, null);

            bool eventFired = false;

            if (imIndex != null)
            {
                imIndex.IndexChanged += delegate(object sender, IndexChangedEventArgs e)
                {
                    eventFired = true;
                };
            }

            sut.Clear(null);

            if (imIndex != null)
            {
                Assert.True(eventFired, "IndexChanged event not fired");
            }
            Assert.Equal(0, sut.TotalDocuments);
            Assert.Equal(0, sut.TotalWords);
            Assert.Equal(0, sut.TotalOccurrences);
            Assert.Empty(sut.Search(new SearchParameters("document")));
        }
Ejemplo n.º 2
0
        public void Clear()
        {
            IIndex         index   = GetIndex();
            IInMemoryIndex imIndex = index as IInMemoryIndex;

            IDocument doc = MockDocument("Doc", "Document", "ptdoc", DateTime.Now);

            if (imIndex != null)
            {
                imIndex.IndexChanged += AutoHandlerForDocumentStorage;
            }

            index.StoreDocument(doc, null, PlainTextDocumentContent, null);

            bool eventFired = false;

            if (imIndex != null)
            {
                imIndex.IndexChanged += delegate(object sender, IndexChangedEventArgs e) {
                    eventFired = true;
                };
            }

            index.Clear(null);

            if (imIndex != null)
            {
                Assert.IsTrue(eventFired, "IndexChanged event not fired");
            }

            Assert.AreEqual(0, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(0, index.TotalWords, "Wrong word count");
            Assert.AreEqual(0, index.TotalOccurrences, "Wrong occurrence count");
            Assert.AreEqual(0, index.Search(new SearchParameters("document")).Count, "Wrong result count");
        }
Ejemplo n.º 3
0
        public void TestClear()
        {
            _index.Clear();

            AssertEquals(0, ((FullTextSearchIndex)_index).Records.Length);
            AssertEquals(0, ((FullTextSearchIndex)_index).Postings.Length);

            AssertSearchContains(_index.Search(new FullTextSearchExpression("chocolate")));
        }
Ejemplo n.º 4
0
 public override void Clear()
 {
     // TODO: not sure but the index might not own the objects in it,
     // so it cannot deallocate them
     //foreach (IPersistent o in this)
     //{
     //    o.Deallocate();
     //}
     index.Clear();
     nElems = 0;
     Modify();
 }
Ejemplo n.º 5
0
        public void Run(TestConfig config)
        {
            int count = config.Count;
            var res   = new TestEnumeratorResult();

            config.Result = res;

            var start = DateTime.Now;

            IDatabase db   = config.GetDatabase();
            Indices   root = (Indices)db.Root;

            Tests.Assert(root == null);
            root          = new Indices();
            root.strIndex = db.CreateIndex <string, Record>(IndexType.NonUnique);
            root.intIndex = db.CreateIndex <long, Record>(IndexType.NonUnique);
            db.Root       = root;
            IIndex <long, Record>   intIndex = root.intIndex;
            IIndex <string, Record> strIndex = root.strIndex;

            Record[] records;

            long key = 1999;
            int  i, j;

            for (i = 0; i < count; i++)
            {
                key = (3141592621L * key + 2718281829L) % 1000000007L;
                Record rec = new Record();
                rec.intKey = key;
                rec.strKey = Convert.ToString(key);
                for (j = (int)(key % 10); --j >= 0;)
                {
                    intIndex[rec.intKey] = rec;
                    strIndex[rec.strKey] = rec;
                }
            }
            db.Commit();
            res.InsertTime = DateTime.Now - start;

            start = DateTime.Now;
            key   = 1999;
            for (i = 0; i < count; i++)
            {
                key = (3141592621L * key + 2718281829L) % 1000000007L;
                Key fromInclusive    = new Key(key);
                Key fromInclusiveStr = new Key(Convert.ToString(key));
                Key fromExclusive    = new Key(key, false);
                Key fromExclusiveStr = new Key(Convert.ToString(key), false);
                key = (3141592621L * key + 2718281829L) % 1000000007L;
                Key tillInclusive    = new Key(key);
                Key tillInclusiveStr = new Key(Convert.ToString(key));
                Key tillExclusive    = new Key(key, false);
                Key tillExclusiveStr = new Key(Convert.ToString(key), false);

                // int key ascent order
                records = intIndex.Get(fromInclusive, tillInclusive);
                j       = 0;
                foreach (Record rec in intIndex.Range(fromInclusive, tillInclusive, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = intIndex.Get(fromInclusive, tillExclusive);
                j       = 0;
                foreach (Record rec in intIndex.Range(fromInclusive, tillExclusive, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = intIndex.Get(fromExclusive, tillInclusive);
                j       = 0;
                foreach (Record rec in intIndex.Range(fromExclusive, tillInclusive, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = intIndex.Get(fromExclusive, tillExclusive);
                j       = 0;
                foreach (Record rec in intIndex.Range(fromExclusive, tillExclusive, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = intIndex.Get(fromInclusive, null);
                j       = 0;
                foreach (Record rec in intIndex.Range(fromInclusive, null, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = intIndex.Get(fromExclusive, null);
                j       = 0;
                foreach (Record rec in intIndex.Range(fromExclusive, null, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = intIndex.Get(null, tillInclusive);
                j       = 0;
                foreach (Record rec in intIndex.Range(null, tillInclusive, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = intIndex.Get(null, tillExclusive);
                j       = 0;
                foreach (Record rec in intIndex.Range(null, tillExclusive, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = intIndex.ToArray();
                j       = 0;
                foreach (Record rec in intIndex)
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                // int key descent order
                records = intIndex.Get(fromInclusive, tillInclusive);
                j       = records.Length;
                foreach (Record rec in intIndex.Range(fromInclusive, tillInclusive, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = intIndex.Get(fromInclusive, tillExclusive);
                j       = records.Length;
                foreach (Record rec in intIndex.Range(fromInclusive, tillExclusive, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = intIndex.Get(fromExclusive, tillInclusive);
                j       = records.Length;
                foreach (Record rec in intIndex.Range(fromExclusive, tillInclusive, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = intIndex.Get(fromExclusive, tillExclusive);
                j       = records.Length;
                foreach (Record rec in intIndex.Range(fromExclusive, tillExclusive, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = intIndex.Get(fromInclusive, null);
                j       = records.Length;
                foreach (Record rec in intIndex.Range(fromInclusive, null, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = intIndex.Get(fromExclusive, null);
                j       = records.Length;
                foreach (Record rec in intIndex.Range(fromExclusive, null, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = intIndex.Get(null, tillInclusive);
                j       = records.Length;
                foreach (Record rec in intIndex.Range(null, tillInclusive, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = intIndex.Get(null, tillExclusive);
                j       = records.Length;
                foreach (Record rec in intIndex.Range(null, tillExclusive, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = intIndex.ToArray();
                j       = records.Length;
                foreach (Record rec in intIndex.Reverse())
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                // str key ascent order
                records = strIndex.Get(fromInclusiveStr, tillInclusiveStr);
                j       = 0;
                foreach (Record rec in strIndex.Range(fromInclusiveStr, tillInclusiveStr, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = strIndex.Get(fromInclusiveStr, tillExclusiveStr);
                j       = 0;
                foreach (Record rec in strIndex.Range(fromInclusiveStr, tillExclusiveStr, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = strIndex.Get(fromExclusiveStr, tillInclusiveStr);
                j       = 0;
                foreach (Record rec in strIndex.Range(fromExclusiveStr, tillInclusiveStr, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = strIndex.Get(fromExclusiveStr, tillExclusiveStr);
                j       = 0;
                foreach (Record rec in strIndex.Range(fromExclusiveStr, tillExclusiveStr, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = strIndex.Get(fromInclusiveStr, null);
                j       = 0;
                foreach (Record rec in strIndex.Range(fromInclusiveStr, null, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = strIndex.Get(fromExclusiveStr, null);
                j       = 0;
                foreach (Record rec in strIndex.Range(fromExclusiveStr, null, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = strIndex.Get(null, tillInclusiveStr);
                j       = 0;
                foreach (Record rec in strIndex.Range(null, tillInclusiveStr, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = strIndex.Get(null, tillExclusiveStr);
                j       = 0;
                foreach (Record rec in strIndex.Range(null, tillExclusiveStr, IterationOrder.AscentOrder))
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                records = strIndex.ToArray();
                j       = 0;
                foreach (Record rec in strIndex)
                {
                    Tests.Assert(rec == records[j++]);
                }
                Tests.Assert(j == records.Length);

                // str key descent order
                records = strIndex.Get(fromInclusiveStr, tillInclusiveStr);
                j       = records.Length;
                foreach (Record rec in strIndex.Range(fromInclusiveStr, tillInclusiveStr, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = strIndex.Get(fromInclusiveStr, tillExclusiveStr);
                j       = records.Length;
                foreach (Record rec in strIndex.Range(fromInclusiveStr, tillExclusiveStr, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = strIndex.Get(fromExclusiveStr, tillInclusiveStr);
                j       = records.Length;
                foreach (Record rec in strIndex.Range(fromExclusiveStr, tillInclusiveStr, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = strIndex.Get(fromExclusiveStr, tillExclusiveStr);
                j       = records.Length;
                foreach (Record rec in strIndex.Range(fromExclusiveStr, tillExclusiveStr, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = strIndex.Get(fromInclusiveStr, null);
                j       = records.Length;
                foreach (Record rec in strIndex.Range(fromInclusiveStr, null, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = strIndex.Get(fromExclusiveStr, null);
                j       = records.Length;
                foreach (Record rec in strIndex.Range(fromExclusiveStr, null, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = strIndex.Get(null, tillInclusiveStr);
                j       = records.Length;
                foreach (Record rec in strIndex.Range(null, tillInclusiveStr, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = strIndex.Get(null, tillExclusiveStr);
                j       = records.Length;
                foreach (Record rec in strIndex.Range(null, tillExclusiveStr, IterationOrder.DescentOrder))
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);

                records = strIndex.ToArray();
                j       = records.Length;
                foreach (Record rec in strIndex.Reverse())
                {
                    Tests.Assert(rec == records[--j]);
                }
                Tests.Assert(j == 0);
            }
            res.IterationTime = DateTime.Now - start;

            strIndex.Clear();
            intIndex.Clear();

            Tests.Assert(!strIndex.GetEnumerator().MoveNext());
            Tests.Assert(!intIndex.GetEnumerator().MoveNext());
            Tests.Assert(!strIndex.Reverse().GetEnumerator().MoveNext());
            Tests.Assert(!intIndex.Reverse().GetEnumerator().MoveNext());
            db.Commit();
            db.Gc();
            db.Close();
        }
Ejemplo n.º 6
0
 internal virtual void Release()
 {
     idx.Clear();
 }
Ejemplo n.º 7
0
        private static void Run <T>(IIndex <int, TRectangle, TPoint> index, IList <Tuple <int, T> > data,
                                    BuildSmallUpdates <T> makeSmallUpdate,
                                    BuildLargeUpdates <T> makeLargeUpdate,
                                    AddEntries <T> addEntries,
                                    DoUpdate <T> doUpdate)
        {
            // Get new randomizer.
            var random = new MersenneTwister(Seed);

            // Get stop watch for profiling.
            var watch = new Stopwatch();

            // Also allocate the ids to look up in advance.
            var rangeQueries = new List <Tuple <TPoint, float> >(Operations);
            var areaQueries  = new List <TRectangle>(Operations);

            // And updates.
            var smallUpdates = new List <Tuple <int, T> >(Operations);
            var largeUpdates = new List <Tuple <int, T> >(Operations);

            var addTime              = new DoubleSampling(Iterations);
            var rangeQueryTime       = new DoubleSampling(Iterations);
            var areaQueryTime        = new DoubleSampling(Iterations);
            var smallUpdateTime      = new DoubleSampling(Iterations);
            var largeUpdateTime      = new DoubleSampling(Iterations);
            var highLoadRemoveTime   = new DoubleSampling(Iterations);
            var mediumLoadRemoveTime = new DoubleSampling(Iterations);
            var lowLoadRemoveTime    = new DoubleSampling(Iterations);

            Console.Write("Doing {0} iterations... ", Iterations);

            for (var i = 0; i < Iterations; i++)
            {
                Console.Write("{0}. ", i + 1);

                // Clear the index.
                index.Clear();

                // Generate look up ids in advance.
                rangeQueries.Clear();
                for (var j = 0; j < Operations; j++)
                {
                    rangeQueries.Add(Tuple.Create(random.NextVector(Area), MinQueryRange + (MaxQueryRange - MinQueryRange) * (float)random.NextDouble()));
                }
                areaQueries.Clear();
                for (var j = 0; j < Operations; j++)
                {
                    areaQueries.Add(random.NextRectangle(Area, MinQueryRange * 2, MaxQueryRange * 2));
                }

                // Generate position updates.
                smallUpdates.Clear();
                largeUpdates.Clear();
                for (var j = 0; j < Operations; j++)
                {
                    // High chance it remains in the same cell.
                    makeSmallUpdate(smallUpdates, data, random, j);
                }
                for (var j = 0; j < Operations; j++)
                {
                    // High chance it will be outside the original cell.
                    makeLargeUpdate(largeUpdates, data, random, j);
                }

                // Test time to add.
                try
                {
                    watch.Reset();
                    watch.Start();
                    addEntries(index, data);
                    watch.Stop();
                    addTime.Put(watch.ElapsedMilliseconds / (double)NumberOfObjects);
                }
                catch (NotSupportedException)
                {
                }

                // Test update time.
                try
                {
                    watch.Reset();
                    watch.Start();
                    foreach (var update in smallUpdates)
                    {
                        doUpdate(index, update);
                    }
                    watch.Stop();
                    smallUpdateTime.Put(watch.ElapsedMilliseconds / (double)smallUpdates.Count);
                }
                catch (NotSupportedException)
                {
                }

                try
                {
                    watch.Reset();
                    watch.Start();
                    foreach (var update in largeUpdates)
                    {
                        doUpdate(index, update);
                    }
                    watch.Stop();
                    largeUpdateTime.Put(watch.ElapsedMilliseconds / (double)largeUpdates.Count);
                }
                catch (NotSupportedException)
                {
                }

                // Test look up time.
                try
                {
                    watch.Reset();
                    watch.Start();
                    for (var j = 0; j < Operations; j++)
                    {
#if USE_CALLBACK
                        index.Find(rangeQueries[j].Item1, rangeQueries[j].Item2, value => true);
#else
                        index.Find(rangeQueries[j].Item1, rangeQueries[j].Item2, ref DummyCollection <int> .Instance);
#endif
                    }
                    watch.Stop();
                    rangeQueryTime.Put(watch.ElapsedMilliseconds / (double)Operations);
                }
                catch (NotSupportedException)
                {
                }

                try
                {
                    watch.Reset();
                    watch.Start();
                    for (var j = 0; j < Operations; j++)
                    {
                        var rect = areaQueries[j];
#if USE_CALLBACK
                        index.Find(rect, value => true);
#else
                        index.Find(rect, ref DummyCollection <int> .Instance);
#endif
                    }
                    watch.Stop();
                    areaQueryTime.Put(watch.ElapsedMilliseconds / (double)Operations);
                }
                catch (NotSupportedException)
                {
                }

                // Test removal time.
                try
                {
                    watch.Reset();
                    watch.Start();
                    for (var j = 0; j < NumberOfObjects / 3; j++)
                    {
                        index.Remove(data[j].Item1);
                    }
                    watch.Stop();
                    highLoadRemoveTime.Put(watch.ElapsedMilliseconds / (double)(NumberOfObjects / 3));
                }
                catch (NotSupportedException)
                {
                }

                try
                {
                    watch.Reset();
                    watch.Start();
                    for (var j = NumberOfObjects / 3; j < NumberOfObjects * 2 / 3; j++)
                    {
                        index.Remove(data[j].Item1);
                    }
                    watch.Stop();
                    mediumLoadRemoveTime.Put(watch.ElapsedMilliseconds / (double)(NumberOfObjects / 3));
                }
                catch (NotSupportedException)
                {
                }

                try
                {
                    watch.Reset();
                    watch.Start();
                    for (var j = NumberOfObjects * 2 / 3; j < NumberOfObjects; j++)
                    {
                        index.Remove(data[j].Item1);
                    }
                    watch.Stop();
                    lowLoadRemoveTime.Put(watch.ElapsedMilliseconds / (double)(NumberOfObjects / 3));
                }
                catch (NotSupportedException)
                {
                }
            }

            Console.WriteLine("Done!");

            Console.WriteLine("Operation           | Mean      | Std.dev.\n" +
                              "Add:                | {0:0.00000}ms | {1:0.00000}ms\n" +
                              "Range query:        | {2:0.00000}ms | {3:0.00000}ms\n" +
                              "Area query:         | {4:0.00000}ms | {5:0.00000}ms\n" +
                              "Update (small):     | {6:0.00000}ms | {7:0.00000}ms\n" +
                              "Update (large):     | {8:0.00000}ms | {9:0.00000}ms\n" +
                              "Remove (high load): | {10:0.00000}ms | {11:0.00000}ms\n" +
                              "Remove (med. load): | {12:0.00000}ms | {13:0.00000}ms\n" +
                              "Remove (low load):  | {14:0.00000}ms | {15:0.00000}ms",
                              addTime.Mean(), addTime.StandardDeviation(),
                              rangeQueryTime.Mean(), rangeQueryTime.StandardDeviation(),
                              areaQueryTime.Mean(), areaQueryTime.StandardDeviation(),
                              smallUpdateTime.Mean(), smallUpdateTime.StandardDeviation(),
                              largeUpdateTime.Mean(), largeUpdateTime.StandardDeviation(),
                              highLoadRemoveTime.Mean(), highLoadRemoveTime.StandardDeviation(),
                              mediumLoadRemoveTime.Mean(), mediumLoadRemoveTime.StandardDeviation(),
                              lowLoadRemoveTime.Mean(), lowLoadRemoveTime.StandardDeviation());
        }