view provides zero-copy access to the element's value, without copying to an intermediate buffer.
(key []byte, fn func([]byte) error, hashVal uint64, peek bool)
| 257 | // view provides zero-copy access to the element's value, without copying to |
| 258 | // an intermediate buffer. |
| 259 | func (seg *segment) view(key []byte, fn func([]byte) error, hashVal uint64, peek bool) (err error) { |
| 260 | hdr, ptrOffset, err := seg.locate(key, hashVal, peek) |
| 261 | if err != nil { |
| 262 | return |
| 263 | } |
| 264 | start := ptrOffset + ENTRY_HDR_SIZE + int64(hdr.keyLen) |
| 265 | val, err := seg.rb.Slice(start, int64(hdr.valLen)) |
| 266 | if err != nil { |
| 267 | return err |
| 268 | } |
| 269 | err = fn(val) |
| 270 | if !peek { |
| 271 | atomic.AddInt64(&seg.hitCount, 1) |
| 272 | } |
| 273 | return |
| 274 | } |
| 275 | |
| 276 | func (seg *segment) locate(key []byte, hashVal uint64, peek bool) (hdrEntry entryHdr, ptrOffset int64, err error) { |
| 277 | slotId := uint8(hashVal >> 8) |