Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
slash
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
slash
Commits
1396585d
Unverified
Commit
1396585d
authored
Oct 02, 2023
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor hash definitions to table file
parent
ecb66d2a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
55 deletions
+31
-55
fellow_hash.c
src/fellow_hash.c
+23
-55
fellow_hash.tbl.h
src/tbl/fellow_hash.tbl.h
+8
-0
No files found.
src/fellow_hash.c
View file @
1396585d
...
...
@@ -44,22 +44,16 @@ fh_assert_xxhash_version(void)
static
const
size_t
fh_len
[
FH_LIM
]
=
{
[
FH_NONE
]
=
0
,
[
FH_SHA256
]
=
FSHA256_LEN
,
#ifdef HAVE_XXHASH_H
[
FH_XXH32
]
=
sizeof
(
XXH32_hash_t
),
[
FH_XXH3_64
]
=
sizeof
(
XXH64_hash_t
),
[
FH_XXH3_128
]
=
sizeof
(
XXH128_hash_t
)
#endif
#define FH(up, lo, len) \
[FH_ ## up] = len,
#include "tbl/fellow_hash.tbl.h"
};
const
char
*
const
fh_name
[
FH_LIM
]
=
{
[
FH_NONE
]
=
"none"
,
[
FH_SHA256
]
=
"sha256"
,
#ifdef HAVE_XXHASH_H
[
FH_XXH32
]
=
"xxh32"
,
[
FH_XXH3_64
]
=
"xxh3_64"
,
[
FH_XXH3_128
]
=
"xxh3_128"
#endif
#define FH(up, lo, len) \
[FH_ ## up] = #lo,
#include "tbl/fellow_hash.tbl.h"
};
static
void
__attribute__
((
constructor
))
...
...
@@ -69,12 +63,9 @@ fh_assert_lengths(void)
union
fh
fhh
=
{{
0
}};
(
void
)
fhh
;
assert
(
fh_len
[
FH_SHA256
]
==
sizeof
fhh
.
sha256
);
#ifdef HAVE_XXHASH_H
assert
(
fh_len
[
FH_XXH32
]
==
sizeof
fhh
.
xxh32
);
assert
(
fh_len
[
FH_XXH3_64
]
==
sizeof
fhh
.
xxh3_64
);
assert
(
fh_len
[
FH_XXH3_128
]
==
sizeof
fhh
.
xxh3_128
);
#endif
#define FH(up, lo, len) \
assert(fh_len[FH_ ## up] == sizeof fhh.lo);
#include "tbl/fellow_hash.tbl.h"
}
#define FH_H_SHA256(d, p, l) sha256(d, p, l)
...
...
@@ -88,29 +79,16 @@ fh_assert_lengths(void)
void
fh
(
uint8_t
fht
,
union
fh
*
fhh
,
const
void
*
p
,
size_t
l
)
{
//lint --e{779,506} == NULL comparison with constant
//lint -e{506} Constant value Boolean (assert)
//lint -e{525} negative indentation
switch
(
fht
)
{
case
FH_SHA256
:
FH_H_SHA256
(
fhh
->
sha256
,
p
,
l
);
#define FH(up, lo, len) \
case FH_ ## up: \
FH_H_ ## up(fhh->lo, p, l); \
break;
#ifdef HAVE_XXHASH_H
case
FH_XXH32
:
FH_H_XXH32
(
fhh
->
xxh32
,
p
,
l
);
break
;
case
FH_XXH3_64
:
FH_H_XXH3_64
(
fhh
->
xxh3_64
,
p
,
l
);
break
;
case
FH_XXH3_128
:
FH_H_XXH3_128
(
fhh
->
xxh3_128
,
p
,
l
);
break
;
#else
case
FH_XXH32
:
case
FH_XXH3_64
:
case
FH_XXH3_128
:
assert
(
"xxhash support not compiled in"
==
NULL
);
#endif
#include "tbl/fellow_hash.tbl.h"
default:
assert
(
"wrong hash type"
==
NULL
);
assert
(
0
&&
"wrong hash type"
);
}
}
...
...
@@ -129,25 +107,15 @@ xxh3_128_cmp(const uint8_t v[16], const void *p, size_t l)
int
fhcmp
(
uint8_t
fht
,
const
union
fh
*
fhh
,
const
void
*
p
,
size_t
l
)
{
//lint --e{779,506} == NULL comparison with constant
//lint -e{506} Constant value Boolean (assert)
//lint -e{525} negative indentation
switch
(
fht
)
{
case
FH_SHA256
:
return
(
FH_C_SHA256
(
fhh
->
sha256
,
p
,
l
));
#ifdef HAVE_XXHASH_H
case
FH_XXH32
:
return
(
FH_C_XXH32
(
fhh
->
xxh32
,
p
,
l
));
case
FH_XXH3_64
:
return
(
FH_C_XXH3_64
(
fhh
->
xxh3_64
,
p
,
l
));
case
FH_XXH3_128
:
return
(
FH_C_XXH3_128
(
fhh
->
xxh3_128
,
p
,
l
));
#else
case
FH_XXH32
:
case
FH_XXH3_64
:
case
FH_XXH3_128
:
assert
(
"xxhash support not compiled in"
==
NULL
);
#endif
#define FH(up, lo, len) \
case FH_ ## up: \
return(FH_C_ ## up(fhh->lo, p, l));
#include "tbl/fellow_hash.tbl.h"
default:
assert
(
"wrong hash type"
==
NULL
);
assert
(
0
&&
"wrong hash type"
);
}
// SunOS gcc says "control reaches...", flint says not
//lint -e{527}
...
...
src/tbl/fellow_hash.tbl.h
0 → 100644
View file @
1396585d
// UPPER, lower, length
FH
(
SHA256
,
sha256
,
FSHA256_LEN
)
#ifdef HAVE_XXHASH_H
FH
(
XXH32
,
xxh32
,
sizeof
(
XXH32_hash_t
))
FH
(
XXH3_64
,
xxh3_64
,
sizeof
(
XXH64_hash_t
))
FH
(
XXH3_128
,
xxh3_128
,
sizeof
(
XXH128_hash_t
))
#endif
#undef FH
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