Exemple #1
0
        public void RemoveAt(int index)
        {
            if (index >= list.Count || index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "Index Out Of Range (0-" + list.Count + "): " + index);
            }

            TKey key = list[index].item1;
            int  num = list[index].item2;

            List <TValue> sub = dict[key];

            sub.RemoveAt(num);
            if (sub.Count == 0)
            {
                dict.Remove(key);
            }

            list.RemoveAt(index);

            //shifting all of the nums
            int listCount = list.Count;

            for (int i = 0; i < listCount; i++)
            {
                TKey ikey = list[i].item1;
                int  inum = list[i].item2;
                if (Equals(key, ikey) && inum >= num)
                {
                    list[i] = new TupleSet <TKey, int, TValue>(ikey, inum - 1, list[i].item3);
                }
            }
        }
Exemple #2
0
        public TValue this[TKey key, int num]
        {
            get { return(dict[key][num]); }
            set {
                if (dict.ContainsKey(key))
                {
                    List <TValue> sub = dict[key];

                    if (num >= sub.Count || num < 0)
                    {
                        throw new ArgumentOutOfRangeException("num", "Index Out Of Range (0-" + sub.Count + "): " + num);
                    }

                    if (num == sub.Count)
                    {
                        Add(key, value);                                      //adding right after the last
                    }
                    else
                    {
                        dict[key][num] = value;
                        list[IndexOfKeyNum(key, num)] = new TupleSet <TKey, int, TValue>(key, num, value);
                    }
                }
                else if (num == 0)
                {
                    Add(key, value);
                }
                else
                {
                    throw new ArgumentException("key", "Key Not Found: " + key);
                }
            }
        }
Exemple #3
0
 public void Set(TKey key, T1 val1, T2 val2)
 {
     if (!dict.ContainsKey(key))
     {
         dict.Add(key, new TupleSet <T1, T2>(val1, val2));
     }
     else
     {
         dict[key] = new TupleSet <T1, T2>(val1, val2);
     }
 }                                                                                                                                                                                    //same as add with owerwrite
Exemple #4
0
 public void CheckAdd(TKey key, T1 val1, T2 val2, bool overwrite = false)
 {
     if (!dict.ContainsKey(key))
     {
         dict.Add(key, new TupleSet <T1, T2>(val1, val2));
     }
     else if (overwrite)
     {
         dict[key] = new TupleSet <T1, T2>(val1, val2);
     }
 }
Exemple #5
0
 public TValue this[TKey key]
 {
     get { return(dict[key]); }
     set {
         if (dict.ContainsKey(key))
         {
             dict[key]             = value;
             list[IndexOfKey(key)] = new TupleSet <TKey, TValue>(key, value);
         }
         else
         {
             Add(key, value);
         }
     }
 }
Exemple #6
0
        public TValue this[int index]
        {
            get {
                if (index >= list.Count || index < 0)
                {
                    throw new ArgumentOutOfRangeException("index", "Index Out Of Range (0-" + list.Count + "): " + index);
                }
                return(list[index].item2);
            }
            set {
                if (index >= list.Count || index < 0)
                {
                    throw new ArgumentOutOfRangeException("index", "Index Out Of Range (0-" + list.Count + "): " + index);
                }

                TKey key = list[index].item1;

                list[index] = new TupleSet <TKey, TValue>(key, value);
                dict[key]   = value;
            }
        }
Exemple #7
0
 public void SetVal2(TKey key, T2 val)
 {
     TupleSet <T1, T2> tuple = dict[key]; tuple.item2 = val; dict[key] = tuple;
 }