Are there any hash functions that allow you to resize a table without re-deleting (deleting + re-pasting) the content?

Is it possible to use a specific hash function and method (split or double hash method) to make a hash table chain that can be changed without having to re-insert (rephrase) each element already in the table?

+3
source share
5 answers

I can only assume the reason why you want to avoid a reboot, all because the resulting high latency operation is not a bandwidth issue, but a problem for the response (both human and in the sense of SLA).

In theory, you can use a modified private destination hash table like this:

  • remember all previous sizes in which elements were added.
  • When resizing, keep the old buckets connected to each other using the size map WhenUsed → buckets (obviously, if the buckets are empty, you need not worry)
  • An invariant mapping of the key k exists in only one of the "internal hash tables" at any time.
  • , , . .
    • / , , -.
  • , O , .
    • , , , X , X - .
    • ( , , , ) ( ), - , .

( ), . .

, , "", , , , . .

, , "" . , , , , .

- ( ) , , , , , , .

+1

, - . , .

.

+2

, - , , .

+1

- , - , , (IE, ), , , -.

0

, , -. -, ( , , , ). .

, - , . , , .

:

if resizing then
    smallTable = bigTable
    bigTable = new T[smallTable.length * 2] //if allocation zeroes memory, we lose O(1)
    set state to zeroing
elseif zeroing then
    zero a small amount of the bigTable memory
    if done zeroing then set state to transfering
elseif transfering then
    transfer a few values in the small table to the big table
    if done transfering then set state to resizing
end if

add new item to small array
add new item to large array
0
source

Source: https://habr.com/ru/post/1715914/


All Articles