Skip to content

Commit b75bcf0

Browse files
committed
docs(fnv1a): documents fnv1a
1 parent 4f545b1 commit b75bcf0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: lib/bson/fnv1a.js

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const FNV_PRIME = new Long(16777619, 0);
1111
const OFFSET_BASIS = new Long(2166136261, 0);
1212
const FNV_MASK = new Long(MASK_32, 0);
1313

14+
/**
15+
* Implementation of the FNV-1a hash for a 32-bit hash value
16+
* Algorithm can be found here: http://www.isthe.com/chongo/tech/comp/fnv/#FNV-1a
17+
* @ignore
18+
*/
1419
function fnv1a32(input, encoding) {
1520
encoding = encoding || 'utf8';
1621
const octets = Buffer.from(input, encoding);
@@ -24,6 +29,12 @@ function fnv1a32(input, encoding) {
2429
return hash.getLowBitsUnsigned();
2530
}
2631

32+
/**
33+
* Implements FNV-1a to generate 32-bit hash, then uses xor-folding
34+
* to convert to a 24-bit hash. See here for more info:
35+
* http://www.isthe.com/chongo/tech/comp/fnv/#xor-fold
36+
* @ignore
37+
*/
2738
function fnv1a24(input, encoding) {
2839
const _32bit = fnv1a32(input, encoding);
2940
const base = _32bit & MASK_24;

0 commit comments

Comments
 (0)