mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
Fix for hash to match isEqual
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23966 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3481a3d002
commit
f03d22e63f
1 changed files with 24 additions and 19 deletions
|
@ -123,7 +123,12 @@
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
if (!sel_eq(((NSSortDescriptor*)other)->_selector, _selector))
|
/* FIXME ... we should use sel_eq to compare selectors, but if we do
|
||||||
|
* our implementation of -hash will be wrong ... so we will need to
|
||||||
|
* store all instances in a set to ensure uniqueness.
|
||||||
|
*/
|
||||||
|
// if (!sel_eq(((NSSortDescriptor*)other)->_selector, _selector))
|
||||||
|
if (((NSSortDescriptor*)other)->_selector != _selector)
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
@ -202,15 +207,15 @@ SwapObjects(id * o1, id * o2)
|
||||||
*/
|
*/
|
||||||
// Quicksort algorithm copied from Wikipedia :-).
|
// Quicksort algorithm copied from Wikipedia :-).
|
||||||
static void
|
static void
|
||||||
SortObjectsWithDescriptor(id * objects,
|
SortObjectsWithDescriptor(id *objects,
|
||||||
NSRange sortRange,
|
NSRange sortRange,
|
||||||
NSSortDescriptor * sortDescriptor)
|
NSSortDescriptor *sortDescriptor)
|
||||||
{
|
{
|
||||||
if (sortRange.length > 1)
|
if (sortRange.length > 1)
|
||||||
{
|
{
|
||||||
id pivot = objects[sortRange.location];
|
id pivot = objects[sortRange.location];
|
||||||
unsigned int left = sortRange.location + 1,
|
unsigned int left = sortRange.location + 1;
|
||||||
right = NSMaxRange(sortRange);
|
unsigned int right = NSMaxRange(sortRange);
|
||||||
|
|
||||||
while (left < right)
|
while (left < right)
|
||||||
{
|
{
|
||||||
|
@ -242,14 +247,14 @@ SortObjectsWithDescriptor(id * objects,
|
||||||
* A pointer to the new location of the array of ranges is returned.
|
* A pointer to the new location of the array of ranges is returned.
|
||||||
*/
|
*/
|
||||||
static NSRange *
|
static NSRange *
|
||||||
FindEqualityRanges(id * objects,
|
FindEqualityRanges(id *objects,
|
||||||
NSRange searchRange,
|
NSRange searchRange,
|
||||||
NSSortDescriptor * sortDescriptor,
|
NSSortDescriptor *sortDescriptor,
|
||||||
NSRange * ranges,
|
NSRange *ranges,
|
||||||
unsigned int * numRanges)
|
unsigned int *numRanges)
|
||||||
{
|
{
|
||||||
unsigned int i = searchRange.location,
|
unsigned int i = searchRange.location;
|
||||||
n = NSMaxRange(searchRange);
|
unsigned int n = NSMaxRange(searchRange);
|
||||||
|
|
||||||
if (n > 1)
|
if (n > 1)
|
||||||
{
|
{
|
||||||
|
@ -257,7 +262,7 @@ FindEqualityRanges(id * objects,
|
||||||
{
|
{
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
|
|
||||||
for (j=i + 1;
|
for (j = i + 1;
|
||||||
j < n &&
|
j < n &&
|
||||||
[sortDescriptor compareObject: objects[i] toObject: objects[j]]
|
[sortDescriptor compareObject: objects[i] toObject: objects[j]]
|
||||||
== NSOrderedSame;
|
== NSOrderedSame;
|
||||||
|
@ -311,10 +316,10 @@ FindEqualityRanges(id * objects,
|
||||||
*/
|
*/
|
||||||
- (void) sortUsingDescriptors: (NSArray *) sortDescriptors
|
- (void) sortUsingDescriptors: (NSArray *) sortDescriptors
|
||||||
{
|
{
|
||||||
id * objects;
|
id *objects;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
|
|
||||||
NSRange * equalityRanges;
|
NSRange *equalityRanges;
|
||||||
unsigned int numEqualityRanges;
|
unsigned int numEqualityRanges;
|
||||||
|
|
||||||
unsigned int i, n;
|
unsigned int i, n;
|
||||||
|
@ -328,13 +333,13 @@ FindEqualityRanges(id * objects,
|
||||||
equalityRanges[0].length = count;
|
equalityRanges[0].length = count;
|
||||||
numEqualityRanges = 1;
|
numEqualityRanges = 1;
|
||||||
|
|
||||||
for (i=0, n = [sortDescriptors count]; i < n && equalityRanges != NULL; i++)
|
for (i = 0, n = [sortDescriptors count]; i < n && equalityRanges != NULL; i++)
|
||||||
{
|
{
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
NSSortDescriptor * sortDescriptor = [sortDescriptors objectAtIndex: i];
|
NSSortDescriptor *sortDescriptor = [sortDescriptors objectAtIndex: i];
|
||||||
|
|
||||||
// pass through all equality ranges and sort each of them
|
// pass through all equality ranges and sort each of them
|
||||||
for (j=0; j < numEqualityRanges; j++)
|
for (j = 0; j < numEqualityRanges; j++)
|
||||||
{
|
{
|
||||||
SortObjectsWithDescriptor(objects, equalityRanges[j],
|
SortObjectsWithDescriptor(objects, equalityRanges[j],
|
||||||
sortDescriptor);
|
sortDescriptor);
|
||||||
|
@ -344,11 +349,11 @@ FindEqualityRanges(id * objects,
|
||||||
if (i < n - 1)
|
if (i < n - 1)
|
||||||
// reconstruct the equality ranges anew.
|
// reconstruct the equality ranges anew.
|
||||||
{
|
{
|
||||||
NSRange * newRanges = NULL;
|
NSRange *newRanges = NULL;
|
||||||
unsigned newNumRanges = 0;
|
unsigned newNumRanges = 0;
|
||||||
|
|
||||||
// process only contents of old equality ranges
|
// process only contents of old equality ranges
|
||||||
for (j=0; j < numEqualityRanges; j++)
|
for (j = 0; j < numEqualityRanges; j++)
|
||||||
{
|
{
|
||||||
newRanges = FindEqualityRanges(objects, equalityRanges[j],
|
newRanges = FindEqualityRanges(objects, equalityRanges[j],
|
||||||
sortDescriptor, newRanges, &newNumRanges);
|
sortDescriptor, newRanges, &newNumRanges);
|
||||||
|
|
Loading…
Reference in a new issue