func asBuckets(f *shm.File) ([]bucket, gommap.MMap, error) { arr, mmap, err := shm.MMapTyped(f, bucket{}) if err != nil { return nil, nil, err } buckets, ok := arr.([]bucket) if !ok { panic("failed to cast []byte to []bucket") } return buckets, mmap, nil }
func Open(name string) (Table, error) { f, err := shm.Open(name, os.O_RDWR) if err != nil { return nil, err } arr, mmap, err := shm.MMapTyped(f, entry{}) if err != nil { return nil, err } entries, ok := arr.([]entry) if !ok { panic("failed to cast []byte to []entry") } return &table{ f: f, entries: entries, mmap: mmap, }, nil }