FreeCalypso > hg > ueda-linux
comparison ueda/uschem-netlist/nets.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 * Working with struct net objects (netheads) | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <strings.h> | |
8 #include "netlist.h" | |
9 | |
10 extern char *malloc(); | |
11 | |
12 #define HASH_SIZE 1103 | |
13 | |
14 static struct net *named_net_hash[HASH_SIZE]; | |
15 int total_named_nets; | |
16 | |
17 struct net **sorted_named_nets; | |
18 | |
19 struct net *unnamed_net_list; | |
20 int total_unnamed_nets; | |
21 | |
22 struct net noconnect_pseudo_net = {"NO_CONNECT", NULL, 0, NULL}; | |
23 | |
24 static int | |
25 hash_netname(str) | |
26 char *str; | |
27 { | |
28 register u_long accum = 0; | |
29 register char *cp; | |
30 register int c, i; | |
31 | |
32 for (cp = str, i = 1; c = *cp; cp++, i++) | |
33 accum += c * i; | |
34 return(accum % HASH_SIZE); | |
35 } | |
36 | |
37 struct net * | |
38 alloc_nethead() | |
39 { | |
40 register struct net *n; | |
41 | |
42 n = (struct net *) malloc(sizeof(struct net)); | |
43 if (!n) { | |
44 perror("malloc"); | |
45 exit(1); | |
46 } | |
47 bzero(n, sizeof(struct net)); | |
48 return(n); | |
49 } | |
50 | |
51 struct net * | |
52 get_nethead_for_netname(netname) | |
53 register char *netname; | |
54 { | |
55 register struct net *n, **np; | |
56 | |
57 for (np = named_net_hash + hash_netname(netname); n = *np; | |
58 np = &n->next) | |
59 if (!strcmp(n->netname, netname)) | |
60 return(n); | |
61 n = alloc_nethead(); | |
62 n->netname = netname; | |
63 *np = n; | |
64 total_named_nets++; | |
65 return(n); | |
66 } | |
67 | |
68 report_named_net_hash_quality() | |
69 { | |
70 int maxchain; | |
71 register int hb, curchain; | |
72 register struct net *n; | |
73 | |
74 for (hb = 0, maxchain = 0; hb < HASH_SIZE; hb++) { | |
75 for (n = named_net_hash[hb], curchain = 0; n; n = n->next) | |
76 curchain++; | |
77 if (curchain > maxchain) | |
78 maxchain = curchain; | |
79 } | |
80 printf("Total named nets: %d\n", total_named_nets); | |
81 printf("Longest hash chain: %d\n", maxchain); | |
82 } | |
83 | |
84 named_net_forall(callback) | |
85 int (*callback)(); | |
86 { | |
87 register struct net *n, **hb; | |
88 register int i; | |
89 | |
90 for (hb = named_net_hash, i = 0; i < HASH_SIZE; hb++, i++) | |
91 for (n = *hb; n; n = n->next) | |
92 callback(n); | |
93 } | |
94 | |
95 static | |
96 netname_sort_compare(net1, net2) | |
97 struct net **net1, **net2; | |
98 { | |
99 return(strcmp((*net1)->netname, (*net2)->netname)); | |
100 } | |
101 | |
102 sort_named_nets() | |
103 { | |
104 register struct net *n, **hb, **op; | |
105 register int i; | |
106 | |
107 sorted_named_nets = | |
108 (struct net **) malloc(sizeof(struct net *) * total_named_nets); | |
109 if (!sorted_named_nets) { | |
110 perror("malloc"); | |
111 exit(1); | |
112 } | |
113 op = sorted_named_nets; | |
114 for (hb = named_net_hash, i = 0; i < HASH_SIZE; hb++, i++) | |
115 for (n = *hb; n; n = n->next) | |
116 *op++ = n; | |
117 qsort(sorted_named_nets, total_named_nets, sizeof(struct net *), | |
118 netname_sort_compare); | |
119 } | |
120 | |
121 add_unnamed_net(n) | |
122 register struct net *n; | |
123 { | |
124 n->next = unnamed_net_list; | |
125 unnamed_net_list = n; | |
126 total_unnamed_nets++; | |
127 } |