コード例 #1
0
        /// <summary>
        /// Joins two Patricia Tries having different keys with common branch.
        /// </summary>
        /// <param name="prefixA">Prfix of the first Trie.</param>
        /// <param name="nodeA">First Patricia Trie.</param>
        /// <param name="prefixB">Prefix of the second Trie.</param>
        /// <param name="nodeB">Second Trie.</param>
        /// <returns>New Patritia Trie node having given nodes as her children.</returns>
        public static IPatriciaNode <T> Join <T>(int prefixA, IPatriciaNode <T> nodeA, int prefixB, IPatriciaNode <T> nodeB)
        {
            var bb        = BranchingBit(prefixA, prefixB);
            var newPrefix = prefixA & (bb - 1);

            return((prefixA & bb) == 0 ? new PatriciaBranch <T>(newPrefix, bb, nodeA, nodeB) : new PatriciaBranch <T>(newPrefix, bb, nodeB, nodeA));
        }
コード例 #2
0
        private IPatriciaNode <T> CreateNode <T>(IEnumerable <T> items)
            where T : class
        {
            IPatriciaNode <T> empty = EmptyPatriciaTrie <T> .Instance;

            return(items.Aggregate(empty, (current, item) => current.Modify(item.GetHashCode(), InsertOperation(item))));
        }
コード例 #3
0
        private ImmutableHashSet(IPatriciaNode <T> root)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }

            _root = root;
        }
コード例 #4
0
        public void RemovingSequentialKeys_Test()
        {
            var items = Enumerable.Range(0, _items.Length).
                        Zip(_items, (i, s) => new KeyValuePair <int, string>(i, s)).ToArray();

            IPatriciaNode <string> empty = EmptyPatriciaTrie <string> .Instance;
            var node = items.Aggregate(empty, (current, item) => current.Modify(item.Key, InsertOperation(item.Value)));

            foreach (var item in items)
            {
                node = node.Modify(item.Key, NullOperation <string>()) ?? EmptyPatriciaTrie <string> .Instance;
                CollectionAssert.DoesNotContain(node.GetItems(), item.Value);
            }
        }
コード例 #5
0
        // Constructors

        public ImmutableHashSet()
        {
            _root = EmptyPatriciaTrie <T> .Instance;
        }
コード例 #6
0
 public PatriciaBranch(int prefix, int mask, IPatriciaNode <T> left, IPatriciaNode <T> right)
     : this(prefix, mask, new[] { left, right })
 {
 }
コード例 #7
0
 private ImmutableHashDictionary(IPatriciaNode <KeyValuePair <TKey, TValue> > root)
 {
     _root = root;
 }
コード例 #8
0
        // Constructors

        public ImmutableHashDictionary()
        {
            _root = EmptyPatriciaTrie <KeyValuePair <TKey, TValue> > .Instance;
        }