diff options
| author | Léo Lam <leo@leolam.fr> | 2020-06-05 17:09:06 +0200 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2020-08-18 22:50:25 +0200 |
| commit | 2de366be0fa75e571c605e017b5604bccbdb75bf (patch) | |
| tree | b8044fc96bba792b1875067032da2fd4498a44a3 /src/KingSystem/Utils/StrTreeMap.h | |
Initial commit
Diffstat (limited to 'src/KingSystem/Utils/StrTreeMap.h')
| -rw-r--r-- | src/KingSystem/Utils/StrTreeMap.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/KingSystem/Utils/StrTreeMap.h b/src/KingSystem/Utils/StrTreeMap.h new file mode 100644 index 00000000..d12bbcc6 --- /dev/null +++ b/src/KingSystem/Utils/StrTreeMap.h @@ -0,0 +1,45 @@ +#pragma once + +#include <basis/seadTypes.h> +#include <codec/seadHashCRC32.h> +#include <container/seadTreeMap.h> + +namespace ksys::util { + +class StrTreeMapKey { +public: + const sead::SafeString& key() const { return mKey; } + + // NON_MATCHING: stack + void setKey(u32 hash, sead::SafeString key) { + mKeyHash = hash; + mKey = key; + } + + void setKey(const sead::SafeString& key) { + setKey(sead::HashCRC32::calcStringHash(key.cstr()), key); + } + + s32 compare(const StrTreeMapKey& rhs) const { + if (mKeyHash < rhs.mKeyHash) + return -1; + if (mKeyHash > rhs.mKeyHash) + return 1; + return mKey.compare(rhs.mKey); + } + +private: + u32 mKeyHash = 0; + sead::SafeString mKey; +}; + +class StrTreeMapNode : public sead::TreeMapNode<StrTreeMapKey> { +public: + ~StrTreeMapNode() override { ; } + void erase_() override { mLeft = mRight = nullptr; } +}; + +template <typename Node> +class StrTreeMap : public sead::IntrusiveTreeMap<StrTreeMapKey, Node> {}; + +} // namespace ksys::util |
