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
e1e0e0ed
Commit
e1e0e0ed
authored
Oct 29, 2012
by
Davis King
Browse files
Added an overload of murmur_hash3_128bit() that takes 4 integers instead
of a block of memory.
parent
9aecb4c4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
0 deletions
+89
-0
dlib/general_hash/murmur_hash3.h
dlib/general_hash/murmur_hash3.h
+47
-0
dlib/general_hash/murmur_hash3_abstract.h
dlib/general_hash/murmur_hash3_abstract.h
+18
-0
dlib/test/hash.cpp
dlib/test/hash.cpp
+24
-0
No files found.
dlib/general_hash/murmur_hash3.h
View file @
e1e0e0ed
...
@@ -326,6 +326,53 @@ namespace dlib
...
@@ -326,6 +326,53 @@ namespace dlib
return
std
::
make_pair
(
h1
,
h2
);
return
std
::
make_pair
(
h1
,
h2
);
}
}
// ----------------------------------------------------------------------------------------
inline
std
::
pair
<
uint64
,
uint64
>
murmur_hash3_128bit
(
const
uint32
&
v1
,
const
uint32
&
v2
,
const
uint32
&
v3
,
const
uint32
&
v4
)
{
uint64
h1
=
0
;
uint64
h2
=
0
;
const
uint64
c1
=
DLIB_BIG_CONSTANT
(
0x87c37b91114253d5
);
const
uint64
c2
=
DLIB_BIG_CONSTANT
(
0x4cf5ad432745937f
);
//----------
// body
uint64
k1
=
(
static_cast
<
uint64
>
(
v2
)
<<
32
)
|
v1
;
uint64
k2
=
(
static_cast
<
uint64
>
(
v4
)
<<
32
)
|
v3
;
k1
*=
c1
;
k1
=
DLIB_ROTL64
(
k1
,
31
);
k1
*=
c2
;
h1
=
DLIB_ROTL64
(
k1
,
27
);
h1
=
h1
*
5
+
0x52dce729
;
k2
*=
c2
;
k2
=
DLIB_ROTL64
(
k2
,
33
);
k2
*=
c1
;
h2
=
DLIB_ROTL64
(
k2
,
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 @
e1e0e0ed
...
@@ -50,6 +50,24 @@ namespace dlib
...
@@ -50,6 +50,24 @@ namespace dlib
See: http://code.google.com/p/smhasher/
See: http://code.google.com/p/smhasher/
!*/
!*/
// ----------------------------------------------------------------------------------------
inline
std
::
pair
<
uint64
,
uint64
>
murmur_hash3_128bit
(
const
uint32
&
v1
,
const
uint32
&
v2
,
const
uint32
&
v3
,
const
uint32
&
v4
);
/*!
ensures
- returns a 128bit hash (as two 64bit numbers) of the 4 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 @
e1e0e0ed
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include <cstdlib>
#include <cstdlib>
#include <ctime>
#include <ctime>
#include <dlib/hash.h>
#include <dlib/hash.h>
#include <dlib/rand.h>
#include <dlib/matrix.h>
#include <dlib/matrix.h>
#include <dlib/byte_orderer.h>
#include <dlib/byte_orderer.h>
...
@@ -107,6 +108,28 @@ namespace
...
@@ -107,6 +108,28 @@ namespace
DLIB_TEST
(
final
==
0x6384BA69
);
DLIB_TEST
(
final
==
0x6384BA69
);
}
}
void
test_murmur_hash_128_4
()
{
dlib
::
rand
rnd
;
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
uint32
buf
[
4
]
=
{
rnd
.
get_random_32bit_number
(),
rnd
.
get_random_32bit_number
(),
rnd
.
get_random_32bit_number
(),
rnd
.
get_random_32bit_number
()
};
std
::
pair
<
uint64
,
uint64
>
temp1
,
temp2
;
// Make sure the 4 integer version of murmur hash does the same thing
// as the memory block version.
temp1
=
murmur_hash3_128bit
(
buf
,
sizeof
(
buf
),
0
);
temp2
=
murmur_hash3_128bit
(
buf
[
0
],
buf
[
1
],
buf
[
2
],
buf
[
3
]);
DLIB_TEST
(
temp1
.
first
==
temp2
.
first
);
DLIB_TEST
(
temp1
.
second
==
temp2
.
second
);
}
}
class
test_hash
:
public
tester
class
test_hash
:
public
tester
{
{
public:
public:
...
@@ -183,6 +206,7 @@ namespace
...
@@ -183,6 +206,7 @@ namespace
DLIB_TEST
(
dlib
::
hash
(
mat2
,
6
)
==
0xb8aa7714
);
DLIB_TEST
(
dlib
::
hash
(
mat2
,
6
)
==
0xb8aa7714
);
DLIB_TEST
(
murmur_hash3
(
&
str1
[
0
],
str1
.
size
(),
1
)
==
0xb17cea93
);
DLIB_TEST
(
murmur_hash3
(
&
str1
[
0
],
str1
.
size
(),
1
)
==
0xb17cea93
);
test_murmur_hash_128_4
();
}
}
}
a
;
}
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