-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathutensor_string.hpp
More file actions
57 lines (49 loc) · 1.31 KB
/
utensor_string.hpp
File metadata and controls
57 lines (49 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef UTENSOR_STRING
#define UTENSOR_STRING
//#include <string.h>
#include <cstdint>
#include <cstring>
namespace uTensor {
class string {
private:
uint32_t value;
const char* cstr = NULL;
uint32_t hash(const char* c) {
int v = 7;
for (uint32_t i = 0; i < strlen(c); i++) {
v = v * 31 + c[i];
}
return (uint32_t)v;
}
public:
string(const char* that) {
value = hash(that);
cstr = that;
}
string() { value = 0; }
string(uint32_t val) : value(val), cstr(NULL) {}
// bool operator < (const string& that){ return this->value < that.value; }
// bool operator == (const string& that){ return this->value == that.value; }
bool operator<(const string& that) const { return this->value < that.value; }
bool operator==(const string& that) const {
return this->value == that.value;
}
bool operator!=(const string& that) const {
return this->value != that.value;
}
uint32_t get_value() const { return value; }
const char* c_str() const { return cstr; }
};
} // namespace uTensor
// namespace std {
// template <>
// struct hash<uTensor::string> {
// typedef uTensor::string argument_type;
// typedef std::size_t result_type;
//
// result_type operator()(argument_type const& s) const noexcept {
// return s.get_value();
// }
//};
//} // namespace std
#endif