head	1.13;
access;
symbols
	r2_1:1.9
	r2_0:1.9
	r1_1_beta:1.9
	r1_1_alpha:1.9
	r1_0:1.9
	r0_11:1.9
	r0_10:1.9
	r0_9:1.8
	Eglin_alpha_1:1.8;
locks; strict;
comment	@// @;


1.13
date	94.11.30.19.28.47;	author fjsoria;	state Exp;
branches;
next	1.12;

1.12
date	94.11.10.19.53.56;	author ljr;	state Exp;
branches;
next	1.11;

1.11
date	94.11.10.19.51.27;	author fjsoria;	state Exp;
branches;
next	1.10;

1.10
date	94.10.06.17.39.00;	author fjsoria;	state Exp;
branches;
next	1.9;

1.9
date	94.01.31.16.36.55;	author thoth;	state Exp;
branches;
next	1.8;

1.8
date	93.05.28.15.05.25;	author thoth;	state Exp;
branches;
next	1.7;

1.7
date	93.05.27.18.05.06;	author thoth;	state Exp;
branches;
next	1.6;

1.6
date	93.05.26.16.57.42;	author thoth;	state Exp;
branches;
next	1.5;

1.5
date	93.02.12.16.21.21;	author thoth;	state Exp;
branches;
next	1.4;

1.4
date	92.12.16.14.48.03;	author thoth;	state Exp;
branches;
next	1.3;

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

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

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


desc
@CFrontified version
@


1.13
log
@thoth added member function for IA_HashTable to print
out the hash table
@
text
@// Emacs: -*- C++ -*-

//
//	Copyright 1993, Center for Computer Vision and Visualization,
//	University of Florida.  All rights reserved.
//

#ifndef IA_NO_RCS_STATIC_DATA
static char copyright[] = "Copyright 1993, Center for Computer Vision and Visualization,\nUniversity of Florida.  All rights reserved.\n";

static char rcsid[] = "$Id: HashTable.c,v 1.12 1994/11/10 19:53:56 ljr Exp thoth $";
#endif

// 
// $Log: HashTable.c,v $
// Revision 1.12  1994/11/10  19:53:56  ljr
// Added IA_NO_RCS_STATIC_DATA guard.
//
// Revision 1.11  1994/11/10  19:51:27  fjsoria
// blah
//
// Revision 1.10  1994/10/06  17:39:00  fjsoria
// commented rscid[] line
//
// Revision 1.9  1994/01/31  16:36:55  thoth
// We now document internal errors when they occur.
//
// Revision 1.8  1993/05/28  15:05:25  thoth
// removed dependency on with-ia-pointset*
//
// Revision 1.7  93/05/27  18:05:06  thoth
// eliminated dependency on internal testing file.
// 
// Revision 1.6  93/05/26  16:57:42  thoth
// Copyright Notices
// 
// Revision 1.5  93/02/12  16:21:21  thoth
// more comments
// 
// Revision 1.4  92/12/16  14:48:03  thoth
// conversion to IA_ mostly complete
// 
// Revision 1.3  92/09/14  10:09:36  thoth
// the hash table data pointers are now the responsibility of IntPointSet
// 
// Revision 1.2  92/08/26  13:42:45  thoth
// eliminated cruft to work around g++ brokenness
// 
// Revision 1.1  92/08/23  13:30:04  thoth
// Initial revision
// 
// 
#ifdef IA_PRII
#pragma implementation "HashTable.h"
#endif

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

IA_HashTable::IA_HashTable() {
    for (int i=0; i<TBLSIZE; i++)
	this->buckets[i] = 0;
}
IA_HashTable::~IA_HashTable() {
    for (int i=0; i<TBLSIZE; i++) {
	link *scan=this->buckets[i];
	while (scan) {
	    link *temp = scan;
	    scan = scan->next;
	    delete temp;
	}
    }
}

int IA_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 IA_HashTable:: remove(HType in)
{
    link	**target;

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

    link	*temp;
    temp = *target;

    if (temp==0) {
	IA::internal_error(__FILE__, __LINE__);
    }

    *target = temp->next;
    // the data is not our responsibility
    delete temp;
}

