summaryrefslogtreecommitdiff
path: root/upb_table.c
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-02 20:19:06 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-02 20:19:06 -0700
commitb0ef7f0b6778addc91ce04ca1d6e835d44387c83 (patch)
treeb67f490bd178d53c5fa2bc550fef77b0062efafb /upb_table.c
parentb8481e0e55aebad1d9ffa0f3845609f929bca02f (diff)
More fixes, completions, still doesn't quite work.
Diffstat (limited to 'upb_table.c')
-rw-r--r--upb_table.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/upb_table.c b/upb_table.c
index 22c0d5a..e572dd1 100644
--- a/upb_table.c
+++ b/upb_table.c
@@ -15,13 +15,11 @@ static const double MAX_LOAD = 0.85;
static uint32_t MurmurHash2(const void *key, size_t len, uint32_t seed);
-static uint32_t max(uint32_t a, uint32_t b) { return a > b ? a : b; }
-
/* We use 1-based indexes into the table so that 0 can be "NULL". */
-static struct upb_inttable_entry *intent(struct upb_inttable *t, uint32_t i) {
+static struct upb_inttable_entry *intent(struct upb_inttable *t, int32_t i) {
return UPB_INDEX(t->t.entries, i-1, t->t.entry_size);
}
-static struct upb_strtable_entry *strent(struct upb_strtable *t, uint32_t i) {
+static struct upb_strtable_entry *strent(struct upb_strtable *t, int32_t i) {
return UPB_INDEX(t->t.entries, i-1, t->t.entry_size);
}
@@ -190,7 +188,33 @@ void upb_strtable_insert(struct upb_strtable *t, struct upb_strtable_entry *e)
upb_strtable_free(t);
*t = new_table;
}
- strinsert(t->t.entries, e);
+ strinsert(t, e);
+}
+
+void *upb_inttable_begin(struct upb_inttable *t) {
+ return upb_inttable_next(t, intent(t, -1));
+}
+
+void *upb_inttable_next(struct upb_inttable *t, struct upb_inttable_entry *cur) {
+ struct upb_inttable_entry *end = intent(t, upb_inttable_size(t));
+ do {
+ cur = (void*)((char*)cur + t->t.entry_size);
+ if(cur == end) return NULL;
+ } while(cur->key == UPB_EMPTY_ENTRY);
+ return cur;
+}
+
+void *upb_strtable_begin(struct upb_strtable *t) {
+ return upb_strtable_next(t, strent(t, -1));
+}
+
+void *upb_strtable_next(struct upb_strtable *t, struct upb_strtable_entry *cur) {
+ struct upb_strtable_entry *end = strent(t, upb_strtable_size(t));
+ do {
+ cur = (void*)((char*)cur + t->t.entry_size);
+ if(cur == end) return NULL;
+ } while(cur->key.byte_len == 0);
+ return cur;
}
#ifdef UPB_UNALIGNED_READS_OK
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback