MCPcopy
hub / github.com/segmentio/ksuid / Next

Method Next

set.go:272–343  ·  view source on GitHub ↗

Next moves the iterator forward, returning true if there a KSUID was found, or false if the iterator as reached the end of the set it was created from.

()

Source from the content-addressed store, hash-verified

270// Next moves the iterator forward, returning true if there a KSUID was found,
271// or false if the iterator as reached the end of the set it was created from.
272func (it *CompressedSetIter) Next() bool {
273 if it.seqlength != 0 {
274 value := incr128(it.lastValue)
275 it.KSUID = value.ksuid(it.timestamp)
276 it.seqlength--
277 it.lastValue = value
278 return true
279 }
280
281 if it.offset == len(it.content) {
282 return false
283 }
284
285 b := it.content[it.offset]
286 it.offset++
287
288 const mask = rawKSUID | timeDelta | payloadDelta | payloadRange
289 tag := int(b) & mask
290 cnt := int(b) & ^mask
291
292 switch tag {
293 case rawKSUID:
294 off0 := it.offset
295 off1 := off0 + byteLength
296
297 copy(it.KSUID[:], it.content[off0:off1])
298
299 it.offset = off1
300 it.timestamp = it.KSUID.Timestamp()
301 it.lastValue = uint128Payload(it.KSUID)
302
303 case timeDelta:
304 off0 := it.offset
305 off1 := off0 + cnt
306 off2 := off1 + payloadLengthInBytes
307
308 it.timestamp += varint32(it.content[off0:off1])
309
310 binary.BigEndian.PutUint32(it.KSUID[:timestampLengthInBytes], it.timestamp)
311 copy(it.KSUID[timestampLengthInBytes:], it.content[off1:off2])
312
313 it.offset = off2
314 it.lastValue = uint128Payload(it.KSUID)
315
316 case payloadDelta:
317 off0 := it.offset
318 off1 := off0 + cnt
319
320 delta := varint128(it.content[off0:off1])
321 value := add128(it.lastValue, delta)
322
323 it.KSUID = value.ksuid(it.timestamp)
324 it.offset = off1
325 it.lastValue = value
326
327 case payloadRange:
328 off0 := it.offset
329 off1 := off0 + cnt

Callers 1

writeToMethod · 0.45

Calls 8

incr128Function · 0.85
uint128PayloadFunction · 0.85
varint32Function · 0.85
varint128Function · 0.85
add128Function · 0.85
varint64Function · 0.85
ksuidMethod · 0.80
TimestampMethod · 0.80

Tested by

no test coverage detected