@@ -30,42 +30,42 @@ #import "OFOutOfRangeException.h" #define MIN_CAPACITY 16 struct of_map_table_bucket { - void *key, *value; + void *key, *object; uint32_t hash; }; static struct of_map_table_bucket deleted = { 0 }; static void* -defaultRetain(void *value) +defaultRetain(void *object) { - return value; + return object; } static void -defaultRelease(void *value) +defaultRelease(void *object) { } static uint32_t -defaultHash(void *value) +defaultHash(void *object) { - return (uint32_t)(uintptr_t)value; + return (uint32_t)(uintptr_t)object; } static bool -defaultEqual(void *value1, void *value2) +defaultEqual(void *object1, void *object2) { - return (value1 == value2); + return (object1 == object2); } @interface OFMapTable () -- (void)OF_setValue: (void*)value - forKey: (void*)key - hash: (uint32_t)hash; +- (void)OF_setObject: (void*)object + forKey: (void*)key + hash: (uint32_t)hash; @end @interface OFMapTableEnumerator () - (instancetype)OF_initWithMapTable: (OFMapTable*)mapTable buckets: (struct of_map_table_bucket**)buckets @@ -74,58 +74,58 @@ @end @interface OFMapTableKeyEnumerator: OFMapTableEnumerator @end -@interface OFMapTableValueEnumerator: OFMapTableEnumerator +@interface OFMapTableObjectEnumerator: OFMapTableEnumerator @end @implementation OFMapTable -@synthesize keyFunctions = _keyFunctions, valueFunctions = _valueFunctions; +@synthesize keyFunctions = _keyFunctions, objectFunctions = _objectFunctions; + (instancetype)mapTableWithKeyFunctions: (of_map_table_functions_t)keyFunctions - valueFunctions: (of_map_table_functions_t) - valueFunctions + objectFunctions: (of_map_table_functions_t) + objectFunctions { return [[[self alloc] initWithKeyFunctions: keyFunctions - valueFunctions: valueFunctions] autorelease]; + objectFunctions: objectFunctions] autorelease]; } + (instancetype)mapTableWithKeyFunctions: (of_map_table_functions_t)keyFunctions - valueFunctions: (of_map_table_functions_t) - valueFunctions + objectFunctions: (of_map_table_functions_t) + objectFunctions capacity: (size_t)capacity { return [[[self alloc] initWithKeyFunctions: keyFunctions - valueFunctions: valueFunctions + objectFunctions: objectFunctions capacity: capacity] autorelease]; } - init { OF_INVALID_INIT_METHOD } - initWithKeyFunctions: (of_map_table_functions_t)keyFunctions - valueFunctions: (of_map_table_functions_t)valueFunctions + objectFunctions: (of_map_table_functions_t)objectFunctions { return [self initWithKeyFunctions: keyFunctions - valueFunctions: valueFunctions + objectFunctions: objectFunctions capacity: 0]; } - initWithKeyFunctions: (of_map_table_functions_t)keyFunctions - valueFunctions: (of_map_table_functions_t)valueFunctions + objectFunctions: (of_map_table_functions_t)objectFunctions capacity: (size_t)capacity { self = [super init]; @try { _keyFunctions = keyFunctions; - _valueFunctions = valueFunctions; + _objectFunctions = objectFunctions; #define SET_DEFAULT(var, value) \ if (var == NULL) \ var = value; @@ -132,14 +132,14 @@ SET_DEFAULT(_keyFunctions.retain, defaultRetain); SET_DEFAULT(_keyFunctions.release, defaultRelease); SET_DEFAULT(_keyFunctions.hash, defaultHash); SET_DEFAULT(_keyFunctions.equal, defaultEqual); - SET_DEFAULT(_valueFunctions.retain, defaultRetain); - SET_DEFAULT(_valueFunctions.release, defaultRelease); - SET_DEFAULT(_valueFunctions.hash, defaultHash); - SET_DEFAULT(_valueFunctions.equal, defaultEqual); + SET_DEFAULT(_objectFunctions.retain, defaultRetain); + SET_DEFAULT(_objectFunctions.release, defaultRelease); + SET_DEFAULT(_objectFunctions.hash, defaultHash); + SET_DEFAULT(_objectFunctions.equal, defaultEqual); #undef SET_DEFAULT if (capacity > UINT32_MAX / sizeof(*_buckets) || capacity > UINT32_MAX / 8) @@ -183,11 +183,11 @@ - (void)dealloc { for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { _keyFunctions.release(_buckets[i]->key); - _valueFunctions.release(_buckets[i]->value); + _objectFunctions.release(_buckets[i]->object); } } [super dealloc]; } @@ -201,18 +201,20 @@ mapTable = object; if (mapTable->_count != _count || mapTable->_keyFunctions.equal != _keyFunctions.equal || - mapTable->_valueFunctions.equal != _valueFunctions.equal) + mapTable->_objectFunctions.equal != _objectFunctions.equal) return false; for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { - void *value = [mapTable valueForKey: _buckets[i]->key]; + void *object = + [mapTable objectForKey: _buckets[i]->key]; - if (!_valueFunctions.equal(value, _buckets[i]->value)) + if (!_objectFunctions.equal(object, + _buckets[i]->object)) return false; } } return true; @@ -223,11 +225,11 @@ uint32_t hash = 0; for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { hash += OF_ROR(_buckets[i]->hash, _rotate); - hash += _valueFunctions.hash(_buckets[i]->value); + hash += _objectFunctions.hash(_buckets[i]->object); } } return hash; } @@ -234,20 +236,20 @@ - copy { OFMapTable *copy = [[OFMapTable alloc] initWithKeyFunctions: _keyFunctions - valueFunctions: _valueFunctions + objectFunctions: _objectFunctions capacity: _capacity]; @try { for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) - [copy OF_setValue: _buckets[i]->value - forKey: _buckets[i]->key - hash: OF_ROR(_buckets[i]->hash, - _rotate)]; + [copy OF_setObject: _buckets[i]->object + forKey: _buckets[i]->key + hash: OF_ROR(_buckets[i]->hash, + _rotate)]; } @catch (id e) { [copy release]; @throw e; } @@ -257,11 +259,11 @@ - (size_t)count { return _count; } -- (void*)valueForKey: (void*)key +- (void*)objectForKey: (void*)key { uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; @@ -272,11 +274,11 @@ for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deleted) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) - return _buckets[i]->value; + return _buckets[i]->object; } if (i < last) return nil; @@ -286,11 +288,11 @@ for (i = 0; i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deleted) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) - return _buckets[i]->value; + return _buckets[i]->object; } return NULL; } @@ -353,18 +355,18 @@ [self freeMemory: _buckets]; _buckets = buckets; _capacity = capacity; } -- (void)OF_setValue: (void*)value - forKey: (void*)key - hash: (uint32_t)hash +- (void)OF_setObject: (void*)object + forKey: (void*)key + hash: (uint32_t)hash { uint32_t i, last; void *old; - if (key == NULL || value == NULL) + if (key == NULL || object == NULL) @throw [OFInvalidArgumentException exception]; hash = OF_ROL(hash, _rotate); last = _capacity; @@ -421,11 +423,11 @@ [self freeMemory: bucket]; @throw e; } @try { - bucket->value = _valueFunctions.retain(value); + bucket->object = _objectFunctions.retain(object); } @catch (id e) { _keyFunctions.release(bucket->key); [self freeMemory: bucket]; @throw e; } @@ -436,24 +438,24 @@ _count++; return; } - old = _buckets[i]->value; - _buckets[i]->value = _valueFunctions.retain(value); - _valueFunctions.release(old); + old = _buckets[i]->object; + _buckets[i]->object = _objectFunctions.retain(object); + _objectFunctions.release(old); } -- (void)setValue: (void*)value - forKey: (void*)key +- (void)setObject: (void*)object + forKey: (void*)key { - [self OF_setValue: value - forKey: key - hash: _keyFunctions.hash(key)]; + [self OF_setObject: object + forKey: key + hash: _keyFunctions.hash(key)]; } -- (void)removeValueForKey: (void*)key +- (void)removeObjectForKey: (void*)key { uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; @@ -467,11 +469,11 @@ if (_keyFunctions.equal(_buckets[i]->key, key)) { _mutations++; _keyFunctions.release(_buckets[i]->key); - _valueFunctions.release(_buckets[i]->value); + _objectFunctions.release(_buckets[i]->object); [self freeMemory: _buckets[i]]; _buckets[i] = &deleted; _count--; @@ -491,11 +493,11 @@ if (_buckets[i] == &deleted) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) { _keyFunctions.release(_buckets[i]->key); - _valueFunctions.release(_buckets[i]->value); + _objectFunctions.release(_buckets[i]->object); [self freeMemory: _buckets[i]]; _buckets[i] = &deleted; _count--; @@ -505,21 +507,21 @@ return; } } } -- (void)removeAllValues +- (void)removeAllObjects { for (uint32_t i = 0; i < _capacity; i++) { if (_buckets[i] != NULL) { if (_buckets[i] == &deleted) { _buckets[i] = NULL; continue; } _keyFunctions.release(_buckets[i]->key); - _valueFunctions.release(_buckets[i]->value); + _objectFunctions.release(_buckets[i]->object); [self freeMemory: _buckets[i]]; _buckets[i] = NULL; } } @@ -542,31 +544,31 @@ #else _rotate = rand() & 31; #endif } -- (bool)containsValue: (void*)value +- (bool)containsObject: (void*)object { - if (value == NULL || _count == 0) + if (object == NULL || _count == 0) return false; for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) - if (_valueFunctions.equal(_buckets[i]->value, value)) + if (_objectFunctions.equal(_buckets[i]->object, object)) return true; return false; } -- (bool)containsValueIdenticalTo: (void*)value +- (bool)containsObjectIdenticalTo: (void*)object { - if (value == NULL || _count == 0) + if (object == NULL || _count == 0) return false; for (uint32_t i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deleted) - if (_buckets[i]->value == value) + if (_buckets[i]->object == object) return true; return false; } @@ -577,13 +579,13 @@ buckets: _buckets capacity: _capacity mutationsPointer: &_mutations] autorelease]; } -- (OFMapTableEnumerator*)valueEnumerator +- (OFMapTableEnumerator*)objectEnumerator { - return [[[OFMapTableValueEnumerator alloc] + return [[[OFMapTableObjectEnumerator alloc] OF_initWithMapTable: self buckets: _buckets capacity: _capacity mutationsPointer: &_mutations] autorelease]; } @@ -612,11 +614,11 @@ return i; } #ifdef OF_HAVE_BLOCKS -- (void)enumerateKeysAndValuesUsingBlock: +- (void)enumerateKeysAndObjectsUsingBlock: (of_map_table_enumeration_block_t)block { bool stop = false; unsigned long mutations = _mutations; @@ -624,15 +626,15 @@ if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; if (_buckets[i] != NULL && _buckets[i] != &deleted) - block(_buckets[i]->key, _buckets[i]->value, &stop); + block(_buckets[i]->key, _buckets[i]->object, &stop); } } -- (void)replaceValuesUsingBlock: (of_map_table_replace_block_t)block +- (void)replaceObjectsUsingBlock: (of_map_table_replace_block_t)block { unsigned long mutations = _mutations; for (size_t i = 0; i < _capacity; i++) { if (_mutations != mutations) @@ -640,18 +642,18 @@ exceptionWithObject: self]; if (_buckets[i] != NULL && _buckets[i] != &deleted) { void *new; - new = block(_buckets[i]->key, _buckets[i]->value); + new = block(_buckets[i]->key, _buckets[i]->object); if (new == NULL) @throw [OFInvalidArgumentException exception]; - if (new != _buckets[i]->value) { - _valueFunctions.release(_buckets[i]->value); - _buckets[i]->value = - _valueFunctions.retain(new); + if (new != _buckets[i]->object) { + _objectFunctions.release(_buckets[i]->object); + _buckets[i]->object = + _objectFunctions.retain(new); } } } } #endif @@ -684,11 +686,11 @@ [_mapTable release]; [super dealloc]; } -- (void*)nextValue +- (void*)nextObject { OF_UNRECOGNIZED_SELECTOR } - (void)reset @@ -700,11 +702,11 @@ _position = 0; } @end @implementation OFMapTableKeyEnumerator -- (void*)nextValue +- (void*)nextObject { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; @@ -716,22 +718,22 @@ else return NULL; } @end -@implementation OFMapTableValueEnumerator -- (void*)nextValue +@implementation OFMapTableObjectEnumerator +- (void*)nextObject { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || _buckets[_position] == &deleted); _position++); if (_position < _capacity) - return _buckets[_position++]->value; + return _buckets[_position++]->object; else return NULL; } @end @@ -758,11 +760,11 @@ - (id)nextObject { id ret; @try { - ret = [_enumerator nextValue]; + ret = [_enumerator nextObject]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithObject: _object]; }