7 #ifndef swcdb_core_Comparators_basic_h
8 #define swcdb_core_Comparators_basic_h
31 mem_cmp(
const uint8_t* b1,
const uint8_t* b2,
size_t count) noexcept
35 mem_eq(
const uint8_t* b1,
const uint8_t* b2,
size_t count) noexcept
40 str_cmp(
const char* s1,
const char* s2) noexcept
44 str_cmp(
const char* s1,
const char* s2,
size_t count) noexcept
49 str_eq(
const char* s1,
const char* s2) noexcept
53 str_eq(
const char* s1,
const char* s2,
size_t count) noexcept
57 str_case_eq(
const char* s1,
const char* s2,
size_t count) noexcept
62 str_eq(
const std::string& s1,
const std::string& s2) noexcept
66 mem_eq(
const std::string& s1,
const std::string& s2) noexcept
74 #if defined(SWC_IMPL_COMPARATORS_BASIC)
77 _mem_cmp(
const uint8_t* b1,
const uint8_t* b2,
size_t count) noexcept
81 _mem_eq(
const uint8_t* b1,
const uint8_t* b2,
size_t count) noexcept
88 _mem_cmp(
const uint8_t* b1,
const uint8_t* b2,
size_t count) noexcept {
89 for(; count; --count, ++b1, ++b2)
91 return *b1 < *b2 ? -1 : 1;
97 _mem_eq(
const uint8_t* b1,
const uint8_t* b2,
size_t count) noexcept {
98 for(; count; --count, ++b1, ++b2) {
106 _str_cmp(
const char* s1,
const char* s2) noexcept
110 _str_cmp(
const char* s1,
const char* s2,
size_t count) noexcept
114 _str_eq(
const char* s1,
const char* s2) noexcept
118 _str_eq(
const char* s1,
const char* s2,
size_t count) noexcept
122 _str_case_eq(
const char* s1,
const char* s2,
size_t count) noexcept
127 SWC_SHOULD_NOT_INLINE
129 _str_cmp(
const char* s1,
const char* s2) noexcept {
130 for(; ; ++s1, ++s2) {
132 return *s1 < *s2 ? -1 : 1;
139 SWC_SHOULD_NOT_INLINE
141 _str_cmp(
const char* s1,
const char* s2,
size_t count) noexcept {
142 for(; count; --count, ++s1, ++s2) {
144 return *s1 < *s2 ? -1 : 1;
151 SWC_SHOULD_NOT_INLINE
153 _str_eq(
const char* s1,
const char* s2) noexcept {
154 for(; ; ++s1, ++s2) {
162 SWC_SHOULD_NOT_INLINE
164 _str_eq(
const char* s1,
const char* s2,
size_t count) noexcept {
165 for(; count; --count, ++s1, ++s2) {
174 SWC_SHOULD_NOT_INLINE
176 _str_case_eq(
const char* s1,
const char* s2,
size_t count) noexcept {
177 for(; count; --count, ++s1, ++s2) {
178 if(*s1 - (*s1 > 96 && *s1 < 123 ? 32 : 0) !=
179 *s2 - (*s2 > 96 && *s2 < 123 ? 32 : 0))
187 #endif // defined(SWC_IMPL_COMPARATORS_BASIC)
197 mem_cmp(
const uint8_t* b1,
const uint8_t* b2,
size_t count) noexcept {
198 #if defined(SWC_IMPL_COMPARATORS_BASIC)
199 return _mem_cmp(b1, b2, count);
201 return memcmp(b1, b2, count);
207 mem_eq(
const uint8_t* b1,
const uint8_t* b2,
size_t count) noexcept {
208 #if defined(SWC_IMPL_COMPARATORS_BASIC)
209 return _mem_eq(b1, b2, count);
211 return !memcmp(b1, b2, count);
217 str_cmp(
const char* s1,
const char* s2) noexcept {
218 #if defined(SWC_IMPL_COMPARATORS_BASIC)
219 return _str_cmp(s1, s2);
221 return strcmp(s1, s2);
227 str_cmp(
const char* s1,
const char* s2,
size_t count) noexcept {
228 #if defined(SWC_IMPL_COMPARATORS_BASIC)
229 return _str_cmp(s1, s2, count);
231 return strncmp(s1, s2, count);
237 str_eq(
const char* s1,
const char* s2) noexcept {
238 #if defined(SWC_IMPL_COMPARATORS_BASIC)
239 return _str_eq(s1, s2);
241 return !strcmp(s1, s2);
247 str_eq(
const char* s1,
const char* s2,
size_t count) noexcept {
248 #if defined(SWC_IMPL_COMPARATORS_BASIC)
249 return _str_eq(s1, s2, count);
251 return !strncmp(s1, s2, count);
257 str_case_eq(
const char* s1,
const char* s2,
size_t count) noexcept {
258 #if defined(SWC_IMPL_COMPARATORS_BASIC)
259 return _str_case_eq(s1, s2, count);
261 return !strncasecmp(s1, s2, count);
268 str_eq(
const std::string& s1,
const std::string& s2) noexcept {
269 return str_eq(s1.c_str(), s2.c_str());
274 mem_eq(
const std::string& s1,
const std::string& s2) noexcept {
275 return s1.length() == s2.length() &&
276 mem_eq(
reinterpret_cast<const uint8_t*
>(s1.c_str()),
277 reinterpret_cast<const uint8_t*
>(s2.c_str()),
286 #endif // swcdb_core_Comparators_basic_h