Browse Source

More dependent base resolution issues

* src/base/hash/cl_hash.h (cl_heap_hashtable<T>::iterator()):
	portable syntactic simplification.
	* src/base/hash/cl_hashset.h: Preceed inherited members with this->.
	* src/base/hash/cl_hash1.h: Likewise for member functions.
	* src/base/hash/cl_hash2.h: Likewise.
	* src/base/hash/cl_hashuniq.h: Likewise.
	* src/base/hash/cl_hashuniqweak.h: Likewise.
	* src/base/hash/cl_hash.h: Revert explicit static member function
	lookup since that was GCC's fault.
	* src/base/hash/cl_hash2weak.h: Likewise.
	* src/base/hash/cl_hashuniqweak.h: Likewise.
master
Richard Kreckel 22 years ago
parent
commit
9220842a15
  1. 15
      ChangeLog
  2. 9
      src/base/hash/cl_hash.h
  3. 11
      src/base/hash/cl_hash1.h
  4. 11
      src/base/hash/cl_hash2.h
  5. 4
      src/base/hash/cl_hash2weak.h
  6. 79
      src/base/hash/cl_hashset.h
  7. 11
      src/base/hash/cl_hashuniq.h
  8. 6
      src/base/hash/cl_hashuniqweak.h

15
ChangeLog

@ -1,3 +1,18 @@
2003-08-01 Richard Kreckel <kreckel@ginac.de>
More dependent base resolution issues
* src/base/hash/cl_hash.h (cl_heap_hashtable<T>::iterator()):
portable syntactic simplification.
* src/base/hash/cl_hashset.h: Preceed inherited members with this->.
* src/base/hash/cl_hash1.h: Likewise for member functions.
* src/base/hash/cl_hash2.h: Likewise.
* src/base/hash/cl_hashuniq.h: Likewise.
* src/base/hash/cl_hashuniqweak.h: Likewise.
* src/base/hash/cl_hash.h: Revert explicit static member function
lookup since that was GCC's fault.
* src/base/hash/cl_hash2weak.h: Likewise.
* src/base/hash/cl_hashuniqweak.h: Likewise.
2003-06-29 Richard Kreckel <kreckel@ginac.de> 2003-06-29 Richard Kreckel <kreckel@ginac.de>
Dependent base resolution needed for GCC-3.4 Dependent base resolution needed for GCC-3.4

9
src/base/hash/cl_hash.h

