# HG changeset patch # User Space Falcon # Date 1438473615 0 # Node ID 1f3283f8e4823104c31e891e8b82644455e5c17b # Parent 51893347bc42a425eb2afe09d5cae5e6349ac2dd unet-bind: instance hash implemented diff -r 51893347bc42 -r 1f3283f8e482 ueda/sverp-bind/Makefile --- a/ueda/sverp-bind/Makefile Sat Aug 01 23:33:05 2015 +0000 +++ b/ueda/sverp-bind/Makefile Sun Aug 02 00:00:15 2015 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= main.o outcomp.o +OBJS= insthash.o main.o outcomp.o LIBS= ../libueda/libueda.a PROG= unet-bind BINDIR= /usr/local/bin diff -r 51893347bc42 -r 1f3283f8e482 ueda/sverp-bind/insthash.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ueda/sverp-bind/insthash.c Sun Aug 02 00:00:15 2015 +0000 @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include "struct.h" + +#define HASH_SIZE 1103 +static struct instance *hashtab[HASH_SIZE]; + +static int +hash_instname(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 instance * +enter_instance(newname) + char *newname; +{ + register struct instance *n, **np; + int namelen; + + for (np = hashtab + hash_instname(newname); n = *np; + np = &n->nextinhash) + if (!strcmp(n->name, newname)) { + fprintf(stderr, "error: duplicate instance name %s\n", + newname); + exit(1); + } + namelen = strlen(newname); + n = (struct instance *) malloc(sizeof(struct instance) + namelen + 1); + if (!n) { + perror("malloc"); + exit(1); + } + bzero(n, sizeof(struct instance)); + n->name = (char *)(n + 1); + strcpy(n->name, newname); + *np = n; + return n; +} + +struct instance * +find_instance(soughtname) + register char *soughtname; +{ + register struct instance *n; + + for (n = hashtab[hash_instname(soughtname)]; n; n = n->nextinhash) + if (!strcmp(n->name, soughtname)) + return(n); + return(0); +}