Esempio n. 1
0
 /// <summary>
 /// Atomically adds a new item to the map
 /// </summary>
 /// <remarks>Null is not allowed for a Key or a Value</remarks>
 /// <param name="key">Key</param>
 /// <param name="value">Value</param>
 /// <exception cref="ArgumentException">Throws ArgumentException if the key already exists</exception>
 /// <exception cref="ArgumentNullException">Throws ArgumentNullException the key or value are null</exception>
 /// <returns>New Map with the item added</returns>
 public Map <K, V> Add(K key, V value)
 {
     if (isnull(key))
     {
         throw new ArgumentNullException(nameof(key));
     }
     if (isnull(value))
     {
         throw new ArgumentNullException(nameof(value));
     }
     return(SetRoot(MapModule.Add(Root, key, value, Comparer <K> .Default)));
 }
Esempio n. 2
0
        /// <summary>
        /// Atomically adds a range of items to the map.
        /// </summary>
        /// <remarks>Null is not allowed for a Key or a Value</remarks>
        /// <param name="range">Range of tuples to add</param>
        /// <exception cref="ArgumentException">Throws ArgumentException if any of the keys already exist</exception>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException the keys or values are null</exception>
        /// <returns>New Map with the items added</returns>
        public Map <K, V> AddRange(IEnumerable <Tuple <K, V> > range)
        {
            if (range == null)
            {
                return(this);
            }
            var self = Root;

            foreach (var item in range)
            {
                if (isnull(item.Item1))
                {
                    throw new ArgumentNullException(nameof(item.Item1));
                }
                self = MapModule.Add(self, item.Item1, item.Item2, Comparer <K> .Default);
            }
            return(SetRoot(self));
        }