clojure.lang.PersistentTreeMap.assoc C# (CSharp) Метод

assoc() публичный Метод

Add a new key/value pair.
Overwrites an exising value for the key, if present.
public assoc ( object key, object val ) : IPersistentMap
key object The key
val object The value
Результат IPersistentMap
        public override IPersistentMap assoc(object key, object val)
        {
            Box found = new Box(null);
            Node t = Add(_tree, key, val, found);
            if (t == null)
            {
                Node foundNode = (Node)found.Val;
                if (foundNode.Val == val)
                    return this;
                return new PersistentTreeMap(_comp, Replace(_tree, key, val), _count, meta());
            }

            return new PersistentTreeMap(_comp, t.Blacken(), _count + 1, meta());
        }

Usage Example

Пример #1
0
        public static PersistentTreeMap create(IComparer comp, ISeq items)
        {
            IPersistentMap ret = new PersistentTreeMap(comp);

            for (; items != null; items = items.next().next())
            {
                if (items.next() == null)
                {
                    throw new ArgumentException(string.Format("No value supplied for key: {0}", items.first()));
                }
                ret = ret.assoc(items.first(), RT.second(items));
            }
            return((PersistentTreeMap)ret);
        }
All Usage Examples Of clojure.lang.PersistentTreeMap::assoc