[Glacier] Add debug methods for HashMap and RefPtr.
This commit is contained in:
parent
d9a4be6555
commit
8c5dd00443
|
@ -6,6 +6,7 @@
|
|||
#include "glacier/container/linked_list.h"
|
||||
#include "glacier/container/pair.h"
|
||||
#include "glacier/status/error.h"
|
||||
#include "glacier/string/str_format.h"
|
||||
#include "glacier/string/string.h"
|
||||
#include "glacier/util/hash.h"
|
||||
|
||||
|
@ -53,6 +54,8 @@ class HashMap {
|
|||
|
||||
void Resize(uint64_t new_size);
|
||||
|
||||
void DebugIntoStr(StringBuilder& builder) const;
|
||||
|
||||
private:
|
||||
Array<LinkedList<Pair<K, V>>> data_;
|
||||
uint64_t size_ = 0;
|
||||
|
@ -211,4 +214,26 @@ void HashMap<K, V, H>::ResizeIfNecessary() {
|
|||
}
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
void StrFormatValue(StringBuilder& builder, const HashMap<K, V>& value,
|
||||
StringView opts) {
|
||||
value.DebugIntoStr(builder);
|
||||
}
|
||||
|
||||
template <typename K, typename V, class H>
|
||||
void HashMap<K, V, H>::DebugIntoStr(StringBuilder& builder) const {
|
||||
for (uint64_t i = 0; i < data_.size(); i++) {
|
||||
if (data_[i].size() == 0) {
|
||||
continue;
|
||||
}
|
||||
StrFormatValue(builder, i, "");
|
||||
builder.PushBack(": ");
|
||||
auto& ll = data_[i];
|
||||
for (auto& item : ll) {
|
||||
StrFormatInternal(builder, "{},", item.first());
|
||||
}
|
||||
builder.PushBack('\n');
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace glcr
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "glacier/string/str_format.h"
|
||||
|
||||
namespace glcr {
|
||||
|
||||
template <typename T>
|
||||
|
@ -100,4 +102,10 @@ RefPtr<T> StaticCastRefPtr(const RefPtr<U>& ref) {
|
|||
return RefPtr(static_cast<T*>(ref.get()), RefPtr<T>::DontAdopt);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void StrFormatValue(StringBuilder& builder, const RefPtr<T>& value,
|
||||
StringView opts) {
|
||||
StrFormatValue(builder, (uint64_t)value.get(), opts);
|
||||
}
|
||||
|
||||
} // namespace glcr
|
||||
|
|
Loading…
Reference in New Issue