diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-11-15 20:42:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-15 20:42:19 +0800 |
commit | 17d67c5834679f2b27ef08eddfce3b3a154a96a8 (patch) | |
tree | 3989575655db27f02641bf1fc7d96f87a9441ebb /vendor/github.com/allegro/bigcache/fnv.go | |
parent | 14346e4ef97ca812fb9f1d5d2cd87021c0155cf6 (diff) | |
parent | 434dd5bc0067cdf604d84426df9086015721dd36 (diff) | |
download | go-tangerine-17d67c5834679f2b27ef08eddfce3b3a154a96a8.tar go-tangerine-17d67c5834679f2b27ef08eddfce3b3a154a96a8.tar.gz go-tangerine-17d67c5834679f2b27ef08eddfce3b3a154a96a8.tar.bz2 go-tangerine-17d67c5834679f2b27ef08eddfce3b3a154a96a8.tar.lz go-tangerine-17d67c5834679f2b27ef08eddfce3b3a154a96a8.tar.xz go-tangerine-17d67c5834679f2b27ef08eddfce3b3a154a96a8.tar.zst go-tangerine-17d67c5834679f2b27ef08eddfce3b3a154a96a8.zip |
Merge pull request #18087 from karalabe/trie-read-cacher
cmd, core, eth, light, trie: add trie read caching layer
Diffstat (limited to 'vendor/github.com/allegro/bigcache/fnv.go')
-rw-r--r-- | vendor/github.com/allegro/bigcache/fnv.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/vendor/github.com/allegro/bigcache/fnv.go b/vendor/github.com/allegro/bigcache/fnv.go new file mode 100644 index 000000000..188c9aa6d --- /dev/null +++ b/vendor/github.com/allegro/bigcache/fnv.go @@ -0,0 +1,28 @@ +package bigcache + +// newDefaultHasher returns a new 64-bit FNV-1a Hasher which makes no memory allocations. +// Its Sum64 method will lay the value out in big-endian byte order. +// See https://en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function +func newDefaultHasher() Hasher { + return fnv64a{} +} + +type fnv64a struct{} + +const ( + // offset64 FNVa offset basis. See https://en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function#FNV-1a_hash + offset64 = 14695981039346656037 + // prime64 FNVa prime value. See https://en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function#FNV-1a_hash + prime64 = 1099511628211 +) + +// Sum64 gets the string and returns its uint64 hash value. +func (f fnv64a) Sum64(key string) uint64 { + var hash uint64 = offset64 + for i := 0; i < len(key); i++ { + hash ^= uint64(key[i]) + hash *= prime64 + } + + return hash +} |