/// <summary> /// Gets the values for the key specified. This method is useful if you want to avoid an exception for key value retrieval and you can't use TryGetValue /// (e.g. in lambdas) /// </summary> /// <param name="key">The key.</param> /// <param name="returnEmptySet">if set to true and the key isn't found, an empty hashset is returned, otherwise, if the key isn't found, null is returned</param> /// <returns> /// This method will return null (or an empty set if returnEmptySet is true) if the key wasn't found, or /// the values if key was found. /// </returns> public MyHashSet <V> GetValues(K key, bool returnEmptySet) { MyHashSet <V> toReturn = null; if (!base.TryGetValue(key, out toReturn) && returnEmptySet) { toReturn = new MyHashSet <V>(); } return(toReturn); }
/// <summary> /// Determines whether this dictionary contains the specified value for the specified key /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <returns>true if the value is stored for the specified key in this dictionary, false otherwise</returns> public bool ContainsValue(K key, V value) { bool toReturn = false; MyHashSet <V> values = null; if (this.TryGetValue(key, out values)) { toReturn = values.contains(value); } return(toReturn); }
/// <summary> /// Adds the specified value under the specified key /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> public void Add(K key, V value) { MyHashSet <V> container = null; if (!this.TryGetValue(key, out container)) { container = new MyHashSet <V>(); base.Add(key, container); } container.add(value); }
public virtual void Map(K key, V value) { MyHashSet <V> elementsForKey; if (!TryGetValue(key, out elementsForKey)) { elementsForKey = new MyHashSet <V>(); this[key] = elementsForKey; } elementsForKey.add(value); }
/// <summary> /// Removes the specified value for the specified key. It will leave the key in the dictionary. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> public void Remove(K key, V value) { MyHashSet <V> container = null; if (this.TryGetValue(key, out container)) { container.remove(value); if (container.size() <= 0) { this.Remove(key); } } }
/// <summary> /// Returns a shallow copy of this <tt>HashSet</tt> instance: the elements /// themselves are not cloned. /// </summary> /// <returns> a shallow copy of this set </returns> public virtual object clone() { try { MyHashSet <E> newSet = new MyHashSet <E>(); newSet.map = new Dictionary <E, object>(this.map); return(newSet); } catch (Exception e) { throw e; } }