Mercurial > hg > sidinfo
changeset 224:4bec78f45188
Use th_datastruct::th_llist_t instead of yet another linked list
implementation. Results in typecast aliasing magick, tho.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 27 Dec 2019 12:45:57 +0200 |
parents | a76276ff7ba8 |
children | 15a51252b73a |
files | sidlib.c sidlib.h |
diffstat | 2 files changed, 14 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/sidlib.c Fri Dec 27 12:15:51 2019 +0200 +++ b/sidlib.c Fri Dec 27 12:45:57 2019 +0200 @@ -292,25 +292,6 @@ } -// Insert given node to db linked list -// -static void sidlib_sldb_node_insert(SIDLibSLDB *dbh, SIDLibSLDBNode *node) -{ - if (dbh->nodes != NULL) - { - node->prev = dbh->nodes->prev; - dbh->nodes->prev->next = node; - dbh->nodes->prev = node; - } - else - { - dbh->nodes = node; - node->prev = node; - } - node->next = NULL; -} - - // Parse a time-entry in SLDB format // static int sidlib_sldb_get_value(const char *str, size_t *pos) @@ -486,7 +467,7 @@ // Parse and add node to db if ((tmnode = sidlib_sldb_parse_entry(ctx, line)) != NULL) { - sidlib_sldb_node_insert(dbh, tmnode); + th_llist_append_node((th_llist_t **) &dbh->nodes, (th_llist_t *) tmnode); } else { @@ -540,18 +521,16 @@ // int sidlib_sldb_build_index(SIDLibSLDB * dbh) { - SIDLibSLDBNode *node; - // Free old index th_free_r(&dbh->pindex); // Get size of db - for (node = dbh->nodes, dbh->nnodes = 0; node != NULL; node = node->next) - dbh->nnodes++; + dbh->nnodes = th_llist_length((th_llist_t *) dbh->nodes); // Check number of nodes if (dbh->nnodes > 0) { + SIDLibSLDBNode *node; size_t i; // Allocate memory for index-table @@ -560,7 +539,8 @@ return THERR_MALLOC; // Get node-pointers to table - for (i = 0, node = dbh->nodes; node && i < dbh->nnodes; node = node->next) + for (i = 0, node = dbh->nodes; node != NULL && i < dbh->nnodes; + node = (SIDLibSLDBNode *) node->node.next) dbh->pindex[i++] = node; // Sort the indexes @@ -660,7 +640,7 @@ node->lengths[index] = tmpl; } - sidlib_sldb_node_insert(dbh, node); + th_llist_append_node((th_llist_t **) &dbh->nodes, (th_llist_t *) node); dbh->pindex[n] = node; } @@ -744,13 +724,8 @@ { if (dbh != NULL) { - SIDLibSLDBNode *node = dbh->nodes; - while (node != NULL) - { - SIDLibSLDBNode *next = node->next; - sidlib_sldb_node_free(node); - node = next; - } + th_llist_free_func((th_llist_t *) dbh->nodes, + (void (*)(void *)) sidlib_sldb_node_free); dbh->nodes = NULL; dbh->nnodes = 0;
--- a/sidlib.h Fri Dec 27 12:15:51 2019 +0200 +++ b/sidlib.h Fri Dec 27 12:45:57 2019 +0200 @@ -9,6 +9,7 @@ #include "th_util.h" #include "th_ioctx.h" #include "th_crypto.h" +#include "th_datastruct.h" #ifdef __cplusplus @@ -49,20 +50,20 @@ // // Structures // -typedef struct _SIDLibSLDBNode +typedef struct { + th_llist_t node; + th_md5hash_t hash; // MD5 hash-digest int nlengths; // Number of lengths int *lengths; // Lengths in seconds - struct _SIDLibSLDBNode *prev, *next; } SIDLibSLDBNode; typedef struct { - SIDLibSLDBNode *nodes, - **pindex; - size_t nnodes; + SIDLibSLDBNode *nodes, **pindex; + size_t nnodes; } SIDLibSLDB;