mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 15:30:38 +00:00
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:
parent
5fdeffdf69
commit
36de572f15
1 changed files with 30 additions and 4 deletions
|
@ -1891,14 +1891,22 @@ static NSRecursiveLock *namedColorLock = nil;
|
|||
return NSLocalizedString(_color_name, @"colour name");
|
||||
}
|
||||
|
||||
- (NSUInteger) hash
|
||||
{
|
||||
return [_catalog_name hash] + [_color_name hash];
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)other
|
||||
{
|
||||
/* Instances of this class are uniqued, so a test for pointer equality
|
||||
* is sufficient.
|
||||
*/
|
||||
if (other == self)
|
||||
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
|
||||
|
@ -2029,6 +2037,24 @@ static NSRecursiveLock *namedColorLock = nil;
|
|||
*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
|
||||
{
|
||||
if (other == self)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue