Пример #1
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);
        }
Пример #2
0
 public bool TryRemoveBySecondKey(TKey2 key2)
 {
     lock (this)
     {
         return(Key2ToKey1.TryRemove(key2, out var relevantKey1S) &&
                relevantKey1S.Aggregate(true,
                                        (current, key1) =>
                                        current && Key1ToKey2.TryGetValue(key1, out var d) &&
                                        d.TryRemove(key2)));
     }
 }
Пример #3
0
 public K2 Get(K1 key1)
 {
     lock (Locker)
     {
         K2 key2;
         if (Key1ToKey2.TryGetValue(key1, out key2))
         {
             return(key2);
         }
         else
         {
             return(default(K2));
         }
     }
 }
Пример #4
0
        public bool Remove(K1 key1)
        {
            lock (Locker)
            {
                K2 key2;
                if (Key1ToKey2.TryGetValue(key1, out key2))
                {
                    Key1ToKey2.Remove(key1);
                    Key2ToKey1.Remove(key2);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }