FindStartKeyInclusivePos() returns the logical entry position for the given (inclusive) start key. With segment keys of [b, d, f], looking for 'c' will return 1. Looking for 'd' will return 1. Looking for 'g' will return 3. Looking for 'a' will return 0.
(startKeyInclusive []byte)
| 482 | // looking for 'c' will return 1. Looking for 'd' will return 1. |
| 483 | // Looking for 'g' will return 3. Looking for 'a' will return 0. |
| 484 | func (a *segment) findStartKeyInclusivePos(startKeyInclusive []byte) int { |
| 485 | kvs := a.kvs |
| 486 | buf := a.buf |
| 487 | |
| 488 | i, j := a.searchIndex(startKeyInclusive) |
| 489 | if i == j { |
| 490 | return i |
| 491 | } |
| 492 | |
| 493 | startKeyLen := int((maskKeyLength & kvs[0]) >> 32) |
| 494 | startKeyBeg := int(kvs[1]) |
| 495 | startCmp := bytes.Compare(startKeyInclusive, |
| 496 | buf[startKeyBeg:startKeyBeg+startKeyLen]) |
| 497 | if startCmp < 0 { // If key smaller than smallest key, return early. |
| 498 | return i |
| 499 | } |
| 500 | |
| 501 | for i < j { |
| 502 | h := i + (j-i)/2 // Keep i <= h < j. |
| 503 | x := h * 2 |
| 504 | klen := int((maskKeyLength & kvs[x]) >> 32) |
| 505 | kbeg := int(kvs[x+1]) |
| 506 | cmp := bytes.Compare(buf[kbeg:kbeg+klen], startKeyInclusive) |
| 507 | if cmp == 0 { |
| 508 | return h |
| 509 | } else if cmp < 0 { |
| 510 | i = h + 1 |
| 511 | } else { |
| 512 | j = h |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | return i |
| 517 | } |
| 518 | |
| 519 | // getOperationKeyVal() returns the operation, key, val for a given |
| 520 | // logical entry position in the segment. |