Add printTree
This commit is contained in:
@@ -1083,8 +1083,25 @@ void bench() {
|
||||
}
|
||||
}
|
||||
|
||||
void printTree() {
|
||||
int64_t writeVersion = 0;
|
||||
ConflictSet::Impl cs{writeVersion};
|
||||
ReferenceImpl refImpl{writeVersion};
|
||||
Arena arena;
|
||||
constexpr int kNumKeys = 5;
|
||||
auto *write = new (arena) ConflictSet::WriteRange[kNumKeys];
|
||||
for (int i = 0; i < kNumKeys; ++i) {
|
||||
write[i].begin = toKey(arena, i);
|
||||
write[i].end.len = 0;
|
||||
write[i].writeVersion = ++writeVersion;
|
||||
}
|
||||
cs.addWrites(write, kNumKeys);
|
||||
debugPrintDot(stdout, cs.root);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
bench();
|
||||
// bench();
|
||||
printTree();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
26
Internal.h
26
Internal.h
@@ -410,28 +410,16 @@ struct ReferenceImpl {
|
||||
using Key = ConflictSet::Key;
|
||||
|
||||
[[maybe_unused]] static Key toKey(Arena &arena, int n) {
|
||||
constexpr int kMaxLength = 8;
|
||||
int i = kMaxLength;
|
||||
uint8_t *itoaBuf = new (arena) uint8_t[kMaxLength];
|
||||
memset(itoaBuf, '0', kMaxLength);
|
||||
do {
|
||||
itoaBuf[--i] = "0123456789abcdef"[n % 16];
|
||||
n /= 16;
|
||||
} while (n);
|
||||
return Key{itoaBuf, kMaxLength};
|
||||
uint8_t *buf = new (arena) uint8_t[sizeof(n)];
|
||||
memcpy(buf, &n, sizeof(n));
|
||||
return Key{buf, sizeof(n)};
|
||||
}
|
||||
|
||||
[[maybe_unused]] static Key toKeyAfter(Arena &arena, int n) {
|
||||
constexpr int kMaxLength = 8;
|
||||
int i = kMaxLength;
|
||||
uint8_t *itoaBuf = new (arena) uint8_t[kMaxLength + 1];
|
||||
memset(itoaBuf, '0', kMaxLength);
|
||||
itoaBuf[kMaxLength] = 0;
|
||||
do {
|
||||
itoaBuf[--i] = "0123456789abcdef"[n % 16];
|
||||
n /= 16;
|
||||
} while (n);
|
||||
return Key{itoaBuf, kMaxLength + 1};
|
||||
uint8_t *buf = new (arena) uint8_t[sizeof(n) + 1];
|
||||
memcpy(buf, &n, sizeof(n));
|
||||
buf[sizeof(n)] = 0;
|
||||
return Key{buf, sizeof(n) + 1};
|
||||
}
|
||||
|
||||
inline std::string printable(std::string_view key) {
|
||||
|
Reference in New Issue
Block a user