Exemplo n.º 1
0
/**
 * 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]);
	}
}
Exemplo n.º 2
0
/**
 * 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);
	}
}
Exemplo n.º 3
0
/**
 * Lookup and get a record.
 * Since we don't copy returned records, we have to lock the memory location
 * where the record is placed and the user must call tdb_rec_put() when finish
 * with the record.
 *
 * The caller must not call sleeping functions during work with the record.
 * Typically there is only one large record per bucket, so the bucket lock
 * is exactly the same as to lock the record. While there could be many
 * small records in a bucket, so the caller should not perform long jobs
 * with small records.
 *
 * @return pointer to record with acquired bucket lock if the record is
 * found and NULL without acquired locks otherwise.
 */
TdbIter
tdb_rec_get(TDB *db, unsigned long key)
{
	TdbIter iter = { NULL };

	iter.bckt = tdb_htrie_lookup(db->hdr, key);
	if (!iter.bckt)
		goto out;

	iter.rec = tdb_htrie_bscan_for_rec(db->hdr, (TdbBucket **)&iter.bckt,
					   key);
out:
	return iter;
}