add a couple of hash implementations... need more

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28810 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-10-12 15:23:24 +00:00
parent 5fdeffdf69
commit 36de572f15

View file

@ -1891,14 +1891,22 @@ static NSRecursiveLock *namedColorLock = nil;
return NSLocalizedString(_color_name, @"colour name"); return NSLocalizedString(_color_name, @"colour name");
} }
- (NSUInteger) hash
{
return [_catalog_name hash] + [_color_name hash];
}
- (BOOL) isEqual: (id)other - (BOOL) isEqual: (id)other
{ {
/* Instances of this class are uniqued, so a test for pointer equality
* is sufficient.
*/
if (other == self) if (other == self)
return YES; return YES;
return NO; if ([other isKindOfClass: [self class]] == NO
|| [[other catalogNameComponent] isEqualToString: _catalog_name] == NO
|| [[other colorNameComponent] isEqualToString: _color_name] == NO)
{
return NO;
}
return YES;
} }
- (NSColor*) colorUsingColorSpaceName: (NSString *)colorSpace - (NSColor*) colorUsingColorSpaceName: (NSString *)colorSpace
@ -2029,6 +2037,24 @@ static NSRecursiveLock *namedColorLock = nil;
*alpha = _alpha_component; *alpha = _alpha_component;
} }
- (NSUInteger) hash
{
union {
uint8_t bytes[sizeof(float)*2];
float floats[2];
} u;
NSUInteger h = 0;
unsigned i;
u.floats[0] = _white_component;
u.floats[1] = _alpha_component;
for (i = 0; i < sizeof(u); i++)
{
h = (h << 5) + h + u.bytes[i];
}
return h;
}
- (BOOL) isEqual: (id)other - (BOOL) isEqual: (id)other
{ {
if (other == self) if (other == self)