2. Contents
7/4/2016 2
• Hash Table Format
• Creating a Hash Table
• Insertion in Hash Table
• Deletion in Hash Table
3. Hash Table Format
7/4/2016 3
Type of hash table, type
Adaptive hash index flag, adaptive
Number of cells in the hash table, n_cells
Pointer to cell array, array
Number of mutexes or rw_locks, n_sync_obj
Synchronization objects (mutex or rw_lock), sync_obj
Heaps, heaps
Heap, heap
Magic number, magic_n
void* node
mutexes
rw_locks
hash_table_t
4. Hash Table Format
7/4/2016 4
• type: type of hash table
HASH_TABLE_SYNC_NONE
HASH_TABLE_SYNC_MUTEX
HASH_TABLE_SYNC_RW_LOCK
• adaptive: TRUE if this is the hash table of the adaptive hash
index
• n_cells: number of cells in the hash table
• array: pointer to cell array
node: hash chain node, NULL if none
5. Hash Table Format
7/4/2016 5
• n_sync_obj: the number of mutexes or rw_locks, must be a
power of 2 or 0
• sync_obj: synchronization objects
① mutexes: NULL or an array of mutexes used to protect segments of
hash table
② rw_locks: NULL or an array of read/write locks
• heaps: if this is non-NULL, hash chain nodes for external
chaining can be allocated from these memory heaps
• heap
• magic_n: magic number (76561114)
16. HASH_INSERT
7/4/2016 16
DATA
(hash entry)
NULL
DATA
(hash entry)
NULL
struct3333
(hash entry)
hash
entry
hash
entry
There is no hash entry
If there are other hash
entries, find last hash entry
and insert DATA into the
next of the last hash entry
• include/hash0hash.h:122
18. HASH_DELETE
7/4/2016 18
1. Check whether the next
hash entry of DATA is valid
2. Change the pointer to point
the next hash entry
DATA
(hash entry)
hash
entry
hash
entry
DATA
(hash entry)
hash
entry
hash
entry
(void*)-1
: invalid address
• include/hash0hash.h:158
Notes de l'éditeur
the clustered key fields, also known as a Primary Key Value
the clustered key fields, also known as a Primary Key Value
the clustered key fields, also known as a Primary Key Value