noun.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/spaolacci/murmur3"
  5. "math/bits"
  6. )
  7. type Cell struct {
  8. head, tail interface{}
  9. mug uint64
  10. }
  11. func byteLength(i uint64) int {
  12. lyn := bits.Len64(i)
  13. byt := lyn >> 3
  14. if lyn&7 != 0 {
  15. return byt + 1
  16. }
  17. return byt
  18. }
  19. func intbytes(i uint64) []byte {
  20. return []byte{byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24), byte(i >> 32), byte(i >> 40), byte(i >> 48), byte(i >> 56)}
  21. }
  22. func mum(syd, fal, key uint64) uint64 {
  23. k := intbytes(key)
  24. for s := syd; s < syd+8; s++ {
  25. haz := murmur3.Sum32WithSeed(k, uint32(s))
  26. ham := (uint64(haz) >> 31) ^ (uint64(haz) & 0x7fffffff)
  27. if ham != 0 {
  28. return ham
  29. }
  30. }
  31. return fal
  32. }
  33. func mugBoth(one, two uint64) uint64 {
  34. return mum(0xdeadbeef, 0xfffe, (two<<32)|one)
  35. }
  36. func (c *Cell) hash() uint64 {
  37. if c.mug == 0 {
  38. c.mug = mugBoth(mug(c.head), mug(c.tail))
  39. }
  40. return c.mug
  41. }
  42. func (c *Cell) equals(other *Cell) bool {
  43. // Implement equality logic as per your requirements
  44. return false
  45. }
  46. func deep(n interface{}) bool {
  47. _, ok := n.(*Cell)
  48. return ok
  49. }
  50. func mug(n interface{}) uint64 {
  51. if deep(n) {
  52. return n.(*Cell).hash()
  53. }
  54. return mum(0xcafebabe, 0x7fff, n.(uint64))
  55. }
  56. // Implement other functions as needed
  57. func main() {
  58. // Test code or main logic
  59. }