Example #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?");
        }
Example #2
0
        public void can_look_up_paths_by_value_from_serialised_data()
        {
            // you can assign the same value to multiple paths
            // this could be quite useful, but I'd like to be able to
            // reverse the process -- see what paths an objects is bound
            // to. Could be a simple set of scans (slow) or a restructuring
            // of the internal data.

            var source = new ReverseTrie <ByteString>();

            source.Add("very different", "value0");
            source.Add("my/path/1", "value1");
            source.Add("my/path/2", "value2");
            source.Add("b - very different", "value0");
            source.Add("my/other/path", "value3");
            source.Add("my/other/path/longer", "value4");
            source.Add("another/path/for/3", "value3");
            source.Add("z - very different", "value0");

            var bytes         = source.Freeze();
            var reconstituted = new ReverseTrie <ByteString>();

            bytes.Seek(0, SeekOrigin.Begin);
            reconstituted.Defrost(bytes);

            var result = string.Join(", ", reconstituted.GetPathsForEntry("value3"));

            Assert.That(result, Is.EqualTo("my/other/path, another/path/for/3"));
        }