Add printTree

This commit is contained in:
2024-01-30 17:16:46 -08:00
parent dad3a8b5ad
commit ecd549857b
2 changed files with 25 additions and 20 deletions

View File

@@ -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) {