}
// Hash code.
-extern unsigned long hashcode (const cl_string& str);
+extern uintptr_t hashcode (const cl_string& str);
// Output.
extern void fprint (std::ostream& stream, const cl_string& str);
}
// Hash code.
-extern unsigned long hashcode (const cl_symbol& s);
+extern uintptr_t hashcode (const cl_symbol& s);
} // namespace cln
namespace cln {
-const long htentry_last = 0; // means that there is no next entry
+const intptr_t htentry_last = 0; // means that there is no next entry
// These forward declarations are needed for Sun CC 3.0.1 and 4.0.1.
template <class htentry> struct _cl_hashtable_iterator;
friend struct _cl_hashtable_iterator<htentry>;
protected:
typedef struct htxentry {
- long next; // > 0: pseudo-list continues at next-1
+ intptr_t next; // > 0: pseudo-list continues at next-1
// == 0: end of pseudo-list
// == -1: end of pseudo-free-list
// < -1: part of pseudo-free-list, continues at -next-2
htentry entry; // if next >= 0
} htxentry;
- long _modulus; // size of the primary entry table, > 0
- long _size; // maximum number of entries
- long _count; // current number of entries
- long _freelist; // start of pseudo-free-list
- long * _slots; // vector of length _modulus
+ intptr_t _modulus; // size of the primary entry table, > 0
+ intptr_t _size; // maximum number of entries
+ intptr_t _count; // current number of entries
+ intptr_t _freelist; // start of pseudo-free-list
+ intptr_t * _slots; // vector of length _modulus
htxentry * _entries; // vector of length _size
void* _total_vector;
bool (*_garcol_fun) (cl_heap*); // Function to make room in the table.
// Deallocation.
void operator delete (void* ptr) { free_hook(ptr); }
// Constructor: build a new, empty table.
- cl_heap_hashtable (long initial_size = 5) : cl_heap (),
+ cl_heap_hashtable (intptr_t initial_size = 5) : cl_heap (),
_size (initial_size), _count (0), _garcol_fun (no_garcol)
{
_modulus = compute_modulus(_size);
- _total_vector = malloc_hook(_modulus*sizeof(long) + _size*sizeof(htxentry));
- _slots = (long*) ((char*)_total_vector + 0);
- _entries = (htxentry *) ((char*)_total_vector + _modulus*sizeof(long));
- for (var long hi = _modulus-1; hi >= 0; hi--)
+ _total_vector = malloc_hook(_modulus*sizeof(intptr_t) + _size*sizeof(htxentry));
+ _slots = (intptr_t*) ((char*)_total_vector + 0);
+ _entries = (htxentry *) ((char*)_total_vector + _modulus*sizeof(intptr_t));
+ for (var intptr_t hi = _modulus-1; hi >= 0; hi--)
_slots[hi] = 0;
- var long free_list_head = -1;
- for (var long i = _size-1; i >= 0; i--) {
+ var intptr_t free_list_head = -1;
+ for (var intptr_t i = _size-1; i >= 0; i--) {
_entries[i].next = free_list_head;
free_list_head = -2-i;
}
// Destructor.
~cl_heap_hashtable ()
{
- for (long i = 0; i < _size; i++)
+ for (intptr_t i = 0; i < _size; i++)
if (_entries[i].next >= 0)
_entries[i].~htxentry();
free_hook(_total_vector);
}
// Count number of entries.
- long num_entries ()
+ intptr_t num_entries ()
{
#if 0
- var long n = 0;
- for (long i = 0; i < _size; i++)
+ var intptr_t n = 0;
+ for (intptr_t i = 0; i < _size; i++)
if (_entries[i].next >= 0)
n++;
return n;
_cl_hashtable_iterator<htentry> iterator ();
protected:
// Compute the modulus, given the maximum number of entries.
- static long compute_modulus (long size)
+ static intptr_t compute_modulus (intptr_t size)
{
// It should be somewhat greater than size, since we want to
// avoid collisions.
// by 2 or 3, and if the modulus were divisible by this number,
// only every second or every third primary slot would be filled,
// resulting in many collisions.
- var long m = 1*size;
+ var intptr_t m = 1*size;
// Make sure m is not divisible by 2.
if ((m % 2) == 0)
m++;
return m;
}
// Return the index of a free entry. Assumes the free list is non-empty.
- long get_free_index ()
+ intptr_t get_free_index ()
{
// Check whether there is some in the free list.
if (_freelist < -1) {
- var long index = -2-_freelist;
+ var intptr_t index = -2-_freelist;
_freelist = _entries[index].next;
return index;
}
return -1; // dummy
}
// Put a free index into the free list.
- void put_free_index (long index)
+ void put_free_index (intptr_t index)
{
_entries[index].next = _freelist;
_freelist = -2-index;
{
private:
typename cl_heap_hashtable<htentry>::htxentry * _entries;
- long _index;
+ intptr_t _index;
public:
_cl_hashtable_iterator () : _entries (0), _index (-1) {}
public: /* ugh */
- _cl_hashtable_iterator (typename cl_heap_hashtable<htentry>::htxentry * e, long i)
+ _cl_hashtable_iterator (typename cl_heap_hashtable<htentry>::htxentry * e, intptr_t i)
: _entries (e), _index (i)
{
do { _index--; }
{
if (_index < 0)
throw runtime_exception();
- var long old_index = _index;
+ var intptr_t old_index = _index;
do { _index--; }
while (_index >= 0 && _entries[_index].next < 0);
return _entries[old_index].entry;
// Requirements:
// - function bool equal (key1_type,key1_type);
-// - function unsigned long hashcode (key1_type);
+// - function uintptr_t hashcode (key1_type);
template <class key1_type, class value_type>
struct cl_htentry1 {
// if it is not NULL.
value_type* get (const key1_type& key)
{
- var long index = this->_slots[hashcode(key) % this->_modulus] - 1;
+ var intptr_t index = this->_slots[hashcode(key) % this->_modulus] - 1;
while (index >= 0) {
if (!(index < this->_size))
throw runtime_exception();
// Store (htset alias puthash).
void put (const key1_type& key, const value_type& val)
{
- var unsigned long hcode = hashcode(key);
+ var uintptr_t hcode = hashcode(key);
// Search whether it is already there.
{
- var long index = this->_slots[hcode % this->_modulus] - 1;
+ var intptr_t index = this->_slots[hcode % this->_modulus] - 1;
while (index >= 0) {
if (!(index < this->_size))
throw runtime_exception();
}
// Put it into the table.
prepare_store();
- var long hindex = hcode % this->_modulus; // _modulus may have changed!
- var long index = this->get_free_index();
+ var intptr_t hindex = hcode % this->_modulus; // _modulus may have changed!
+ var intptr_t index = this->get_free_index();
new (&this->_entries[index].entry) cl_htentry1<key1_type,value_type> (key,val);
this->_entries[index].next = this->_slots[hindex];
this->_slots[hindex] = 1+index;
// Remove (htrem alias remhash).
void remove (const key1_type& key)
{
- var long* _index = &this->_slots[hashcode(key) % this->_modulus];
+ var intptr_t* _index = &this->_slots[hashcode(key) % this->_modulus];
while (*_index > 0) {
- var long index = *_index - 1;
+ var intptr_t index = *_index - 1;
if (!(index < this->_size))
throw runtime_exception();
if (equal(key,this->_entries[index].entry.key)) {
}
void grow ()
{
- 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 long* new_slots = (long*) ((char*)new_total_vector + 0);
- var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long));
- for (var long hi = new_modulus-1; hi >= 0; hi--)
+ var intptr_t new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5
+ var intptr_t new_modulus = inherited::compute_modulus(new_size);
+ var void* new_total_vector = malloc_hook(new_modulus*sizeof(intptr_t) + new_size*sizeof(htxentry));
+ var intptr_t* new_slots = (intptr_t*) ((char*)new_total_vector + 0);
+ var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(intptr_t));
+ for (var intptr_t hi = new_modulus-1; hi >= 0; hi--)
new_slots[hi] = 0;
- var long free_list_head = -1;
- for (var long i = new_size-1; i >= 0; i--) {
+ var intptr_t free_list_head = -1;
+ for (var intptr_t i = new_size-1; i >= 0; i--) {
new_entries[i].next = free_list_head;
free_list_head = -2-i;
}
var htxentry* old_entries = this->_entries;
- for (var long old_index = 0; old_index < this->_size; old_index++)
+ for (var intptr_t old_index = 0; old_index < this->_size; old_index++)
if (old_entries[old_index].next >= 0) {
var key1_type& key = old_entries[old_index].entry.key;
var value_type& val = old_entries[old_index].entry.val;
- var long hindex = hashcode(key) % new_modulus;
- var long index = -2-free_list_head;
+ var intptr_t hindex = hashcode(key) % new_modulus;
+ var intptr_t index = -2-free_list_head;
free_list_head = new_entries[index].next;
new (&new_entries[index].entry) cl_htentry1<key1_type,value_type> (key,val);
new_entries[index].next = new_slots[hindex];
if (ht->_count < 100)
return false;
// Do a garbage collection.
- var long removed = 0;
- for (long i = 0; i < ht->_size; i++)
+ var intptr_t removed = 0;
+ for (intptr_t i = 0; i < ht->_size; i++)
if (ht->_entries[i].next >= 0) {
var cl_htentry1<key1_type,value_type>& entry = ht->_entries[i].entry;
if (ht->_maygc_htentry(entry)) {
// Requirements:
// - function bool equal (key1_type,key1_type);
// - function bool equal (key2_type,key2_type);
-// - function unsigned long hashcode (key1_type,key2_type);
+// - function uintptr_t hashcode (key1_type,key2_type);
template <class key1_type, class key2_type, class value_type>
struct cl_htentry2 {
// if it is not NULL.
value_type* get (const key1_type& key1, const key2_type& key2)
{
- var long index = this->_slots[hashcode(key1,key2) % this->_modulus] - 1;
+ var intptr_t index = this->_slots[hashcode(key1,key2) % this->_modulus] - 1;
while (index >= 0) {
if (!(index < this->_size))
throw runtime_exception();
// Store (htset alias puthash).
void put (const key1_type& key1, const key2_type& key2, const value_type& val)
{
- var unsigned long hcode = hashcode(key1,key2);
+ var uintptr_t hcode = hashcode(key1,key2);
// Search whether it is already there.
{
- var long index = this->_slots[hcode % this->_modulus] - 1;
+ var intptr_t index = this->_slots[hcode % this->_modulus] - 1;
while (index >= 0) {
if (!(index < this->_size))
throw runtime_exception();
}
// Put it into the table.
prepare_store();
- var long hindex = hcode % this->_modulus; // _modulus may have changed!
- var long index = this->get_free_index();
+ var intptr_t hindex = hcode % this->_modulus; // _modulus may have changed!
+ var intptr_t index = this->get_free_index();
new (&this->_entries[index].entry) cl_htentry2<key1_type,key2_type,value_type> (key1,key2,val);
this->_entries[index].next = this->_slots[hindex];
this->_slots[hindex] = 1+index;
// Remove (htrem alias remhash).
void remove (const key1_type& key1, const key2_type& key2)
{
- var long* _index = &this->_slots[hashcode(key1,key2) % this->_modulus];
+ var intptr_t* _index = &this->_slots[hashcode(key1,key2) % this->_modulus];
while (*_index > 0) {
- var long index = *_index - 1;
+ var intptr_t index = *_index - 1;
if (!(index < this->_size))
throw runtime_exception();
if (equal(key1,this->_entries[index].entry.key1)
}
void grow ()
{
- 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 long* new_slots = (long*) ((char*)new_total_vector + 0);
- var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long));
- for (var long hi = new_modulus-1; hi >= 0; hi--)
+ var intptr_t new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5
+ var intptr_t new_modulus = inherited::compute_modulus(new_size);
+ var void* new_total_vector = malloc_hook(new_modulus*sizeof(intptr_t) + new_size*sizeof(htxentry));
+ var intptr_t* new_slots = (intptr_t*) ((char*)new_total_vector + 0);
+ var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(intptr_t));
+ for (var intptr_t hi = new_modulus-1; hi >= 0; hi--)
new_slots[hi] = 0;
- var long free_list_head = -1;
- for (var long i = new_size-1; i >= 0; i--) {
+ var intptr_t free_list_head = -1;
+ for (var intptr_t i = new_size-1; i >= 0; i--) {
new_entries[i].next = free_list_head;
free_list_head = -2-i;
}
var htxentry* old_entries = this->_entries;
- for (var long old_index = 0; old_index < this->_size; old_index++)
+ for (var intptr_t old_index = 0; old_index < this->_size; old_index++)
if (old_entries[old_index].next >= 0) {
var key1_type& key1 = old_entries[old_index].entry.key1;
var key2_type& key2 = old_entries[old_index].entry.key2;
var value_type& val = old_entries[old_index].entry.val;
- var long hindex = hashcode(key1,key2) % new_modulus;
- var long index = -2-free_list_head;
+ var intptr_t hindex = hashcode(key1,key2) % new_modulus;
+ var intptr_t index = -2-free_list_head;
free_list_head = new_entries[index].next;
new (&new_entries[index].entry) cl_htentry2<key1_type,key2_type,value_type> (key1,key2,val);
new_entries[index].next = new_slots[hindex];
if (ht->_count < 100)
return false;
// Do a garbage collection.
- var long removed = 0;
- for (long i = 0; i < ht->_size; i++)
+ var intptr_t removed = 0;
+ for (intptr_t i = 0; i < ht->_size; i++)
if (ht->_entries[i].next >= 0) {
var cl_htentry2<key1_type,key2_type,value_type>& entry = ht->_entries[i].entry;
if (ht->_maygc_htentry(entry)) {
// Requirements:
// - function bool equal (key1_type,key1_type);
-// - function unsigned long hashcode (key1_type);
+// - function uintptr_t hashcode (key1_type);
template <class key1_type>
struct cl_htsetentry {
// Lookup (htref alias gethash).
bool get (const key1_type& key)
{
- var long index = this->_slots[hashcode(key) % this->_modulus] - 1;
+ var intptr_t index = this->_slots[hashcode(key) % this->_modulus] - 1;
while (index >= 0) {
if (!(index < this->_size))
throw runtime_exception();
// Store (htset alias puthash).
void put (const key1_type& key)
{
- var unsigned long hcode = hashcode(key);
+ var uintptr_t hcode = hashcode(key);
// Search whether it is already there.
{
- var long index = this->_slots[hcode % this->_modulus] - 1;
+ var intptr_t index = this->_slots[hcode % this->_modulus] - 1;
while (index >= 0) {
if (!(index < this->_size))
throw runtime_exception();
}
// Put it into the table.
prepare_store();
- var long hindex = hcode % this->_modulus; // _modulus may have changed!
- var long index = this->get_free_index();
+ var intptr_t hindex = hcode % this->_modulus; // _modulus may have changed!
+ var intptr_t 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;
// Remove (htrem alias remhash).
void remove (const key1_type& key)
{
- var long* _index = &this->_slots[hashcode(key) % this->_modulus];
+ var intptr_t* _index = &this->_slots[hashcode(key) % this->_modulus];
while (*_index > 0) {
- var long index = *_index - 1;
+ var intptr_t index = *_index - 1;
if (!(index < this->_size))
throw runtime_exception();
if (equal(key,this->_entries[index].entry.key)) {
}
void grow ()
{
- 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 long* new_slots = (long*) ((char*)new_total_vector + 0);
- var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long));
- for (var long hi = new_modulus-1; hi >= 0; hi--)
+ var intptr_t new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5
+ var intptr_t new_modulus = inherited::compute_modulus(new_size);
+ var void* new_total_vector = malloc_hook(new_modulus*sizeof(intptr_t) + new_size*sizeof(htxentry));
+ var intptr_t* new_slots = (intptr_t*) ((char*)new_total_vector + 0);
+ var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(intptr_t));
+ for (var intptr_t hi = new_modulus-1; hi >= 0; hi--)
new_slots[hi] = 0;
- var long free_list_head = -1;
- for (var long i = new_size-1; i >= 0; i--) {
+ var intptr_t free_list_head = -1;
+ for (var intptr_t i = new_size-1; i >= 0; i--) {
new_entries[i].next = free_list_head;
free_list_head = -2-i;
}
var htxentry* old_entries = this->_entries;
- for (var long old_index = 0; old_index < this->_size; old_index++)
+ for (var intptr_t old_index = 0; old_index < this->_size; old_index++)
if (old_entries[old_index].next >= 0) {
var key1_type& key = old_entries[old_index].entry.key;
- var long hindex = hashcode(key) % new_modulus;
- var long index = -2-free_list_head;
+ var intptr_t hindex = hashcode(key) % new_modulus;
+ var intptr_t index = -2-free_list_head;
free_list_head = new_entries[index].next;
new (&new_entries[index].entry) cl_htsetentry<key1_type> (key);
new_entries[index].next = new_slots[hindex];
// Requirements:
// - function bool equal (key1_type,key1_type);
-// - function unsigned long hashcode (key1_type);
+// - function uintptr_t hashcode (key1_type);
// - function key1_type hashkey (value_type);
// - constructor value_type::value_type (struct hashuniq *, key1_type);
// if it is not NULL.
value_type * get (const key1_type& key)
{
- var long index = this->_slots[hashcode(key) % this->_modulus] - 1;
+ var intptr_t index = this->_slots[hashcode(key) % this->_modulus] - 1;
while (index >= 0) {
if (!(index < this->_size))
throw runtime_exception();
// Store (htset alias puthash).
void put (const key1_type& key)
{
- var unsigned long hcode = hashcode(key);
+ var uintptr_t hcode = hashcode(key);
// Search whether it is already there.
{
- var long index = this->_slots[hcode % this->_modulus] - 1;
+ var intptr_t index = this->_slots[hcode % this->_modulus] - 1;
while (index >= 0) {
if (!(index < this->_size))
throw runtime_exception();
}
// Put it into the table.
prepare_store();
- var long hindex = hcode % this->_modulus; // _modulus may have changed!
- var long index = this->get_free_index();
+ var intptr_t hindex = hcode % this->_modulus; // _modulus may have changed!
+ var intptr_t index = this->get_free_index();
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->_slots[hindex] = 1+index;
// Remove (htrem alias remhash).
void remove (const key1_type& key)
{
- var long* _index = &this->_slots[hashcode(key) % this->_modulus];
+ var intptr_t* _index = &this->_slots[hashcode(key) % this->_modulus];
while (*_index > 0) {
- var long index = *_index - 1;
+ var intptr_t index = *_index - 1;
if (!(index < this->_size))
throw runtime_exception();
if (equal(key,hashkey(this->_entries[index].entry.val))) {
}
void grow ()
{
- 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 long* new_slots = (long*) ((char*)new_total_vector + 0);
- var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(long));
- for (var long hi = new_modulus-1; hi >= 0; hi--)
+ var intptr_t new_size = this->_size + (this->_size >> 1) + 1; // _size*1.5
+ var intptr_t new_modulus = inherited::compute_modulus(new_size);
+ var void* new_total_vector = malloc_hook(new_modulus*sizeof(intptr_t) + new_size*sizeof(htxentry));
+ var intptr_t* new_slots = (intptr_t*) ((char*)new_total_vector + 0);
+ var htxentry* new_entries = (htxentry *) ((char*)new_total_vector + new_modulus*sizeof(intptr_t));
+ for (var intptr_t hi = new_modulus-1; hi >= 0; hi--)
new_slots[hi] = 0;
- var long free_list_head = -1;
- for (var long i = new_size-1; i >= 0; i--) {
+ var intptr_t free_list_head = -1;
+ for (var intptr_t i = new_size-1; i >= 0; i--) {
new_entries[i].next = free_list_head;
free_list_head = -2-i;
}
var htxentry* old_entries = this->_entries;
- for (var long old_index = 0; old_index < this->_size; old_index++)
+ for (var intptr_t old_index = 0; old_index < this->_size; old_index++)
if (old_entries[old_index].next >= 0) {
var value_type& val = old_entries[old_index].entry.val;
- var long hindex = hashcode(hashkey(val)) % new_modulus;
- var long index = -2-free_list_head;
+ var intptr_t hindex = hashcode(hashkey(val)) % new_modulus;
+ var intptr_t index = -2-free_list_head;
free_list_head = new_entries[index].next;
new (&new_entries[index].entry) cl_htuniqentry<key1_type,value_type> (val);
new_entries[index].next = new_slots[hindex];
if (ht->_count < 100)
return false;
// Do a garbage collection.
- var long removed = 0;
- for (long i = 0; i < ht->_size; i++)
+ var intptr_t removed = 0;
+ for (intptr_t i = 0; i < ht->_size; i++)
if (ht->_entries[i].next >= 0) {
var value_type& v = ht->_entries[i].entry.val;
if (!v.pointer_p() || (v.heappointer->refcount == 1)) {
{ return (x.pointer == y.pointer); }
// Hash code. Luckily objects don't move around in memory.
-inline unsigned long hashcode (const cl_rcpointer& x1, const cl_rcpointer& x2)
+inline uintptr_t hashcode (const cl_rcpointer& x1, const cl_rcpointer& x2)
{
- var unsigned long hashcode1 = (unsigned long)x1.pointer;
- var unsigned long hashcode2 = (unsigned long)x2.pointer;
+ var uintptr_t hashcode1 = (uintptr_t)x1.pointer;
+ var uintptr_t hashcode2 = (uintptr_t)x2.pointer;
hashcode2 = (hashcode2 << 5) | (hashcode2 >> (long_bitsize-5)); // rotate
return hashcode1 ^ hashcode2;
}
{ return (x.pointer == y.pointer); }
// Hash code. Luckily objects don't move around in memory.
-inline unsigned long hashcode (const cl_rcpointer& x)
-{ return (unsigned long)x.pointer; }
+inline uintptr_t hashcode (const cl_rcpointer& x)
+{ return (uintptr_t)x.pointer; }
typedef cl_htentry1<cl_rcpointer,cl_rcpointer> cl_htentry_from_rcpointer_to_rcpointer;
namespace cln {
-unsigned long hashcode (const cl_string& str)
+uintptr_t hashcode (const cl_string& str)
{
- var unsigned long code = 0x61284AF3;
+ var uintptr_t code = 0x61284AF3;
// We walk through all characters. It may take some time for very
// long strings, but it's better than completely ignoring some characters.
- var long len = str.size();
+ var intptr_t len = str.size();
var const char * ptr = str.asciz();
for (; len > 0; len--) {
var unsigned char c = *ptr++;
code = (code << 5) | (code >> 27); // rotate left 5 bits
- code += (long)c << 16;
- code ^= (long)c;
+ code += (intptr_t)c << 16;
+ code ^= (intptr_t)c;
code &= 0xFFFFFFFF;
}
return code;
#define declare_alignof(where,type) \
struct CONCAT(aligndummy,__LINE__) { char slot1; type slot2; }; \
- const unsigned long where = offsetof(CONCAT(aligndummy,__LINE__), slot2);
+ const uintptr_t where = offsetof(CONCAT(aligndummy,__LINE__), slot2);
-unsigned long hashcode (const cl_symbol& s)
+uintptr_t hashcode (const cl_symbol& s)
{
// Strings don't move in memory, so we can just take the address.
declare_alignof(string_alignment,cl_heap_string);
- return (unsigned long)(s.pointer)
+ return (uintptr_t)(s.pointer)
/ (string_alignment & -string_alignment); // divide by power of 2
}
// Hash code.
- extern unsigned long hashcode (const cl_I& x);
+ extern uintptr_t hashcode (const cl_I& x);
// A fixnum (cl_FN) is an immediate integer.
namespace cln {
-unsigned long hashcode (const cl_I& x)
+uintptr_t hashcode (const cl_I& x)
{
- var unsigned long code = 0x814BE3A5;
+ var uintptr_t code = 0x814BE3A5;
// We walk through all limbs. It may take some time for very large
// integers, but it's better than completely ignoring some limbs.
if (fixnump(x)) {
for (; len > 0; len--) {
var uintD c = msprefnext(MSDptr);
code = (code << 5) | (code >> 27); // rotate left 5 bits
- code += (long)c << 16;
- code ^= (long)c;
+ code += (intptr_t)c << 16;
+ code ^= (intptr_t)c;
code &= 0xFFFFFFFF;
}
}