public void ThreeItems() { var dict = new SmallDictionary<int, string>(); dict[2] = "abc"; dict[5] = "def"; dict[11] = "third"; Assert.AreEqual(3, dict.Count); Assert.AreEqual("abc", dict[2]); Assert.AreEqual("def", dict[5]); Assert.AreEqual("third", dict[11]); string output; Assert.IsFalse(dict.TryGetValue(3, out output)); Assert.IsNull(output); Assert.IsTrue(dict.TryGetValue(2, out output)); Assert.AreEqual("abc", output); Assert.IsTrue(dict.TryGetValue(5, out output)); Assert.AreEqual("def", output); Assert.IsTrue(dict.TryGetValue(11, out output)); Assert.AreEqual("third", output); Assert.IsFalse(dict.ContainsKey(3)); Assert.IsTrue(dict.ContainsKey(2)); Assert.IsTrue(dict.ContainsKey(5)); Assert.IsTrue(dict.ContainsKey(11)); }
public void OneItem() { var dict = new SmallDictionary<int, string>(); dict[2] = "abc"; Assert.AreEqual(1, dict.Count); Assert.AreEqual("abc", dict[2]); string output; Assert.IsFalse(dict.TryGetValue(3, out output)); Assert.IsNull(output); Assert.IsTrue(dict.TryGetValue(2, out output)); Assert.AreEqual("abc", output); Assert.IsFalse(dict.ContainsKey(3)); Assert.IsTrue(dict.ContainsKey(2)); }
public WithLambdaParametersBinder(LambdaSymbol lambdaSymbol, Binder enclosing) : base(enclosing) { this.lambdaSymbol = lambdaSymbol; this.parameterMap = new MultiDictionary <string, ParameterSymbol>(); var parameters = lambdaSymbol.Parameters; if (!parameters.IsDefaultOrEmpty) { _definitionMap = new SmallDictionary <string, ParameterSymbol>(); foreach (var parameter in parameters) { if (!parameter.IsDiscard) { var name = parameter.Name; this.parameterMap.Add(name, parameter); if (!_definitionMap.ContainsKey(name)) { _definitionMap.Add(name, parameter); } } } } }
/// <summary> /// Synthesizes the correct receiver of a witness invocation. /// </summary> /// <param name="syntax">The syntax to be attached to the node.</param> /// <param name="witness">The witness we are calling into.</param> /// <returns> /// The appropriate receiver for this witness. /// If we're in a block, this will be a local variable; /// otherwise, this will be a <c>default()</c>. /// </returns> private BoundExpression SynthesizeWitnessReceiver(SyntaxNode syntax, TypeSymbol witness) { Debug.Assert(syntax != null, "Syntax for witness receiver should not be null"); Debug.Assert(witness != null, "Witness receiver should not be null"); Debug.Assert(witness.IsInstanceType() || witness.IsConceptWitness, "Witness receiver should be a valid witness"); // If we're not in a block, we can't synthesise a local if (_rootStatement.Kind != BoundKind.Block) { return(new BoundDefaultExpression(syntax, witness) { WasCompilerGenerated = true }); } // TODO(@MattWindsor91): this is probably inefficient if (_conceptWitnessesToHoist == null) { _conceptWitnessesToHoist = new SmallDictionary <TypeSymbol, LocalSymbol>(); } if (!_conceptWitnessesToHoist.ContainsKey(witness)) { _conceptWitnessesToHoist.Add(witness, WitnessDictionaryLocal(witness, syntax)); } var local = _conceptWitnessesToHoist[witness]; return(new BoundLocal(syntax, local, null, witness) { WasCompilerGenerated = true }); }
private void DeclareLocals <TSymbol>(Scope scope, ImmutableArray <TSymbol> locals) where TSymbol : Symbol { foreach (var local in locals) { Debug.Assert(!_localToScope.ContainsKey(local)); _localToScope[local] = scope; } }
public void Empty() { var dict = new SmallDictionary<int, string>(); Assert.AreEqual(0, dict.Count); string output; Assert.IsFalse(dict.TryGetValue(2, out output)); Assert.IsNull(output); Assert.IsFalse(dict.ContainsKey(3)); }
public override BoundNode VisitLocal(BoundLocal node) { if (lambdaLevel != 0 && locals.ContainsKey(node.LocalSymbol)) { captured = true; } return(null); }
private static void RecordDefinition <T>(SmallDictionary <string, Symbol> declarationMap, ImmutableArray <T> definitions) where T : Symbol { foreach (Symbol s in definitions) { if (!declarationMap.ContainsKey(s.Name)) { declarationMap.Add(s.Name, s); } } }
private void DeclareLocals <TSymbol>(Scope scope, ImmutableArray <TSymbol> locals, bool declareAsFree = false) where TSymbol : Symbol { foreach (var local in locals) { Debug.Assert(!_localToScope.ContainsKey(local)); if (declareAsFree) { #if DEBUG Debug.Assert(_freeVariables.Add(local)); #endif } else { _localToScope.Add(local, scope); } } }