examples/Makefile.am, examples/Makefile.def, examples/adder/Makefile.am, examples/calculator/Makefile.am, examples/cmilner/Makefile.am, examples/fdd/Makefile.am, examples/internal/Makefile.am, examples/milner/Makefile.am, examples/money/Makefile.am, examples/queen/Makefile.am, examples/solitar/Makefile.am, m4/debug.m4, m4/gccwarns.m4, ChangeLog, INSTALL: New files. * config, makefile, src/makefile, doc/makefile, examples/adder/makefile, examples/calculator/makefile examples/cmilner/makefile, examples/fdd/makefile, examples/internal/makefile, examples/milner/makefile, examples/money/makefile, examples/queen/makefile, examples/solitare/makefile : Delete. * examples/adder/adder.cxx, examples/fdd/statespace.cxx, examples/internal/bddtest.cxx, examples/milner/milner.cxx, examples/money/money.cxx, examples/queen/queen.cxx, examples/solitare/solitare.cxx: Include iostream. * examples/calculator/parser.y: Rename as ... * examples/calculator/parser.yxx: ... this. Remove spurious comas in %token, %right, and %left arguments. * examples/calculator/parser.h: Rename as ... * examples/calculator/parser_.h: ... this, because the bison rule with output parser.h (not tokens.h) from parser.y. * examples/calculator/lexer.l: Rename as ... * examples/calculator/lexer.lxx: ... this. Include parser.h instead of tokens.h. * examples/calculator/slist.h (voidSList::voisSListElem, SList::ite): Fix friend usage. * src/kernel.h (DEFAULT_CLOCK): Default to 60 if not already defined. * README: Update build instruction, and file listing.
174 lines
3 KiB
C++
174 lines
3 KiB
C++
/*************************************************************************
|
|
$Header: /Volumes/CVS/repository/spot/spot/buddy/examples/calculator/Attic/hashtbl.cxx,v 1.2 2003/05/05 13:44:53 aduret Exp $
|
|
FILE: hashtbl.cc
|
|
DESCR: Compiler hash table
|
|
AUTH: Jorn Lind
|
|
DATE: (C) september 1998
|
|
*************************************************************************/
|
|
#include "hashtbl.h"
|
|
|
|
/*************************************************************************
|
|
*************************************************************************/
|
|
|
|
/*======================================================================*/
|
|
|
|
hashTable::hashTable(void)
|
|
{
|
|
table = NULL;
|
|
clear();
|
|
}
|
|
|
|
|
|
hashTable::~hashTable(void)
|
|
{
|
|
delete[] table;
|
|
}
|
|
|
|
|
|
void hashTable::add(hashData &d)
|
|
{
|
|
if (freepos == -1)
|
|
reallocate_table();
|
|
|
|
unsigned int h = hashval(d.id);
|
|
int tmppos = table[freepos].next;
|
|
|
|
table[freepos].data = d;
|
|
table[freepos].next = table[h].first;
|
|
table[h].first = freepos;
|
|
freepos = tmppos;
|
|
}
|
|
|
|
|
|
int hashTable::exists(const char *id)
|
|
{
|
|
if (size == 0)
|
|
return 0;
|
|
|
|
int p = table[hashval(id)].first;
|
|
|
|
while (p != -1)
|
|
{
|
|
if (strcmp(id, table[p].data.id) == 0)
|
|
return 1;
|
|
p = table[p].next;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int hashTable::lookup(const char *id, hashData &d) const
|
|
{
|
|
if (size == 0)
|
|
return -1;
|
|
|
|
int p = table[hashval(id)].first;
|
|
|
|
while (p != -1)
|
|
{
|
|
if (strcmp(id, table[p].data.id) == 0)
|
|
{
|
|
d = table[p].data;
|
|
return 0;
|
|
}
|
|
p = table[p].next;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
|
|
int hashTable::remove(const char *id)
|
|
{
|
|
if (size == 0)
|
|
return -1;
|
|
|
|
int h = hashval(id);
|
|
int next = table[h].first;
|
|
int prev = -1;
|
|
|
|
while (next != -1)
|
|
{
|
|
if (strcmp(id, table[next].data.id) == 0)
|
|
{
|
|
if (prev == -1)
|
|
table[h].first = table[next].next;
|
|
else
|
|
table[prev].next = table[next].next;
|
|
|
|
table[next].next = freepos;
|
|
freepos = next;
|
|
|
|
return 0;
|
|
}
|
|
|
|
prev = next;
|
|
next = table[next].next;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
|
|
void hashTable::clear(void)
|
|
{
|
|
delete[] table;
|
|
freepos = -1;
|
|
size = 0;
|
|
}
|
|
|
|
|
|
void hashTable::reallocate_table(void)
|
|
{
|
|
hashElement *newtable;
|
|
int oldsize = size;
|
|
int n;
|
|
|
|
if (size > 0)
|
|
{
|
|
size *= 2;
|
|
newtable = new hashElement[size];
|
|
for (int n=0 ; n<oldsize ; n++)
|
|
newtable[n] = table[n];
|
|
delete[] table;
|
|
table = newtable;
|
|
}
|
|
else
|
|
{
|
|
size = 10;
|
|
table = new hashElement[size];
|
|
}
|
|
|
|
for (n=0 ; n<oldsize ; n++)
|
|
table[n].first = -1;
|
|
|
|
for (n=oldsize ; n<size ; n++)
|
|
{
|
|
table[n].first = -1;
|
|
table[n].next = n+1;
|
|
}
|
|
table[size-1].next = -1;
|
|
freepos = oldsize;
|
|
|
|
for (n=0 ; n<oldsize ; n++)
|
|
{
|
|
unsigned int h = hashval(table[n].data.id);
|
|
table[n].next = table[h].first;
|
|
table[h].first = n;
|
|
}
|
|
}
|
|
|
|
|
|
unsigned int hashTable::hashval(const char *s) const
|
|
{
|
|
unsigned int h = 0;
|
|
|
|
for (const char *p=s ; *p!=0 ; p++)
|
|
h = (h + *p) % size;
|
|
|
|
return h;
|
|
}
|
|
|
|
|
|
/* EOF */
|