hash.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/*
* hash.c
*
* Manage hash tables.
*
* The following functions are visible:
*
* char *mystrdup(char *); Make space and copy string
* Entry **newHashTable(); Create and return initialized hash table
* Entry *hash_add(Entry **, char *, Entry *)
* Entry *hash_get(Entry **, char *)
*
* SOFTWARE RIGHTS
*
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
* company may do whatever they wish with source code distributed with
* PCCTS or the code generated by PCCTS, including the incorporation of
* PCCTS, or its output, into commerical software.
*
* We encourage users to develop software with PCCTS. However, we do ask
* that credit is given to us for developing PCCTS. By "credit",
* we mean that if you incorporate our source code into one of your
* programs (commercial product, research project, or otherwise) that you
* acknowledge this fact somewhere in the documentation, research report,
* etc... If you like PCCTS and have developed a nice tool with the
* output, please mention that you developed it using PCCTS. In
* addition, we ask that this header remain intact in our source code.
* As long as these guidelines are kept, we expect to continue enhancing
* this system and expect to make other tools available as they are
* completed.
*
* ANTLR 1.33
* Terence Parr
* Parr Research Corporation
* with Purdue University and AHPCRC, University of Minnesota
* 1989-2001
*/
#include <stdio.h>
#include "pcctscfg.h"
#include "hash.h"
#ifdef __USE_PROTOS
#include <stdlib.h>
#else
#ifdef VAXC
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#endif
#include <string.h>
#define StrSame 0
static unsigned size = HashTableSize;
static char *strp;
static unsigned strsize = StrTableSize;
/* create the hash table and string table for terminals (string table only once) */
Entry **
#ifdef __USE_PROTOS
newHashTable( void )
#else
newHashTable( )
#endif
{
{
}
return table;
}
void
#ifdef __USE_PROTOS
#else
#endif
{
/* for now, just free table, forget entries */
}
/* Given a table, add 'rec' with key 'key' (add to front of list). return ptr to entry */
Entry *
#ifdef __USE_PROTOS
#else
char *key;
#endif
{
unsigned h=0;
char *p=key;
return rec;
}
/* Return ptr to 1st entry found in table under key (return NULL if none found) */
Entry *
#ifdef __USE_PROTOS
#else
char *key;
#endif
{
unsigned h=0;
char *p=key;
Entry *q;
{
}
return( NULL );
}
#ifdef DEBUG_HASH
void
#ifdef __USE_PROTOS
#else
#endif
{
static unsigned short count[20];
Entry **p;
float avg=0.0;
for (i=0; i<20; i++) count[i] = 0;
{
Entry *q = *p;
int len;
len = 0;
while ( q != NULL )
{
len++;
n++;
q = q->next;
}
}
for (i=0; i<20; i++)
{
if ( count[i] != 0 )
{
}
}
}
#endif
/* Add a string to the string table and return a pointer to it.
* Bump the pointer into the string table to next avail position.
*/
char *
#ifdef __USE_PROTOS
mystrdup( char *s )
#else
mystrdup( s )
char *s;
#endif
{
while ( *s != '\0' )
{
*strp++ = *s++;
}
*strp++ = '\0';
return( start );
}