예제 #1
0
        /// <summary>
        /// Updates values of all keys. For each key in the dictionary, the
        /// value is replaced with <code>func(key, this[key])</code>.
        /// </summary>
        /// <typeparam name="TValue1">The type of the values in the returned dictionary.</typeparam>
        /// <param name="func">The updating function.</param>
        /// <returns>The resulting dictionary.</returns>
        public TreeDictionary <TKey, TValue1, TComparer> MapPartial <TValue1>(Func <TKey, TValue, Optional <TValue1> > func)
        {
            if (Count == 0)
            {
                return(TreeDictionary <TKey, TValue1, TComparer> .Empty);
            }
            var newValue = func(_key, _value);

            return(newValue.HasValue
                       ? TreeDictionary <TKey, TValue1, TComparer> .Unbalanced(_key, newValue.Value, _left.MapPartial(func), _right.MapPartial(func))
                       : TreeDictionary <TKey, TValue1, TComparer> .GlueUnbalanced(_left.MapPartial(func), _right.MapPartial(func)));
        }