Example #1
0
        private void Rehash(int newCapacity, IntIntMap source)
        {
            m_threshold = (int)(newCapacity * m_fillFactor);
            m_mask      = newCapacity - 1;
            m_mask2     = newCapacity * 2 - 1;

            int[] sourceData = source.m_data;
            int   oldLength  = sourceData.Length;

            m_data = new int[newCapacity * 2];
            m_size = m_hasFreeKey ? 1 : 0;

            for (int i = 0; i < oldLength; i += 2)
            {
                int oldKey = sourceData[i];
                if (oldKey != FreeKey)
                {
                    Put(oldKey, sourceData[i + 1]);
                }
            }
        }
Example #2
0
        public IntIntMap(IntIntMap other, int newSize = 0)
        {
            m_fillFactor = other.m_fillFactor;

            if (newSize < 0)
            {
                InitializeEmpty(DefaultSize);
                return;
            }

            if (newSize < other.m_size)
            {
                newSize = other.m_size;
            }

            if (newSize < DefaultSize)
            {
                newSize = DefaultSize;
            }

            m_mask      = other.m_mask;
            m_mask2     = other.m_mask2;
            m_threshold = other.m_threshold;

            m_hasFreeKey = other.m_hasFreeKey;
            m_freeValue  = other.m_freeValue;

            int newCapacity = Tools.ArraySize(newSize, m_fillFactor);

            if (2 * newCapacity == other.m_data.Length)
            {
                m_data = Arrays.CopyOf(other.m_data, other.m_data.Length);
                m_size = other.m_size;
            }
            else
            {
                Rehash(newCapacity, other);
            }
        }
Example #3
0
        public IntIntMap(IntIntMap other, int newSize = 0)
        {
            m_fillFactor = other.m_fillFactor;

            if (newSize < 0)
            {
                InitializeEmpty(DefaultSize);
                return;
            }

            if (newSize < other.m_size)
                newSize = other.m_size;

            if (newSize < DefaultSize)
                newSize = DefaultSize;

            m_mask = other.m_mask;
            m_mask2 = other.m_mask2;
            m_threshold = other.m_threshold;

            m_hasFreeKey = other.m_hasFreeKey;
            m_freeValue = other.m_freeValue;

            int newCapacity = Tools.ArraySize(newSize, m_fillFactor);

            if (2 * newCapacity == other.m_data.Length)
            {
                m_data = Arrays.CopyOf(other.m_data, other.m_data.Length);
                m_size = other.m_size;
            }
            else
            {
                Rehash(newCapacity, other);
            }
        }
Example #4
0
        private void Rehash(int newCapacity, IntIntMap source)
        {
            m_threshold = (int)(newCapacity * m_fillFactor);
            m_mask = newCapacity - 1;
            m_mask2 = newCapacity * 2 - 1;

            int[] sourceData = source.m_data;
            int oldLength    = sourceData.Length;

            m_data = new int[newCapacity * 2];
            m_size = m_hasFreeKey ? 1 : 0;

            for (int i = 0; i < oldLength; i += 2)
            {
                int oldKey = sourceData[i];
                if (oldKey != FreeKey)
                {
                    Put(oldKey, sourceData[i + 1]);
                }
            }
        }
Example #5
0
        private ValuesByUnderlying InitializeIntLookup()
        {
            var vals = new IntIntMap(values.Count + 1, 0.55f);

            for (int i = 0; i < values.Count; ++i)
            {
                var value = values[i].IntValue();
                if (vals.Get(value) == IntIntMap.NoValue)
                    vals.Put(value, i);
            }

            return new ValuesByUnderlying {IntMap = vals};
        }