Skip to content

Commit

Permalink
Merge pull request #971 from ampli/no-E_list
Browse files Browse the repository at this point in the history
Eliminate E_list
  • Loading branch information
linas authored Jul 18, 2019
2 parents c98b712 + d9252e4 commit 72d1f03
Show file tree
Hide file tree
Showing 24 changed files with 536 additions and 508 deletions.
1 change: 0 additions & 1 deletion link-grammar/api-structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ struct Sentence_s
String_set * string_set; /* Used for assorted strings */
Pool_desc * fm_Match_node; /* Fast-matcher Match_node memory pool */
Pool_desc * Table_connector_pool; /* Count memoizing memory pool */
Pool_desc * E_list_pool;
Pool_desc * Exp_pool;
Pool_desc * X_node_pool;
Pool_desc * Disjunct_pool;
Expand Down
5 changes: 0 additions & 5 deletions link-grammar/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,6 @@ Sentence sentence_create(const char *input_string, Dictionary dict)
sent->dict = dict;
sent->string_set = string_set_create();
sent->rand_state = global_rand_state;
sent->E_list_pool = pool_new(__func__, "E_list", /*num_elements*/4096,
sizeof(E_list), /*zero_out*/false,
/*align*/false, /*exact*/false);
sent->Exp_pool = pool_new(__func__, "Exp", /*num_elements*/4096,
sizeof(Exp), /*zero_out*/false,
/*align*/false, /*exact*/false);
Expand Down Expand Up @@ -533,13 +530,11 @@ void sentence_delete(Sentence sent)
global_rand_state = sent->rand_state;
pool_delete(sent->fm_Match_node);
pool_delete(sent->Table_connector_pool);
pool_delete(sent->E_list_pool);
pool_delete(sent->Exp_pool);
pool_delete(sent->X_node_pool);
if (IS_DB_DICT(sent->dict))
{
condesc_reuse(sent->dict);
pool_reuse(sent->dict->E_list_pool);
pool_reuse(sent->dict->Exp_pool);
}

Expand Down
6 changes: 3 additions & 3 deletions link-grammar/connectors.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ static size_t get_connectors_from_expression(condesc_t **conlist, const Exp *e)
{
if (e->type == CONNECTOR_type)
{
if (NULL != conlist) *conlist = e->u.condesc;
if (NULL != conlist) *conlist = e->condesc;
return 1;
}

size_t cl_size = 0;
for (E_list *l = e->u.l; l != NULL; l = l->next)
for (Exp *opd = e->operand_first; opd != NULL; opd = opd->operand_next)
{
cl_size += get_connectors_from_expression(conlist, l->e);
cl_size += get_connectors_from_expression(conlist, opd);
if (NULL != conlist) conlist++;
}

Expand Down
6 changes: 3 additions & 3 deletions link-grammar/corpus/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static Exp * make_exp(const char *djstr, double cost)
lhead = l;

e->type = AND_type;
e->u.l = lhead;
e->operand_first = lhead;

return e;
}
Expand Down Expand Up @@ -219,7 +219,7 @@ static Exp * or_exp(Exp *p1, Exp *p2)
l->e = p1;
lhead = l;

