public bool ContainsKey(K1 key1) { lock (Locker) { return(Key1ToKey2.ContainsKey(key1)); } }
public void TryAdd(TKey1 key1, TKey2 key2) { lock (this) { Key1ToKey2.GetOrAdd(key1, new ConcurrentHash <TKey2>()).TryAdd(key2); Key2ToKey1.GetOrAdd(key2, new ConcurrentHash <TKey1>()).TryAdd(key1); } }
public void Add(K1 key1, K2 key2) { lock (Locker) { Key1ToKey2.Add(key1, key2); Key2ToKey1.Add(key2, key1); } }
public bool TryGetValueByFirstKey(TKey1 key1, out IEnumerable <TKey2> result) { if (!Key1ToKey2.TryGetValue(key1, out var res)) { result = null; return(false); } result = res; return(true); }
public bool TryRemoveByFirstKey(TKey1 key1) { lock (this) { return(Key1ToKey2.TryRemove(key1, out var relevantKey2S) && relevantKey2S.Aggregate(true, (current, key2) => current && Key2ToKey1.TryGetValue(key2, out var d) && d.TryRemove(key1))); } }
public K2 Get(K1 key1) { lock (Locker) { K2 key2; if (Key1ToKey2.TryGetValue(key1, out key2)) { return(key2); } else { return(default(K2)); } } }
public bool Remove(K2 key2) { lock (Locker) { K1 key1; if (Key2ToKey1.TryGetValue(key2, out key1)) { Key2ToKey1.Remove(key2); Key1ToKey2.Remove(key1); return(true); } else { return(false); } } }