示例#1
0
        // ------------------------------------------------------------------
        // deserialization thereof

        public static IPersistentMap DeserializeKeyVarMap(string[] ks, string[] vs)
        {
            ITransientMap m = (ITransientMap)PersistentHashMap.EMPTY.asTransient();

            for (int i = 0; i < ks.Length; i++)
            {
                m.assoc(Keyword.intern(ks[i]), DeserializeVar(vs[i]));
            }
            return(m.persistent());
        }
示例#2
0
        public static IPersistentMap DictionaryToMap <T1, T2> (Dictionary <T1, T2> dict)
        {
            ITransientMap bldg = (ITransientMap)PersistentHashMap.EMPTY.asTransient();

            foreach (var kv in dict)
            {
                bldg = bldg.assoc(kv.Key, kv.Value);
            }
            return(bldg.persistent());
        }
        public static IPersistentMap create(IDictionary other)
        {
            ITransientMap ret = (ITransientMap)EMPTY.asTransient();

            foreach (DictionaryEntry de in other)
            {
                ret = ret.assoc(de.Key, de.Value);
            }
            return(ret.persistent());
        }
示例#4
0
        public ITransientCollection conj(object val)
        {
            ITransientMap m = _impl.assoc(val, val);

            if (m != _impl)
            {
                _impl = m;
            }
            return(this);
        }
示例#5
0
        private object ReadMap(TextReader source)
        {
            ConsumeChar(source);
            ReadWhiteSpace(source);
            ITransientMap transientMap = (ITransientMap)PersistentHashMap.EMPTY.asTransient();

            while (PeekChar(source) != '}')
            {
                var key = Read(source);
                ReadWhiteSpace(source);
                var val = Read(source);
                ReadWhiteSpace(source);
                transientMap = transientMap.assoc(key, val);
            }

            ConsumeChar(source);
            return(transientMap.persistent());
        }
示例#6
0
        public ITransientMap conj(object val)
        {
            EnsureEditable();

            {
                IMapEntry e = val as IMapEntry;
                if (e != null)
                {
                    return(assoc(e.key(), e.val()));
                }
            }

            if (val is DictionaryEntry)
            {
                DictionaryEntry de = (DictionaryEntry)val;
                return(assoc(de.Key, de.Value));
            }

            {
                IPersistentVector v = val as IPersistentVector;
                if (v != null)
                {
                    if (v.count() != 2)
                    {
                        throw new ArgumentException("Vector arg to map conj must be a pair");
                    }
                    return(assoc(v.nth(0), v.nth(1)));
                }
            }

            // TODO: also handle KeyValuePair?
            ITransientMap ret = this;

            for (ISeq es = RT.seq(val); es != null; es = es.next())
            {
                IMapEntry e = (IMapEntry)es.first();
                ret = ret.assoc(e.key(), e.val());
            }
            return(ret);
        }