aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/yson_string/string-inl.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/yt/yson_string/string-inl.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/yt/yson_string/string-inl.h')
-rw-r--r--library/cpp/yt/yson_string/string-inl.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/library/cpp/yt/yson_string/string-inl.h b/library/cpp/yt/yson_string/string-inl.h
new file mode 100644
index 0000000000..5c41629cc0
--- /dev/null
+++ b/library/cpp/yt/yson_string/string-inl.h
@@ -0,0 +1,93 @@
+#ifndef STRING_INL_H_
+#error "Direct inclusion of this file is not allowed, include string.h"
+// For the sake of sane code completion.
+#include "string.h"
+#endif
+
+namespace NYT::NYson {
+
+////////////////////////////////////////////////////////////////////////////////
+
+namespace NDetail {
+
+template <typename TLeft, typename TRight>
+bool Equals(const TLeft& lhs, const TRight& rhs)
+{
+ auto lhsNull = !lhs.operator bool();
+ auto rhsNull = !rhs.operator bool();
+ if (lhsNull != rhsNull) {
+ return false;
+ }
+ if (lhsNull && rhsNull) {
+ return true;
+ }
+ return
+ lhs.AsStringBuf() == rhs.AsStringBuf() &&
+ lhs.GetType() == rhs.GetType();
+}
+
+} // namespace NDetail
+
+inline bool operator == (const TYsonString& lhs, const TYsonString& rhs)
+{
+ return NDetail::Equals(lhs, rhs);
+}
+
+inline bool operator == (const TYsonString& lhs, const TYsonStringBuf& rhs)
+{
+ return NDetail::Equals(lhs, rhs);
+}
+
+inline bool operator == (const TYsonStringBuf& lhs, const TYsonString& rhs)
+{
+ return NDetail::Equals(lhs, rhs);
+}
+
+inline bool operator == (const TYsonStringBuf& lhs, const TYsonStringBuf& rhs)
+{
+ return NDetail::Equals(lhs, rhs);
+}
+
+inline bool operator != (const TYsonString& lhs, const TYsonString& rhs)
+{
+ return !(lhs == rhs);
+}
+
+inline bool operator != (const TYsonString& lhs, const TYsonStringBuf& rhs)
+{
+ return !(lhs == rhs);
+}
+
+inline bool operator != (const TYsonStringBuf& lhs, const TYsonString& rhs)
+{
+ return !(lhs == rhs);
+}
+
+inline bool operator != (const TYsonStringBuf& lhs, const TYsonStringBuf& rhs)
+{
+ return !(lhs == rhs);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT::NYson
+
+//! A hasher for TYsonString
+template <>
+struct THash<NYT::NYson::TYsonString>
+{
+ size_t operator () (const NYT::NYson::TYsonString& str) const
+ {
+ return str.ComputeHash();
+ }
+};
+
+//! A hasher for TYsonStringBuf
+template <>
+struct THash<NYT::NYson::TYsonStringBuf>
+{
+ size_t operator () (const NYT::NYson::TYsonStringBuf& str) const
+ {
+ return THash<TStringBuf>()(str.AsStringBuf());
+ }
+};