Branch Coverage

sortedset.h
Criterion Covered Total %
branch 339 554 61.1


line true false branch
142 0 35 if (v < 2) return 1;
156 772078 2522829 if (sa < sb) return -1;
157 367429 2155400 if (sa > sb) return 1;
158 407429 1747971 return (ma < mb) ? -1 : (ma > mb) ? 1 : 0;
192 0 0 if (pid == 0) return 1; /* no owner recorded, assume alive */
193 0 0 return !(kill((pid_t)pid, 0) == -1 && errno == ESRCH);
0 0 return !(kill((pid_t)pid, 0) == -1 && errno == ESRCH);
203 0 0 if (!__atomic_compare_exchange_n(&hdr->rwlock, &observed_rwlock,
209 0 0 if (__atomic_load_n(&hdr->rwlock_waiters, __ATOMIC_RELAXED) > 0)
233 234374 30 if (__builtin_expect(cur_gen == h->cached_fork_gen && h->my_slot_idx != UINT32_MAX, 1))
234374 0 if (__builtin_expect(cur_gen == h->cached_fork_gen && h->my_slot_idx != UINT32_MAX, 1))
244 33 0 for (uint32_t i = 0; i < SS_READER_SLOTS; i++) {
247 30 3 if (__atomic_compare_exchange_n(&h->reader_slots[s].pid,
267 0 0 if (!sub) return;
270 0 0 uint32_t want = (cur > sub) ? cur - sub : 0;
271 0 0 if (__atomic_compare_exchange_n(p, &cur, want,
294 0 0 if (!__atomic_compare_exchange_n(&h->reader_slots[i].pid, &expected, 0,
299 0 0 if (wp) ss_atomic_sub_cap(&hdr->rwlock_waiters, wp);
300 0 0 if (writp) ss_atomic_sub_cap(&hdr->rwlock_writers_waiting, writp);
314 0 0 if (!h->reader_slots) return;
327 0 0 for (uint32_t i = 0; i < SS_READER_SLOTS; i++) {
329 0 0 if (pid == 0) continue;
331 0 0 if (ss_pid_alive(pid)) {
332 0 0 if (sc > 0) any_live_reader = 1;
335 0 0 if (sc > 0) { found_dead_reader = 1; continue; }
352 0 0 if (found_dead_reader && !any_live_reader) {
0 0 if (found_dead_reader && !any_live_reader) {
354 0 0 if (cur > 0 && cur < SS_RWLOCK_WRITER_BIT) {
0 0 if (cur > 0 && cur < SS_RWLOCK_WRITER_BIT) {
355 0 0 if (__atomic_compare_exchange_n(&hdr->rwlock, &cur, 0,
357 0 0 if (__atomic_load_n(&hdr->rwlock_waiters, __ATOMIC_RELAXED) > 0)
361 0 0 for (uint32_t i = 0; i < SS_READER_SLOTS; i++) {
363 0 0 if (pid == 0 || ss_pid_alive(pid)) continue;
0 0 if (pid == 0 || ss_pid_alive(pid)) continue;
376 0 0 if (val >= SS_RWLOCK_WRITER_BIT) {
378 0 0 if (!ss_pid_alive(pid))
390 0 0 if (h->my_slot_idx != UINT32_MAX)
396 0 0 if (h->my_slot_idx != UINT32_MAX)
400 0 0 if (h->my_slot_idx != UINT32_MAX) {
410 0 0 if (h->my_slot_idx != UINT32_MAX) {
428 76430 0 if (h->my_slot_idx != UINT32_MAX)
435 0 76430 if (cur > 0 && cur < SS_RWLOCK_WRITER_BIT) {
0 0 if (cur > 0 && cur < SS_RWLOCK_WRITER_BIT) {
436 0 0 if (__atomic_compare_exchange_n(lock, &cur, cur + 1,
439 76430 0 } else if (cur == 0 && !__atomic_load_n(writers_waiting, __ATOMIC_RELAXED)) {
76430 0 } else if (cur == 0 && !__atomic_load_n(writers_waiting, __ATOMIC_RELAXED)) {
440 76430 0 if (__atomic_compare_exchange_n(lock, &cur, 1,
444 0 0 if (__builtin_expect(spin < SS_RWLOCK_SPIN_LIMIT, 1)) {
451 0 0 if (cur >= SS_RWLOCK_WRITER_BIT || cur == 0) {
0 0 if (cur >= SS_RWLOCK_WRITER_BIT || cur == 0) {
454 0 0 if (rc == -1 && errno == ETIMEDOUT) {
0 0 if (rc == -1 && errno == ETIMEDOUT) {
474 76430 0 if (h->my_slot_idx != UINT32_MAX)
476 76430 0 if (after == 0 && __atomic_load_n(&hdr->rwlock_waiters, __ATOMIC_RELAXED) > 0)
0 76430 if (after == 0 && __atomic_load_n(&hdr->rwlock_waiters, __ATOMIC_RELAXED) > 0)
489 157974 0 if (__atomic_compare_exchange_n(lock, &expected, mypid,
492 0 0 if (__builtin_expect(spin < SS_RWLOCK_SPIN_LIMIT, 1)) {
498 0 0 if (cur != 0) {
501 0 0 if (rc == -1 && errno == ETIMEDOUT) {
0 0 if (rc == -1 && errno == ETIMEDOUT) {
516 0 157974 if (__atomic_load_n(&hdr->rwlock_waiters, __ATOMIC_RELAXED) > 0)
570 15457 30 for (uint32_t i = 0; i < node_capacity; i++)
571 15427 30 nodes[i].parent = (i + 1 < node_capacity) ? (i + 1) : SS_NONE;
581 0 35 if (!h) {
583 0 0 if (backing_fd >= 0) close(backing_fd);
591 9 26 h->path = path ? strdup(path) : NULL;
600 0 5 if (hdr->magic != SS_MAGIC) return 0;
601 0 5 if (hdr->version != SS_VERSION) return 0;
602 5 0 if (hdr->max_entries == 0 || hdr->max_entries > SS_MAX_CAPACITY) return 0;
0 5 if (hdr->max_entries == 0 || hdr->max_entries > SS_MAX_CAPACITY) return 0;
603 5 0 if (hdr->index_slots == 0 || (hdr->index_slots & (hdr->index_slots - 1)) != 0) return 0; /* pow2 */
0 5 if (hdr->index_slots == 0 || (hdr->index_slots & (hdr->index_slots - 1)) != 0) return 0; /* pow2 */
604 0 5 if (hdr->node_capacity == 0) return 0;
605 0 5 if (hdr->total_size != file_size) return 0;
606 0 5 if (hdr->total_size != ss_total_size(hdr->index_slots, hdr->node_capacity)) return 0;
608 0 5 if (hdr->reader_slots_off != L.reader_slots) return 0;
609 0 5 if (hdr->index_off != L.index) return 0;
610 0 5 if (hdr->nodes_off != L.nodes) return 0;
611 0 5 if (hdr->count > hdr->max_entries) return 0;
612 3 2 if (hdr->root != SS_NONE && hdr->root >= hdr->node_capacity) return 0;
0 3 if (hdr->root != SS_NONE && hdr->root >= hdr->node_capacity) return 0;
613 2 3 if (hdr->root == SS_NONE && hdr->count != 0) return 0;
0 2 if (hdr->root == SS_NONE && hdr->count != 0) return 0;
622 36 0 if (errbuf) errbuf[0] = '\0';
623 1 35 if (max_entries == 0) { SS_ERR("max_entries must be > 0"); return 0; }
1 0 if (max_entries == 0) { SS_ERR("max_entries must be > 0"); return 0; }
624 0 35 if (max_entries > SS_MAX_CAPACITY) { SS_ERR("max_entries too large (max %u)", SS_MAX_CAPACITY); return 0; }
0 0 if (max_entries > SS_MAX_CAPACITY) { SS_ERR("max_entries too large (max %u)", SS_MAX_CAPACITY); return 0; }
626 0 35 if (want > SS_MAX_CAPACITY) want = SS_MAX_CAPACITY;
634 1 34 if (!ss_validate_create_args(max_entries, &index_slots, &node_capacity, errbuf)) return NULL;
642 24 10 if (anonymous) {
645 0 24 if (base == MAP_FAILED) { SS_ERR("mmap: %s", strerror(errno)); return NULL; }
0 0 if (base == MAP_FAILED) { SS_ERR("mmap: %s", strerror(errno)); return NULL; }
648 0 10 if (fd < 0) { SS_ERR("open: %s", strerror(errno)); return NULL; }
0 0 if (fd < 0) { SS_ERR("open: %s", strerror(errno)); return NULL; }
649 0 10 if (flock(fd, LOCK_EX) < 0) { SS_ERR("flock: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (flock(fd, LOCK_EX) < 0) { SS_ERR("flock: %s", strerror(errno)); close(fd); return NULL; }
651 0 10 if (fstat(fd, &st) < 0) { SS_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
0 0 if (fstat(fd, &st) < 0) { SS_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
653 5 5 if (!is_new && (uint64_t)st.st_size < sizeof(SsHeader)) {
1 4 if (!is_new && (uint64_t)st.st_size < sizeof(SsHeader)) {
654 1 0 SS_ERR("%s: file too small (%lld)", path, (long long)st.st_size);
657 5 4 if (is_new && ftruncate(fd, (off_t)total) < 0) {
0 5 if (is_new && ftruncate(fd, (off_t)total) < 0) {
658 0 0 SS_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL;
660 4 5 map_size = is_new ? (size_t)total : (size_t)st.st_size;
662 0 9 if (base == MAP_FAILED) { SS_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
0 0 if (base == MAP_FAILED) { SS_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
663 4 5 if (!is_new) {
664 0 4 if (!ss_validate_header((SsHeader *)base, (uint64_t)st.st_size)) {
665 0 0 SS_ERR("invalid sorted-set file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL;
672 5 24 if (fd >= 0) { flock(fd, LOCK_UN); close(fd); }
678 0 1 if (!ss_validate_create_args(max_entries, &index_slots, &node_capacity, errbuf)) return NULL;
681 1 0 int fd = memfd_create(name ? name : "sortedset", MFD_CLOEXEC | MFD_ALLOW_SEALING);
682 0 1 if (fd < 0) { SS_ERR("memfd_create: %s", strerror(errno)); return NULL; }
0 0 if (fd < 0) { SS_ERR("memfd_create: %s", strerror(errno)); return NULL; }
683 0 1 if (ftruncate(fd, (off_t)total) < 0) {
684 0 0 SS_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL;
688 0 1 if (base == MAP_FAILED) { SS_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (base == MAP_FAILED) { SS_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; }
694 1 0 if (errbuf) errbuf[0] = '\0';
696 0 1 if (fstat(fd, &st) < 0) { SS_ERR("fstat: %s", strerror(errno)); return NULL; }
0 0 if (fstat(fd, &st) < 0) { SS_ERR("fstat: %s", strerror(errno)); return NULL; }
697 0 1 if ((uint64_t)st.st_size < sizeof(SsHeader)) { SS_ERR("too small"); return NULL; }
0 0 if ((uint64_t)st.st_size < sizeof(SsHeader)) { SS_ERR("too small"); return NULL; }
700 0 1 if (base == MAP_FAILED) { SS_ERR("mmap: %s", strerror(errno)); return NULL; }
0 0 if (base == MAP_FAILED) { SS_ERR("mmap: %s", strerror(errno)); return NULL; }
701 0 1 if (!ss_validate_header((SsHeader *)base, (uint64_t)st.st_size)) {
702 0 0 SS_ERR("invalid sorted-set"); munmap(base, ms); return NULL;
705 0 1 if (myfd < 0) { SS_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; }
0 0 if (myfd < 0) { SS_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; }
710 0 35 if (!h) return;
711 1 34 if (h->notify_fd >= 0) close(h->notify_fd);
712 2 33 if (h->backing_fd >= 0) close(h->backing_fd);
713 35 0 if (h->hdr) munmap(h->hdr, h->mmap_size);
719 5 0 if (!h || !h->hdr) return 0;
0 5 if (!h || !h->hdr) return 0;
724 0 1 if (h->notify_fd >= 0) return h->notify_fd;
726 0 1 if (efd < 0) return -1;
732 0 1 if (h->notify_fd < 0) return 0;
738 0 1 if (h->notify_fd < 0) return -1;
740 0 1 if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1;
756 490 3 for (uint32_t i = 0; i < hdr->node_capacity; i++)
757 487 3 h->nodes[i].parent = (i + 1 < hdr->node_capacity) ? (i + 1) : SS_NONE;
765 0 6667 if (idx == SS_NONE) return SS_NONE;
780 230609 168890 while (h->index[i].state) {
781 191117 39492 if (h->index[i].member == member) { if (found) *found = 1; return i; }
158343 32774 if (h->index[i].member == member) { if (found) *found = 1; return i; }
784 90344 78546 if (found) *found = 0;
789 122814 90344 if (f) { *score = h->index[i].score; return 1; }
801 12452 794 if (nd->is_leaf) return nd->num;
803 6749 794 for (int i = 0; i < nd->num; i++) t += nd->counts[i];
810 1402855 426690 while (lo < hi) {
812 804553 598302 if (ss_key_cmp(score, member, nd->scores[mid], nd->members[mid]) < 0) hi = mid;
825 111293 261347 if (nd->is_leaf) {
827 750004 13352 while (pos < nd->num && ss_key_cmp(nd->scores[pos], nd->members[pos], score, member) < 0) pos++;
652063 97941 while (pos < nd->num && ss_key_cmp(nd->scores[pos], nd->members[pos], score, member) < 0) pos++;
828 604323 111293 for (int i = nd->num; i > pos; i--) { nd->scores[i] = nd->scores[i-1]; nd->members[i] = nd->members[i-1]; }
830 105067 6226 if (nd->num <= SS_ORDER) return r;
835 56034 6226 for (int i = 0; i < rc; i++) { rn->scores[i] = nd->scores[mid+i]; rn->members[i] = nd->members[mid+i]; }
838 5686 540 if (nd->next != SS_NONE) h->nodes[nd->next].prev = ridx; else h->hdr->rightmost = ridx;
845 254741 6606 if (!cr.split) { nd->counts[c]++; return r; }
846 35734 6606 for (int i = nd->num; i > c + 1; i--) { nd->children[i] = nd->children[i-1]; nd->counts[i] = nd->counts[i-1]; }
847 35734 6606 for (int i = nd->num - 1; i > c; i--) { nd->scores[i] = nd->scores[i-1]; nd->members[i] = nd->members[i-1]; }
853 6209 397 if (nd->num <= SS_ORDER) return r;
858 3573 397 for (int i = 0; i < rch; i++) {
863 3176 397 for (int i = 0; i < rch - 1; i++) { rn->scores[i] = nd->scores[midc+i]; rn->members[i] = nd->members[midc+i]; }
873 27 111293 if (hdr->root == SS_NONE) {
883 17 111276 if (r.split) {
902 0 35529 if (!f) return;
906 35529 6107 if (!h->index[j].state) break;
908 6107 0 int in = (i < j) ? (i < k && k <= j) : (k > i || k <= j); /* k in (i, j] ? */
4665 1442 int in = (i < j) ? (i < k && k <= j) : (k > i || k <= j); /* k in (i, j] ? */
4665 0 int in = (i < j) ? (i < k && k <= j) : (k > i || k <= j); /* k in (i, j] ? */
0 0 int in = (i < j) ? (i < k && k <= j) : (k > i || k <= j); /* k in (i, j] ? */
0 0 int in = (i < j) ? (i < k && k <= j) : (k > i || k <= j); /* k in (i, j] ? */
909 1442 4665 if (!in) { h->index[i] = h->index[j]; i = j; }
920 2307 27 if (ln->is_leaf) {
921 17155 2307 for (int i = 0; i < rn->num; i++) { ln->scores[ln->num+i] = rn->scores[i]; ln->members[ln->num+i] = rn->members[i]; }
923 1834 473 if (rn->next != SS_NONE) h->nodes[rn->next].prev = lidx; else h->hdr->rightmost = lidx;
927 207 27 for (int i = 0; i < rn->num; i++) { ln->children[ln->num+i] = rn->children[i]; ln->counts[ln->num+i] = rn->counts[i]; h->nodes[rn->children[i]].parent = lidx; }
928 180 27 for (int i = 0; i < rn->num - 1; i++) { ln->scores[ln->num+i] = rn->scores[i]; ln->members[ln->num+i] = rn->members[i]; }
932 13233 2334 for (int i = c+1; i+1 < p->num; i++) { p->children[i] = p->children[i+1]; p->counts[i] = p->counts[i+1]; }
933 13233 2334 for (int i = c; i+1 < p->num-1; i++) { p->scores[i] = p->scores[i+1]; p->members[i] = p->members[i+1]; }
943 9105 2803 if (c > 0) {
945 6195 2910 if (ln->num > SS_MIN) { /* borrow from left */
946 6143 52 if (cn->is_leaf) {
947 43001 6143 for (int i = cn->num; i > 0; i--) { cn->scores[i] = cn->scores[i-1]; cn->members[i] = cn->members[i-1]; }
954 364 52 for (int i = cn->num; i > 0; i--) { cn->children[i] = cn->children[i-1]; cn->counts[i] = cn->counts[i-1]; }
955 312 52 for (int i = cn->num-1; i > 0; i--) { cn->scores[i] = cn->scores[i-1]; cn->members[i] = cn->members[i-1]; }
967 5091 622 if (c < p->num - 1) {
969 3379 1712 if (rn->num > SS_MIN) { /* borrow from right */
970 3327 52 if (cn->is_leaf) {
972 30987 3327 for (int i = 0; i+1 < rn->num; i++) { rn->scores[i] = rn->scores[i+1]; rn->members[i] = rn->members[i+1]; }
983 474 52 for (int i = 0; i+1 < rn->num; i++) { rn->children[i] = rn->children[i+1]; rn->counts[i] = rn->counts[i+1]; }
984 422 52 for (int i = 0; i+1 < rn->num-1; i++) { rn->scores[i] = rn->scores[i+1]; rn->members[i] = rn->members[i+1]; }
991 1310 1024 ss_merge(h, pidx, (c > 0) ? c - 1 : c); /* merge with a sibling */
998 68303 136294 if (nd->is_leaf) {
1000 380161 0 while (pos < nd->num && ss_key_cmp(nd->scores[pos], nd->members[pos], score, member) != 0) pos++;
311858 68303 while (pos < nd->num && ss_key_cmp(nd->scores[pos], nd->members[pos], score, member) != 0) pos++;
1001 373588 68303 for (int i = pos; i+1 < nd->num; i++) { nd->scores[i] = nd->scores[i+1]; nd->members[i] = nd->members[i+1]; }
1008 11908 124386 if (under) ss_fix_underflow(h, nidx, c);
1016 23 68280 if (root->is_leaf) {
1017 3 20 if (root->num == 0) {
1021 1 68279 } else if (root->num == 1) {
1032 27138 70226 if (ss_idx_get(h, member, &old)) {
1033 26051 1087 if (old != score) { ss_tree_del(h, old, member); ss_tree_add(h, score, member); ss_idx_set(h, member, score); }
1036 3 70223 if (h->hdr->count >= h->hdr->max_entries) return -1;
1045 11689 11747 if (!ss_idx_get(h, member, &old)) return 0;
1055 8072 8323 if (ss_idx_get(h, member, &old)) {
1057 1 8071 if (ns != ns) return -2;
1058 6723 1348 if (ns != old) { ss_tree_del(h, old, member); ss_tree_add(h, ns, member); ss_idx_set(h, member, ns); }
1061 0 8323 if (h->hdr->count >= h->hdr->max_entries) return -1;
1063 0 8323 if (delta != delta) return -2;
1070 2 23782 if (h->hdr->root == SS_NONE) return 0;
1071 8833 14949 SsNode *nd = &h->nodes[max ? h->hdr->rightmost : h->hdr->leftmost];
1072 8833 14949 int pos = max ? nd->num - 1 : 0;
1083 34888 0 if (nd->num < 1 || nd->num > SS_ORDER) return -1;
0 34888 if (nd->num < 1 || nd->num > SS_ORDER) return -1;
1084 34784 104 if (!is_root && nd->num < SS_MIN) return -1;
0 34784 if (!is_root && nd->num < SS_MIN) return -1;
1085 31710 3178 if (nd->is_leaf) {
1086 104 31606 if (*leaf_depth < 0) *leaf_depth = depth;
1087 0 31606 else if (*leaf_depth != depth) return -1;
1088 348996 31710 for (int i = 0; i < nd->num; i++) {
1089 348892 104 if (*hp && ss_key_cmp(*ps, *pm, nd->scores[i], nd->members[i]) >= 0) return -1;
0 348892 if (*hp && ss_key_cmp(*ps, *pm, nd->scores[i], nd->members[i]) >= 0) return -1;
1095 34784 3178 for (int i = 0; i < nd->num; i++) {
1097 34784 0 if (c < 0 || (uint32_t)c != nd->counts[i]) return -1;
0 34784 if (c < 0 || (uint32_t)c != nd->counts[i]) return -1;
1104 1 104 if (hdr->root == SS_NONE) return hdr->count == 0 && hdr->leftmost == SS_NONE;
1 0 if (hdr->root == SS_NONE) return hdr->count == 0 && hdr->leftmost == SS_NONE;
1 0 if (hdr->root == SS_NONE) return hdr->count == 0 && hdr->leftmost == SS_NONE;
1107 104 0 if (total < 0 || (uint32_t)total != hdr->count) return 0;
0 104 if (total < 0 || (uint32_t)total != hdr->count) return 0;
1110 31710 104 while (leaf != SS_NONE) {
1112 0 31710 if (!nd->is_leaf) return 0;
1113 348996 31710 for (int i = 0; i < nd->num; i++) {
1114 348892 104 if (lh && ss_key_cmp(ls, lm, nd->scores[i], nd->members[i]) >= 0) return 0;
0 348892 if (lh && ss_key_cmp(ls, lm, nd->scores[i], nd->members[i]) >= 0) return 0;
1117 104 31606 if (nd->next == SS_NONE && leaf != hdr->rightmost) return 0;
0 104 if (nd->next == SS_NONE && leaf != hdr->rightmost) return 0;
1120 0 104 if (seen != hdr->count) return 0;
1123 348996 2447060 for (uint32_t i = 0; i < hdr->index_slots; i++) if (h->index[i].state) icount++;
2796056 104 for (uint32_t i = 0; i < hdr->index_slots; i++) if (h->index[i].state) icount++;
1132 29049 10339 while (!h->nodes[n].is_leaf) {
1135 136280 29049 for (int i = 0; i < c; i++) rank += nd->counts[i];
1140 64103 27 while (pos < nd->num && ss_key_cmp(nd->scores[pos], nd->members[pos], score, member) < 0) pos++;
53791 10312 while (pos < nd->num && ss_key_cmp(nd->scores[pos], nd->members[pos], score, member) < 0) pos++;
1147 1083 381 while (!h->nodes[n].is_leaf) {
1150 3377 0 while (c < nd->num && r >= nd->counts[c]) { r -= nd->counts[c]; c++; }
2294 1083 while (c < nd->num && r >= nd->counts[c]) { r -= nd->counts[c]; c++; }
1161 103 1 if (h->hdr->root == SS_NONE || !(min <= max)) { if (lo_out) *lo_out = 0; return 0; }
0 103 if (h->hdr->root == SS_NONE || !(min <= max)) { if (lo_out) *lo_out = 0; return 0; }
0 1 if (h->hdr->root == SS_NONE || !(min <= max)) { if (lo_out) *lo_out = 0; return 0; }
1163 64 39 if (lo_out) *lo_out = lo;
1166 4 99 if (ss_idx_get(h, INT64_MAX, &sc) && sc == max) hi++; /* + the (max, INT64_MAX) entry itself */
2 2 if (ss_idx_get(h, INT64_MAX, &sc) && sc == max) hi++; /* + the (max, INT64_MAX) entry itself */
1173 315 93418 if (c->n == c->cap) {
1174 238 77 size_t nc = c->cap ? c->cap * 2 : 64;
1176 0 315 if (!nm) return 0; c->members = nm;
1178 0 315 if (!ns) return 0; c->scores = ns;
1188 77 6 if (len == 0 || h->hdr->root == SS_NONE) return 1;
0 77 if (len == 0 || h->hdr->root == SS_NONE) return 1;
1190 26 51 uint32_t leaf = ss_at_rank(h, reverse ? (start + len - 1) : start, &pos);
1192 51 26 if (!reverse) {
1193 5565 24 while (leaf != SS_NONE && got < len) {
5538 27 while (leaf != SS_NONE && got < len) {
1195 60420 5504 for (; pos < nd->num && got < len; pos++, got++)
60386 34 for (; pos < nd->num && got < len; pos++, got++)
1196 0 60386 if (!ss_rcollect_push(c, nd->members[pos], nd->scores[pos])) return 0;
1200 3066 4 while (leaf != SS_NONE && got < len) {
3044 22 while (leaf != SS_NONE && got < len) {
1202 33370 3021 for (; pos >= 0 && got < len; pos--, got++)
33347 23 for (; pos >= 0 && got < len; pos--, got++)
1203 0 33347 if (!ss_rcollect_push(c, nd->members[pos], nd->scores[pos])) return 0;
1205 3040 4 if (leaf != SS_NONE) pos = h->nodes[leaf].num - 1;