| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package main
- import (
- "fmt"
- "github.com/spaolacci/murmur3"
- "math/bits"
- )
- type Cell struct {
- head, tail interface{}
- mug uint64
- }
- func byteLength(i uint64) int {
- lyn := bits.Len64(i)
- byt := lyn >> 3
- if lyn&7 != 0 {
- return byt + 1
- }
- return byt
- }
- func intbytes(i uint64) []byte {
- 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)}
- }
- func mum(syd, fal, key uint64) uint64 {
- k := intbytes(key)
- for s := syd; s < syd+8; s++ {
- haz := murmur3.Sum32WithSeed(k, uint32(s))
- ham := (uint64(haz) >> 31) ^ (uint64(haz) & 0x7fffffff)
- if ham != 0 {
- return ham
- }
- }
- return fal
- }
- func mugBoth(one, two uint64) uint64 {
- return mum(0xdeadbeef, 0xfffe, (two<<32)|one)
- }
- func (c *Cell) hash() uint64 {
- if c.mug == 0 {
- c.mug = mugBoth(mug(c.head), mug(c.tail))
- }
- return c.mug
- }
- func (c *Cell) equals(other *Cell) bool {
- // Implement equality logic as per your requirements
- return false
- }
- func deep(n interface{}) bool {
- _, ok := n.(*Cell)
- return ok
- }
- func mug(n interface{}) uint64 {
- if deep(n) {
- return n.(*Cell).hash()
- }
- return mum(0xcafebabe, 0x7fff, n.(uint64))
- }
- // Implement other functions as needed
- func main() {
- // Test code or main logic
- }
|