Ejemplo n.º 1
0
int main()
{
	plan(8);

	trie_init(&trie);

	ok(trie_set(&trie, "foo", 10), "Add `foo` and set it to 10");
	is(trie.size, (size_t)1, "%zu", "`foo` was added");

	ok(trie_set(&trie, "foobar", 20), "Add `foobar` and set it to 20");
	is(trie.size, (size_t)2, "%zu", "`foobar` was added");

	ok(trie_set(&trie, "foo", 30), "Set `foo` to 30");
	is(trie.size, (size_t)2, "%zu", "No key was added because `foo` already exists");

	ok(trie_set(&trie, "", 50), "Add `` and set it to 50");
	is(trie.size, (size_t)3, "%zu", "`` was added");

	trie_release(&trie);

	done_testing();
}
Ejemplo n.º 2
0
/* Stores id of a file with given fingerprint in the trie. */
static void
put_file_id(trie_t *trie, const char path[], const char fingerprint[], int id,
		CompareType ct)
{
	compare_record_t *const record = malloc(sizeof(*record));
	void *data = NULL;
	(void)trie_get(trie, fingerprint, &data);

	record->id = id;
	record->next = data;

	/* Comparison by contents is the only one when we need to resolve fingerprint
	 * conflicts. */
	if(ct == CT_CONTENTS)
	{
		record->path = strdup(path);
	}
	else
	{
		record->path = NULL;
	}

	trie_set(trie, fingerprint, record);
}
Ejemplo n.º 3
0
int
trie_put(trie_t trie, const char str[])
{
	return trie_set(trie, str, NULL);
}