15#define IsRationalTerm(TERM) ((int) TERM == 7)
24void term_array_init(
term_array *array,
int capacity);
26void term_array_push(
term_array *array,
void* t,
void* n);
27void* term_array_member(
term_array array,
void* t);
29void term_array_init(
term_array *array,
int capacity) {
31 array->terms = malloc(capacity *
sizeof(
void*));
32 if (array->terms != NULL) {
33 array->capacity = capacity;
35 Yap_Error(RESOURCE_ERROR_HEAP, TermNil,
"Out of memory.");
36 array->capacity = capacity;
37 array->nodes = malloc(capacity *
sizeof(
void*));
38 if (array->nodes == NULL)
39 Yap_Error(RESOURCE_ERROR_HEAP, TermNil,
"Out of memory.");
51void term_array_push(
term_array *array,
void* t,
void* n) {
52 if (array->length == array->capacity) {
53 int new_capacity = array->capacity * 2;
54 void *new_terms = realloc(array->terms, new_capacity *
sizeof(
void*));
55 if (new_terms != NULL) {
56 array->terms = new_terms;
58 Yap_Error(RESOURCE_ERROR_HEAP, TermNil,
"Out of memory.");
59 void *new_nodes = realloc(array->nodes, new_capacity *
sizeof(
void *));
60 if (new_nodes != NULL) {
61 array->nodes = new_nodes;
63 Yap_Error(RESOURCE_ERROR_HEAP, TermNil,
"Out of memory.");
64 array->capacity = new_capacity;
66 array->terms[array->length] = t;
67 array->nodes[array->length] = n;
71void* term_array_member(
term_array array,
void* t) {
73 for (i = 0; i < array.length; i++)
74 if (array.terms[i] == t)
return array.nodes[i];