Ejemplo n.º 1
0
// Looks up the item with the key `key` in `object` and returns its value.
//
// If there is no item with the `key`, `nfcd_null()` is returned.
//
// Note that the lookup uses linear search O(n) to find the entry with the
// specified key. Objects are assumed to be "smallish" so that the extra
// overhead for more complicated lookups (hashtables, etc) is not needed.
// If you are dealing with an object with tens of thousands of keys, consider
// holding your own lookup structures to be able to quickly find items in
// the object, without the O(n) cost of `nfcd_object_lookup()`.
nfcd_loc nfcd_object_lookup(struct ConfigData *cd, nfcd_loc object, const char *key)
{
	nfcd_loc key_loc = MAKE_LOC(NFCD_TYPE_STRING, nfst_to_symbol_const(STRINGTABLE(cd), key));

	struct block *block = (struct block *)((char *)cd + LOC_OFFSET(object));
	while (1) {
		struct object_item *items = (struct object_item *)(block + 1);
		for (int i=0; i<block->size; ++i) {
			if (key_loc == items[i].key)
				return items[i].value;
		}
		if (block->next_block == 0)
			break;
		block = (struct block *)((char *)cd + LOC_OFFSET(block->next_block));
	}

	return nfcd_null();
}
Ejemplo n.º 2
0
int32_t Q_STLookup(const stable_t *st, const char *string) {
    assert(st != NULL && st->st != NULL && string != NULL);
    return nfst_to_symbol_const((struct nfst_StringTable *)st->st, string);
};
Ejemplo n.º 3
0
int32_t Q_STLookup(stable_t st, const char *string) {
    return nfst_to_symbol_const((struct nfst_StringTable *)st.st, string);
};