Bugfix in array - use insertion sort to make sure we delete objects at indices

correctly.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3723 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-02-16 16:08:59 +00:00
parent 8e5e283ba6
commit 0971f55ab2
3 changed files with 46 additions and 3 deletions

View file

@ -1,3 +1,9 @@
Tue Feb 16 15:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSArray.m: ([-removeObjectsFromIndices:]) rewrite to
work according to spec.
* Testing/nsarray.m: Fixed check on joining strings.
Mon Feb 15 06:14:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/include/NSDebug.h: Declare strerror() if not known to system

View file

@ -911,8 +911,45 @@ static NSString *indentStrings[] = {
- (void) removeObjectsFromIndices: (unsigned*)indices
numIndices: (unsigned)count
{
while (count--)
[self removeObjectAtIndex:indices[count]];
if (count > 0)
{
unsigned sorted[count];
unsigned to = 0;
unsigned from = 0;
unsigned i;
while (from < count)
{
unsigned val = indices[from++];
i = to;
while (i > 0 && sorted[i] > val)
{
i--;
}
if (i == to)
{
sorted[to++] = val;
}
else if (sorted[i] < val)
{
unsigned j = to++;
i++;
while (j > i)
{
sorted[j] = sorted[j-1];
j--;
}
sorted[i] = val;
}
}
while (to--)
{
[self removeObjectAtIndex: indices[to]];
}
}
}
- (void) removeObjectsInArray: (NSArray*)otherArray

View file

@ -185,7 +185,7 @@ main()
// Joining string elements
printf("Method: -componentsJoinedByString:\n");
i = [c componentsJoinedByString: @"/"];
if ([i isEqual: @"NSObject/NSArray/NSMutableArray"])
if ([i isEqual: @"<NSObject>/<NSArray>/<NSMutableArray>"])
printf("%s is correct\n", [i cString]);
else
{