mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Implement more methods
This commit is contained in:
parent
f45a231211
commit
09bae157fe
2 changed files with 93 additions and 2 deletions
|
@ -181,7 +181,7 @@ extern "C" {
|
||||||
- (void)removeObjectAtIndex:(NSUInteger)integer;
|
- (void)removeObjectAtIndex:(NSUInteger)integer;
|
||||||
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes;
|
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes;
|
||||||
- (void)removeObjectsInArray:(GS_GENERIC_CLASS(NSArray, ElementT)*)otherArray;
|
- (void)removeObjectsInArray:(GS_GENERIC_CLASS(NSArray, ElementT)*)otherArray;
|
||||||
- (void)removeObjectsInRange:(NSRange *)range;
|
- (void)removeObjectsInRange:(NSRange)range;
|
||||||
- (void)removeAllObjects;
|
- (void)removeAllObjects;
|
||||||
- (void)replaceObjectAtIndex:(NSUInteger)index
|
- (void)replaceObjectAtIndex:(NSUInteger)index
|
||||||
withObject:(GS_GENERIC_TYPE(ElementT))object;
|
withObject:(GS_GENERIC_TYPE(ElementT))object;
|
||||||
|
|
|
@ -971,16 +971,107 @@ static SEL rlSel;
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) _removeObjectsFromIndices: (NSUInteger*)indices
|
||||||
|
numIndices: (NSUInteger)count
|
||||||
|
{
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
NSUInteger to = 0;
|
||||||
|
NSUInteger from = 0;
|
||||||
|
NSUInteger i;
|
||||||
|
GS_BEGINITEMBUF(sorted, count, NSUInteger);
|
||||||
|
|
||||||
|
while (from < count)
|
||||||
|
{
|
||||||
|
NSUInteger val = indices[from++];
|
||||||
|
|
||||||
|
i = to;
|
||||||
|
while (i > 0 && sorted[i-1] > val)
|
||||||
|
{
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
if (i == to)
|
||||||
|
{
|
||||||
|
sorted[to++] = val;
|
||||||
|
}
|
||||||
|
else if (sorted[i] != val)
|
||||||
|
{
|
||||||
|
NSUInteger j = to++;
|
||||||
|
|
||||||
|
if (sorted[i] < val)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (j > i)
|
||||||
|
{
|
||||||
|
sorted[j] = sorted[j-1];
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
sorted[i] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (to > 0)
|
||||||
|
{
|
||||||
|
IMP rem = [self methodForSelector: remSel];
|
||||||
|
|
||||||
|
while (to--)
|
||||||
|
{
|
||||||
|
(*rem)(self, remSel, sorted[to]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GS_ENDITEMBUF();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes
|
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes
|
||||||
{
|
{
|
||||||
|
NSUInteger count = [indexes count];
|
||||||
|
NSUInteger indexArray[count];
|
||||||
|
|
||||||
|
[indexes getIndexes: indexArray
|
||||||
|
maxCount: count
|
||||||
|
inIndexRange: NULL];
|
||||||
|
|
||||||
|
[self _removeObjectsFromIndices: indexArray
|
||||||
|
numIndices: count];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeObjectsInArray:(NSArray *)otherArray
|
- (void)removeObjectsInArray:(NSArray *)otherArray
|
||||||
{
|
{
|
||||||
|
NSUInteger c = [otherArray count];
|
||||||
|
|
||||||
|
if (c > 0)
|
||||||
|
{
|
||||||
|
NSUInteger i;
|
||||||
|
IMP get = [otherArray methodForSelector: oaiSel];
|
||||||
|
IMP rem = [self methodForSelector: @selector(removeObject:)];
|
||||||
|
|
||||||
|
for (i = 0; i < c; i++)
|
||||||
|
(*rem)(self, @selector(removeObject:), (*get)(otherArray, oaiSel, i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeObjectsInRange:(NSRange *)range
|
- (void)removeObjectsInRange:(NSRange)aRange
|
||||||
{
|
{
|
||||||
|
NSUInteger i;
|
||||||
|
NSUInteger s = aRange.location;
|
||||||
|
NSUInteger c = [self count];
|
||||||
|
|
||||||
|
i = aRange.location + aRange.length;
|
||||||
|
|
||||||
|
if (c < i)
|
||||||
|
i = c;
|
||||||
|
|
||||||
|
if (i > s)
|
||||||
|
{
|
||||||
|
IMP rem = [self methodForSelector: remSel];
|
||||||
|
|
||||||
|
while (i-- > s)
|
||||||
|
{
|
||||||
|
(*rem)(self, remSel, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeAllObjects
|
- (void)removeAllObjects
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue