Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
c-stuff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruce Cowan
c-stuff
Commits
6ae08640
Verified
Commit
6ae08640
authored
2 years ago
by
Bruce Cowan
Browse files
Options
Downloads
Patches
Plain Diff
Handle different unsigned sizes for hash function
parent
4c22ddf7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/utils/hash.c
+17
-2
17 additions, 2 deletions
lib/utils/hash.c
meson.build
+2
-0
2 additions, 0 deletions
meson.build
with
19 additions
and
2 deletions
lib/utils/hash.c
+
17
−
2
View file @
6ae08640
...
...
@@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include
"config.h"
#include
"hash.h"
#include
<string.h>
...
...
@@ -16,13 +18,26 @@ str_hash (const void *data)
size_t
length
=
strlen
((
const
char
*
)
data
);
XXH64_hash_t
hash
=
XXH3_64bits
(
data
,
length
);
return
(
unsigned
)
(
hash
^
(
hash
>>
32
));
#if (SIZEOF_UNSIGNED == 2)
unsigned
ret
=
hash
&
0xffff
;
ret
^=
(
unsigned
)
(
hash
>>
16
&
0xffff
);
ret
^=
(
unsigned
)
(
hash
>>
32
&
0xffff
);
ret
^=
(
unsigned
)
(
hash
>>
48
&
0xffff
);
return
ret
;
#elif (SIZEOF_UNSIGNED == 4)
return
(
hash
&
0xffffffff
)
^
(
hash
>>
32
&
0xffffffff
);
#elif (SIZEOF_UNSIGNED == 8)
return
(
unsigned
)
hash
;
#else
# error "Unsupported unsigned integer size"
#endif
}
bool
str_equal
(
const
void
*
a
,
const
void
*
b
)
{
return
!
strcmp
(
a
,
b
);
return
!
strcmp
(
(
const
char
*
)
a
,
(
const
char
*
)
b
);
}
This diff is collapsed.
Click to expand it.
meson.build
+
2
−
0
View file @
6ae08640
...
...
@@ -16,6 +16,8 @@ xxhash_dep = dependency('libxxhash')
conf_data
=
configuration_data
()
conf_data
.
set
(
'SIZEOF_UNSIGNED'
,
cc
.
sizeof
(
'unsigned'
))
if
cc
.
has_function
(
'reallocarray'
,
prefix
:
'#define _GNU_SOURCE
\n
#include <stdlib.h>'
)
conf_data
.
set
(
'HAVE_REALLOCARRAY'
,
1
)
endif
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment