Commit e7b7e187 authored by Tony Finch's avatar Tony Finch Committed by Daniel Salzman

trie: refactor to prepare for copy-on-write support

No functional change.

The point of this commit is to make it possible to stash a few
flags in leaf nodes as well as branch nodes, though we don't
yet exercise this possibility in any meaningful way.

This fixes a foolish mistake in the original qp trie data structure
declarations: the combination of unions and bitfields is a complete
disaster for portability, and it gets into dangerous territory wrt
compiler optimization. Instead, we just use a big enough word (uint64_t)
which is broken up into fields using accessor macros and inline functions,
and cast it to a pointer when necessary. We don't actually care about
the detailed layout in memory, just the numeric value, so a union was
the wrong tool.
parent c3c9c308
This diff is collapsed.
......@@ -110,8 +110,10 @@ int main(int argc, char *argv[])
unsigned key_count = 100000;
char **keys = malloc(sizeof(char*) * key_count);
/* key must have at least one char and a nul terminator
so that the before/after checks have a char to modify */
for (unsigned i = 0; i < key_count; ++i) {
keys[i] = str_key_rand(KEY_MAXLEN);
keys[i] = str_key_rand(rand() % (KEY_MAXLEN - 2) + 2);
/* Sort random keys. */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment