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
OpenDAS
dlib
Commits
52aeba58
Commit
52aeba58
authored
Nov 24, 2012
by
Davis King
Browse files
Added test_murmur_hash_128_3(). Also fixed an endianness error in the hashing
unit test code.
parent
ec79a937
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
0 deletions
+86
-0
dlib/general_hash/murmur_hash3.h
dlib/general_hash/murmur_hash3.h
+42
-0
dlib/general_hash/murmur_hash3_abstract.h
dlib/general_hash/murmur_hash3_abstract.h
+17
-0
dlib/test/hash.cpp
dlib/test/hash.cpp
+27
-0
No files found.
dlib/general_hash/murmur_hash3.h
View file @
52aeba58
...
...
@@ -372,6 +372,48 @@ namespace dlib
return
std
::
make_pair
(
h1
,
h2
);
}
// ----------------------------------------------------------------------------------------
inline
std
::
pair
<
uint64
,
uint64
>
murmur_hash3_128bit_3
(
uint64
k1
,
uint64
k2
,
uint64
k3
)
{
uint64
h1
=
k3
;
uint64
h2
=
k3
;
const
uint64
c1
=
DLIB_BIG_CONSTANT
(
0x87c37b91114253d5
);
const
uint64
c2
=
DLIB_BIG_CONSTANT
(
0x4cf5ad432745937f
);
//----------
// body
k1
*=
c1
;
k1
=
DLIB_ROTL64
(
k1
,
31
);
k1
*=
c2
;
h1
^=
k1
;
h1
=
DLIB_ROTL64
(
h1
,
27
);
h1
+=
h2
;
h1
=
h1
*
5
+
0x52dce729
;
k2
*=
c2
;
k2
=
DLIB_ROTL64
(
k2
,
33
);
k2
*=
c1
;
h2
^=
k2
;
h2
=
DLIB_ROTL64
(
h2
,
31
);
h2
+=
h1
;
h2
=
h2
*
5
+
0x38495ab5
;
//----------
// finalization
h1
^=
16
;
h2
^=
16
;
h1
+=
h2
;
h2
+=
h1
;
h1
=
murmur_fmix
(
h1
);
h2
=
murmur_fmix
(
h2
);
h1
+=
h2
;
h2
+=
h1
;
return
std
::
make_pair
(
h1
,
h2
);
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/general_hash/murmur_hash3_abstract.h
View file @
52aeba58
...
...
@@ -68,6 +68,23 @@ namespace dlib
See: http://code.google.com/p/smhasher/
!*/
// ----------------------------------------------------------------------------------------
std
::
pair
<
uint64
,
uint64
>
murmur_hash3_128bit_3
(
uint64
k1
,
uint64
k2
,
uint64
k3
);
/*!
ensures
- returns a 128bit hash (as two 64bit numbers) of the 3 integers given to this
function.
- This function is machine architecture agnostic and should always give the
same hash value when presented with the same inputs.
- This hashing algorithm is Austin Appleby's excellent MurmurHash3_x64_128.
See: http://code.google.com/p/smhasher/
!*/
// ----------------------------------------------------------------------------------------
}
...
...
dlib/test/hash.cpp
View file @
52aeba58
...
...
@@ -110,6 +110,7 @@ namespace
void
test_murmur_hash_128_4
()
{
byte_orderer
bo
;
dlib
::
rand
rnd
;
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
...
...
@@ -119,6 +120,7 @@ namespace
rnd
.
get_random_32bit_number
()
};
bo
.
host_to_little
(
buf
);
std
::
pair
<
uint64
,
uint64
>
temp1
,
temp2
;
// Make sure the 4 integer version of murmur hash does the same thing
...
...
@@ -130,6 +132,30 @@ namespace
}
}
void
test_murmur_hash_128_3
()
{
byte_orderer
bo
;
dlib
::
rand
rnd
;
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
uint64
buf
[
2
]
=
{
rnd
.
get_random_64bit_number
(),
rnd
.
get_random_64bit_number
(),
};
const
uint32
seed
=
rnd
.
get_random_32bit_number
();
bo
.
host_to_little
(
buf
);
std
::
pair
<
uint64
,
uint64
>
temp1
,
temp2
;
// Make sure the 3 integer version of murmur hash does the same thing
// as the memory block version.
temp1
=
murmur_hash3_128bit
(
buf
,
sizeof
(
buf
),
seed
);
temp2
=
murmur_hash3_128bit_3
(
buf
[
0
],
buf
[
1
],
seed
);
DLIB_TEST
(
temp1
.
first
==
temp2
.
first
);
DLIB_TEST
(
temp1
.
second
==
temp2
.
second
);
}
}
class
test_hash
:
public
tester
{
public:
...
...
@@ -207,6 +233,7 @@ namespace
DLIB_TEST
(
murmur_hash3
(
&
str1
[
0
],
str1
.
size
(),
1
)
==
0xb17cea93
);
test_murmur_hash_128_4
();
test_murmur_hash_128_3
();
}
}
a
;
...
...
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