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
49f2d6f9
Commit
49f2d6f9
authored
Nov 27, 2012
by
Davis King
Browse files
Added murmur_hash3_2()
parent
484e8a3d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
0 deletions
+74
-0
dlib/general_hash/murmur_hash3.h
dlib/general_hash/murmur_hash3.h
+37
-0
dlib/general_hash/murmur_hash3_abstract.h
dlib/general_hash/murmur_hash3_abstract.h
+15
-0
dlib/test/hash.cpp
dlib/test/hash.cpp
+22
-0
No files found.
dlib/general_hash/murmur_hash3.h
View file @
49f2d6f9
...
@@ -218,6 +218,43 @@ namespace dlib
...
@@ -218,6 +218,43 @@ namespace dlib
return
h1
;
return
h1
;
}
}
// ----------------------------------------------------------------------------------------
inline
uint32
murmur_hash3_2
(
const
uint32
v1
,
const
uint32
v2
)
{
uint32
h1
=
v2
;
uint32
c1
=
0xcc9e2d51
;
uint32
c2
=
0x1b873593
;
//----------
// body
uint32
k1
=
v1
;
k1
*=
c1
;
k1
=
DLIB_ROTL32
(
k1
,
15
);
k1
*=
c2
;
h1
^=
k1
;
h1
=
DLIB_ROTL32
(
h1
,
13
);
h1
=
h1
*
5
+
0xe6546b64
;
//----------
// finalization
h1
^=
4
;
// =^ by length in bytes
h1
=
murmur_fmix
(
h1
);
return
h1
;
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
inline
std
::
pair
<
uint64
,
uint64
>
murmur_hash3_128bit
(
inline
std
::
pair
<
uint64
,
uint64
>
murmur_hash3_128bit
(
...
...
dlib/general_hash/murmur_hash3_abstract.h
View file @
49f2d6f9
...
@@ -29,6 +29,21 @@ namespace dlib
...
@@ -29,6 +29,21 @@ namespace dlib
See: http://code.google.com/p/smhasher/
See: http://code.google.com/p/smhasher/
!*/
!*/
// ----------------------------------------------------------------------------------------
inline
uint32
murmur_hash3_2
(
const
uint32
v1
,
const
uint32
v2
);
/*!
ensures
- returns a 32bit hash of the two 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_x86_32.
See: http://code.google.com/p/smhasher/
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
std
::
pair
<
uint64
,
uint64
>
murmur_hash3_128bit
(
std
::
pair
<
uint64
,
uint64
>
murmur_hash3_128bit
(
...
...
dlib/test/hash.cpp
View file @
49f2d6f9
...
@@ -162,6 +162,27 @@ namespace
...
@@ -162,6 +162,27 @@ namespace
}
}
}
}
void
test_murmur_hash_64_2
()
{
byte_orderer
bo
;
dlib
::
rand
rnd
;
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
uint32
val
=
rnd
.
get_random_32bit_number
();
const
uint32
seed
=
rnd
.
get_random_32bit_number
();
bo
.
host_to_little
(
val
);
uint32
temp1
,
temp2
;
// Make sure the 2 integer version of murmur hash does the same thing
// as the memory block version.
temp1
=
murmur_hash3
(
&
val
,
sizeof
(
val
),
seed
);
temp2
=
murmur_hash3_2
(
val
,
seed
);
DLIB_TEST
(
temp1
==
temp2
);
}
}
class
test_hash
:
public
tester
class
test_hash
:
public
tester
{
{
public:
public:
...
@@ -240,6 +261,7 @@ namespace
...
@@ -240,6 +261,7 @@ namespace
test_murmur_hash_128_4
();
test_murmur_hash_128_4
();
test_murmur_hash_128_3
();
test_murmur_hash_128_3
();
test_murmur_hash_64_2
();
}
}
}
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