Exemple #1
0
 public bool ContainsKey(K1 key1)
 {
     lock (Locker)
     {
         return(Key1ToKey2.ContainsKey(key1));
     }
 }
Exemple #2
0
 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);
     }
 }
Exemple #3
0
 public void Add(K1 key1, K2 key2)
 {
     lock (Locker)
     {
         Key1ToKey2.Add(key1, key2);
         Key2ToKey1.Add(key2, key1);
     }
 }
Exemple #4
0
        public bool TryGetValueByFirstKey(TKey1 key1, out IEnumerable <TKey2> result)
        {
            if (!Key1ToKey2.TryGetValue(key1, out var res))
            {
                result = null;
                return(false);
            }

            result = res;
            return(true);
        }
Exemple #5
0
 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)));
     }
 }
Exemple #6
0
 public K2 Get(K1 key1)
 {
     lock (Locker)
     {
         K2 key2;
         if (Key1ToKey2.TryGetValue(key1, out key2))
         {
             return(key2);
         }
         else
         {
             return(default(K2));
         }
     }
 }
Exemple #7
0
        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);
                }
            }
        }