MCPcopy
hub / github.com/coocood/freecache / nextForSlot

Method nextForSlot

iterator.go:53–74  ·  view source on GitHub ↗
(seg *segment, slotId int)

Source from the content-addressed store, hash-verified

51}
52
53func (it *Iterator) nextForSlot(seg *segment, slotId int) *Entry {
54 slotOff := int32(it.slotIdx) * seg.slotCap
55 slot := seg.slotsData[slotOff : slotOff+seg.slotLens[it.slotIdx] : slotOff+seg.slotCap]
56 for it.entryIdx < len(slot) {
57 ptr := slot[it.entryIdx]
58 it.entryIdx++
59 now := seg.timer.Now()
60 var hdrBuf [ENTRY_HDR_SIZE]byte
61 seg.rb.ReadAt(hdrBuf[:], ptr.offset)
62 hdr := (*entryHdr)(unsafe.Pointer(&hdrBuf[0]))
63 if hdr.expireAt == 0 || hdr.expireAt > now {
64 entry := new(Entry)
65 entry.Key = make([]byte, hdr.keyLen)
66 entry.Value = make([]byte, hdr.valLen)
67 entry.ExpireAt = hdr.expireAt
68 seg.rb.ReadAt(entry.Key, ptr.offset+ENTRY_HDR_SIZE)
69 seg.rb.ReadAt(entry.Value, ptr.offset+ENTRY_HDR_SIZE+int64(hdr.keyLen))
70 return entry
71 }
72 }
73 return nil
74}
75
76// NewIterator creates a new iterator for the cache.
77func (cache *Cache) NewIterator() *Iterator {

Callers 1

nextForSegmentMethod · 0.95

Calls 2

ReadAtMethod · 0.80
NowMethod · 0.65

Tested by

no test coverage detected