@ -43,7 +43,7 @@ public:
void operator delete (void* ptr) { free_hook(ptr); } void operator delete (void* ptr) { free_hook(ptr); }
// Constructor: build a new, empty table. // Constructor: build a new, empty table.
cl_heap_hashtable (long initial_size = 5) : cl_heap (), cl_heap_hashtable (long initial_size = 5) : cl_heap (),
_size (initial_size), _count (0), _garcol_fun (cl_heap_hashtable<htentry>::no_garcol)
_size (initial_size), _count (0), _garcol_fun (no_garcol)
{ {
_modulus = compute_modulus(_size); _modulus = compute_modulus(_size);
_total_vector = malloc_hook(_modulus*sizeof(long) + _size*sizeof(htxentry)); _total_vector = malloc_hook(_modulus*sizeof(long) + _size*sizeof(htxentry));
@ -181,12 +181,7 @@ public:
template <class htentry> template <class htentry>
inline _cl_hashtable_iterator<htentry> cl_heap_hashtable<htentry>::iterator () inline _cl_hashtable_iterator<htentry> cl_heap_hashtable<htentry>::iterator ()
{ {
#if defined(__GNUC__)
return _cl_hashtable_iterator<htentry>::_cl_hashtable_iterator(_entries,_size);
#else // workaround most C++ compilers' bug
typedef _cl_hashtable_iterator<htentry> _cl_hashtable_iterator_type;
return _cl_hashtable_iterator_type(_entries,_size);
#endif
return _cl_hashtable_iterator<htentry>(_entries,_size);
} }
} // namespace cln } // namespace cln

11
src/base/hash/cl_hash1.h

@ -32,8 +32,9 @@ struct cl_htentry1 {
template <class key1_type, class value_type> template <class key1_type, class value_type>
struct cl_heap_hashtable_1 : public cl_heap_hashtable <cl_htentry1 <key1_type,value_type> > { struct cl_heap_hashtable_1 : public cl_heap_hashtable <cl_htentry1 <key1_type,value_type> > {
protected: protected:
// Abbreviation.
typedef typename cl_heap_hashtable <cl_htentry1 <key1_type,value_type> >::htxentry htxentry;
// Abbreviations.
typedef cl_heap_hashtable <cl_htentry1 <key1_type,value_type> > inherited;
typedef typename inherited::htxentry htxentry;
public: public:
// Allocation. // Allocation.
void* operator new (size_t size) { return malloc_hook(size); } void* operator new (size_t size) { return malloc_hook(size); }
@ -75,7 +76,7 @@ public:
// Put it into the table. // Put it into the table.
prepare_store(); prepare_store();
var long hindex = hcode % this->_modulus; // _modulus may have changed! var long hindex = hcode % this->_modulus; // _modulus may have changed!
var long index = get_free_index();
var long index = this->get_free_index();
new (&this->_entries[index].entry) cl_htentry1<key1_type,value_type> (key,val); new (&this->_entries[index].entry) cl_htentry1<key1_type,value_type> (key,val);
this->_entries[index].next = this->_slots[hindex]; this->_entries[index].next = this->_slots[hindex];
this->_slots[hindex] = 1+index; this->_slots[hindex] = 1+index;
@ -94,7 +95,7 @@ public:
*_index = this->_entries[index].next; *_index = this->_entries[index].next;
this->_entries[index].~htxentry(); this->_entries[index].~htxentry();
// The entry is now free. // The entry is now free.
put_free_index(index);
this->put_free_index(index);
// That's it. // That's it.
this->_count--; this->_count--;
return; return;
@ -132,7 +133,7 @@ private:
void grow () void grow ()
{ {
var long new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5 var long new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5
var long new_modulus = compute_modulus(new_size);
var long new_modulus = inherited::compute_modulus(new_size);
var void* new_total_vector = malloc_hook(new_modulus*sizeof(long) + new_size*sizeof(htxentry)); var void* new_total_vector = malloc_hook(new_modulus*sizeof(long) + new_size*sizeof(htxentry));
var long* new_slots = (long*) ((char*)new_total_vector + 0); var long* new_slots = (long*) ((char*)new_total_vector + 0);
var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long)); var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long));

11
src/base/hash/cl_hash2.h

@ -30,8 +30,9 @@ struct cl_htentry2 {
template <class key1_type, class key2_type, class value_type> template <class key1_type, class key2_type, class value_type>
struct cl_heap_hashtable_2 : public cl_heap_hashtable <cl_htentry2 <key1_type,key2_type,value_type> > { struct cl_heap_hashtable_2 : public cl_heap_hashtable <cl_htentry2 <key1_type,key2_type,value_type> > {
protected: protected:
// Abbreviation.
typedef typename cl_heap_hashtable <cl_htentry2 <key1_type,key2_type,value_type> >::htxentry htxentry;
// Abbreviations.
typedef cl_heap_hashtable <cl_htentry2 <key1_type,key2_type,value_type> > inherited;
typedef typename inherited::htxentry htxentry;
public: public:
// Allocation. // Allocation.
void* operator new (size_t size) { return malloc_hook(size); } void* operator new (size_t size) { return malloc_hook(size); }
@ -75,7 +76,7 @@ public:
// Put it into the table. // Put it into the table.
prepare_store(); prepare_store();
var long hindex = hcode % this->_modulus; // _modulus may have changed! var long hindex = hcode % this->_modulus; // _modulus may have changed!
var long index = get_free_index();
var long index = this->get_free_index();
new (&this->_entries[index].entry) cl_htentry2<key1_type,key2_type,value_type> (key1,key2,val); new (&this->_entries[index].entry) cl_htentry2<key1_type,key2_type,value_type> (key1,key2,val);
this->_entries[index].next = this->_slots[hindex]; this->_entries[index].next = this->_slots[hindex];
this->_slots[hindex] = 1+index; this->_slots[hindex] = 1+index;
@ -95,7 +96,7 @@ public:
*_index = this->_entries[index].next; *_index = this->_entries[index].next;
this->_entries[index].~htxentry(); this->_entries[index].~htxentry();
// The entry is now free. // The entry is now free.
put_free_index(index);
this->put_free_index(index);
// That's it. // That's it.
this->_count--; this->_count--;
return; return;
@ -133,7 +134,7 @@ private:
void grow () void grow ()
{ {
var long new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5 var long new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5
var long new_modulus = compute_modulus(new_size);
var long new_modulus = inherited::compute_modulus(new_size);
var void* new_total_vector = malloc_hook(new_modulus*sizeof(long) + new_size*sizeof(htxentry)); var void* new_total_vector = malloc_hook(new_modulus*sizeof(long) + new_size*sizeof(htxentry));
var long* new_slots = (long*) ((char*)new_total_vector + 0); var long* new_slots = (long*) ((char*)new_total_vector + 0);
var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long)); var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long));

4
src/base/hash/cl_hash2weak.h

@ -33,7 +33,7 @@ public:
: cl_heap_hashtable_2 <key1_type,key2_type,value_type> (), : cl_heap_hashtable_2 <key1_type,key2_type,value_type> (),
_maygc_htentry (maygc_htentry) _maygc_htentry (maygc_htentry)
{ {
this->_garcol_fun = cl_heap_weak_hashtable_2<key1_type,key2_type,value_type>::garcol;
this->_garcol_fun = garcol;
} }
private: private:
// Garbage collection. // Garbage collection.
@ -75,7 +75,7 @@ private:
else if (2*removed < ht->_count) { else if (2*removed < ht->_count) {
// Table shrank by less than a factor of 1/1.5. // Table shrank by less than a factor of 1/1.5.
// Don't expand the table now, but expand it next time. // Don't expand the table now, but expand it next time.
ht->_garcol_fun = cl_heap_weak_hashtable_2<key1_type,key2_type,value_type>::garcol_nexttime;
ht->_garcol_fun = garcol_nexttime;
return cl_true; return cl_true;
} else { } else {
// Table shrank much. Don't expand the table now, // Table shrank much. Don't expand the table now,

79
src/base/hash/cl_hashset.h

@ -23,8 +23,9 @@ struct cl_htsetentry {
template <class key1_type> template <class key1_type>
struct cl_heap_hashtable_set : public cl_heap_hashtable <cl_htsetentry <key1_type> > { struct cl_heap_hashtable_set : public cl_heap_hashtable <cl_htsetentry <key1_type> > {
protected: protected:
// Abbreviation.
typedef typename cl_heap_hashtable <cl_htsetentry <key1_type> >::htxentry htxentry;
// Abbreviations.
typedef cl_heap_hashtable <cl_htsetentry <key1_type> > inherited;
typedef typename inherited::htxentry htxentry;
public: public:
// Allocation. // Allocation.
void* operator new (size_t size) { return malloc_hook(size); } void* operator new (size_t size) { return malloc_hook(size); }
@ -34,13 +35,13 @@ public:
// Lookup (htref alias gethash). // Lookup (htref alias gethash).
bool get (const key1_type& key) bool get (const key1_type& key)
{ {
var long index = _slots[hashcode(key) % _modulus] - 1;
var long index = this->_slots[hashcode(key) % this->_modulus] - 1;
while (index >= 0) { while (index >= 0) {
if (!(index < _size))
if (!(index < this->_size))
cl_abort(); cl_abort();
if (equal(key,_entries[index].entry.key))
if (equal(key,this->_entries[index].entry.key))
return true; return true;
index = _entries[index].next - 1;
index = this->_entries[index].next - 1;
} }
return false; return false;
} }
@ -50,43 +51,43 @@ public:
var unsigned long hcode = hashcode(key); var unsigned long hcode = hashcode(key);
// Search whether it is already there. // Search whether it is already there.
{ {
var long index = _slots[hcode % _modulus] - 1;
var long index = this->_slots[hcode % this->_modulus] - 1;
while (index >= 0) { while (index >= 0) {
if (!(index < _size))
if (!(index < this->_size))
cl_abort(); cl_abort();
if (equal(key,_entries[index].entry.key))
if (equal(key,this->_entries[index].entry.key))
return; return;
index = _entries[index].next - 1;
index = this->_entries[index].next - 1;
} }
} }
// Put it into the table. // Put it into the table.
prepare_store(); prepare_store();
var long hindex = hcode % _modulus; // _modulus may have changed!
var long index = get_free_index();
new (&_entries[index].entry) cl_htsetentry<key1_type> (key);
_entries[index].next = _slots[hindex];
_slots[hindex] = 1+index;
_count++;
var long hindex = hcode % this->_modulus; // _modulus may have changed!
var long index = this->get_free_index();
new (&this->_entries[index].entry) cl_htsetentry<key1_type> (key);
this->_entries[index].next = this->_slots[hindex];
this->_slots[hindex] = 1+index;
this->_count++;
} }
// Remove (htrem alias remhash). // Remove (htrem alias remhash).
void remove (const key1_type& key) void remove (const key1_type& key)
{ {
var long* _index = &_slots[hashcode(key) % _modulus];
var long* _index = &this->_slots[hashcode(key) % this->_modulus];
while (*_index > 0) { while (*_index > 0) {
var long index = *_index - 1; var long index = *_index - 1;
if (!(index < _size))
if (!(index < this->_size))
cl_abort(); cl_abort();
if (equal(key,_entries[index].entry.key)) {
if (equal(key,this->_entries[index].entry.key)) {
// Remove _entries[index].entry // Remove _entries[index].entry
*_index = _entries[index].next;
_entries[index].~htxentry();
*_index = this->_entries[index].next;
this->_entries[index].~htxentry();
// The entry is now free. // The entry is now free.
put_free_index(index);
this->put_free_index(index);
// That's it. // That's it.
_count--;
this->_count--;
return; return;
} }
_index = &_entries[index].next;
_index = &this->_entries[index].next;
} }
} }
// Iterate through the table. // Iterate through the table.
@ -100,26 +101,26 @@ private:
void prepare_store () void prepare_store ()
{ {
#if !(defined(__sparc__) && !defined(__GNUC__)) #if !(defined(__sparc__) && !defined(__GNUC__))
if (_freelist < -1)
if (this->_freelist < -1)
return; return;
// Can we make room? // Can we make room?
if (_garcol_fun(this)) if (_garcol_fun(this))
if (_freelist < -1)
if (this->_freelist < -1)
return; return;
// No! Have to grow the hash table. // No! Have to grow the hash table.
grow(); grow();
#else #else
// workaround Sun C++ 4.1 inline function compiler bug // workaround Sun C++ 4.1 inline function compiler bug
if (_freelist >= -1) {
if (!_garcol_fun(this) || (_freelist >= -1))
if (this->_freelist >= -1) {
if (!_garcol_fun(this) || (this->_freelist >= -1))
grow(); grow();
} }
#endif #endif
} }
void grow () void grow ()
{ {
var long new_size = _size + (_size >> 1) + 1; // _size*1.5
var long new_modulus = compute_modulus(new_size);
var long new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5
var long new_modulus = inherited::compute_modulus(new_size);
var void* new_total_vector = malloc_hook(new_modulus*sizeof(long) + new_size*sizeof(htxentry)); var void* new_total_vector = malloc_hook(new_modulus*sizeof(long) + new_size*sizeof(htxentry));
var long* new_slots = (long*) ((char*)new_total_vector + 0); var long* new_slots = (long*) ((char*)new_total_vector + 0);
var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long)); var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long));
@ -130,8 +131,8 @@ private:
new_entries[i].next = free_list_head; new_entries[i].next = free_list_head;
free_list_head = -2-i; free_list_head = -2-i;
} }
var htxentry* old_entries = _entries;
for (var long old_index = 0; old_index < _size; old_index++)
var htxentry* old_entries = this->_entries;
for (var long old_index = 0; old_index < this->_size; old_index++)
if (old_entries[old_index].next >= 0) { if (old_entries[old_index].next >= 0) {
var key1_type& key = old_entries[old_index].entry.key; var key1_type& key = old_entries[old_index].entry.key;
var long hindex = hashcode(key) % new_modulus; var long hindex = hashcode(key) % new_modulus;
@ -142,13 +143,13 @@ private:
new_slots[hindex] = 1+index; new_slots[hindex] = 1+index;
old_entries[old_index].~htxentry(); old_entries[old_index].~htxentry();
} }
free_hook(_total_vector);
_modulus = new_modulus;
_size = new_size;
_freelist = free_list_head;
_slots = new_slots;
_entries = new_entries;
_total_vector = new_total_vector;
free_hook(this->_total_vector);
this->_modulus = new_modulus;
this->_size = new_size;
this->_freelist = free_list_head;
this->_slots = new_slots;
this->_entries = new_entries;
this->_total_vector = new_total_vector;
} }
}; };

