Index: src/OFMapTable.h ================================================================== --- src/OFMapTable.h +++ src/OFMapTable.h @@ -71,11 +71,11 @@ OF_SUBCLASSING_RESTRICTED @interface OFMapTable: OFObject { OFMapTableFunctions _keyFunctions, _objectFunctions; struct OFMapTableBucket *_Nonnull *_Nullable _buckets; - unsigned long _count, _capacity; + uint32_t _count, _capacity; unsigned char _rotate; unsigned long _mutations; } /** @@ -233,12 +233,12 @@ */ @interface OFMapTableEnumerator: OFObject { OFMapTable *_mapTable; struct OFMapTableBucket *_Nonnull *_Nullable _buckets; - unsigned long _capacity, _mutations, *_Nullable _mutationsPtr; - unsigned long _position; + uint32_t _capacity; + unsigned long _mutations, *_Nullable _mutationsPtr, _position; } - (instancetype)init OF_UNAVAILABLE; /** Index: src/OFMapTable.m ================================================================== --- src/OFMapTable.m +++ src/OFMapTable.m @@ -26,17 +26,17 @@ #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" -extern unsigned long OFHashSeed; +extern uint32_t OFHashSeed; -static const unsigned long minCapacity = 16; +static const uint32_t minCapacity = 16; struct OFMapTableBucket { void *key, *object; - unsigned long hash; + uint32_t hash; }; static struct OFMapTableBucket deletedBucket = { 0 }; static void * defaultRetain(void *object) @@ -63,11 +63,11 @@ OF_DIRECT_MEMBERS @interface OFMapTableEnumerator () - (instancetype)of_initWithMapTable: (OFMapTable *)mapTable buckets: (struct OFMapTableBucket **)buckets - capacity: (unsigned long)capacity + capacity: (uint32_t)capacity mutationsPointer: (unsigned long *)mutationsPtr OF_METHOD_FAMILY(init); @end @interface OFMapTableKeyEnumerator: OFMapTableEnumerator @@ -134,23 +134,23 @@ SET_DEFAULT(_objectFunctions.hash, defaultHash); SET_DEFAULT(_objectFunctions.equal, defaultEqual); #undef SET_DEFAULT - if (capacity > ULONG_MAX / sizeof(*_buckets) || - capacity > ULONG_MAX / 8) + if (capacity > UINT32_MAX / sizeof(*_buckets) || + capacity > UINT32_MAX / 8) @throw [OFOutOfRangeException exception]; for (_capacity = 1; _capacity < capacity;) { - if (_capacity > ULONG_MAX / 2) + if (_capacity > UINT32_MAX / 2) @throw [OFOutOfRangeException exception]; _capacity *= 2; } if (capacity * 8 / _capacity >= 6) - if (_capacity <= ULONG_MAX / 2) + if (_capacity <= UINT32_MAX / 2) _capacity *= 2; if (_capacity < minCapacity) _capacity = minCapacity; @@ -166,11 +166,11 @@ return self; } - (void)dealloc { - for (unsigned long i = 0; i < _capacity; i++) { + for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); @@ -181,23 +181,23 @@ [super dealloc]; } static void -resizeForCount(OFMapTable *self, unsigned long count) +resizeForCount(OFMapTable *self, uint32_t count) { - unsigned long fullness, capacity; + uint32_t fullness, capacity; struct OFMapTableBucket **buckets; - if (count > ULONG_MAX / sizeof(*self->_buckets) || - count > ULONG_MAX / 8) + if (count > UINT32_MAX / sizeof(*self->_buckets) || + count > UINT32_MAX / 8) @throw [OFOutOfRangeException exception]; fullness = count * 8 / self->_capacity; if (fullness >= 6) { - if (self->_capacity > ULONG_MAX / 2) + if (self->_capacity > UINT32_MAX / 2) return; capacity = self->_capacity * 2; } else if (fullness <= 1) capacity = self->_capacity / 2; @@ -212,14 +212,14 @@ capacity < minCapacity) return; buckets = OFAllocZeroedMemory(capacity, sizeof(*buckets)); - for (unsigned long i = 0; i < self->_capacity; i++) { + for (uint32_t i = 0; i < self->_capacity; i++) { if (self->_buckets[i] != NULL && self->_buckets[i] != &deletedBucket) { - unsigned long j, last; + uint32_t j, last; last = capacity; for (j = self->_buckets[i]->hash & (capacity - 1); j < last && buckets[j] != NULL; j++); @@ -243,14 +243,13 @@ self->_buckets = buckets; self->_capacity = capacity; } static void -setObject(OFMapTable *restrict self, void *key, void *object, - unsigned long hash) +setObject(OFMapTable *restrict self, void *key, void *object, uint32_t hash) { - unsigned long i, last; + uint32_t i, last; void *old; if (key == NULL || object == NULL) @throw [OFInvalidArgumentException exception]; @@ -351,11 +350,11 @@ if (mapTable->_count != _count || mapTable->_keyFunctions.equal != _keyFunctions.equal || mapTable->_objectFunctions.equal != _objectFunctions.equal) return false; - for (unsigned long i = 0; i < _capacity; i++) { + for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { void *objectIter = [mapTable objectForKey: _buckets[i]->key]; if (!_objectFunctions.equal(objectIter, @@ -387,11 +386,11 @@ initWithKeyFunctions: _keyFunctions objectFunctions: _objectFunctions capacity: _capacity]; @try { - for (unsigned long i = 0; i < _capacity; i++) + for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) setObject(copy, _buckets[i]->key, _buckets[i]->object, OFRotateRight(_buckets[i]->hash, _rotate)); @@ -408,16 +407,16 @@ return _count; } - (void *)objectForKey: (void *)key { - unsigned long i, hash, last; + uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; - hash = OFRotateLeft(_keyFunctions.hash(key), _rotate); + hash = OFRotateLeft((uint32_t)_keyFunctions.hash(key), _rotate); last = _capacity; for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deletedBucket) continue; @@ -443,21 +442,21 @@ return NULL; } - (void)setObject: (void *)object forKey: (void *)key { - setObject(self, key, object,_keyFunctions.hash(key)); + setObject(self, key, object, (uint32_t)_keyFunctions.hash(key)); } - (void)removeObjectForKey: (void *)key { - unsigned long i, hash, last; + uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; - hash = OFRotateLeft(_keyFunctions.hash(key), _rotate); + hash = OFRotateLeft((uint32_t)_keyFunctions.hash(key), _rotate); last = _capacity; for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deletedBucket) continue; @@ -504,11 +503,11 @@ } } - (void)removeAllObjects { - for (unsigned long i = 0; i < _capacity; i++) { + for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL) { if (_buckets[i] == &deletedBucket) { _buckets[i] = NULL; continue; } @@ -536,11 +535,11 @@ - (bool)containsObject: (void *)object { if (object == NULL || _count == 0) return false; - for (unsigned long i = 0; i < _capacity; i++) + for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) if (_objectFunctions.equal(_buckets[i]->object, object)) return true; return false; @@ -549,11 +548,11 @@ - (bool)containsObjectIdenticalTo: (void *)object { if (object == NULL || _count == 0) return false; - for (unsigned long i = 0; i < _capacity; i++) + for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) if (_buckets[i]->object == object) return true; return false; @@ -651,11 +650,11 @@ OF_INVALID_INIT_METHOD } - (instancetype)of_initWithMapTable: (OFMapTable *)mapTable buckets: (struct OFMapTableBucket **)buckets - capacity: (unsigned long)capacity + capacity: (uint32_t)capacity mutationsPointer: (unsigned long *)mutationsPtr { self = [super init]; _mapTable = [mapTable retain];