Warning, file /include/upb/hash/common.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #ifndef UPB_HASH_COMMON_H_
0028 #define UPB_HASH_COMMON_H_
0029
0030 #include <string.h>
0031
0032 #include "upb/base/string_view.h"
0033 #include "upb/mem/arena.h"
0034
0035
0036 #include "upb/port/def.inc"
0037
0038 #ifdef __cplusplus
0039 extern "C" {
0040 #endif
0041
0042
0043
0044 typedef struct {
0045 uint64_t val;
0046 } upb_value;
0047
0048 UPB_INLINE void _upb_value_setval(upb_value* v, uint64_t val) { v->val = val; }
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 #define FUNCS(name, membername, type_t, converter) \
0059 UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \
0060 val->val = (converter)cval; \
0061 } \
0062 UPB_INLINE upb_value upb_value_##name(type_t val) { \
0063 upb_value ret; \
0064 upb_value_set##name(&ret, val); \
0065 return ret; \
0066 } \
0067 UPB_INLINE type_t upb_value_get##name(upb_value val) { \
0068 return (type_t)(converter)val.val; \
0069 }
0070
0071 FUNCS(int32, int32, int32_t, int32_t)
0072 FUNCS(int64, int64, int64_t, int64_t)
0073 FUNCS(uint32, uint32, uint32_t, uint32_t)
0074 FUNCS(uint64, uint64, uint64_t, uint64_t)
0075 FUNCS(bool, _bool, bool, bool)
0076 FUNCS(cstr, cstr, char*, uintptr_t)
0077 FUNCS(uintptr, uptr, uintptr_t, uintptr_t)
0078 FUNCS(ptr, ptr, void*, uintptr_t)
0079 FUNCS(constptr, constptr, const void*, uintptr_t)
0080
0081 #undef FUNCS
0082
0083 UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) {
0084 memcpy(&val->val, &cval, sizeof(cval));
0085 }
0086
0087 UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) {
0088 memcpy(&val->val, &cval, sizeof(cval));
0089 }
0090
0091 UPB_INLINE upb_value upb_value_float(float cval) {
0092 upb_value ret;
0093 upb_value_setfloat(&ret, cval);
0094 return ret;
0095 }
0096
0097 UPB_INLINE upb_value upb_value_double(double cval) {
0098 upb_value ret;
0099 upb_value_setdouble(&ret, cval);
0100 return ret;
0101 }
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 typedef uintptr_t upb_tabkey;
0113
0114 UPB_INLINE char* upb_tabstr(upb_tabkey key, uint32_t* len) {
0115 char* mem = (char*)key;
0116 if (len) memcpy(len, mem, sizeof(*len));
0117 return mem + sizeof(*len);
0118 }
0119
0120 UPB_INLINE upb_StringView upb_tabstrview(upb_tabkey key) {
0121 upb_StringView ret;
0122 uint32_t len;
0123 ret.data = upb_tabstr(key, &len);
0124 ret.size = len;
0125 return ret;
0126 }
0127
0128
0129
0130 typedef struct upb_tabval {
0131 uint64_t val;
0132 } upb_tabval;
0133
0134 #define UPB_TABVALUE_EMPTY_INIT \
0135 { -1 }
0136
0137
0138
0139 typedef struct _upb_tabent {
0140 upb_tabkey key;
0141 upb_tabval val;
0142
0143
0144
0145
0146
0147 const struct _upb_tabent* next;
0148 } upb_tabent;
0149
0150 typedef struct {
0151 size_t count;
0152 uint32_t mask;
0153 uint32_t max_count;
0154 uint8_t size_lg2;
0155 upb_tabent* entries;
0156 } upb_table;
0157
0158 UPB_INLINE size_t upb_table_size(const upb_table* t) {
0159 return t->size_lg2 ? 1 << t->size_lg2 : 0;
0160 }
0161
0162
0163
0164 UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { return e->key == 0; }
0165
0166 uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed);
0167
0168 #ifdef __cplusplus
0169 }
0170 #endif
0171
0172 #include "upb/port/undef.inc"
0173
0174 #endif