Exemple #1
0
        /// <summary>
        /// Get/set value for given key.
        /// Time complexity: O(log(n)).
        /// </summary>
        public V this[K key]
        {
            get
            {
                var node = binarySearchTree.FindNode(new SortedDictionaryNode <K, V>(key, default(V)));
                if (node == null)
                {
                    throw new Exception("Key not found.");
                }

                return(node.Value.Value);
            }
            set
            {
                if (ContainsKey(key))
                {
                    Remove(key);
                }

                Add(key, value);
            }
        }