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
cc0d339b
Commit
cc0d339b
authored
Feb 25, 2015
by
antirez
Browse files
utils/hashtable/rehashing.c test updated to use new API.
parent
126462ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
utils/hashtable/rehashing.c
View file @
cc0d339b
...
...
@@ -68,26 +68,30 @@ int sortPointers(const void *a, const void *b) {
return
la
-
lb
;
}
void
stressGetKeys
(
dict
*
d
,
int
times
)
{
void
stressGetKeys
(
dict
*
d
,
int
times
,
int
*
perfect_run
,
int
*
approx_run
)
{
int
j
;
dictEntry
**
des
=
zmalloc
(
sizeof
(
dictEntry
*
)
*
dictSize
(
d
));
for
(
j
=
0
;
j
<
times
;
j
++
)
{
int
requested
=
rand
()
%
(
dictSize
(
d
)
+
1
);
int
returned
=
dictGetSomeKeys
(
d
,
des
,
requested
);
if
(
requested
!=
returned
)
{
printf
(
"*** ERROR! Req: %d, Ret: %d
\n
"
,
requested
,
returned
);
exit
(
1
);
}
int
dup
=
0
;
qsort
(
des
,
returned
,
sizeof
(
dictEntry
*
),
sortPointers
);
if
(
returned
>
1
)
{
int
i
;
for
(
i
=
0
;
i
<
returned
-
1
;
i
++
)
{
if
(
des
[
i
]
==
des
[
i
+
1
])
{
printf
(
"*** ERROR! Duplicated element detected
\n
"
);
exit
(
1
);
}
if
(
des
[
i
]
==
des
[
i
+
1
])
dup
++
;
}
}
if
(
requested
==
returned
&&
dup
==
0
)
{
(
*
perfect_run
)
++
;
}
else
{
(
*
approx_run
)
++
;
printf
(
"Requested, returned, duplicated: %d %d %d
\n
"
,
requested
,
returned
,
dup
);
}
}
zfree
(
des
);
}
...
...
@@ -113,18 +117,24 @@ int main(void) {
dictRelease
(
d
);
d
=
dictCreate
(
&
dictTypeTest
,
NULL
);
printf
(
"Getkeys stress test
\n
"
);
printf
(
"Stress testing dictGetSomeKeys
\n
"
);
int
perfect_run
=
0
,
approx_run
=
0
;
for
(
i
=
0
;
i
<
MAX2
;
i
++
)
{
dictAdd
(
d
,(
void
*
)
i
,
NULL
);
stressGetKeys
(
d
,
100
);
stressGetKeys
(
d
,
100
,
&
perfect_run
,
&
approx_run
);
}
for
(
i
=
0
;
i
<
MAX2
;
i
++
)
{
dictDelete
(
d
,(
void
*
)
i
);
dictResize
(
d
);
stressGetKeys
(
d
,
100
);
stressGetKeys
(
d
,
100
,
&
perfect_run
,
&
approx_run
);
}
printf
(
"dictGetSomeKey, %d perfect runs, %d approximated runs
\n
"
,
perfect_run
,
approx_run
);
dictRelease
(
d
);
printf
(
"TEST PASSED!
\n
"
);
...
...
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