示例#1
0
        public AbstractStaticStore(string filePathWithoutExtension, long capacity, BaseHashTableOptions <TKey, TValue> options)
        {
            config.RecordSize        = GetRecordSize();
            config.HashTableFilePath = filePathWithoutExtension + ".HashTable";
            config.DataFilePath      = filePathWithoutExtension + ".DataFile";
            config.IsNew             = !File.Exists(config.HashTableFilePath);

            if (options != null)
            {
                config.HashFunction  = options.HashFunction;
                config.KeyComparer   = options.KeyComparer ?? EqualityComparer <TKey> .Default;
                config.ValueComparer = options.ValueComparer ?? EqualityComparer <TValue> .Default;
            }

            // SlotCount 1, 2, 4, and 8 are edge cases that is not worth to support. So min slot count is 16, it doesn't show "anomalies".
            // (capacity + 6) / 7 is Ceil(capacity FloatDiv 7)
            // we want a MaxLoadFactor = Capacity/SlotCount = 87.5% this is why we set SlotCount = capacity + capacity/7 => 7 * slotCount = 8 * capacity => capacity/SlotCount = 7/8 = 87.5%
            config.SlotCount = Math.Max(capacity + (capacity + 6) / 7, 16);
            config.SlotCount = Bits.IsPowerOfTwo(config.SlotCount) ? config.SlotCount : Bits.NextPowerOf2(config.SlotCount);
        }
示例#2
0
        public AbstractDynamicStore(string filePathWithoutExtension, long initialCapacity, BaseHashTableOptions <TKey, TValue> options)
        {
            config.RecordSize        = GetRecordSize();
            config.HashTableFilePath = filePathWithoutExtension + ".HashTable";
            config.DataFilePath      = filePathWithoutExtension + ".DataFile";
            config.IsNew             = !File.Exists(config.HashTableFilePath);

            if (options != null)
            {
                config.HashFunction  = options.HashFunction;
                config.KeyComparer   = options.KeyComparer ?? EqualityComparer <TKey> .Default;
                config.ValueComparer = options.ValueComparer ?? EqualityComparer <TValue> .Default;
            }

            sizeState = new DynamicHashTableSizeState();


            // SlotCount 1, 2, 4, and 8, 16 are edge cases that is not worth to support. So min slot count is 32, it doesn't show "anomalies".
            // we want a MaxLoadFactor = Capacity/SlotCount = 80% this is why we set SlotCount = capacity + capacity/4 => 4 * slotCount = 5 * capacity => capacity/SlotCount = 4/5 = 80%
            sizeState.SlotCount          = Math.Max(initialCapacity + initialCapacity / 4, 32);
            sizeState.SlotCount          = Bits.IsPowerOfTwo(sizeState.SlotCount) ? sizeState.SlotCount : Bits.NextPowerOf2(sizeState.SlotCount);
            sizeState.OverflowAreaLength = (int)Math.Min(sizeState.SlotCount, 256);
            sizeState.TotalSlotCount     = sizeState.SlotCount + sizeState.OverflowAreaLength;
        }