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) {
|
int main(void) {
|
||||||
bench();
|
// bench();
|
||||||
|
printTree();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
26
Internal.h
26
Internal.h
@@ -410,28 +410,16 @@ struct ReferenceImpl {
|
|||||||
using Key = ConflictSet::Key;
|
using Key = ConflictSet::Key;
|
||||||
|
|
||||||
[[maybe_unused]] static Key toKey(Arena &arena, int n) {
|
[[maybe_unused]] static Key toKey(Arena &arena, int n) {
|
||||||
constexpr int kMaxLength = 8;
|
uint8_t *buf = new (arena) uint8_t[sizeof(n)];
|
||||||
int i = kMaxLength;
|
memcpy(buf, &n, sizeof(n));
|
||||||
uint8_t *itoaBuf = new (arena) uint8_t[kMaxLength];
|
return Key{buf, sizeof(n)};
|
||||||
memset(itoaBuf, '0', kMaxLength);
|
|
||||||
do {
|
|
||||||
itoaBuf[--i] = "0123456789abcdef"[n % 16];
|
|
||||||
n /= 16;
|
|
||||||
} while (n);
|
|
||||||
return Key{itoaBuf, kMaxLength};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[maybe_unused]] static Key toKeyAfter(Arena &arena, int n) {
|
[[maybe_unused]] static Key toKeyAfter(Arena &arena, int n) {
|
||||||
constexpr int kMaxLength = 8;
|
uint8_t *buf = new (arena) uint8_t[sizeof(n) + 1];
|
||||||
int i = kMaxLength;
|
memcpy(buf, &n, sizeof(n));
|
||||||
uint8_t *itoaBuf = new (arena) uint8_t[kMaxLength + 1];
|
buf[sizeof(n)] = 0;
|
||||||
memset(itoaBuf, '0', kMaxLength);
|
return Key{buf, sizeof(n) + 1};
|
||||||
itoaBuf[kMaxLength] = 0;
|
|
||||||
do {
|
|
||||||
itoaBuf[--i] = "0123456789abcdef"[n % 16];
|
|
||||||
n /= 16;
|
|
||||||
} while (n);
|
|
||||||
return Key{itoaBuf, kMaxLength + 1};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string printable(std::string_view key) {
|
inline std::string printable(std::string_view key) {
|
||||||
|
Reference in New Issue
Block a user