ref: e78b5e27f582a692b81369be4614d0a7b8eee9cb
dir: /tuple.c/
#include <u.h> #include <libc.h> #include <String.h> #include "dat.h" #include "fns.h" Tuple* findtuple(Block *b, char *key) { Tuple *t; for (int i = 0; i < b->ntuples; i++) { t = &b->tuples[i]; if (t->key && strcmp(t->key, key) == 0) return t; } return nil; } void addtuple(Block *b, char *key, char *value, int ipnet) { Tuple *t; if (!b->tuples) { b->ntuples = 1; b->tuples = mallocz(sizeof(Tuple) * nsystuples, 1); t = b->tuples; } else { t = &b->tuples[b->ntuples]; b->ntuples++; } t->key = key; t->value = value; t->ipnet = ipnet; } void fortuple(Block *b, void (*f)(Tuple*,void*), void *aux) { for (int i = 0; i < b->ntuples; i++) f(&b->tuples[i], aux); }