Beispiel #1
0
        /// <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(TKey key, TValue value)
        {
            ShardingAssert.ShouldBeNotNull(key, "key");
            bool             toReturn = false;
            HashSet <TValue> values;

            if (this.TryGetValue(key, out values))
            {
                toReturn = values.Contains(value);
            }
            return(toReturn);
        }
Beispiel #2
0
        /// <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(TKey key, TValue value)
        {
            ShardingAssert.ShouldBeNotNull(key, "key");

            HashSet <TValue> container;

            if (!this.TryGetValue(key, out container))
            {
                container = new HashSet <TValue>(_valueComparer);
                this.Add(key, container);
            }
            container.Add(value);
        }
Beispiel #3
0
        /// <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(TKey key, TValue value)
        {
            ShardingAssert.ShouldBeNotNull(key, "key");

            HashSet <TValue> container;

            if (this.TryGetValue(key, out container))
            {
                container.Remove(value);
                if (container.Count <= 0)
                {
                    this.Remove(key);
                }
            }
        }