mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Implement some hash methods
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4400 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
27118f1f54
commit
c1356f021c
3 changed files with 81 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
Sat Jun 12 10:25:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSConcreteValue.m: Implemented [hash and isEqualToValue
|
||||
* Source/NSCTemplateValue.m: Implemented hash
|
||||
|
||||
Thu Jun 4 13:55:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSCharacterSet.m: prepare for GC
|
||||
|
|
|
@ -120,6 +120,54 @@
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (unsigned) hash
|
||||
{
|
||||
#if TYPE_ORDER == 0
|
||||
return [data hash];
|
||||
#elif TYPE_ORDER == 1
|
||||
union {
|
||||
double d;
|
||||
unsigned char c[sizeof(double)];
|
||||
} val;
|
||||
unsigned hash = 0;
|
||||
int i;
|
||||
|
||||
val.d = data.x + data.y;
|
||||
for (i = 0; i < sizeof(double); i++) {
|
||||
hash += val.c[i];
|
||||
}
|
||||
return hash;
|
||||
#elif TYPE_ORDER == 2
|
||||
return (unsigned)(gsaddr)data;
|
||||
#elif TYPE_ORDER == 3
|
||||
union {
|
||||
double d;
|
||||
unsigned char c[sizeof(double)];
|
||||
} val;
|
||||
unsigned hash = 0;
|
||||
int i;
|
||||
|
||||
val.d = data.origin.x + data.origin.y + data.size.width + data.size.height;
|
||||
for (i = 0; i < sizeof(double); i++) {
|
||||
hash += val.c[i];
|
||||
}
|
||||
return hash;
|
||||
#elif TYPE_ORDER == 4
|
||||
union {
|
||||
double d;
|
||||
unsigned char c[sizeof(double)];
|
||||
} val;
|
||||
unsigned hash = 0;
|
||||
int i;
|
||||
|
||||
val.d = data.width + data.height;
|
||||
for (i = 0; i < sizeof(double); i++) {
|
||||
hash += val.c[i];
|
||||
}
|
||||
return hash;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (const char *)objCType
|
||||
{
|
||||
typedef _dt = data;
|
||||
|
|
|
@ -113,9 +113,36 @@
|
|||
memcpy( value, data, objc_sizeof_type([objctype cString]) );
|
||||
}
|
||||
|
||||
-(BOOL) isEqualToValue: (NSValue*)aValue
|
||||
- (unsigned) hash
|
||||
{
|
||||
const char* type = [objctype cString];
|
||||
unsigned size = objc_sizeof_type(type);
|
||||
unsigned hash = 0;
|
||||
|
||||
while (size-- > 0)
|
||||
hash += ((unsigned char*)data)[size];
|
||||
return hash;
|
||||
}
|
||||
|
||||
- (BOOL) isEqualToValue: (NSValue*)aValue
|
||||
{
|
||||
const char* type;
|
||||
|
||||
if ([aValue class] != [self class])
|
||||
return NO;
|
||||
type = [objctype cString];
|
||||
if (strcmp(type, [aValue objCType]) != 0)
|
||||
return NO;
|
||||
else
|
||||
{
|
||||
unsigned size = objc_sizeof_type(type);
|
||||
char buf[size];
|
||||
|
||||
[aValue getValue: buf];
|
||||
if (memcmp(buf, data, size) != 0)
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (const char *)objCType
|
||||
|
|
Loading…
Reference in a new issue