/// <inheritdoc cref="IDictionaryEx{K,V}.GetAndEdit"/> public bool GetAndEdit(ref K key, ref V value, DictEditMode mode) { if ((mode & DictEditMode.AddIfNotPresent) == 0 && !ContainsKey(key)) { return(false); } var pair = new KeyValuePair <K, V>(key, value); bool result = !AddOrFind(ref pair, (mode & DictEditMode.ReplaceIfPresent) != 0); key = pair.Key; value = pair.Value; return(result); }
public int AddRange(IEnumerable <KeyValuePair <K, V> > data, DictEditMode mode) { if ((mode & DictEditMode.AddIfNotPresent) != 0) { int added = _set.UnionWith(data, Comparer, (mode & DictEditMode.ReplaceIfPresent) != 0); _count += added; return(added); } else { return(DictionaryExt.AddRange(this, data, mode)); } }
public bool GetAndEdit(ref K key, ref V value, DictEditMode mode) { var op = new AListSingleOperation <K, KeyValuePair <K, V> >(); op.Mode = (AListOperation)((int)mode & 3); op.Item = new KeyValuePair <K, V>(key, value); DoSingleOperation(ref op); if (op.Found) { key = op.Item.Key; value = op.Item.Value; return(true); } else { return(false); } }
// TODO: TEST THIS! public int AddRange(IEnumerable <KeyValuePair <K, V> > e, DictEditMode mode) { var op = new AListSingleOperation <K, KeyValuePair <K, V> >(); op.Mode = (AListOperation)((int)mode & 3); int numNewPairs = 0; foreach (var pair in e) { op.Item = pair; DoSingleOperation(ref op); if (!op.Found) { numNewPairs++; } } return(numNewPairs); }
/// <summary>Default implementation of <see cref="IDictionaryEx{K, V}.AddRange"/>. /// Merges the contents of the specified sequence into this map.</summary> public static int AddRange <K, V>(this IDictionary <K, V> dict, IEnumerable <KeyValuePair <K, V> > data, DictEditMode mode) { var e = data.GetEnumerator(); int numMissing = 0; foreach (var pair in data) { K key = pair.Key; V val = pair.Value; if (!LCInterfaces.GetAndEdit(dict, key, ref val, mode)) { numMissing++; } } return(numMissing); }
/// <summary>Default implementation of <see cref="IDictionaryEx{K, V}.GetAndEdit"/>.</summary> public static bool GetAndEdit <K, V>(IDictionary <K, V> dict, K key, ref V value, DictEditMode mode) { V newValue = value; if (dict.TryGetValue(key, out value)) { if ((mode & DictEditMode.ReplaceIfPresent) != 0) { dict[key] = newValue; } return(true); } else { if ((mode & DictEditMode.AddIfNotPresent) != 0) { dict[key] = newValue; } return(false); } }