Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
6a439c95
Unverified
Commit
6a439c95
authored
Aug 20, 2019
by
Lee Yunsu
Committed by
GitHub
Aug 20, 2019
Browse files
update dict.c
fix to
https://github.com/antirez/redis/issues/4493
at 2.8 version
parent
4a63c443
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/dict.c
View file @
6a439c95
...
@@ -62,7 +62,7 @@ static unsigned int dict_force_resize_ratio = 5;
...
@@ -62,7 +62,7 @@ static unsigned int dict_force_resize_ratio = 5;
static
int
_dictExpandIfNeeded
(
dict
*
ht
);
static
int
_dictExpandIfNeeded
(
dict
*
ht
);
static
unsigned
long
_dictNextPower
(
unsigned
long
size
);
static
unsigned
long
_dictNextPower
(
unsigned
long
size
);
static
int
_dictKeyIndex
(
dict
*
ht
,
const
void
*
key
);
static
long
_dictKeyIndex
(
dict
*
ht
,
const
void
*
key
);
static
int
_dictInit
(
dict
*
ht
,
dictType
*
type
,
void
*
privDataPtr
);
static
int
_dictInit
(
dict
*
ht
,
dictType
*
type
,
void
*
privDataPtr
);
/* -------------------------- hash functions -------------------------------- */
/* -------------------------- hash functions -------------------------------- */
...
@@ -100,7 +100,8 @@ uint32_t dictGetHashFunctionSeed(void) {
...
@@ -100,7 +100,8 @@ uint32_t dictGetHashFunctionSeed(void) {
* 2. It will not produce the same results on little-endian and big-endian
* 2. It will not produce the same results on little-endian and big-endian
* machines.
* machines.
*/
*/
unsigned
int
dictGenHashFunction
(
const
void
*
key
,
int
len
)
{
uint64_t
dictGenHashFunction
(
const
void
*
key
,
int
len
)
{
/* 'm' and 'r' are mixing constants generated offline.
/* 'm' and 'r' are mixing constants generated offline.
They're not really 'magic', they just happen to work well. */
They're not really 'magic', they just happen to work well. */
uint32_t
seed
=
dict_hash_function_seed
;
uint32_t
seed
=
dict_hash_function_seed
;
...
@@ -144,7 +145,7 @@ unsigned int dictGenHashFunction(const void *key, int len) {
...
@@ -144,7 +145,7 @@ unsigned int dictGenHashFunction(const void *key, int len) {
}
}
/* And a case insensitive hash function (based on djb hash) */
/* And a case insensitive hash function (based on djb hash) */
u
nsigned
in
t
dictGenCaseHashFunction
(
const
unsigned
char
*
buf
,
int
len
)
{
u
int64_
t
dictGenCaseHashFunction
(
const
unsigned
char
*
buf
,
int
len
)
{
unsigned
int
hash
=
(
unsigned
int
)
dict_hash_function_seed
;
unsigned
int
hash
=
(
unsigned
int
)
dict_hash_function_seed
;
while
(
len
--
)
while
(
len
--
)
...
@@ -256,7 +257,7 @@ int dictRehash(dict *d, int n) {
...
@@ -256,7 +257,7 @@ int dictRehash(dict *d, int n) {
de
=
d
->
ht
[
0
].
table
[
d
->
rehashidx
];
de
=
d
->
ht
[
0
].
table
[
d
->
rehashidx
];
/* Move all the keys in this bucket from the old to the new hash HT */
/* Move all the keys in this bucket from the old to the new hash HT */
while
(
de
)
{
while
(
de
)
{
u
nsigned
in
t
h
;
u
int64_
t
h
;
nextde
=
de
->
next
;
nextde
=
de
->
next
;
/* Get the index in the new hash table */
/* Get the index in the new hash table */
...
@@ -331,7 +332,7 @@ int dictAdd(dict *d, void *key, void *val)
...
@@ -331,7 +332,7 @@ int dictAdd(dict *d, void *key, void *val)
*/
*/
dictEntry
*
dictAddRaw
(
dict
*
d
,
void
*
key
)
dictEntry
*
dictAddRaw
(
dict
*
d
,
void
*
key
)
{
{
int
index
;
long
index
;
dictEntry
*
entry
;
dictEntry
*
entry
;
dictht
*
ht
;
dictht
*
ht
;
...
@@ -394,7 +395,7 @@ dictEntry *dictReplaceRaw(dict *d, void *key) {
...
@@ -394,7 +395,7 @@ dictEntry *dictReplaceRaw(dict *d, void *key) {
/* Search and remove an element */
/* Search and remove an element */
static
int
dictGenericDelete
(
dict
*
d
,
const
void
*
key
,
int
nofree
)
static
int
dictGenericDelete
(
dict
*
d
,
const
void
*
key
,
int
nofree
)
{
{
u
nsigned
in
t
h
,
idx
;
u
int64_
t
h
,
idx
;
dictEntry
*
he
,
*
prevHe
;
dictEntry
*
he
,
*
prevHe
;
int
table
;
int
table
;
...
@@ -475,7 +476,7 @@ void dictRelease(dict *d)
...
@@ -475,7 +476,7 @@ void dictRelease(dict *d)
dictEntry
*
dictFind
(
dict
*
d
,
const
void
*
key
)
dictEntry
*
dictFind
(
dict
*
d
,
const
void
*
key
)
{
{
dictEntry
*
he
;
dictEntry
*
he
;
u
nsigned
in
t
h
,
idx
,
table
;
u
int64_
t
h
,
idx
,
table
;
if
(
d
->
ht
[
0
].
size
==
0
)
return
NULL
;
/* We don't have a table at all */
if
(
d
->
ht
[
0
].
size
==
0
)
return
NULL
;
/* We don't have a table at all */
if
(
dictIsRehashing
(
d
))
_dictRehashStep
(
d
);
if
(
dictIsRehashing
(
d
))
_dictRehashStep
(
d
);
...
@@ -609,7 +610,7 @@ void dictReleaseIterator(dictIterator *iter)
...
@@ -609,7 +610,7 @@ void dictReleaseIterator(dictIterator *iter)
dictEntry
*
dictGetRandomKey
(
dict
*
d
)
dictEntry
*
dictGetRandomKey
(
dict
*
d
)
{
{
dictEntry
*
he
,
*
orighe
;
dictEntry
*
he
,
*
orighe
;
unsigned
int
h
;
unsigned
long
h
;
int
listlen
,
listele
;
int
listlen
,
listele
;
if
(
dictSize
(
d
)
==
0
)
return
NULL
;
if
(
dictSize
(
d
)
==
0
)
return
NULL
;
...
@@ -853,9 +854,10 @@ static unsigned long _dictNextPower(unsigned long size)
...
@@ -853,9 +854,10 @@ static unsigned long _dictNextPower(unsigned long size)
*
*
* Note that if we are in the process of rehashing the hash table, the
* Note that if we are in the process of rehashing the hash table, the
* index is always returned in the context of the second (new) hash table. */
* index is always returned in the context of the second (new) hash table. */
static
int
_dictKeyIndex
(
dict
*
d
,
const
void
*
key
)
static
long
_dictKeyIndex
(
dict
*
d
,
const
void
*
key
)
{
{
unsigned
int
h
,
idx
,
table
;
unsigned
long
h
,
idx
,
table
;
dictEntry
*
he
;
dictEntry
*
he
;
/* Expand the hash table if needed */
/* Expand the hash table if needed */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment