Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Go package porting the standard hashing algorithms to a more efficient implementation.

License

NotificationsYou must be signed in to change notification settings

segmentio/fasthash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go package porting the standard hashing algorithms to a more efficient implementation.

Note
Segment has paused maintenance on this project, but may return it to an active status in the future. Issues and pull requests from external contributors are not being considered, although internal contributions may appear from time to time. The project remains available under its open source license for anyone to use.

Motivations

Go has great support for hashing algorithms in the standard library, but theAPIs are all exposed as interfaces, which means passing strings or byte slicesto those require dynamic memory allocations. Hashing a string typically requires2 allocations, one for the Hash value, and one to covert the string to a byteslice.

This package attempts to solve this issue by exposing functions that implementstring hashing algorithms and don't require dynamic memory alloations.

Testing

To ensure consistency between thefasthash package and the standard library,all tests must be implemented to run against the standard hash functions andvalidate that both packages produced the same results.

Benchmarks

The implementations also have to prove that they are more efficient in terms ofCPU and memory usage than the functions found in the standard library.
Here's an example with fnv-1a:

BenchmarkHash64/standard_hash_function 20000000   105.0 ns/op   342.31 MB/s   56 B/op   2 allocs/opBenchmarkHash64/hash_function          50000000    38.6 ns/op   932.35 MB/s    0 B/op   0 allocs/op

Usage Example: FNV-1a

package mainimport ("fmt""github.com/segmentio/fasthash/fnv1a")funcmain() {// Hash a single string.h1:=fnv1a.HashString64("Hello World!")fmt.Println("FNV-1a hash of 'Hello World!':",h1)// Incrementally compute a hash value from a sequence of strings.h2:=fnv1a.Init64h2=fnv1a.AddString64(h2,"A")h2=fnv1a.AddString64(h2,"B")h2=fnv1a.AddString64(h2,"C")fmt.Println("FNV-1a hash of 'ABC':",h2)}

About

Go package porting the standard hashing algorithms to a more efficient implementation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors6

Languages


[8]ページ先頭

©2009-2025 Movatter.jp