diff --git a/bithack.go b/bithack.go index be13d69..19847d7 100644 --- a/bithack.go +++ b/bithack.go @@ -22,6 +22,12 @@ func makeUint64BucketArray(size int) unsafe.Pointer { } func matchTopHash(tophash [bucketCnt]uint8, top uint8) bitmask64 { + // For the technique, see: + // http://graphics.stanford.edu/~seander/bithacks.html##ValueInWord + // (Determine if a word has a byte equal to n). + // + // The idea comes from SwissTable C++ version: + // https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h#L661 ctrl := littleEndianBytesToUint64(tophash) cmp := ctrl ^ (lsbs * uint64(top)) return bitmask64((cmp - lsbs) & ^cmp & msbs) diff --git a/readme.md b/readme.md index 087fa86..51593d5 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ umap is a fast, reliable, simple hashmap that only supports the uint64 key/value pair. It is faster than the runtime hashmap in most cases. -The umap is mainly based on the SwissTable(https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h). +The umap is mainly based on the SwissTable(https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h), it is portable for all platforms and doesn't require SSE or AVX. ## QuickStart