About _dictNextPower function #1201

Open
xuxiaoliang opened this Issue Jul 18, 2013 · 4 comments

Projects

None yet

2 participants

@xuxiaoliang

if size >=LONG_MAX,so the returned value doesnt match 2^n, and the trick key%size == key&sizemask????

I think that sizemask dont need exsit. beacaus sizemask = size-1;
typedef struct dictht {
dictEntry **table;
unsigned long size;
unsigned long sizemask;
unsigned long used;
} dictht;

/* Our hash table capability is a power of two */
static unsigned long _dictNextPower(unsigned long size)
{
unsigned long i = DICT_HT_INITIAL_SIZE;

if (size >= LONG_MAX) return LONG_MAX;
while(1) {
    if (i >= size)
        return i;
    i *= 2;
}

}

@xuxiaoliang

please help me...

@kgcrom
kgcrom commented Jul 18, 2013

I think it's only save operation. ( assembly "sub ")

dict.c

h & d->ht[table].sizemask
to
h & d->ht[table].size-1
@xuxiaoliang

so ,if size >=LONG_MAX, the value doesnt match 2^n....
the function is correct?

@kgcrom
kgcrom commented Jul 19, 2013

so so. if you have a massive memory, LONG_MAX modify ULONG_MAX. ; )

size is one of the 4, 8, 16, 32, ..., 2147483638, because DICT_HT_INITIAL_SIZE is defined 4.
and it's enough to using Redis.

it used about (2G*(sizeof(struct dictEntry))) + (sizeof(struct dictht)) + (sizeof(struct dict)) + sizeof(struct dictType)... 
when used variable is 2^31. 

Above example is only key size. Adding a value size is amazing.

I think 2^31, 2^32... is......needed to sharding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment