FreeCalypso > hg > ueda-linux
comparison ueda/libuschem/compinst.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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cd92449fdb51 |
---|---|
1 /* | |
2 * Component instance hash table logic | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <strings.h> | |
8 #include "schemstruct.h" | |
9 | |
10 extern char *malloc(); | |
11 | |
12 #define HASH_SIZE 1103 | |
13 | |
14 static int | |
15 hash_instname(str) | |
16 char *str; | |
17 { | |
18 register u_long accum; | |
19 register char *cp; | |
20 register int c; | |
21 | |
22 for (cp = str, accum = 0; c = *cp; cp++) { | |
23 accum <<= 4; | |
24 accum |= c & 0x0F; | |
25 } | |
26 return(accum % HASH_SIZE); | |
27 } | |
28 | |
29 hash_component_instances(schem) | |
30 struct schem *schem; | |
31 { | |
32 struct schemobj **hashtab; | |
33 register struct schemobj *obj, *hc, **hcp; | |
34 int errflag = 0, errstat = 0; | |
35 | |
36 hashtab = (struct schemobj **) | |
37 malloc(sizeof(struct schemobj *) * HASH_SIZE); | |
38 if (!hashtab) { | |
39 perror("malloc"); | |
40 exit(1); | |
41 } | |
42 bzero(hashtab, sizeof(struct schemobj *) * HASH_SIZE); | |
43 | |
44 for (obj = schem->obj_next; obj != (struct schemobj *)schem; | |
45 obj = obj->obj_next) { | |
46 if (obj->obj_type != OBJTYPE_COMPINST) | |
47 continue; | |
48 hcp = hashtab + hash_instname(obj->compobj_instname); | |
49 for (; hc = *hcp; hcp = &hc->compobj_nextinhash) | |
50 if (!strcmp(obj->compobj_instname, hc->compobj_instname)) { | |
51 fprintf(stderr, | |
52 "%s: %s: duplicate component instance name (line %d, line %d)\n", | |
53 schem->orig_filename, obj->compobj_instname, | |
54 hc->obj_lineno, obj->obj_lineno); | |
55 errflag = 1; | |
56 break; | |
57 } | |
58 if (errflag) { | |
59 errflag = 0; | |
60 errstat = -1; | |
61 } else | |
62 *hcp = obj; | |
63 } | |
64 schem->compinst_hash = hashtab; | |
65 return(errstat); | |
66 } | |
67 | |
68 report_compinst_hash_quality(schem) | |
69 struct schem *schem; | |
70 { | |
71 struct schemobj **hashtab; | |
72 int maxchain, total; | |
73 register int hb, curchain; | |
74 register struct schemobj *obj; | |
75 | |
76 hashtab = schem->compinst_hash; | |
77 for (hb = 0, total = maxchain = 0; hb < HASH_SIZE; hb++) { | |
78 for (obj = hashtab[hb], curchain = 0; obj; | |
79 obj = obj->compobj_nextinhash) { | |
80 curchain++; | |
81 total++; | |
82 } | |
83 if (curchain > maxchain) | |
84 maxchain = curchain; | |
85 } | |
86 printf("%s: %d component instances total, longest hash chain is %d\n", | |
87 schem->orig_filename, total, maxchain); | |
88 } | |
89 | |
90 struct schemobj * | |
91 find_component_instance(schem, instname) | |
92 struct schem *schem; | |
93 register char *instname; | |
94 { | |
95 register struct schemobj *obj; | |
96 | |
97 for (obj = schem->compinst_hash[hash_instname(instname)]; obj; | |
98 obj = obj->compobj_nextinhash) | |
99 if (!strcmp(obj->compobj_instname, instname)) | |
100 return(obj); | |
101 return(NULL); | |
102 } |