/** * Read stored variable sized records. */ static void lookup_varsz_records(TdbHdr *dbh) { int i; TestUrl *u; for (i = 0, u = urls; i < DATA_N; ++u, ++i) { unsigned long k = tdb_hash_calc(u->data, u->len); TdbBucket *b; print_bin_url(u); b = tdb_htrie_lookup(dbh, k); if (!b) { fprintf(stderr, "ERROR: can't find bucket for URL" " [%.20s...] (key=%#lx)\n", u->data, k); fflush(NULL); continue; } BUG_ON(!TDB_HTRIE_VARLENRECS(dbh)); if (!tdb_htrie_bscan_for_rec(dbh, b, k)) fprintf(stderr, "ERROR: can't find URL %#lx\n", k); } }
/** * Read stored fixed size records. */ static void lookup_fixsz_records(TdbHdr *dbh) { int i; for (i = 0; i < DATA_N; ++i) { TdbBucket *b; printf("results for int %u lookup:\n", ints[i]); fflush(NULL); b = tdb_htrie_lookup(dbh, ints[i]); if (!b) { fprintf(stderr, "ERROR: can't find bucket for int %u\n", ints[i]); fflush(NULL); continue; } BUG_ON(TDB_HTRIE_VARLENRECS(dbh)); if (!tdb_htrie_bscan_for_rec(dbh, b, ints[i])) fprintf(stderr, "ERROR: can't find int %u\n", ints[i]); } }
void * tdb_lookup(TDB *db, unsigned long key) { TdbFRec *r; TdbBucket *b; /* @db can be uninitialized, see tdb_open(). */ if (!db->hdr) return NULL; BUG_ON(!TDB_HTRIE_VARLENRECS(db->hdr)); b = tdb_htrie_lookup(db->hdr, key); if (!b) return NULL; TDB_HTRIE_FOREACH_REC(db->hdr, b, r) if (tdb_live_fsrec(db->hdr, r)) return r; return NULL; }