| 501 | } |
| 502 | |
| 503 | func (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 | |
| 530 | func checkBounds(start, end int, size int) (int, int, error) { |
| 531 | if start >= 0 && end < 0 { |