FreeCalypso > hg > ueda-linux
view ueda/uschem-netlist/nets.c @ 154:2328205328a9 default tip
m4-fp: WR-FPC 1mm pitch FFC/FPC connectors
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 25 Oct 2022 07:36:09 +0000 |
parents | cd92449fdb51 |
children |
line wrap: on
line source
/* * Working with struct net objects (netheads) */ #include <sys/types.h> #include <stdio.h> #include <strings.h> #include "netlist.h" extern char *malloc(); #define HASH_SIZE 1103 static struct net *named_net_hash[HASH_SIZE]; int total_named_nets; struct net **sorted_named_nets; struct net *unnamed_net_list; int total_unnamed_nets; struct net noconnect_pseudo_net = {"NO_CONNECT", NULL, 0, NULL}; static int hash_netname(str) char *str; { register u_long accum = 0; register char *cp; register int c, i; for (cp = str, i = 1; c = *cp; cp++, i++) accum += c * i; return(accum % HASH_SIZE); } struct net * alloc_nethead() { register struct net *n; n = (struct net *) malloc(sizeof(struct net)); if (!n) { perror("malloc"); exit(1); } bzero(n, sizeof(struct net)); return(n); } struct net * get_nethead_for_netname(netname) register char *netname; { register struct net *n, **np; for (np = named_net_hash + hash_netname(netname); n = *np; np = &n->next) if (!strcmp(n->netname, netname)) return(n); n = alloc_nethead(); n->netname = netname; *np = n; total_named_nets++; return(n); } report_named_net_hash_quality() { int maxchain; register int hb, curchain; register struct net *n; for (hb = 0, maxchain = 0; hb < HASH_SIZE; hb++) { for (n = named_net_hash[hb], curchain = 0; n; n = n->next) curchain++; if (curchain > maxchain) maxchain = curchain; } printf("Total named nets: %d\n", total_named_nets); printf("Longest hash chain: %d\n", maxchain); } named_net_forall(callback) int (*callback)(); { register struct net *n, **hb; register int i; for (hb = named_net_hash, i = 0; i < HASH_SIZE; hb++, i++) for (n = *hb; n; n = n->next) callback(n); } static netname_sort_compare(net1, net2) struct net **net1, **net2; { return(strcmp((*net1)->netname, (*net2)->netname)); } sort_named_nets() { register struct net *n, **hb, **op; register int i; sorted_named_nets = (struct net **) malloc(sizeof(struct net *) * total_named_nets); if (!sorted_named_nets) { perror("malloc"); exit(1); } op = sorted_named_nets; for (hb = named_net_hash, i = 0; i < HASH_SIZE; hb++, i++) for (n = *hb; n; n = n->next) *op++ = n; qsort(sorted_named_nets, total_named_nets, sizeof(struct net *), netname_sort_compare); } add_unnamed_net(n) register struct net *n; { n->next = unnamed_net_list; unnamed_net_list = n; total_unnamed_nets++; }