Taskolib  1.3.3
hash_string.h
Go to the documentation of this file.
1 
33 // SPDX-License-Identifier: MIT
34 
35 #ifndef TASKOLIB_CASE_STRING_H_
36 #define TASKOLIB_CASE_STRING_H_
37 
38 #include <gul14/string_view.h>
39 
40 namespace task {
41 
45 inline constexpr unsigned long hash_djb2a(gul14::string_view sv) {
46  unsigned long hash{ 5381 };
47  for (unsigned char c : sv) {
48  hash = ((hash << 5) + hash) ^ c;
49  }
50  return hash;
51 }
52 
56 inline constexpr unsigned long operator"" _sh(const char *str, std::size_t len) {
57  return hash_djb2a(gul14::string_view{ str, len });
58 }
59 
60 } // namespace task
61 
62 #endif
Namespace task contains all Taskolib functions and classes.
Definition: CommChannel.h:33
constexpr unsigned long hash_djb2a(gul14::string_view sv)
Adapt switch statement with stringify items: https://learnmoderncpp.com/2020/06/01/strings-as-switch-...
Definition: hash_string.h:45