blob: dfe4183fdfbe09902d3b5289ec5b40441519a246 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#pragma once
#include <basis/seadTypes.h>
#include <codec/seadHashCRC32.h>
#include <container/seadTreeMap.h>
#include <prim/seadDelegate.h>
namespace ksys::util {
class StrTreeMapKey {
public:
StrTreeMapKey() = default;
StrTreeMapKey(u32 key_hash, const sead::SafeString& key) : mKeyHash(key_hash), mKey(key) {}
StrTreeMapKey(const sead::SafeString& key)
: StrTreeMapKey(sead::HashCRC32::calcStringHash(key), key) {}
const sead::SafeString& key() const { return mKey; }
void setKey(const sead::SafeString& key) { *this = StrTreeMapKey{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:
using KeyType = StrTreeMapKey;
~StrTreeMapNode() override { ; }
void erase_() override { mLeft = mRight = nullptr; }
};
template <typename Node>
class StrTreeMap : public sead::IntrusiveTreeMap<StrTreeMapKey, Node> {};
} // namespace ksys::util
|