Skip to content

Commit

Permalink
free_extractor(): Improve the x_table stats
Browse files Browse the repository at this point in the history
  • Loading branch information
ampli committed Mar 27, 2024
1 parent d96da4d commit e347855
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions link-grammar/parse/extract-links.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include "tokenize/word-structures.h" // Word_Struct

//#define RECOUNT
//#define DEBUG_X_TABLE
#ifdef DEBUG
#define DEBUG_X_TABLE
#endif

typedef struct Parse_choice_struct Parse_choice;

Expand Down Expand Up @@ -221,11 +223,6 @@ extractor_t * extractor_new(Sentence sent)
pex->log2_x_table_size = log2_table_size;
pex->x_table_size = (1 << log2_table_size);

#ifdef DEBUG_X_TABLE
printf("Allocating x_table of size %u (log2 %d)\n",
pex->x_table_size, log2_table_size);
#endif /* DEBUG_X_TABLE */

pex->x_table = (Pset_bucket**) xalloc(pex->x_table_size * sizeof(Pset_bucket*));
memset(pex->x_table, 0, pex->x_table_size * sizeof(Pset_bucket*));

Expand All @@ -249,35 +246,32 @@ extractor_t * extractor_new(Sentence sent)
}

/**
* This is the function that should be used to free the set structure. Since
* it's a dag, a recursive free function won't work. Every time we create
* a set element, we put it in the hash table, so this is OK.
* Free the x_table memory by freeing the hash table pointers and the
* memory pools of the Pset_bucket and Parse_choice elements.
*/
void free_extractor(extractor_t * pex)
{
if (!pex) return;

#ifdef DEBUG_X_TABLE
int N = 0;
unsigned int num_entries = 0;

for (unsigned int i = 0; i < pex->x_table_size; i++)
{
int c = 0;
for (Pset_bucket *t = pex->x_table[i]; t != NULL; t = t->next)
c++;

if (c > 0)
;//printf("I %d: chain %d\n", i, c);
else
N++;
if (pex->x_table[i] == NULL) continue;
num_entries++;
}
printf("Used x_table %u/%u %.2f%%\n",
pex->x_table_size-N, pex->x_table_size,
100.0f*(pex->x_table_size-N)/pex->x_table_size);
printf("x_table: used=%u/%u (%.2f%%) pset_bucket=%zu (avg chain %.2f) "
"parse_choice=%zu\n",
num_entries, pex->x_table_size,
100.0f*num_entries / pex->x_table_size,
pool_num_elements_issued(pex->Pset_bucket_pool),
1.0f*pool_num_elements_issued(pex->Pset_bucket_pool) / pex->x_table_size,
pool_size(pex->Parse_choice_pool));
#endif /* DEBUG_X_TABLE */

pex->parse_set = NULL;

//printf("Freeing x_table of size %d\n", pex->x_table_size);
xfree((void *) pex->x_table, pex->x_table_size * sizeof(Pset_bucket*));
pex->x_table_size = 0;
pex->x_table = NULL;
Expand Down

0 comments on commit e347855

Please sign in to comment.