Пример #1
0
        public object FindKey(object key)
        {
            int             hashValue = _GetHash(key);
            LinearHashtable subTable  = _GetSubTable(hashValue);

            return(subTable._FindKey(key, hashValue));
        }
Пример #2
0
        public void DeleteKey(object key)
        {
            int             hashValue = _GetHash(key);
            LinearHashtable subTable  = _GetSubTable(hashValue);

            subTable._DeleteKey(key, hashValue);
        }
Пример #3
0
        // used to share code between the two constructors
        // out parameters are necessary for readonly variables (can only be set in ctor)
        private void _CtorMakeSubTables(int subTableCount, out LinearHashtable[] subTables, out int subTableMask)
        {
            subTables = new LinearHashtable[subTableCount];

            subTableMask = subTableCount - 1;
            // power of 2?
            if ((subTableMask & subTableCount) != 0)
            {
                subTableMask = -1;
            }
        }
Пример #4
0
        // paramaters -
        //      bool onlyAdd
        //          false - allows overwriting at key
        //          true  - throws exception if key exists
        //
        // return - returns the previous value at key
        //      Notes: return can be null key is new or if value at key is null
        public object Insert(object key, object value, bool onlyAdd)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            int             hashValue = _GetHash(key);
            LinearHashtable subTable  = _GetSubTable(hashValue);

            return(subTable._Insert(key, value, hashValue, onlyAdd));
        }
Пример #5
0
        public LkrHashtable(
            string name,         // an identifier for debugging
            int initialCapacity, // initial size of hash table (entries, not buckets like C++ LkrHash)
            double maxLoad,      // bound on the average chain length
            int subTableCount,   // number of subordinate hash tables
            IHashCodeProvider hcp,
            IComparer comparer)
        {
            _hcp = hcp;

            if (initialCapacity < MIN_INITIAL_CAPACITY)
            {
                // initialCapacity must be greater than MIN_INITIAL_CAPACITY
                throw new ArgumentOutOfRangeException("initialCapacity", initialCapacity, null);
            }

            _CtorCheckParameters(maxLoad, subTableCount);

            if (subTableCount == 0) // get default from initialCapacity
            {
                subTableCount = _GetSubTableCount(initialCapacity, maxLoad);
            }

            Debug.Trace("LkrHashtable", "LkrHashtable: name=" + name +
                        " subtables=" + subTableCount + ", capacity=" + initialCapacity);

            _CtorMakeSubTables(subTableCount, out _subTables, out _subTableMask);

            for (int i = 0; i < subTableCount; ++i)
            {
                string subTableName = name + " sub " + i.ToString();
                _subTables[i] = new LinearHashtable(
                    subTableName,
                    initialCapacity / subTableCount,
                    maxLoad,
                    hcp,
                    comparer);
            }
        }
Пример #6
0
        public LkrHashtable(
            string name,
            TableSize size,
            double maxLoad,
            int subTableCount,
            IHashCodeProvider hcp,
            IComparer comparer)
        {
            _hcp = hcp;

            if (size == TableSize.Default)
            {
                size = DEFAULT_META_TABLE_SIZE;
            }

            _CtorCheckParameters(maxLoad, subTableCount);

            if (subTableCount == 0)
            {
                subTableCount = _SubTableCountFromTableSize(size);
            }

            Debug.Trace("LkrHashtable", "LkrHashtable.ctor  name=" + name + " size=" +
                        size + " subtables=" + subTableCount);

            _CtorMakeSubTables(subTableCount, out _subTables, out _subTableMask);

            for (int i = 0; i < subTableCount; ++i)
            {
                string subTableName = name + " sub " + i.ToString();
                _subTables[i] = new LinearHashtable(
                    subTableName,
                    size,
                    maxLoad,
                    hcp,
                    comparer);
            }
        }