Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-selector
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-selector
Commits
7a96693c
Commit
7a96693c
authored
Jun 02, 2020
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PH_Stats().
parent
43e4b858
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
0 deletions
+58
-0
ph.c
src/ph.c
+32
-0
ph.h
src/ph.h
+14
-0
bench_ph.c
src/tests/bench/bench_ph.c
+12
-0
No files found.
src/ph.c
View file @
7a96693c
...
...
@@ -437,6 +437,38 @@ PH_Dump(struct ph *ph, char **strings)
return
(
sb
);
}
void
PH_Stats
(
const
struct
ph
*
const
restrict
ph
,
char
*
const
restrict
*
const
restrict
strings
,
struct
ph_stats
*
const
restrict
stats
)
{
CHECK_OBJ_NOTNULL
(
stats
,
PH_STATS_MAGIC
);
memset
(
stats
,
0
,
sizeof
(
*
stats
));
if
(
ph
==
NULL
)
return
;
CHECK_OBJ
(
ph
,
PH_MAGIC
);
CHECK_OBJ_NOTNULL
(
ph
->
h1
,
HASH_MAGIC
);
AN
(
ph
->
tbl
);
AN
(
ph
->
collision
);
AN
(
strings
);
stats
->
buckets
=
ph
->
h1
->
mask
+
1
;
stats
->
klen
=
ph
->
l
;
stats
->
minlen
=
ph
->
minlen
;
stats
->
maxlen
=
ph
->
maxlen
;
for
(
unsigned
i
=
0
;
i
<=
ph
->
h1
->
mask
;
i
++
)
if
(
vbit_test
(
ph
->
collision
,
i
))
{
struct
hash
*
h2
;
h2
=
ph
->
tbl
[
i
].
h2
;
CHECK_OBJ_NOTNULL
(
h2
,
HASH_MAGIC
);
stats
->
collisions
++
;
}
}
void
PH_Free
(
struct
ph
*
ph
)
{
...
...
src/ph.h
View file @
7a96693c
...
...
@@ -42,6 +42,16 @@
*/
struct
ph
;
struct
ph_stats
{
unsigned
magic
;
#define PH_STATS_MAGIC 0x68b803bb
uint64_t
buckets
;
uint64_t
collisions
;
uint64_t
klen
;
uint64_t
minlen
;
uint64_t
maxlen
;
};
/*
* Initialize perfect hashing. Supplies a seed for random number
* generation, which should be obtained from an entropy source. Only
...
...
@@ -76,6 +86,10 @@ unsigned PH_Lookup(const struct ph * const restrict ph,
char
*
const
restrict
*
const
restrict
strings
,
const
char
*
const
restrict
subject
);
void
PH_Stats
(
const
struct
ph
*
const
restrict
ph
,
char
*
const
restrict
*
const
restrict
strings
,
struct
ph_stats
*
const
restrict
stats
);
/*
* Return a string dump of ph as generated for strings.
*
...
...
src/tests/bench/bench_ph.c
View file @
7a96693c
...
...
@@ -115,6 +115,7 @@ main(int argc, char *argv[])
struct
timespec
before
,
after
,
start
,
finish
;
uint64_t
ns
=
0
,
iters
,
matches
;
uint32_t
seed
[
4
];
struct
ph_stats
stats
=
{
.
magic
=
PH_STATS_MAGIC
};
int
opt
,
do_shuf
=
0
,
do_iters
=
ITERATIONS
;
struct
rusage
rusage
;
...
...
@@ -314,6 +315,17 @@ main(int argc, char *argv[])
printf
(
"... done.
\n
"
);
}
printf
(
"
\n
Getting stats ...
\n
"
);
(
void
)
clock_gettime
(
CLOCK
,
&
before
);
PH_Stats
(
ph
,
strings
,
&
stats
);
(
void
)
clock_gettime
(
CLOCK
,
&
after
);
printf
(
"Stats computed in %lu ns
\n
"
,
tdiff
(
&
before
,
&
after
));
printf
(
"%lu buckets
\n
"
,
stats
.
buckets
);
printf
(
"%lu collisions
\n
"
,
stats
.
collisions
);
printf
(
"%lu key vector length
\n
"
,
stats
.
klen
);
printf
(
"%lu min string length
\n
"
,
stats
.
minlen
);
printf
(
"%lu max string length
\n
"
,
stats
.
maxlen
);
if
(
do_iters
==
0
)
exit
(
EXIT_SUCCESS
);
...
...
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