mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Implemented [hash] and [isEqual:] for NSHost and added some retain/release
macros to NSObject.h git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3197 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3e96691fc2
commit
5ac6523902
2 changed files with 59 additions and 0 deletions
|
@ -250,11 +250,38 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The OpenStep spec says that [-hash] must be the same for any two
|
||||
* objects that [-isEqual:] returns YES for. We have a problem in
|
||||
* that [-isEqualToHost:] is specified to return YES if any name or
|
||||
* address part of two hosts is the same. That means we can't
|
||||
* reasonably calculate a hash since two hosts with radically
|
||||
* different ivar contents may be 'equal'. The best I can think of
|
||||
* is for all hosts to hash to the same value - which makes it very
|
||||
* inefficient to store them in a set, dictionary, map or hash table.
|
||||
*/
|
||||
- (unsigned) hash
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)other
|
||||
{
|
||||
if (other == self)
|
||||
return YES;
|
||||
if ([other isKindOfClass: [NSHost class]])
|
||||
return [self isEqualToHost: (NSHost*)other];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isEqualToHost:(NSHost *)aHost
|
||||
{
|
||||
NSArray* a;
|
||||
int i;
|
||||
|
||||
if (aHost == self)
|
||||
return YES;
|
||||
|
||||
a = [aHost addresses];
|
||||
for (i = 0; i < [a count]; i++)
|
||||
if ([addresses containsObject:[a objectAtIndex:i]])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue