Ejemplo n.º 1
0
        public void Add(T1 t1, T2 t2)
        {
            t1 = GetIndex(t1);
            t2 = GetIndex(t2);

            if (Forward.ContainsKey(t1))
            {
                return;
            }

            lock (_locker)
            {
                if (Forward.ContainsKey(t1))
                {
                    return;
                }

                _forward = _forward.Add(t1, t2);
                _reverse = _reverse.Add(GetIndex(t2), t1);

                var forward = new Indexer <T1, T2>(_forward);
                var reverse = new Indexer <T2, T1>(_reverse);
                Interlocked.Exchange(ref _forwardIndexer, forward);
                Interlocked.Exchange(ref _reverseIndexer, reverse);
            }
        }
Ejemplo n.º 2
0
        void InternalAdd(T1 t1, T2 t2)
        {
            try
            {
                if (t1 == null || t2 == null)
                {
                    throw new ArgumentException("Null key value", "Null value is not allowed.");
                }

                if (Forward.ContainsKey(t1) || Reverse.ContainsKey(t2))
                {
                    throw new System.ArgumentException("A pair with same item already exist!");
                }
                else
                {
                    Forward.Add(t1, t2);
                    Reverse.Add(t2, t1);
                }
            }
            catch (Exception e)
            {
                // throw new System.Exception("BiMap: Unknow exception in Add().");
                throw e;
            }
        }
Ejemplo n.º 3
0
 public bool Contains(T1 key)
 {
     if (key == null)
     {
         throw new ArgumentException("Null key query", "Null is not allowed.");
     }
     return(Forward.ContainsKey(key));
 }
Ejemplo n.º 4
0
#pragma warning restore CS8601

        public bool ContainsKey(T1 key) => Forward.ContainsKey(key);
Ejemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="first"></param>
 /// <returns></returns>
 public IEnumerable <TSecond> GetByFirst(TFirst first)
 {
     return(Forward.ContainsKey(first) ? Forward[first] : EmptySecondList);
 }
Ejemplo n.º 6
0
 public bool ContainsKey(T1 key)
 {
     ContainingCheck(key);
     return(Forward.ContainsKey(key));
 }
Ejemplo n.º 7
0
 public bool Contains(KeyValuePair <T2, T1> item)
 {
     return(((ICollection <KeyValuePair <T2, T1> >)Reverse).Contains(item) && Forward.ContainsKey(item.Value) && Forward[item.Value].Equals(item.Key));
 }
Ejemplo n.º 8
0
 public bool ContainsKey(K key)
 {
     return(Forward.ContainsKey(key));
 }