ezEngine  Milestone 7
HashedString_inl.h
1 #pragma once
2 
3 #include <Foundation/Algorithm/Hashing.h>
4 
6 {
7  m_Data = rhs.m_Data;
8 
9  // the string has a refcount of at least one (rhs holds a reference), thus it will definitely not get deleted on some other thread
10  // therefore we can simply increase the refcount without locking
11  m_Data.Value().m_iRefCount.Increment();
12 }
13 
15 {
16  // just decrease the refcount of the object that we are set to, it might reach refcount zero, but we don't care about that here
17  m_Data.Value().m_iRefCount.Decrement();
18 }
19 
21 {
22  // just decrease the refcount of the object that we are set to, it might reach refcount zero, but we don't care about that here
23  m_Data.Value().m_iRefCount.Decrement();
24 
25  m_Data = rhs.m_Data;
26  m_Data.Value().m_iRefCount.Increment();
27 }
28 
29 template <size_t N>
30 EZ_FORCE_INLINE void ezHashedString::Assign(const char(&szString)[N])
31 {
32  // just decrease the refcount of the object that we are set to, it might reach refcount zero, but we don't care about that here
33  m_Data.Value().m_iRefCount.Decrement();
34 
35  // this function will already increase the refcount as needed
36  m_Data = AddHashedString(szString, ezHashing::MurmurHash(szString));
37 }
38 
39 EZ_FORCE_INLINE void ezHashedString::Assign(ezHashing::StringWrapper szString)
40 {
41  // just decrease the refcount of the object that we are set to, it might reach refcount zero, but we don't care about that here
42  m_Data.Value().m_iRefCount.Decrement();
43 
44  // this function will already increase the refcount as needed
45  m_Data = AddHashedString(szString.m_str, ezHashing::MurmurHash(szString));
46 }
47 
48 inline bool ezHashedString::operator== (const ezHashedString& rhs) const
49 {
50  return &m_Data.Key() == &rhs.m_Data.Key();
51 }
52 
53 inline bool ezHashedString::operator!= (const ezHashedString& rhs) const
54 {
55  return !(*this == rhs);
56 }
57 
58 inline bool ezHashedString::operator== (const ezTempHashedString& rhs) const
59 {
60  return m_Data.Value().m_uiHash == rhs.m_uiHash;
61 }
62 
63 inline bool ezHashedString::operator!= (const ezTempHashedString& rhs) const
64 {
65  return !(*this == rhs);
66 }
67 
68 inline bool ezHashedString::operator< (const ezHashedString& rhs) const
69 {
70  return m_Data.Value().m_uiHash < rhs.m_Data.Value().m_uiHash;
71 }
72 
73 inline bool ezHashedString::operator< (const ezTempHashedString& rhs) const
74 {
75  return m_Data.Value().m_uiHash < rhs.m_uiHash;
76 }
77 
78 inline const ezString& ezHashedString::GetString() const
79 {
80  return m_Data.Key();
81 }
82 
83 inline const char* ezHashedString::GetData() const
84 {
85  return m_Data.Key().GetData();
86 }
87 
88 inline ezUInt32 ezHashedString::GetHash() const
89 {
90  return m_Data.Value().m_uiHash;
91 }
92 
93 template <size_t N>
94 inline ezTempHashedString::ezTempHashedString(const char(&szString)[N])
95 {
96  m_uiHash = ezHashing::MurmurHash(szString);
97 }
98 
100 {
101  m_uiHash = ezHashing::MurmurHash(szString);
102 }
103 
105 {
106  m_uiHash = rhs.m_uiHash;
107 }
108 
110 {
111  m_uiHash = rhs.GetHash();
112 }
113 
115 {
116  m_uiHash = uiHash;
117 }
118 
119 template <size_t N>
120 inline void ezTempHashedString::operator= (const char(&szString)[N])
121 {
122  m_uiHash = ezHashing::MurmurHash(szString);
123 }
124 
126 {
127  m_uiHash = ezHashing::MurmurHash(szString);
128 }
129 
131 {
132  m_uiHash = rhs.m_uiHash;
133 }
134 
136 {
137  m_uiHash = rhs.GetHash();
138 }
139 
141 {
142  return m_uiHash == rhs.m_uiHash;
143 }
144 
146 {
147  return !(m_uiHash == rhs.m_uiHash);
148 }
149 
151 {
152  return m_uiHash < rhs.m_uiHash;
153 }
154 
155 EZ_FORCE_INLINE ezUInt32 ezTempHashedString::GetHash() const
156 {
157  return m_uiHash;
158 }
159 
160 
161 template <>
163 {
164  EZ_FORCE_INLINE static ezUInt32 Hash(const ezHashedString& value)
165  {
166  return value.GetHash();
167  }
168 
169  EZ_FORCE_INLINE static ezUInt32 Hash(const ezTempHashedString& value)
170  {
171  return value.GetHash();
172  }
173 
174  EZ_FORCE_INLINE static bool Equal(const ezHashedString& a, const ezHashedString& b)
175  {
176  return a == b;
177  }
178 
179  EZ_FORCE_INLINE static bool Equal(const ezHashedString& a, const ezTempHashedString& b)
180  {
181  return a == b;
182  }
183 };
184 
185 template <>
187 {
188  EZ_FORCE_INLINE static ezUInt32 Hash(const ezTempHashedString& value)
189  {
190  return value.GetHash();
191  }
192 
193  EZ_FORCE_INLINE static bool Equal(const ezTempHashedString& a, const ezTempHashedString& b)
194  {
195  return a == b;
196  }
197 };
198 
199