e->u.l = lhead;
e->operand_first = lhead;
return e;
}
#endif
Expand All @@ -228,7 +228,7 @@ static void free_exp(Exp *e)
{
if (CONNECTOR_type != e->type)
{
E_list *l = e->u.l;
E_list *l = e->operand_first;
while(l)
{
E_list *ln = l->next;
Expand Down
1 change: 0 additions & 1 deletion link-grammar/dict-common/dict-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ static void free_dictionary(Dictionary dict)
free_dict_node_recursive(dict->root);
free_Word_file(dict->word_file_header);
pool_delete(dict->Exp_pool);
pool_delete(dict->E_list_pool);
}

static void affix_list_delete(Dictionary dict)
Expand Down
2 changes: 0 additions & 2 deletions link-grammar/dict-common/dict-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ struct Dictionary_s
Word_file * word_file_header;
ConTable contable;

/* Memory pools */
Pool_desc * Exp_pool;
Pool_desc * E_list_pool;

/* Private data elements that come in play only while the
* dictionary is being read, and are not otherwise used.
Expand Down
8 changes: 4 additions & 4 deletions link-grammar/dict-common/dict-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,23 @@ const char * linkgrammar_get_dict_locale(Dictionary dict)
goto locale_error;
}

if (0 == strcmp(dn->exp->u.condesc->string, "C"))
if (0 == strcmp(dn->exp->condesc->string, "C"))
{
locale = string_set_add("C", dict->string_set);
}
else
{
char c;
char locale_ll[4], locale_cc[3];
int locale_numelement = sscanf(dn->exp->u.condesc->string, "%3[A-Z]4%2[a-z]%c",
int locale_numelement = sscanf(dn->exp->condesc->string, "%3[A-Z]4%2[a-z]%c",
locale_ll, locale_cc, &c);
if (2 != locale_numelement)
{
prt_error("Error: \"<dictionary-locale>: %s\" "
"should be in the form LL4cc+\n"
"\t(LL: language code; cc: territory code) "
"\tor C+ for transliterated dictionaries.\n",
dn->exp->u.condesc->string);
dn->exp->condesc->string);
goto locale_error;
}

Expand Down Expand Up @@ -268,7 +268,7 @@ const char * linkgrammar_get_dict_version(Dictionary dict)
if (NULL == dn) return "[unknown]";

e = dn->exp;
ver = strdup(&e->u.condesc->string[1]);
ver = strdup(&e->condesc->string[1]);
p = strchr(ver, 'v');
while (p)
{
Expand Down
34 changes: 16 additions & 18 deletions link-grammar/dict-common/dict-structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ LINK_BEGIN_DECLS
/* Forward decls */
typedef struct Dict_node_struct Dict_node;
typedef struct Exp_struct Exp;
typedef struct E_list_struct E_list;
typedef struct Word_file_struct Word_file;
typedef struct condesc_struct condesc_t;

Expand All @@ -37,36 +36,35 @@ typedef enum
} Exp_type;

/**
* The E_list and Exp structures defined below comprise the expression
* trees that are stored in the dictionary. The expression has a type
* (OR_type, AND_type or CONNECTOR_type). If it is not a terminal it
* has a list (an E_list) of children. Else "condesc" is the connector
* descriptor, when "dir" indicates the connector direction.
* The Exp structure defined below comprises the expression trees that are
* stored in the dictionary. The expression has a type (OR_type, AND_type
* or CONNECTOR_type). If it is not a terminal "operand" points to its
* list of operands (when each of them points to the next one through
* "next"). Else "condesc" is the connector descriptor, when "dir"
* indicates the connector direction.
*/
struct Exp_struct
{
Exp *operand_next; /* Next same-level operand. */
Exp_type type; /* One of three types: AND, OR, or connector. */
char dir; /* The connector connects to: '-': the left; '+': the right */
bool multi; /* TRUE if a multi-connector (for connector) */
union {
E_list * l; /* Only needed for non-terminals */
condesc_t * condesc; /* Only needed if it's a connector */
} u;
char dir; /* The connector connects to the left ('-') or right ('+'). */
bool multi; /* TRUE if a multi-connector (for connector). */
union
{
Exp *operand_first; /* First operand (for non-terminals). */
condesc_t *condesc; /* Only needed if it's a connector. */
};
double cost; /* The cost of using this expression. */
};

struct E_list_struct
{
E_list * next;
Exp * e;
};

/* API to access the above structure. */
static inline Exp_type lg_exp_get_type(const Exp* exp) { return exp->type; }
static inline char lg_exp_get_dir(const Exp* exp) { return exp->dir; }
static inline bool lg_exp_get_multi(const Exp* exp) { return exp->multi; }
const char* lg_exp_get_string(const Exp*);
static inline double lg_exp_get_cost(const Exp* exp) { return exp->cost; }
static inline Exp* lg_exp_operand_first(Exp* exp) { return exp->operand_first; }
static inline Exp* lg_exp_operand_next(Exp* exp) { return exp->operand_next; }

/**
* The dictionary is stored as a binary tree comprised of the following
Expand Down
Loading

0 comments on commit 72d1f03

Please sign in to comment.