11
src/base/hash/cl_hashuniq.h

@ -32,8 +32,9 @@ struct cl_htuniqentry {
template <class key1_type, class value_type> template <class key1_type, class value_type>
struct cl_heap_hashtable_uniq : public cl_heap_hashtable <cl_htuniqentry <key1_type,value_type> > { struct cl_heap_hashtable_uniq : public cl_heap_hashtable <cl_htuniqentry <key1_type,value_type> > {
protected: protected:
// Abbreviation.
typedef typename cl_heap_hashtable <cl_htuniqentry <key1_type,value_type> >::htxentry htxentry;
// Abbreviations.
typedef cl_heap_hashtable <cl_htuniqentry <key1_type,value_type> > inherited;
typedef typename inherited::htxentry htxentry;
public: public:
// Allocation. // Allocation.
void* operator new (size_t size) { return malloc_hook(size); } void* operator new (size_t size) { return malloc_hook(size); }
@ -73,7 +74,7 @@ public:
// Put it into the table. // Put it into the table.
prepare_store(); prepare_store();
var long hindex = hcode % this->_modulus; // _modulus may have changed! var long hindex = hcode % this->_modulus; // _modulus may have changed!
var long index = get_free_index();
var long index = this->get_free_index();
new (&this->_entries[index].entry) cl_htuniqentry<key1_type,value_type> (value_type((struct hashuniq *)0, key)); new (&this->_entries[index].entry) cl_htuniqentry<key1_type,value_type> (value_type((struct hashuniq *)0, key));
this->_entries[index].next = this->_slots[hindex]; this->_entries[index].next = this->_slots[hindex];
this->_slots[hindex] = 1+index; this->_slots[hindex] = 1+index;
@ -92,7 +93,7 @@ public:
*_index = this->_entries[index].next; *_index = this->_entries[index].next;
this->_entries[index].~htxentry(); this->_entries[index].~htxentry();
// The entry is now free. // The entry is now free.
put_free_index(index);
this->put_free_index(index);
// That's it. // That's it.
this->_count--; this->_count--;
return; return;
@ -130,7 +131,7 @@ private:
void grow () void grow ()
{ {
var long new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5 var long new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5
var long new_modulus = compute_modulus(new_size);
var long new_modulus = inherited::compute_modulus(new_size);
var void* new_total_vector = malloc_hook(new_modulus*sizeof(long) + new_size*sizeof(htxentry)); var void* new_total_vector = malloc_hook(new_modulus*sizeof(long) + new_size*sizeof(htxentry));
var long* new_slots = (long*) ((char*)new_total_vector + 0); var long* new_slots = (long*) ((char*)new_total_vector + 0);
var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long)); var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long));

6
src/base/hash/cl_hashuniqweak.h

@ -32,7 +32,7 @@ public:
cl_heap_weak_hashtable_uniq () cl_heap_weak_hashtable_uniq ()
: cl_heap_hashtable_uniq <key1_type,value_type> () : cl_heap_hashtable_uniq <key1_type,value_type> ()
{ {
this->_garcol_fun = cl_heap_weak_hashtable_uniq<key1_type,value_type>::garcol;
this->_garcol_fun = garcol;
} }
private: private:
// Garbage collection. // Garbage collection.
@ -75,7 +75,7 @@ private:
else if (2*removed < ht->_count) { else if (2*removed < ht->_count) {
// Table shrank by less than a factor of 1/1.5. // Table shrank by less than a factor of 1/1.5.
// Don't expand the table now, but expand it next time. // Don't expand the table now, but expand it next time.
ht->_garcol_fun = cl_heap_weak_hashtable_uniq<key1_type,value_type>::garcol_nexttime;
ht->_garcol_fun = garcol_nexttime;
return cl_true; return cl_true;
} else { } else {
// Table shrank much. Don't expand the table now, // Table shrank much. Don't expand the table now,
@ -87,7 +87,7 @@ private:
{ {
var cl_heap_weak_hashtable_uniq* ht = (cl_heap_weak_hashtable_uniq*)_ht; var cl_heap_weak_hashtable_uniq* ht = (cl_heap_weak_hashtable_uniq*)_ht;
// Now ht->_garcol_fun = garcol_nexttime. // Now ht->_garcol_fun = garcol_nexttime.
ht->_garcol_fun = cl_heap_weak_hashtable_uniq<key1_type,value_type>::garcol;
ht->_garcol_fun = garcol;
return cl_false; return cl_false;
} }
}; };

Loading…
Cancel
Save