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

@ -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