MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / GeneratePushKey

Method GeneratePushKey

internal/data/list.go:503–528  ·  view source on GitHub ↗
(key []byte, isLeft bool)

Source from the content-addressed store, hash-verified

501}
502
503func (l *List) GeneratePushKey(key []byte, isLeft bool) []byte {
504 // Retrieve or initialize the HeadTailSeq for the list
505 keyStr := string(key)
506 seq, ok := l.Seq[keyStr]
507 if !ok {
508 // If no seq entry exists, infer boundaries from existing items first
509 if items, exists := l.Items[keyStr]; exists && items.Count() > 0 {
510 minSeq, okMinSeq := items.Min()
511 maxSeq, okMaxSeq := items.Max()
512 if !okMinSeq || !okMaxSeq {
513 seq = &HeadTailSeq{Head: InitialListSeq, Tail: InitialListSeq + 1}
514 } else {
515 seq = &HeadTailSeq{
516 Head: utils.ConvertBigEndianBytesToUint64(minSeq.Key) - 1,
517 Tail: utils.ConvertBigEndianBytesToUint64(maxSeq.Key) + 1,
518 }
519 }
520 } else {
521 seq = &HeadTailSeq{Head: InitialListSeq, Tail: InitialListSeq + 1}
522 }
523 l.Seq[keyStr] = seq
524 }
525
526 seqValue := seq.GenerateSeq(isLeft)
527 return utils.EncodeListKey(key, seqValue)
528}
529
530func checkBounds(start, end int, size int) (int, int, error) {
531 if start >= 0 && end < 0 {

Callers 4

TestList_ErrListNotFoundFunction · 0.95
TestList_Push_SuccessFunction · 0.95
RPushMethod · 0.80
LPushMethod · 0.80

Calls 6

EncodeListKeyFunction · 0.92
GenerateSeqMethod · 0.80
CountMethod · 0.65
MinMethod · 0.65
MaxMethod · 0.65

Tested by 2

TestList_ErrListNotFoundFunction · 0.76
TestList_Push_SuccessFunction · 0.76