| 319 | } |
| 320 | |
| 321 | func (seg *segment) ttl(key []byte, hashVal uint64) (timeLeft uint32, err error) { |
| 322 | slotId := uint8(hashVal >> 8) |
| 323 | hash16 := uint16(hashVal >> 16) |
| 324 | slot := seg.getSlot(slotId) |
| 325 | idx, match := seg.lookup(slot, hash16, key) |
| 326 | if !match { |
| 327 | err = ErrNotFound |
| 328 | return |
| 329 | } |
| 330 | ptr := &slot[idx] |
| 331 | |
| 332 | var hdrBuf [ENTRY_HDR_SIZE]byte |
| 333 | seg.rb.ReadAt(hdrBuf[:], ptr.offset) |
| 334 | hdr := (*entryHdr)(unsafe.Pointer(&hdrBuf[0])) |
| 335 | |
| 336 | if hdr.expireAt == 0 { |
| 337 | return |
| 338 | } else { |
| 339 | now := seg.timer.Now() |
| 340 | if !isExpired(hdr.expireAt, now) { |
| 341 | timeLeft = hdr.expireAt - now |
| 342 | return |
| 343 | } |
| 344 | } |
| 345 | err = ErrNotFound |
| 346 | return |
| 347 | } |
| 348 | |
| 349 | func (seg *segment) expand() { |
| 350 | newSlotData := make([]entryPtr, seg.slotCap*2*256) |