comparison ueda/libueda/hashmcl.c @ 0:cd92449fdb51

initial import of ueda and ifctf-part-lib from ifctfvax CVS
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 20 Jul 2015 00:24:37 +0000
parents
children c91e7a30fab3
comparison
equal deleted inserted replaced
-1:000000000000 0:cd92449fdb51
1 /*
2 * MCL hash table logic
3 *
4 * This module implements construction and use of a hash table indexing
5 * the MCL components by refdes. It facilitates checking the MCL for
6 * duplicate refdes errors and fast component lookups.
7 */
8
9 #include <sys/types.h>
10 #include <stdio.h>
11 #include <strings.h>
12 #include "mcl.h"
13
14 extern struct component components[];
15 extern int ncomponents;
16
17 #define HASH_SIZE 1103
18
19 static struct component *mclhashtab[HASH_SIZE];
20
21 static int
22 hash_refdes(str)
23 char *str;
24 {
25 register u_long accum;
26 register char *cp;
27 register int c;
28
29 for (cp = str, accum = 0; c = *cp; cp++) {
30 accum <<= 4;
31 accum |= c & 0x0F;
32 }
33 return(accum % HASH_SIZE);
34 }
35
36 hash_MCL()
37 {
38 register struct component *comp, *hc, **hcp;
39 int i;
40 int errflag = 0, errstat = 0;
41
42 for (comp = components, i = 0; i < ncomponents; comp++, i++) {
43 hcp = mclhashtab + hash_refdes(comp->name);
44 for (; hc = *hcp; hcp = &hc->nextinhash)
45 if (!strcmp(comp->name, hc->name)) {
46 fprintf(stderr,
47 "%s: duplicate refdes in the MCL\n",
48 comp->name);
49 errflag = 1;
50 break;
51 }
52 if (errflag) {
53 errflag = 0;
54 errstat = -1;
55 } else
56 *hcp = comp;
57 }
58 if (errstat)
59 exit(1);
60 }
61
62 report_mclhash_quality()
63 {
64 int maxchain;
65 register int hb, curchain;
66 register struct component *comp;
67
68 for (hb = 0, maxchain = 0; hb < HASH_SIZE; hb++) {
69 for (comp = mclhashtab[hb], curchain = 0; comp;
70 comp = comp->nextinhash)
71 curchain++;
72 if (curchain > maxchain)
73 maxchain = curchain;
74 }
75 printf("Total components: %d\n", ncomponents);
76 printf("Longest hash chain: %d\n", maxchain);
77 }
78
79 struct component *
80 find_comp_by_refdes(refdes)
81 register char *refdes;
82 {
83 register struct component *comp;
84
85 for (comp = mclhashtab[hash_refdes(refdes)]; comp;
86 comp = comp->nextinhash)
87 if (!strcmp(comp->name, refdes))
88 return(comp);
89 return(NULL);
90 }