Redis dict and_rehash
Upcoming SlideShare
Loading in...5
×
 

Redis dict and_rehash

on

  • 4,157 views

 

Statistics

Views

Total Views
4,157
Views on SlideShare
2,325
Embed Views
1,832

Actions

Likes
2
Downloads
9
Comments
0

9 Embeds 1,832

http://charsyam.wordpress.com 1731
http://www.hanrss.com 39
https://twitter.com 32
https://charsyam.wordpress.com 21
http://tweetedtimes.com 3
http://charsyam.wordpress.com.s1.gvirabi.com 3
http://twitter.com 1
http://translate.googleusercontent.com 1
https://translate.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Redis dict and_rehash Presentation Transcript

  • 1. Redis Dict Data Structure charsyam@naver.com
  • 2. Redis Insert Flow
  • 3. dictAdd dictAddRaw 1. Redis uses two tables: table[0], table[1] 2. Tables have buckets for dictEntry dictSetVal dictAddRaw_dictRehashStep 1. dictAddRaw actually makes new dirEntry. 2. If rehash is possbile, conduct rehashing. 3. _dictKeyIndex check the item is existed. If it is existed, dictAddRaw will fail. _dictKeyIndex 4. Used++ _dictSetKey
  • 4. 1. dictRehash’s parameter n is the variable that howdictRehashStep many buckets will be rehashed. For performance, it is always 1. 2. If Ht[0]used is 0, rehashng is finished. Ht[0] = ht[1] and return; dictRehash 3. while(d->ht[0].table[d->rehashidx] == NULL) d- >rehashidx++; if current bucket is NULL, go next bucket. 4. Bucket size is always increased as twice. 5. And divide dictEntry with hashmask. For example, at the first time. mask is 3 and hash value 2, 5 were in same bucket . After doubling bucket size, mask will be 7, so hash value 2 will be in bucket #2, and 5 will be in bucket #5
  • 5. Redis Dict is Hash
  • 6. Dynamic HashExpand twiceLinear probing
  • 7. Add 0,1,2,3 Bucket #0 0 Bucket #1 1 Bucket #2 2 Bucket #3 3
  • 8. Add 4 with line Probing Bucket #0 4 0 Bucket #1 1 Bucket #2 2 Bucket #3 3
  • 9. Rehashing with HT[1]Bucket #0 4 0Bucket #1 1 Bucket #0 Bucket #1Bucket #2 2 Bucket #2Bucket #3 3 Bucket #3 Bucket #4 Bucket #5 Bucket #6 Bucket #7
  • 10. Rehashing one step #1 Bucket #0 Used--; Used--; Bucket #1 1 Bucket #0 0 Bucket #1 Bucket #2 2 Bucket #2 Bucket #3 3 Bucket #3 Bucket #4 4 Bucket #5 Bucket #6 Bucket #7
  • 11. After all rehashinght[0] = ht[1]reset ht[1]For next rehashing