init 2019 day 7 with day 5 source, typo in day 6

This commit is contained in:
2022-09-30 16:28:22 +02:00
parent 8ed39e52b7
commit 626bd1df41
9 changed files with 516 additions and 5 deletions

View File

@@ -46,10 +46,10 @@
* | |---------| |
* +-------------------+---->| child |<---------+-----------------+
* | | |---------| | |
* | | | sibling | | |
* | | +---------+ | |
* | | | |
* | +---------+ | | +---------+ |
* | | +-->| sibling |<--+ | |
* | | | +---------+ | | |
* | | | | | |
* | +---------+ | +-----------------+ | +---------+ |
* | | N1 |<---+-----+ | | N2 | |
* | |---------| | | | |---------| |
* | | parent |----+ | +--| parent | |
@@ -121,7 +121,8 @@ static pool_t *pool_tries, *pool_objects;
static trie_t *trie_get(trie_t *parent, char *name, int pos)
{
trie_t *trie;
static int total = 0;
total ++;
if ((trie = pool_get(pool_tries))) {
for (int i = 0; i < TRIESIZE; ++i)
trie->child[i] = NULL;
@@ -129,6 +130,7 @@ static trie_t *trie_get(trie_t *parent, char *name, int pos)
if (parent)
parent->child[c2index(name[pos])] = trie;
}
printf ("tot=%d\n", total);
return trie;
}
@@ -146,12 +148,15 @@ static trie_t *trie_find(trie_t *root, char *name)
static object_t *object_find(trie_t *root, char *name)
{
trie_t *trie = trie_find(root, name);
static int total = 0;
if (!trie->object) {
total ++;
trie->object = pool_get(pool_objects);
trie->object->parent = NULL;
strcpy(trie->object->name, name);
INIT_LIST_HEAD(&trie->object->child);
INIT_LIST_HEAD(&trie->object->sibling);
printf ("tot2=%d\n", total);
}
return trie->object;
}