@@ -32,11 +32,11 @@ #define MIN_CAPACITY 16 struct of_map_table_bucket { void *key, *object; - uint32_t hash; + unsigned long hash; }; static struct of_map_table_bucket deleted = { 0 }; static void * defaultRetain(void *object) @@ -47,14 +47,14 @@ static void defaultRelease(void *object) { } -static uint32_t +static unsigned long defaultHash(void *object) { - return (uint32_t)(uintptr_t)object; + return (unsigned long)(uintptr_t)object; } static bool defaultEqual(void *object1, void *object2) { @@ -63,18 +63,18 @@ OF_DIRECT_MEMBERS @interface OFMapTable () - (void)of_setObject: (void *)object forKey: (void *)key - hash: (uint32_t)hash; + hash: (unsigned long)hash; @end OF_DIRECT_MEMBERS @interface OFMapTableEnumerator () - (instancetype)of_initWithMapTable: (OFMapTable *)mapTable buckets: (struct of_map_table_bucket **)buckets - capacity: (uint32_t)capacity + capacity: (unsigned long)capacity mutationsPointer: (unsigned long *)mutationsPtr OF_METHOD_FAMILY(init); @end @interface OFMapTableKeyEnumerator: OFMapTableEnumerator @@ -143,23 +143,23 @@ SET_DEFAULT(_objectFunctions.hash, defaultHash); SET_DEFAULT(_objectFunctions.equal, defaultEqual); #undef SET_DEFAULT - if (capacity > UINT32_MAX / sizeof(*_buckets) || - capacity > UINT32_MAX / 8) + if (capacity > ULONG_MAX / sizeof(*_buckets) || + capacity > ULONG_MAX / 8) @throw [OFOutOfRangeException exception]; for (_capacity = 1; _capacity < capacity;) { - if (_capacity > UINT32_MAX / 2) + if (_capacity > ULONG_MAX / 2) @throw [OFOutOfRangeException exception]; _capacity *= 2; } if (capacity * 8 / _capacity >= 6) - if (_capacity <= UINT32_MAX / 2) + if (_capacity <= ULONG_MAX / 2) _capacity *= 2; if (_capacity < MIN_CAPACITY) _capacity = MIN_CAPACITY; @@ -176,11 +176,11 @@ return self; } - (void)dealloc { - for (uint32_t i = 0; i < _capacity; i++) { + for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); } } @@ -203,11 +203,11 @@ if (mapTable->_count != _count || mapTable->_keyFunctions.equal != _keyFunctions.equal || mapTable->_objectFunctions.equal != _objectFunctions.equal) return false; - for (uint32_t i = 0; i < _capacity; i++) { + for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { void *objectIter = [mapTable objectForKey: _buckets[i]->key]; if (!_objectFunctions.equal(objectIter, @@ -217,18 +217,18 @@ } return true; } -- (uint32_t)hash +- (unsigned long)hash { - uint32_t hash = 0; + unsigned long hash = 0; - for (uint32_t i = 0; i < _capacity; i++) { + for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { - hash += OF_ROR(_buckets[i]->hash, _rotate); - hash += _objectFunctions.hash(_buckets[i]->object); + hash ^= OF_ROR(_buckets[i]->hash, _rotate); + hash ^= _objectFunctions.hash(_buckets[i]->object); } } return hash; } @@ -239,11 +239,11 @@ initWithKeyFunctions: _keyFunctions objectFunctions: _objectFunctions capacity: _capacity]; @try { - for (uint32_t i = 0; i < _capacity; i++) + for (unsigned long i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) [copy of_setObject: _buckets[i]->object forKey: _buckets[i]->key hash: OF_ROR(_buckets[i]->hash, _rotate)]; @@ -260,11 +260,11 @@ return _count; } - (void *)objectForKey: (void *)key { - uint32_t i, hash, last; + unsigned long i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; hash = OF_ROL(_keyFunctions.hash(key), _rotate); @@ -293,22 +293,22 @@ } return NULL; } -- (void)of_resizeForCount: (uint32_t)count OF_DIRECT +- (void)of_resizeForCount: (unsigned long)count OF_DIRECT { - uint32_t fullness, capacity; + unsigned long fullness, capacity; struct of_map_table_bucket **buckets; - if (count > UINT32_MAX / sizeof(*_buckets) || count > UINT32_MAX / 8) + if (count > ULONG_MAX / sizeof(*_buckets) || count > ULONG_MAX / 8) @throw [OFOutOfRangeException exception]; fullness = count * 8 / _capacity; if (fullness >= 6) { - if (_capacity > UINT32_MAX / 2) + if (_capacity > ULONG_MAX / 2) return; capacity = _capacity * 2; } else if (fullness <= 1) capacity = _capacity / 2; @@ -323,13 +323,13 @@ return; buckets = [self allocZeroedMemoryWithSize: sizeof(*buckets) count: capacity]; - for (uint32_t i = 0; i < _capacity; i++) { + for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { - uint32_t j, last; + unsigned long j, last; last = capacity; for (j = _buckets[i]->hash & (capacity - 1); j < last && buckets[j] != NULL; j++); @@ -354,13 +354,13 @@ _capacity = capacity; } - (void)of_setObject: (void *)object forKey: (void *)key - hash: (uint32_t)hash + hash: (unsigned long)hash { - uint32_t i, last; + unsigned long i, last; void *old; if (key == NULL || object == NULL) @throw [OFInvalidArgumentException exception]; @@ -450,11 +450,11 @@ hash: _keyFunctions.hash(key)]; } - (void)removeObjectForKey: (void *)key { - uint32_t i, hash, last; + unsigned long i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; hash = OF_ROL(_keyFunctions.hash(key), _rotate); @@ -506,11 +506,11 @@ } } - (void)removeAllObjects { - for (uint32_t i = 0; i < _capacity; i++) { + for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL) { if (_buckets[i] == &deleted) { _buckets[i] = NULL; continue; } @@ -540,11 +540,11 @@ - (bool)containsObject: (void *)object { if (object == NULL || _count == 0) return false; - for (uint32_t i = 0; i < _capacity; i++) + for (unsigned long i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) if (_objectFunctions.equal(_buckets[i]->object, object)) return true; return false; @@ -553,11 +553,11 @@ - (bool)containsObjectIdenticalTo: (void *)object { if (object == NULL || _count == 0) return false; - for (uint32_t i = 0; i < _capacity; i++) + for (unsigned long i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) if (_buckets[i]->object == object) return true; return false; @@ -583,11 +583,11 @@ - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state objects: (id *)objects count: (int)count { - uint32_t j = (uint32_t)state->state; + unsigned long j = state->state; int i; for (i = 0; i < count; i++) { for (; j < _capacity && (_buckets[j] == NULL || _buckets[j] == &deleted); j++); @@ -656,11 +656,11 @@ OF_INVALID_INIT_METHOD } - (instancetype)of_initWithMapTable: (OFMapTable *)mapTable buckets: (struct of_map_table_bucket **)buckets - capacity: (uint32_t)capacity + capacity: (unsigned long)capacity mutationsPointer: (unsigned long *)mutationsPtr { self = [super init]; _mapTable = [mapTable retain];