예제 #1
0
        public void SeqOnEmptyReturnNull()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();
            IPersistentMap           m = PersistentArrayMap.create(d);
            ISeq s = m.seq();

            Expect(s, Null);
        }
예제 #2
0
        public static int mapHasheq(IPersistentMap m)
        {
            int hash = 0;

            for (ISeq s = m.seq(); s != null; s = s.next())
            {
                IMapEntry e = (IMapEntry)s.first();
                hash += Util.hasheq(e.key()) ^ Util.hasheq(e.val());
            }
            return(hash);
        }
예제 #3
0
        public static int mapHash(IPersistentMap m)
        {
            int hash = 0;

            for (ISeq s = m.seq(); s != null; s = s.next())
            {
                IMapEntry me = (IMapEntry)s.first();
                hash += (me.key() == null ? 0 : me.key().GetHashCode())
                        ^ (me.val() == null ? 0 : me.val().GetHashCode());
            }
            return(hash);
        }
예제 #4
0
            static public ValSeq createFromMap(IPersistentMap map)
            {
                if (map == null)
                {
                    return(null);
                }
                ISeq seq = map.seq();

                if (seq == null)
                {
                    return(null);
                }
                return(new ValSeq(seq, map));
            }
예제 #5
0
        /// <summary>
        /// Notify all watchers.
        /// </summary>
        public void notifyWatches(object oldval, object newval)
        {
            IPersistentMap ws = _watches;

            if (ws.count() > 0)
            {
                for (ISeq s = ws.seq(); s != null; s = s.next())
                {
                    IMapEntry me = (IMapEntry)s.first();
                    IFn       fn = (IFn)me.val();
                    if (fn != null)
                    {
                        fn.invoke(me.key(), this, oldval, newval);
                    }
                }
            }
        }
예제 #6
0
        public void SeqOnNonEmptyIterates()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";
            IPersistentMap m   = PersistentArrayMap.create(d);
            ISeq           s   = m.seq();
            IMapEntry      me1 = (IMapEntry)s.first();
            IMapEntry      me2 = (IMapEntry)s.next().first();
            ISeq           end = s.next().next();

            Expect(s.count(), EqualTo(2));
            Expect(me1.key(), EqualTo(1) | EqualTo(2));
            Expect(me1.val(), EqualTo(((int)me1.key() == 1 ? "a" : "b")));
            Expect(me2.key(), EqualTo(1) | EqualTo(2));
            Expect(me2.val(), EqualTo(((int)me2.key() == 1 ? "a" : "b")));
            Expect(end, Null);
        }
예제 #7
0
        public static bool mapEquals(IPersistentMap m1, Object obj)
        {
            if (m1 == obj)
            {
                return(true);
            }

            //if(!(obj instanceof Map))
            //    return false;
            //Map m = (Map) obj;

            IDictionary d = obj as IDictionary;

            if (d == null)
            {
                return(false);
            }

            // Java had the following.
            // This works on other APersistentMap implementations, but not on
            //  arbitrary dictionaries.
            //if (d.Count != m1.Count || d.GetHashCode() != m1.GetHashCode())
            //    return false;

            if (d.Count != m1.count())
            {
                return(false);
            }

            for (ISeq s = m1.seq(); s != null; s = s.next())
            {
                IMapEntry me    = (IMapEntry)s.first();
                bool      found = d.Contains(me.key());
                if (!found || !Util.equals(me.val(), d[me.key()]))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #8
0
 /// <summary>
 /// Return a seq of the items after the first.  Calls <c>seq</c> on its argument.  If there are no more items, returns nil."
 /// </summary>
 /// <returns>A seq of the items after the first, or <c>nil</c> if there are no more items.</returns>
 public override ISeq next()
 {
     return((_i + 1 < _vals.Length)
         ? new Seq(_meta, _keys.next(), _vals, _i + 1, _ext)
         : _ext.seq());
 }
예제 #9
0
 /// <summary>
 /// Construct a <see cref="MapEnumerator">MapEnumerator</see> from a persistent map.
 /// </summary>
 /// <param name="map">The map to iterate over.</param>
 public MapEnumerator(IPersistentMap map)
 {
     _seqEnum = new SeqEnumerator(map.seq());
 }
예제 #10
0
 /// <summary>
 /// Gets an ISeq to allow first/rest iteration through the collection.
 /// </summary>
 /// <returns>An ISeq for iteration.</returns>
 public ISeq seq()
 {
     return(APersistentMap.KeySeq.create(_impl.seq()));
 }
예제 #11
0
 /// <summary>
 /// Construct a <see cref="MapEnumerator">MapEnumerator</see> from a persistent map.
 /// </summary>
 /// <param name="map">The map to iterate over.</param>
 public MapEnumerator(IPersistentMap map)
 {
     _seqEnum = new SeqEnumerator(map.seq());
 }
예제 #12
0
        private static void EmitExposers(TypeBuilder proxyTB, Type superClass, IPersistentMap exposesFields)
        {
            for ( ISeq s = exposesFields.seq(); s != null; s = s.next() )
            {
                IMapEntry me = (IMapEntry)s.first();
                Symbol protectedFieldSym = (Symbol)me.key();
                IPersistentMap accessMap = (IPersistentMap)me.val();

                string fieldName = protectedFieldSym.Name;
                Symbol getterSym = (Symbol)accessMap.valAt(_getKw, null);
                Symbol setterSym = (Symbol)accessMap.valAt(_setKW, null);

                FieldInfo fld = null;

                if ( getterSym != null || setterSym != null )
                    fld = superClass.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance);

                if (getterSym != null)
                {
                    MethodAttributes attribs = MethodAttributes.Public;
                    if (fld.IsStatic)
                        attribs |= MethodAttributes.Static;

                    MethodBuilder mb = proxyTB.DefineMethod(getterSym.Name, attribs, fld.FieldType, Type.EmptyTypes);
                    ILGenerator gen = mb.GetILGenerator();
                    if (fld.IsStatic)
                        gen.Emit(OpCodes.Ldsfld, fld);
                    else
                    {
                        gen.Emit(OpCodes.Ldarg_0);
                        gen.Emit(OpCodes.Ldfld, fld);
                    }
                    gen.Emit(OpCodes.Ret);
                }

                if (setterSym != null)
                {
                    MethodAttributes attribs = MethodAttributes.Public;
                    if (fld.IsStatic)
                        attribs |= MethodAttributes.Static;

                    MethodBuilder mb = proxyTB.DefineMethod(setterSym.Name, attribs, typeof(void), new Type[] { fld.FieldType });
                    ILGenerator gen = mb.GetILGenerator();
                    if (fld.IsStatic)
                    {
                        gen.Emit(OpCodes.Ldarg_0);
                        gen.Emit(OpCodes.Stsfld, fld);
                    }
                    else
                    {
                        gen.Emit(OpCodes.Ldarg_0);
                        gen.Emit(OpCodes.Ldarg_1);
                        gen.Emit(OpCodes.Stfld, fld);
                    }
                    gen.Emit(OpCodes.Ret);
                }
            }
        }