Skip to content

Add variable size prefix for key generator class + improve documentation #13709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor Next function
KareemOtoum committed Jun 18, 2025
commit 576d2a0b2396c632e2625ccdb4a0efab09acffb2
7 changes: 3 additions & 4 deletions microbench/db_basic_bench.cc
Original file line number Diff line number Diff line change
@@ -51,13 +51,11 @@ class KeyGenerator {
if (prefix_only) {
return {buff, prefix_size_};
}
}

if (prefix_num_ > 0) {
Encode(buff + prefix_size_, k, sizeof(uint32_t));
} else {
Encode(buff, k, sizeof(uint32_t));
}

return {buff, key_size_};
}

@@ -129,9 +127,10 @@ class KeyGenerator {

// helper function to encode variable size prefix or key numbers
void static Encode(char* buf, uint32_t value, uint32_t size) {
Copy link
Author

@KareemOtoum KareemOtoum Jun 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that as of now, the encode function can only encode up to 4 bytes for the prefix/key, I am planning on changing this with my next pr where I will look at extending the max number of keys that can be generated.

assert(size <= sizeof(uint32_t));
if (port::kLittleEndian) {
const size_t bits{size * 8};
for (int i{}; i < size; ++size) {
for (int i{}; i < size; ++i) {
buf[i] = static_cast<char>((value >> (bits - (i + 1) * 8)) & 0xff);
}
} else {