head     1.3;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @// @;


1.3
date     92.08.20.11.02.32;  author thoth;  state Exp;
branches ;
next     1.2;

1.2
date     92.07.21.11.24.42;  author thoth;  state Exp;
branches ;
next     1.1;

1.1
date     92.07.16.11.56.07;  author thoth;  state Exp;
branches ;
next     ;


desc
@implementation of the IntPointSet hash table.
@


1.3
log
@Reference counting is now the responsibility of IntPointSet
@
text
@// Emacs: -*- C++ -*-

// 
// $Log:	HashTable.cc,v $
// Revision 1.2  92/07/21  11:24:42  thoth
// found screwy problems, probably didn't REALLY solve it, but
// its a workaround for now.
// 
// Revision 1.1  92/07/16  11:56:07  thoth
// Initial revision
// 
// 

// #include <stdlib.h>
#include "HashTable.h"

#pragma implementation

int HashTable::reference(HType in, HType *out)
{
    *out = in;

    link	**scan;

    for (scan = &this->buckets[in->hash_self(TBLSIZE)];
	 *scan && !(*scan)->data->equal(in);
	 scan = &(*scan)->next) {
    }

    if (*scan) {
	// we found an ->equal()
	*out = (*scan)->data;
	return 1;
    } else {
	// there are none ->equal()
	*scan = new link;
	(*scan)->next = 0;
	(*scan)->data = in;
	return 0;
    }
}

void HashTable:: remove(HType in)
{
    link	**target;

    for (target = &this->buckets[in->hash_self(TBLSIZE)];
	 *target && (*target)->data != in;
	 target = &(*target)->next) {
    }

    // no one is referencing this bugger anymore.


    // all this malloc_verify bullsh*t is to hack around some strange core
    // dump inside g++'s __builtin_delete.  I don't know whether the problem
    // is mine, or theirs, but using free seems to work and the heap doesn't
    // seem to be corrupted.

    link	*temp;
    temp = *target;

    if (temp==0) {
	// internal error
	abort();
    }

    *target = temp->next;
    malloc_verify();
    delete temp->data;
    // prevent malloc error?
    temp->data=0;
    malloc_verify();
    {
	int	print;
	print =0;
	if (print)
	    mallocmap();
    }
#if 0
    delete temp;
#else
    free(temp);
#endif
}
@


1.2
log
@found screwy problems, probably didn't REALLY solve it, but
its a workaround for now.
@
text
@d5 4
a32 1
	(*scan)->refcount++;
a38 1
	(*scan)->refcount=1;
d43 1
a43 1
void HashTable:: unreference(HType in)
d52 1
a52 1
    (*target)->refcount--;
a53 2
    if ((*target)->refcount)
	return;
d55 4
a58 1
    // no one is referencing this bugger anymore.
d62 6
@


1.1
log
@Initial revision
@
text
@d4 3
a6 1
// $Log$
d8 1
d60 1
d62 10
d73 3
@
