示例#1
0
static void
do_varsz(TdbHdr *dbh)
{
	int i;
	TestUrl *u;

	/* Store records. */
	for (i = 0, u = urls; i < DATA_N; ++u, ++i) {
		unsigned long k = tdb_hash_calc(u->data, u->len);
		size_t copied, to_copy = u->len;
		TdbVRec *rec;

		print_bin_url(u);

		rec = (TdbVRec *)tdb_htrie_insert(dbh, k, u->data, &to_copy);
		assert((u->len && rec) || (!u->len && !rec));

		copied = to_copy;

		while (copied != u->len) {
			char *p;

			rec = tdb_htrie_extend_rec(dbh, rec, u->len - copied);
			assert(rec);

			p = (char *)(rec + 1);
			memcpy(p, u->data + copied, rec->len);

			copied += rec->len;
		}
	}

	lookup_varsz_records(dbh);
}
示例#2
0
文件: main.c 项目: yulintao/tempesta
/**
 * Check available room in @trec and allocate new record if it's not enough.
 * Chop tail of @trec if we allocated more space, but can't use the tail
 * w/o data fragmentation.
 */
void *
tdb_entry_get_room(TDB *db, TdbVRec **r, char *curr_ptr, size_t tail_len,
		   size_t tot_size)
{
	if (likely((*r)->data + (*r)->len - curr_ptr >= tail_len))
		return curr_ptr;

	(*r)->len -= curr_ptr - (*r)->data;

	*r = tdb_htrie_extend_rec(db->hdr, *r, tot_size);
	return *r ? (*r)->data : NULL;
}
示例#3
0
文件: main.c 项目: yulintao/tempesta
/**
 * @return pointer to free area of size at least @size bytes or allocate
 * a new record and link it with the current one.
 *
 * TODO update @size to actually allocated space.
 */
TdbVRec *
tdb_entry_add(TDB *db, TdbVRec *r, size_t size)
{
	return tdb_htrie_extend_rec(db->hdr, r, size);
}