Beispiel #1
0
        /// <summary>
        /// True if the dictionary contains an element with the specified key; otherwise, false.
        /// </summary>
        /// <param name="key">The key</param>
        /// <returns></returns>
        public Boolean ContainsKey(TKey key)
        {
            DictionaryPair <TKey, TValue> pair = new DictionaryPair <TKey, TValue>(key, default(TValue));
            Boolean contains = this.treeContainer.Search(ref pair);

            return(contains);
        }
Beispiel #2
0
        /// <summary>
        /// Return value of given key.
        /// Add a new pair with given key and value to the dictionary.
        /// If the key is invalid, generate exception.
        /// </summary>
        /// <param name="key"> The key</param>
        /// <returns></returns>
        public TValue this[TKey key]
        {
            get
            {
                DictionaryPair <TKey, TValue> item = new DictionaryPair <TKey, TValue>(key, default(TValue));
                Boolean contains = treeContainer.Search(ref item);
                if (contains)
                {
                    return(item.Value);
                }

                throw new Exception("Invalid key");
            }

            set
            {
                DictionaryPair <TKey, TValue> item = new DictionaryPair <TKey, TValue>(key, default(TValue));
                Boolean contains = treeContainer.Search(ref item);
                if (contains)
                {
                    item.Value = value;
                }

                throw new Exception("Invalid key");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds the specified key and value to the dictionary.
        /// </summary>
        /// <param name="key">The key</param>
        /// <param name="value">The value</param>
        public void Add(TKey key, TValue value)
        {
            DictionaryPair <TKey, TValue> pair = new DictionaryPair <TKey, TValue>(key, value);

            this.treeContainer.Insert(pair);
        }