public ImmutableHashSet <T> Add(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var operation = new SetAddOperation <T>(item);
            var newRoot   = _root.Modify(item.GetHashCode(), operation) ?? EmptyPatriciaTrie <T> .Instance;

            return(newRoot == _root ? this : new ImmutableHashSet <T>(newRoot));
        }
Exemplo n.º 2
0
        public ImmutableHashDictionary <TKey, TValue> Add(KeyValuePair <TKey, TValue> item)
        {
            if (item.Key == null)
            {
                throw ExceptionHelper.GetKeyCannotBeNullException("item");
            }

            var operation = new DictionaryAddOperation <TKey, TValue>(item);
            var newRoot   = _root.Modify(item.Key.GetHashCode(), operation);

            if (newRoot == _root)
            {
                throw ExceptionHelper.GetKeyAlreadyExistsException(item.Key, "item");
            }

            return(new ImmutableHashDictionary <TKey, TValue>(newRoot));
        }