Permalink
Browse files

Fixed Hashing to allow passing in HashableUser in testing.

  • Loading branch information...
1 parent 714942f commit 69a5b0b22b4a6dcb5f91ddd12d497e404a9d77a7 Alan Condit committed Apr 19, 2012
Showing with 14 additions and 8 deletions.
  1. +2 −2 runtime/ObjC/Framework/HashMap.h
  2. +12 −6 runtime/ObjC/Framework/HashMap.m
@@ -132,7 +132,7 @@
- (BOOL) contains:(id)o;
- (BOOL) remove:(id)o;
- (void) clear;
-- (NSArray *)toArray;
+- (AMutableArray *)toArray;
@end
@interface Values : PtrBuffer
@@ -151,7 +151,7 @@
- (NSUInteger) count;
- (BOOL) contains:(id)o;
- (void) clear;
-- (NSArray *)toArray;
+- (AMutableArray *)toArray;
@end
@interface HMEntrySet : NSSet
@@ -91,7 +91,7 @@ - (BOOL) isEqualTo:(id)o
- (NSInteger) hashCode
{
- return (key == nil ? 0 : [key hashCode]) ^ (value == nil ? 0 : [value hash]);
+ return (key == nil ? 0 : [key hash]) ^ (value == nil ? 0 : [value hash]);
}
- (NSString *) description
@@ -311,7 +311,7 @@ - (void) clear {
[hm clear];
}
-- (NSArray *)toArray
+- (AMutableArray *)toArray
{
return anArray;
}
@@ -362,7 +362,7 @@ - (void) clear {
[hm clear];
}
-- (NSArray *)toArray
+- (AMutableArray *)toArray
{
return anArray;
}
@@ -709,6 +709,7 @@ -(void)dealloc
- (NSUInteger)count
{
+/*
NSUInteger aCnt = 0;
for (NSUInteger i = 0; i < Capacity; i++) {
@@ -717,6 +718,8 @@ - (NSUInteger)count
}
}
return aCnt;
+ */
+ return count;
}
- (NSInteger) size
@@ -1127,7 +1130,8 @@ - (id) get:(NSString *)key
{
if (key == nil)
return [self getForNullKey];
- NSInteger hash = [self hashInt:[self hash:key]];
+ // NSInteger hash = [self hashInt:[self hash:key]];
+ NSInteger hash = [self hashInt:[key hash]];
for (HMEntry *e = (HMEntry *)ptrBuffer[[self indexFor:hash length:[self capacity]]]; e != nil; e = e.next) {
NSString *k;
@@ -1159,7 +1163,8 @@ - (BOOL) containsKey:(NSString *)key
*/
- (HMEntry *) getEntry:(NSString *)key
{
- NSInteger hash = (key == nil) ? 0 : [self hashInt:[self hash:key]];
+ // NSInteger hash = (key == nil) ? 0 : [self hashInt:[self hash:key]];
+ NSInteger hash = (key == nil) ? 0 : [self hashInt:[key hash]];
for (HMEntry *e = (HMEntry *)ptrBuffer[[self indexFor:hash length:Capacity]]; e != nil; e = e.next) {
NSString *k;
@@ -1187,7 +1192,8 @@ - (id) put:(NSString *)key value:(id)value
{
if (key == nil)
return [self putForNullKey:value];
- NSInteger hash = [self hashInt:[self hash:key]];
+// NSInteger hash = [self hashInt:[self hash:key]];
+ NSInteger hash = [self hashInt:[key hash]];
NSInteger i = [self indexFor:hash length:[self capacity]];
for (HMEntry *e = (HMEntry *)ptrBuffer[i]; e != nil; e = e.next) {

0 comments on commit 69a5b0b

Please sign in to comment.