Ejemplo n.º 1
0
        /// <summary>
        /// if key doesn't exist, add it else update it
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void AddOrUpdate(int key, T value)
        {
            if (key < 0)
            {
                if (_Negative == null)
                {
                    _Negative = new IntDictionary <T>(_Capability, _BucketSize);
                }

                _Negative.Add(0 - key, value);
                return;
            }

            if (key >= _Capability)
            {
                Resize(key);
            }

            int index = key / _BucketSize;

            if (_Index[index] == null)
            {
                _Index[index] = new Bucket(_BucketSize);
            }

            int subIndex = key % _BucketSize;

            if (_Index[index].Used[subIndex] != 0)
            {
                _Index[index].Data[subIndex] = value;
                return;
            }

            _Count++;
            _Index[index].Used[subIndex] = 1;
            _Index[index].Data[subIndex] = value;
        }
Ejemplo n.º 2
0
        public void Add(int key, T value)
        {
            if (key < 0)
            {
                if (_Negative == null)
                {
                    _Negative = new IntDictionary <T>(_Capability, _BucketSize);
                }

                _Negative.Add(0 - key, value);
                return;
            }

            if (key >= _Capability)
            {
                Resize(key);
            }

            int index = key / _BucketSize;

            if (_Index[index] == null)
            {
                _Index[index] = new Bucket(_BucketSize);
            }

            int subIndex = key % _BucketSize;

            if (_Index[index].Used[subIndex] != 0)
            {
                throw new System.ArgumentException("Adding duplicate key");
            }

            _Count++;
            _Index[index].Used[subIndex] = 1;
            _Index[index].Data[subIndex] = value;
        }
Ejemplo n.º 3
0
 public void Clear()
 {
     _Count    = 0;
     _Index    = new Bucket[_Capability / _BucketSize];
     _Negative = null;
 }
Ejemplo n.º 4
0
 internal KeyCollection(IntDictionary <T> dictionary)
 {
     _Dictionary = dictionary;
 }
Ejemplo n.º 5
0
 internal ValueCollection(IntDictionary <T> dictionary)
 {
     _Dictionary = dictionary;
 }