Last active
November 28, 2019 08:08
-
-
Save ayende/a810b3ffe6e0f346563cb74e81d0e9bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (p->bytes_used == 0) { | |
size_t max_overflow = 0; | |
for (size_t j = 0; j < MAX_CHAIN_LENGTH; j++) { | |
if (b->pieces[(piece_idx + i + j) % NUMBER_OF_HASH_BUCKET_PIECES].overflowed) | |
max_overflow++; | |
} | |
// we scan keys as far as possible first, to move them closer to their ideal location | |
for (size_t j = max_overflow - 1; j >= 0; j--) | |
{ | |
hash_bucket_piece_t* cur = &b->pieces[(piece_idx + i + j) % NUMBER_OF_HASH_BUCKET_PIECES]; | |
buf = cur->data; | |
end = buf + cur->bytes_used; | |
while (buf < end) { | |
cur_buf_start = buf; | |
varint_decode(&buf, &k); | |
varint_decode(&buf, &v); | |
if (k % NUMBER_OF_HASH_BUCKET_PIECES == piece_idx) { | |
diff = buf - cur_buf_start; | |
if (diff + p->bytes_used <= PIECE_BUCKET_BUFFER_SIZE) { | |
memmove(p->data + p->bytes_used, cur_buf_start, diff); | |
memmove(cur_buf_start, buf, end - buf); | |
cur->bytes_used -= (uint8_t)diff; | |
p->bytes_used += (uint8_t)diff; | |
end -= diff; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment