/// <summary> /// Adds a key/value pair to the lookup /// </summary> /// <remarks>If the value is already present it will be duplicated</remarks> public void Add([NotNull] TKey key, TElement value) { if (!_groups.TryGetValue(key, out LookupGrouping group)) { group = new LookupGrouping(key); _groups.Add(key, group); } group.Add(value); }
/// <summary> /// Adds a key/value pair to the lookup /// </summary> /// <remarks>If the value is already present it will be duplicated</remarks> public void Add(TKey key, TElement value) { LookupGrouping group; if (!groups.TryGetValue(key, out group)) { group = new LookupGrouping(key); groups.Add(key, group); } group.Add(value); }
/// <summary> /// Adds a range of values against a single key /// </summary> /// <remarks>Any values already present will be duplicated</remarks> public void AddRange([NotNull] TKey key, [NotNull] IEnumerable <TElement> values) { if (!_groups.TryGetValue(key, out LookupGrouping group)) { group = new LookupGrouping(key); _groups.Add(key, group); } foreach (TElement value in values) { group.Add(value); } if (group.Count == 0) { _groups.Remove(key); // nothing there after all! } }
/// <summary> /// Adds a range of values against a single key /// </summary> /// <remarks>Any values already present will be duplicated</remarks> public void AddRange(TKey key, IEnumerable <TElement> values) { values.ThrowIfNull("values"); LookupGrouping group; if (!groups.TryGetValue(key, out group)) { group = new LookupGrouping(key); groups.Add(key, group); } foreach (TElement value in values) { group.Add(value); } if (group.Count == 0) { groups.Remove(key); // nothing there after all! } }