Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -15,10 +15,11 @@ #import "OFDictionary.h" #import "OFIterator.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" +#import "OFMacros.h" #define BUCKET_SIZE sizeof(struct of_dictionary_bucket) /* References for static linking */ void _references_to_categories_of_OFDictionary() @@ -249,15 +250,24 @@ - (id)mutableCopy { return [[OFMutableDictionary alloc] initWithDictionary: self]; } -/* FIXME: Implement this! -- (BOOL)isEqual +- (BOOL)isEqual: (OFDictionary*)dict { + size_t i; + + if ([dict count] != count) + return NO; + + for (i = 0; i < size; i++) + if (data[i].key != nil && + ![[dict objectForKey: data[i].key] isEqual: data[i].object]) + return NO; + + return YES; } -*/ - (void)dealloc { size_t i; @@ -282,11 +292,33 @@ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } -/* FIXME: Implement! - (uint32_t)hash { + size_t i; + uint32_t hash; + + OF_HASH_INIT(hash); + + for (i = 0; i < size; i++) { + if (data[i].key != nil) { + uint32_t kh = [data[i].key hash]; + + OF_HASH_ADD(hash, kh >> 24); + OF_HASH_ADD(hash, (kh >> 16) & 0xFF); + OF_HASH_ADD(hash, (kh >> 8) & 0xFF); + OF_HASH_ADD(hash, kh & 0xFF); + + OF_HASH_ADD(hash, data[i].hash >> 24); + OF_HASH_ADD(hash, (data[i].hash >> 16) & 0xFF); + OF_HASH_ADD(hash, (data[i].hash >> 8) & 0xFF); + OF_HASH_ADD(hash, data[i].hash & 0xFF); + } + } + + OF_HASH_FINALIZE(hash); + + return hash; } -*/ @end Index: tests/OFDictionary.m ================================================================== --- tests/OFDictionary.m +++ tests/OFDictionary.m @@ -30,11 +30,11 @@ void dictionary_tests() { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFDictionary *dict = [OFMutableDictionary dictionary]; + OFDictionary *dict = [OFMutableDictionary dictionary], *dict2; OFIterator *iter; of_iterator_pair_t pair[3]; OFArray *akeys, *avalues; [dict setObject: values[0] @@ -84,12 +84,14 @@ TEST(@"-[copy]", (dict = [[dict copy] autorelease]) && [[dict objectForKey: keys[0]] isEqual: values[0]] && [[dict objectForKey: keys[1]] isEqual: values[1]]) + dict2 = dict; TEST(@"-[mutableCopy]", (dict = [[dict mutableCopy] autorelease]) && + [dict count] == [dict2 count] && [[dict objectForKey: keys[0]] isEqual: values[0]] && [[dict objectForKey: keys[1]] isEqual: values[1]] && [dict setObject: @"value3" forKey: @"key3"] && [[dict objectForKey: @"key3"] isEqual: @"value3"] && @@ -99,7 +101,16 @@ TEST(@"-[removeObjectForKey:]", [dict removeObjectForKey: keys[0]] && [dict objectForKey: keys[0]] == nil) + [dict setObject: @"foo" + forKey: keys[0]]; + TEST(@"-[isEqual:]", ![dict isEqual: dict2] && + [dict removeObjectForKey: @"key3"] && + ![dict isEqual: dict2] && + [dict setObject: values[0] + forKey: keys[0]] && + [dict isEqual: dict2]) + [pool release]; }