From 95fa2a46519d0820548ab7855b32182ff81f0435 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 20 Feb 2019 22:35:24 +0100 Subject: Change linux platform from 64 to x86_64, add sibs platforms command --- include/StringView.hpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'include/StringView.hpp') diff --git a/include/StringView.hpp b/include/StringView.hpp index 4d87d8a..8ca685d 100644 --- a/include/StringView.hpp +++ b/include/StringView.hpp @@ -7,6 +7,7 @@ #include "env.hpp" #include #include +#include #include namespace sibs @@ -36,8 +37,7 @@ namespace sibs bool equals(const StringView &other) const { - if(size != other.size) return false; - return memcmp(data, other.data, size) == 0; + return size == other.size && memcmp(data, other.data, size) == 0; } size_t hash() const @@ -54,6 +54,31 @@ namespace sibs assert(index < size); return data[index]; } + + bool operator < (const StringView &other) const + { + return ((ssize)size - (ssize)other.size < 0) || strncmp(data, other.data, size) < 0; + } + + bool operator > (const StringView &other) const + { + return !operator<(other); + } + + size_t operator()() const + { + return hash(); + } + + bool operator()(const StringView &other) const + { + return equals(other); + } + + bool operator == (const StringView &other) const + { + return equals(other); + } const char *data; usize size; @@ -75,9 +100,21 @@ namespace sibs return lhs.equals(rhs); } }; + + struct StringViewCompareSorted + { + public: + bool operator()(const StringView &lhs, const StringView &rhs) const + { + return lhs < rhs; + } + }; template using StringViewMap = std::unordered_map; + + // template + // using StringViewMapSorted = std::map; } #endif // SIBS_STRING_VIEW_HPP -- cgit v1.2.3