Ejemplo n.º 1
0
        public void deleting_a_value_from_a_path()
        {
            var subject = new ReverseTrie <SerialGuid>();

            var val1 = SerialGuid.Wrap(Guid.NewGuid());
            var val2 = SerialGuid.Wrap(Guid.NewGuid());

            subject.Add("Deleted: no", val1);
            subject.Add("Deleted: yes", val2);

            subject.Delete("Deleted: yes");
            subject.Delete("Not present"); // ok to try non-paths

            // Get
            Assert.That(subject.Get("Deleted: no"), Is.EqualTo(val1), "Failed to find data to a known path");
            Assert.That(subject.Get("Deleted: yes"), Is.Null, "Should have been removed, but it's still there");

            // Search
            var all = string.Join(",", subject.Search("Deleted"));

            Assert.That(all, Is.EqualTo("Deleted: no"));

            // Look-up
            Assert.That(subject.GetPathsForEntry(val2), Is.Empty, "Value cache was not updated");
            Assert.That(subject.GetPathsForEntry(val1), Is.Not.Empty, "Value cache was destroyed?");
        }
Ejemplo n.º 2
0
        public void construction()
        {
            // Idea:
            // We build a trie (wide, not ternary) using backward links only (as an alternative to a persistent trie)
            // This is our permanent and growable data structure.
            // We then make a separate 'forward links index' as a NON-STORED in-memory cache.
            // This cache gets invalidated on every write, and rebuilt during a read if the invalidation flag is set.
            // (ThreadStatic on cache?)
            //
            // Note: using a normal persistent trie might cause an issue, as it duplicates on prefix reuse.

            var subject = new ReverseTrie <SerialGuid>();

            var val1 = SerialGuid.Wrap(Guid.NewGuid());
            var val2 = SerialGuid.Wrap(Guid.NewGuid());
            var val3 = SerialGuid.Wrap(Guid.NewGuid());
            var val4 = SerialGuid.Wrap(Guid.NewGuid());

            subject.Add("Hello world", val1);
            subject.Add("Hello Dave", val2);
            subject.Add("Jello world", val3);
            subject.Add("Hello worldly goods", val4);

            Console.WriteLine($"\r\nResult:\r\n{subject.DiagnosticDescription()}");
        }
Ejemplo n.º 3
0
        public void query_exact_path()
        {
            var subject = new ReverseTrie <SerialGuid>();

            var val1 = SerialGuid.Wrap(Guid.NewGuid());
            var val2 = SerialGuid.Wrap(Guid.NewGuid());
            var val3 = SerialGuid.Wrap(Guid.NewGuid());
            var val4 = SerialGuid.Wrap(Guid.NewGuid());

            subject.Add("Hello world", val1);
            subject.Add("Hello Dave", val2);
            subject.Add("Jello world", val3);
            subject.Add("Hello worldly goods", val4);

            var result1 = subject.Get("Hello Dave");
            var result2 = subject.Get("Hello Sam");

            Assert.That(result1, Is.EqualTo(val2), "Failed to find data to a known path");
            Assert.That(result2, Is.Null, "Was given a result to a path that was not added");
        }