void IA_HashTable::print(ostream &o) const
{
    int	start, end;
    start =0;

    while (start<TBLSIZE) {
	for (end=start; end<TBLSIZE && buckets[end]==0; end++)
	    ;
	if (end>start+1) {
	    o << "buckets " << start << " through " << end-1 << " are empty\n";
	} else if (end>start) {
	    o << "bucket " << start << " is empty\n";
	}
	if (end<TBLSIZE) {
	    o << "bucket " << end << " has:\n";
	    link *scan = buckets[end];
	    while (scan) {
		o << "   pointset: " << hex << long(scan->data) << "\n";
		scan->data->output(o,8);
		scan = scan->next;
	    }
	    o<< "    end of bucket "<<end<<"\n";
	}
	start = end+1;
    }
}
@


1.12
log
@Added IA_NO_RCS_STATIC_DATA guard.
@
text
@d11 1
a11 1
static char rcsid[] = "$Id: HashTable.c,v 1.11 1994/11/10 19:51:27 fjsoria Exp ljr $";
d16 3
d118 27
@


1.11
log
@blah
@
text
@d8 2
a9 1
//static char copyright[] = "Copyright 1993, Center for Computer Vision and Visualization,\nUniversity of Florida.  All rights reserved.\n";
d11 2
a12 1
//static char rcsid[] = "$Id: HashTable.c,v 1.10 1994/10/06 17:39:00 fjsoria Exp fjsoria $";
d16 3
@


1.10
log
@commented rscid[] line
@
text
@d10 1
a10 1
//static char rcsid[] = "$Id: HashTable.c,v 1.9 1994/01/31 16:36:55 thoth Exp fjsoria $";
d14 3
d45 3
a50 4

#ifdef IA_PRII
#pragma implementation
#endif
@


1.9
log
@We now document internal errors when they occur.
@
text
@d8 1
a8 1
static char copyright[] = "Copyright 1993, Center for Computer Vision and Visualization,\nUniversity of Florida.  All rights reserved.\n";
d10 1
a10 1
static char rcsid[] = "$Id: HashTable.c,v 1.8 1993/05/28 15:05:25 thoth Exp thoth $";
d14 3
@


1.8
log
@removed dependency on with-ia-pointset*
@
text
@d10 1
a10 1
static char rcsid[] = "$Id: HashTable.c,v 1.7 93/05/27 18:05:06 thoth Exp Locker: thoth $";
d13 4
a16 1
// $Log:	HashTable.c,v $
d99 1
a99 1
	abort(); // internal error
@


1.7
log
@eliminated dependency on internal testing file.
@
text
@d10 1
a10 1
static char rcsid[] = "$Id: HashTable.c,v 1.6 93/05/26 16:57:42 thoth Exp Locker: thoth $";
d14 3
d44 1
a44 3
#include "with-ia-pointset-P.h"

HashTable::IA_HashTable() {
d48 1
a48 1
HashTable::~IA_HashTable() {
d59 1
a59 1
int HashTable::reference(HType in, HType *out)
d83 1
a83 1
void HashTable:: remove(HType in)
@


1.6
log
@Copyright Notices
@
text
@d10 1
a10 1
static char rcsid[] = "$Id: HashTable.c,v 1.5 93/02/12 16:21:21 thoth Exp Locker: thoth $";
d14 3
d34 1
a34 1
#include "dev-frags.h"
@


1.5
log
@more comments
@
text
@a1 1
static char rcsid[] = "$Id: HashTable.c,v 1.4 92/12/16 14:48:03 thoth Exp Locker: thoth $";
d3 9
d14 3
@


1.4
log
@conversion to IA_ mostly complete
@
text
@d2 1
a2 1
static char rcsid[] = "$Id: HashTable.c,v 1.3 92/09/14 10:09:36 thoth Exp Locker: thoth $";
d6 3
d85 1
a85 1
    // delete temp->data; // no longer our responsibility
@


1.3
log
@the hash table data pointers are now the responsibility of IntPointSet
@
text
@d2 1
a2 1
static char rcsid[] = "$Id$";
d5 4
a8 1
// $Log:	HashTable.C,v $
d24 3
a26 1
HashTable::HashTable() {
d30 1
a30 1
HashTable::~HashTable() {
@


1.2
log
@eliminated cruft to work around g++ brokenness
@
text
@d2 1
d6 3
a28 1
	    delete scan->data;
a68 8
    // 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.

d77 1
a77 1
    delete temp->data;
@


1.1
log
@Initial revision
@
text
@d4 3
a6 1
// $Log:	HashTable.cc,v $
d8 1
d78 1
a78 2
	// internal error
	abort();
a81 1
    malloc_verify();
a82 10
    // prevent malloc error?
    temp->data=0;
    malloc_verify();
    {
	int	print;
	print =0;
	if (print)
	    mallocmap();
    }
#if 1
a83 3
#else
    free(temp);
#endif
@
