city64.go 705 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package cityhash
  2. import (
  3. "encoding/binary"
  4. "hash"
  5. )
  6. type City64 struct {
  7. s []byte
  8. }
  9. var _ hash.Hash64 = (*City64)(nil)
  10. var _ hash.Hash = (*City64)(nil)
  11. func New64() hash.Hash64 {
  12. return &City64{}
  13. }
  14. func (this *City64) Sum(b []byte) []byte {
  15. b2 := make([]byte, 8)
  16. binary.BigEndian.PutUint64(b2, this.Sum64())
  17. b = append(b, b2...)
  18. return b
  19. }
  20. func (this *City64) Sum64() uint64 {
  21. return CityHash64(this.s, uint32(len(this.s)))
  22. }
  23. func (this *City64) Reset() {
  24. this.s = this.s[0:0]
  25. }
  26. func (this *City64) BlockSize() int {
  27. return 1
  28. }
  29. func (this *City64) Write(s []byte) (n int, err error) {
  30. this.s = append(this.s, s...)
  31. return len(s), nil
  32. }
  33. func (this *City64) Size() int {
  34. return 8
  35. }