template<typename K_TYPE, typename V_TYPE, typename ALLOC = allocator<K_TYPE>, typename HASH = hash<K_TYPE>>
class original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >
Hash table implementation with separate chaining.
- Template Parameters
-
K_TYPE | Key type (must be hashable) |
V_TYPE | Value type |
ALLOC | Allocator type (default: allocator<K_TYPE>) |
HASH | Hash function type (default: hash<K_TYPE>) |
This class provides a generic hash table implementation that serves as the base for hash-based containers. It implements:
- Key-value pair storage
- Dynamic resizing
- Basic hash table operations
Performance Characteristics:
- Insertion: Average O(1), Worst O(n)
- Lookup: Average O(1), Worst O(n)
- Deletion: Average O(1), Worst O(n)
The implementation guarantees:
- Unique keys (no duplicates)
- Automatic resizing when load factor thresholds are crossed
- Exception safety (basic guarantee)
template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
Creates a deep copy of the hash table's bucket array.
- Parameters
-
old_buckets | The original old_buckets array to copy |
- Returns
- A new old_buckets array with cloned nodes
This function performs a deep copy of the entire old_buckets array used by the hash table, including the internal linked list in each bucket (used for separate chaining).
Copying strategy:
- For each bucket index, traverse the linked list of hash nodes
- Use
createNode()
to allocate a new node for each entry
- Preserve the order of elements within each bucket's chain
This method is typically used in:
- Copy constructors
- Copy assignment operators
The function ensures that:
- The original and copied hash tables do not share memory
- All keys and values are copied correctly
- Iterator validity is preserved for the new structure
- Note
- This function assumes the original old_buckets are well-formed (no cycles).
-
Uses allocator rebound to allocate memory for the new nodes.
template<typename K_TYPE, typename V_TYPE, typename ALLOC = allocator<K_TYPE>, typename HASH = hash<K_TYPE>>
Initial value:= {
17, 29, 53, 97, 193,
389, 769, 1543, 3079, 6151,
12289, 24593, 49157, 98317, 196613,
393241, 786433, 1572869, 3145739, 6291469,
12582917, 25165843, 50331653, 100663319, 201326611,
402653189, 805306457, 1610612741, 3221225473, 4294967291
}
Predefined bucket sizes for hash table resizing.
An array of prime numbers carefully selected for hash table bucket sizes. These primes are used during table resizing to maintain optimal performance characteristics.
Key Properties:
- All values are prime numbers to reduce hash collisions
- Each size is approximately double the previous (with some variance)
- Covers a wide range from small to very large tables
- Specifically chosen to avoid common modulo patterns
Selection Criteria:
- Primes spaced roughly exponentially (growth factor ~1.8-2.2)
- Avoid primes close to powers of 2 to prevent clustering
- Sufficient gaps between sizes to justify resize operations
- Includes sizes suitable for both small and large datasets
Performance Impact:
- Larger sizes reduce collisions but increase memory usage
- Smaller sizes conserve memory but may increase collisions
- The growth factor balances between resize frequency and memory overhead
The sequence continues until reaching sizes suitable for maximum practical in-memory hash tables (over 100 million buckets).
- Note
- The actual resize operation only occurs when the load factor exceeds thresholds, not necessarily at every size transition.
- See also
- LOAD_FACTOR_MIN
-
LOAD_FACTOR_MAX