public void ContainsKeyOnExistingKeyIsTrue() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.containsKey(1)); Expect(m.containsKey(2)); }
public void addAlias(Symbol alias, Namespace ns) { if (alias == null) { throw new ArgumentNullException("alias", "Expecting Symbol + Namespace"); } if (ns == null) { throw new ArgumentNullException("ns", "Expecting Symbol + Namespace"); } IPersistentMap map = Aliases; // race condition while (!map.containsKey(alias)) { IPersistentMap newMap = map.assoc(alias, ns); _aliases.CompareAndSet(map, newMap); map = Aliases; } // you can rebind an alias, but only to the initially-aliased namespace if (!map.valAt(alias).Equals(ns)) { throw new InvalidOperationException(String.Format("Alias {0} already exists in namespace {1}, aliasing {2}", alias, _name, map.valAt(alias))); } }
internal Expression GenLocal(GenContext context, LocalBinding lb) { if (context.Mode == CompilerMode.File && _closes.containsKey(lb)) { Expression expr = Expression.Field(_thisParam, lb.Name); Type primtType = lb.PrimitiveType; if (primtType != null) { expr = Compiler.MaybeBox(Expression.Convert(expr, primtType)); } return(expr); } else { return(lb.ParamExpression); } }
public void ContainsKeyOnMissingKeyIsFalse() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.containsKey(3), False); }
public void ContainsKeyNotConfusedByValue() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.containsKey("a"), False); }
public void removeAlias(Symbol alias) { IPersistentMap map = Aliases; while (map.containsKey(alias)) { IPersistentMap newMap = map.without(alias); _aliases.CompareAndSet(map, newMap); map = Aliases; } }
public void CreateOnISeqReturnsMap() { object[] items = new object[] { 1, "a", 2, "b" }; ArrayList a = new ArrayList(items); ISeq s = PersistentList.create(a).seq(); IPersistentMap m = PersistentTreeMap.create(s); Expect(m.count(), EqualTo(2)); Expect(m.valAt(1), EqualTo("a")); Expect(m.valAt(2), EqualTo("b")); Expect(m.containsKey(3), False); }
public void CreateOnListReturnsMap() { object[] items = new object[] { 1, "a", 2, "b" }; ArrayList a = new ArrayList(items); IPersistentMap m = PersistentHashMap.create1(a); Expect(m.count(), EqualTo(2)); Expect(m.valAt(1), EqualTo("a")); Expect(m.valAt(2), EqualTo("b")); Expect(m.containsKey(3), False); }
public void CreateOnISeqReturnsMap() { object[] items = new object[] { 1, "a", 2, "b" }; ArrayList a = new ArrayList(items); ISeq s = PersistentList.create(a).seq(); IPersistentMap m = PersistentHashMap.create(s); Expect(m.count()).To.Equal(2); Expect(m.valAt(1)).To.Equal("a"); Expect(m.valAt(2)).To.Equal("b"); Expect(m.containsKey(3)).To.Be.False(); }
private static Type RegisterBaseClass(Type superType, Type baseType) { IPersistentMap map = _baseClassMapRef.Get(); while (!map.containsKey(superType)) { IPersistentMap newMap = map.assoc(superType, baseType); _baseClassMapRef.CompareAndSet(map, newMap); map = _baseClassMapRef.Get(); } return(LookupBaseClass(superType)); // may not be the one we defined -- race condition }
public void CreateOnDictionaryReturnsMap() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentTreeMap.create(d); Expect(m.count(), EqualTo(2)); Expect(m.valAt(1), EqualTo("a")); Expect(m.valAt(2), EqualTo("b")); Expect(m.containsKey(3), False); }
public void CreateOnDictionaryReturnsMap() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.count()).To.Equal(2); Expect(m.valAt(1)).To.Equal("a"); Expect(m.valAt(2)).To.Equal("b"); Expect(m.containsKey(3)).To.Be.False(); }
public void AssocExModifiesOnNewKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m1 = PersistentArrayMap.create(d); IPersistentMap m2 = m1.assocEx(3, "c"); Expect(m1.count(), EqualTo(2)); Expect(m1.containsKey(3), False); Expect(m2.count(), EqualTo(3)); Expect(m2.valAt(3), EqualTo("c")); }
public void AssocAddsOnNewKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m1 = PersistentArrayMap.create(d); IPersistentMap m2 = m1.assoc(3, "c"); Expect(m1.count()).To.Equal(2); Expect(m1.containsKey(3)).To.Be.False(); Expect(m2.count()).To.Equal(3); Expect(m2.valAt(3)).To.Equal("c"); }
public void WithoutOnExistingKeyRemovesKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[3] = "a"; d[5] = "b"; d[7] = "c"; IPersistentMap m1 = PersistentArrayMap.create(d); IPersistentMap m2 = m1.without(5); Expect(m1.count(), EqualTo(3)); Expect(m1.valAt(5), EqualTo("b")); Expect(m2.count(), EqualTo(2)); Expect(m2.containsKey(5), False); }
public void unmap(Symbol sym) { if (sym.Namespace != null) { throw new ArgumentException("Can't unintern a namespace-qualified symbol"); } IPersistentMap map = Mappings; while (map.containsKey(sym)) { IPersistentMap newMap = map.without(sym); _mappings.CompareAndSet(map, newMap); map = Mappings; } }
protected override object Read(PushbackTextReader r, char c, object opts) { object o = read(r, true, null, true, opts); Symbol oSym = o as Symbol; if (oSym == null) { throw new Exception("Invalid token: ##" + o); } if (!_specials.containsKey(oSym)) { throw new Exception("Unknown symbolic value: ##" + o); } return(_specials.valAt(oSym)); }
public void GetClojureFnMappingsWorks() { IProxy ip = _obj as IProxy; IPersistentMap map = ip.__getClojureFnMappings(); Expect(map.count()).To.Equal(6); Expect(map.containsKey("m1")); Expect(map.containsKey("m2")); Expect(map.containsKey("m2s")); Expect(map.containsKey("m2v")); Expect(map.containsKey("m3")); Expect(map.containsKey("m4")); }
private static void EmitMethods(TypeBuilder proxyTB, List <MethodSignature> sigs, Dictionary <string, List <MethodSignature> > overloads, Dictionary <string, FieldBuilder> varMap, IPersistentMap exposesMethods) { foreach (MethodSignature sig in sigs) { FieldBuilder regularFB = varMap[sig.Name]; FieldBuilder overloadFB = null; if (overloads.ContainsKey(sig.Name)) { overloadFB = varMap[OverloadName(sig)]; } switch (sig.Source) { case "super": EmitForwardingMethod(proxyTB, false, regularFB, overloadFB, sig, delegate(CljILGen gen) { gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0); for (int i = 0; i < sig.ParamTypes.Length; i++) { gen.EmitLoadArg(i + 1); // gen.Emit(OpCodes.Ldarg, (i + 1)); } gen.Emit(OpCodes.Call, sig.Method); // not gen.EmitCall(sig.Method) -- we need call versus callvirt }); break; case "interface": EmitForwardingMethod(proxyTB, false, regularFB, overloadFB, sig, delegate(CljILGen gen) { EmitUnsupported(gen, sig.Name); }); break; default: EmitForwardingMethod(proxyTB, sig.IsStatic, regularFB, overloadFB, sig, delegate(CljILGen gen) { EmitUnsupported(gen, sig.Name); }); break; } } if (exposesMethods != null) { foreach (MethodSignature sig in sigs) { if (sig.Source == "super") { Symbol name = Symbol.intern(sig.Name); if (exposesMethods.containsKey(name)) { CreateSuperCall(proxyTB, (Symbol)exposesMethods.valAt(name), sig.Method); } } } } }
/// <summary> /// Test if the set contains the key. /// </summary> /// <param name="key">The value to test for membership in the set.</param> /// <returns>True if the item is in the collection; false, otherwise.</returns> public bool contains(object key) { return(_impl.containsKey(key)); }
public static Object read(PushbackTextReader r, IPersistentMap opts) { return(read(r, !opts.containsKey(EOF), opts.valAt(EOF), false, opts)); }
private static void EmitMethods(TypeBuilder proxyTB, List<MethodSignature> sigs, Dictionary<string,List<MethodSignature>> overloads, Dictionary<string,FieldBuilder> varMap, IPersistentMap exposesMethods) { foreach (MethodSignature sig in sigs) { FieldBuilder regularFB = varMap[sig.Name]; FieldBuilder overloadFB = null; if (overloads.ContainsKey(sig.Name)) overloadFB = varMap[OverloadName(sig)]; switch (sig.Source) { case "super": EmitForwardingMethod(proxyTB, false, regularFB, overloadFB, sig, delegate(ILGen gen) { gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0); for (int i = 0; i < sig.ParamTypes.Length; i++) gen.EmitLoadArg(i + 1); // gen.Emit(OpCodes.Ldarg, (i + 1)); gen.Emit(OpCodes.Call, sig.Method); // not gen.EmitCall(sig.Method) -- we need call versus callvirt }); break; case "interface": EmitForwardingMethod(proxyTB, false, regularFB, overloadFB, sig, delegate(ILGen gen) { EmitUnsupported(gen, sig.Name); }); break; default: EmitForwardingMethod(proxyTB, sig.IsStatic, regularFB, overloadFB, sig, delegate(ILGen gen) { EmitUnsupported(gen, sig.Name); }); break; } } if (exposesMethods != null) { foreach (MethodSignature sig in sigs) { if (sig.Source == "super") { Symbol name = Symbol.intern(sig.Name); if (exposesMethods.containsKey(name)) CreateSuperCall(proxyTB, (Symbol)exposesMethods.valAt(name), sig.Method); } } } }
public static Object read(PushbackTextReader r, IPersistentMap opts) { return read(r, !opts.containsKey(EOF), opts.valAt(EOF), false, opts); }