viric@5: #include viric@5: #include "dictre.h" viric@5: viric@5: extern struct Def defs[]; viric@5: extern int ndefs; viric@5: viric@5: enum viric@5: { viric@5: MAXLEN = 200 viric@5: }; viric@5: viric@5: struct HashElement viric@5: { viric@5: struct HashElement *next; viric@5: struct Def *def; viric@5: int index; viric@5: }; viric@5: viric@5: static struct HashElement *dhash[MAXLEN]; viric@5: static int ndhash[MAXLEN]; viric@5: static struct HashElement *dhash_last[MAXLEN]; viric@5: viric@5: void init_repeated() viric@5: { viric@5: int i; viric@5: for(i=0; ilength % MAXLEN; viric@5: return hash; viric@5: } viric@5: viric@5: void new_hashdef(struct Def *ptr, int index) viric@5: { viric@5: int hash; viric@5: struct HashElement *el; viric@5: viric@5: hash = calc_hash(ptr); viric@5: viric@5: el = (struct HashElement *) fastmalloc(sizeof(*el)); viric@5: el->def = ptr; viric@5: el->next = 0; viric@5: el->index = index; viric@6: /* viric@6: printf("New index: %i\n", index); viric@6: */ viric@5: viric@5: /* Let the last point to the new element */ viric@5: if (ndhash[hash] != 0) viric@5: { viric@5: dhash_last[hash]->next = el; viric@5: } else /* 0 elements in row */ viric@5: { viric@5: dhash[hash] = el; viric@5: } viric@5: ndhash[hash] += 1; viric@5: dhash_last[hash] = el; viric@5: } viric@5: viric@5: int def_repeated(struct Def *ptr) viric@5: { viric@5: int hash; viric@5: int i; viric@5: struct HashElement *h; viric@5: viric@5: hash = calc_hash(ptr); viric@5: viric@5: h = dhash[hash]; viric@5: for(i=0; i < ndhash[hash]; ++i) viric@5: { viric@5: struct Def *hdef = h->def; viric@5: if (hdef->length == ptr->length viric@5: && (strncmp(hdef->d, ptr->d, ptr->length) == 0)) viric@5: /* Repeated found !*/ viric@6: { viric@6: /* viric@6: printf("Found: l1: %i l2: %i => %i\n", ptr->length, hdef->length, viric@6: h->index); viric@6: */ viric@5: return h->index; viric@6: } viric@6: h = h->next; viric@5: } viric@5: viric@5: /* Not found */ viric@5: return -1; viric@5: }