-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAccurate.php
More file actions
34 lines (32 loc) · 929 Bytes
/
Accurate.php
File metadata and controls
34 lines (32 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php declare(strict_types=1);
namespace Jspeedz\PhpConsistentHashing\HashFunctions;
/**
* 5 probes.
*
* This one is a bit more accurate that the Standard version.
* But also, slower.
*/
class Accurate {
/**
* @return callable[]
*/
public function __invoke(): array {
return [
function(string $key): int {
return crc32($key);
},
function(string $key): int|float {
return hexdec(substr(hash('sha1', $key), 0, 8));
},
function(string $key): float|int {
return hexdec(substr(hash('sha256', $key), 0, 8));
},
function(string $key): int|float {
return hexdec(substr(hash('md4', $key), 0, 8));
},
function(string $key): float|int {
return hexdec(substr(hash('md5', $key), 0, 8));
},
];
}
}