File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
include/pulsar/structures Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,19 @@ namespace Pulsar
4848 return m_Data[m_Start+idx];
4949 }
5050
51+ bool operator ==(const StringView& other) const
52+ {
53+ if (Length () != other.Length ())
54+ return false ;
55+ for (size_t i = 0 ; i < other.Length (); i++) {
56+ if ((*this )[i] != other[i])
57+ return false ;
58+ }
59+ return true ;
60+ }
61+
62+ bool operator !=(const StringView& other) const { return !(*this == other); }
63+
5164 size_t Length () const { return Empty () ? 0 : m_End - m_Start; }
5265 bool Empty () const { return m_Start >= m_End; }
5366 size_t GetStart () const { return m_Start; }
@@ -61,4 +74,16 @@ namespace Pulsar
6174 };
6275}
6376
77+ template <>
78+ struct std ::hash<Pulsar::StringView>
79+ {
80+ size_t operator ()(const Pulsar::StringView& strView) const
81+ {
82+ size_t hash = 0 ;
83+ for (size_t i = 0 ; i < strView.Length (); i++)
84+ hash += std::hash<char >{}(strView[i]);
85+ return hash;
86+ }
87+ };
88+
6489#endif // _PULSAR_STRUCTURES_STRINGVIEW_H
You can’t perform that action at this time.
0 commit comments