File indexing completed on 2026-09-12 09:28:49
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef UPB_HASH_STR_TABLE_H_
0009 #define UPB_HASH_STR_TABLE_H_
0010
0011 #include <stddef.h>
0012 #include <stdint.h>
0013 #include <string.h>
0014
0015 #include "upb/base/string_view.h"
0016 #include "upb/hash/common.h"
0017 #include "upb/mem/arena.h"
0018
0019
0020 #include "upb/port/def.inc"
0021
0022 typedef struct {
0023 upb_table t;
0024 } upb_strtable;
0025
0026 #ifdef __cplusplus
0027 extern "C" {
0028 #endif
0029
0030
0031
0032 bool upb_strtable_init(upb_strtable* table, size_t expected_size, upb_Arena* a);
0033
0034
0035 UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) {
0036 return t->t.count;
0037 }
0038
0039 void upb_strtable_clear(upb_strtable* t);
0040
0041
0042
0043
0044
0045
0046
0047 bool upb_strtable_insert(upb_strtable* t, const char* key, size_t len,
0048 upb_value val, upb_Arena* a);
0049
0050
0051
0052 bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len,
0053 upb_value* v);
0054
0055
0056 UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key,
0057 upb_value* v) {
0058 return upb_strtable_lookup2(t, key, strlen(key), v);
0059 }
0060
0061
0062
0063 bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len,
0064 upb_value* val);
0065
0066 UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key,
0067 upb_value* v) {
0068 return upb_strtable_remove2(t, key, strlen(key), v);
0069 }
0070
0071
0072 bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a);
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 #define UPB_STRTABLE_BEGIN -1
0085
0086 bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key,
0087 upb_value* val, intptr_t* iter);
0088 void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter);
0089 void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v);
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 typedef struct {
0125 const upb_strtable* t;
0126 size_t index;
0127 } upb_strtable_iter;
0128
0129 UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) {
0130 return &i->t->t.entries[i->index];
0131 }
0132
0133 void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t);
0134 void upb_strtable_next(upb_strtable_iter* i);
0135 bool upb_strtable_done(const upb_strtable_iter* i);
0136 upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i);
0137 upb_value upb_strtable_iter_value(const upb_strtable_iter* i);
0138 void upb_strtable_iter_setdone(upb_strtable_iter* i);
0139 bool upb_strtable_iter_isequal(const upb_strtable_iter* i1,
0140 const upb_strtable_iter* i2);
0141
0142 #ifdef __cplusplus
0143 }
0144 #endif
0145
0146 #include "upb/port/undef.inc"
0147
0148 #endif