/// <summary>Adds an element with the provided key and value to the <see cref="T:System.Collections.Generic.IDictionary`2" />.</summary> /// <param name="key">The object to use as the key of the element to add.</param> /// <param name="value">The object to use as the value of the element to add.</param> public void Add(IJaggedIndex <TKey> key, TValue value) { var dictionary = ResolveLeafDictionary(i => key[i], true); dictionary.Add(key[key.Depth - 1], value); _count++; }
public override bool Contains(IJaggedIndex <TKey> keys) { var dictionary = _dictionary.ResolveLeafDictionary(i => keys[i], false); if (dictionary == null) { throw new KeyNotFoundException(); } return(dictionary.ContainsKey(keys[keys.Depth - 1])); }
/// <summary>Determines whether the <see cref="T:System.Collections.Generic.IDictionary`2" /> contains a specific key.</summary> /// <returns>true if the <see cref="T:System.Collections.Generic.IDictionary`2" /> contains an element with the key; otherwise, false.</returns> /// <param name="key">The key to locate in the <see cref="T:System.Collections.Generic.IDictionary`2" />.</param> public bool ContainsKey(IJaggedIndex <TKey> key) { var dictionary = ResolveLeafDictionary(i => key[i], false); if (dictionary == null) { return(false); } return(dictionary.ContainsKey(key[key.Depth - 1])); }
/// <summary>Gets the value associated with the specified key.</summary> /// <param name="key">The key whose value to get.</param> /// <param name="value">When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the <paramref name="value" /> parameter. This parameter is passed uninitialized.</param> /// <returns>true if the object that implements <see cref="T:System.Collections.Generic.IDictionary`2" /> contains an element with the specified key; otherwise, false.</returns> public bool TryGetValue(IJaggedIndex <TKey> key, out TValue value) { var dictionary = ResolveLeafDictionary(i => key[i], false); if (dictionary != null) { return(dictionary.TryGetValue(key[key.Depth - 1], out value)); } value = default(TValue); return(false); }
/// <summary>Removes the element with the specified key from the <see cref="T:System.Collections.Generic.IDictionary`2" />.</summary> /// <param name="key">The key of the element to remove.</param> /// <returns>true if the element is successfully removed; otherwise, false. This method also returns false if <paramref name="key" /> was not found in the original <see cref="T:System.Collections.Generic.IDictionary`2" />.</returns> public bool Remove(IJaggedIndex <TKey> key) { var dictionary = ResolveLeafDictionary(i => key[i], false); if (dictionary == null || !dictionary.Remove(key[key.Depth - 1])) { return(false); } _count--; return(true); }
/// <summary>Gets or sets the value associated with the specified jagged index.</summary> /// <returns>The value associated with the specified key. If the specified key is not found, a get operation throws a <see cref="T:System.Collections.Generic.KeyNotFoundException" />, and a set operation creates a new element with the specified key.</returns> /// <param name="key">The key of the value to get or set.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="key" /> is null.</exception> /// <exception cref="T:System.Collections.Generic.KeyNotFoundException">The property is retrieved and <paramref name="key" /> does not exist in the collection.</exception> public TValue this[IJaggedIndex <TKey> key] { get { var dictionary = ResolveLeafDictionary(i => key[i], false); if (dictionary == null) { throw new KeyNotFoundException(); } return(dictionary[key[key.Depth - 1]]); } set { var dictionary = ResolveLeafDictionary(i => key[i], true); var prevCount = dictionary.Count; dictionary[key[key.Depth - 1]] = value; if (prevCount != dictionary.Count) { _count++; } } }