mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Implemented a bit more stuff and tidied some existing code.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18656 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3559990368
commit
6d8828396e
1 changed files with 115 additions and 52 deletions
|
@ -35,6 +35,7 @@
|
||||||
#include "GNUstepBase/GSIArray.h"
|
#include "GNUstepBase/GSIArray.h"
|
||||||
|
|
||||||
#define _array ((GSIArray)(self->_data))
|
#define _array ((GSIArray)(self->_data))
|
||||||
|
#define _other ((GSIArray)(aSet->_data))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the position in the array at which the index should be inserted.
|
* Returns the position in the array at which the index should be inserted.
|
||||||
|
@ -109,17 +110,15 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
||||||
- (BOOL) containsIndex: (unsigned int)anIndex
|
- (BOOL) containsIndex: (unsigned int)anIndex
|
||||||
{
|
{
|
||||||
unsigned pos;
|
unsigned pos;
|
||||||
|
NSRange r;
|
||||||
|
|
||||||
if (_array == 0 || GSIArrayCount(_array) == 0)
|
if (_array == 0 || GSIArrayCount(_array) == 0
|
||||||
|
|| (pos = posForIndex(_array, anIndex)) >= GSIArrayCount(_array))
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
pos = posForIndex(_array, anIndex);
|
r = GSIArrayItemAtIndex(_array, pos).ext;
|
||||||
if (pos >= GSIArrayCount(_array))
|
return NSLocationInRange(anIndex, r);
|
||||||
{
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
return NSLocationInRange(anIndex, GSIArrayItemAtIndex(_array, pos).ext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) containsIndexes: (NSIndexSet*)aSet
|
- (BOOL) containsIndexes: (NSIndexSet*)aSet
|
||||||
|
@ -135,8 +134,10 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
||||||
- (BOOL) containsIndexesInRange: (NSRange)aRange
|
- (BOOL) containsIndexesInRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
unsigned pos;
|
unsigned pos;
|
||||||
|
NSRange r;
|
||||||
|
|
||||||
if (_array == 0 || GSIArrayCount(_array) == 0)
|
if (_array == 0 || GSIArrayCount(_array) == 0
|
||||||
|
|| (pos = posForIndex(_array, aRange.location)) >= GSIArrayCount(_array))
|
||||||
{
|
{
|
||||||
return NO; // Empty ... contains no indexes.
|
return NO; // Empty ... contains no indexes.
|
||||||
}
|
}
|
||||||
|
@ -144,13 +145,9 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
||||||
{
|
{
|
||||||
return YES; // No indexes needed.
|
return YES; // No indexes needed.
|
||||||
}
|
}
|
||||||
pos = posForIndex(_array, aRange.location);
|
r = GSIArrayItemAtIndex(_array, pos).ext;
|
||||||
if (pos >= GSIArrayCount(_array))
|
if (NSLocationInRange(aRange.location, r)
|
||||||
{
|
&& NSLocationInRange(NSMaxRange(aRange)-1, r))
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
if (NSLocationInRange(aRange.location, GSIArrayItemAtIndex(_array, pos).ext)
|
|
||||||
&& NSLocationInRange(NSMaxRange(aRange)-1, GSIArrayItemAtIndex(_array, pos).ext))
|
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
@ -270,93 +267,105 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
||||||
- (unsigned int) indexGreaterThanIndex: (unsigned int)anIndex
|
- (unsigned int) indexGreaterThanIndex: (unsigned int)anIndex
|
||||||
{
|
{
|
||||||
unsigned pos;
|
unsigned pos;
|
||||||
|
NSRange r;
|
||||||
|
|
||||||
if (_array == 0 || GSIArrayCount(_array) == 0)
|
if (anIndex++ == NSNotFound)
|
||||||
{
|
{
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
}
|
}
|
||||||
pos = posForIndex(_array, anIndex + 1);
|
if (_array == 0 || GSIArrayCount(_array) == 0
|
||||||
if (pos >= GSIArrayCount(_array))
|
|| (pos = posForIndex(_array, anIndex)) >= GSIArrayCount(_array))
|
||||||
{
|
{
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
}
|
}
|
||||||
if (NSLocationInRange(anIndex + 1, GSIArrayItemAtIndex(_array, pos).ext))
|
r = GSIArrayItemAtIndex(_array, pos).ext;
|
||||||
|
if (NSLocationInRange(anIndex, r))
|
||||||
{
|
{
|
||||||
return anIndex + 1;
|
return anIndex;
|
||||||
}
|
}
|
||||||
return GSIArrayItemAtIndex(_array, pos+1).ext.location;
|
if (++pos >= GSIArrayCount(_array))
|
||||||
|
{
|
||||||
|
return NSNotFound;
|
||||||
|
}
|
||||||
|
r = GSIArrayItemAtIndex(_array, pos).ext;
|
||||||
|
return r.location;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned int) indexGreaterThanOrEqualToIndex: (unsigned int)anIndex
|
- (unsigned int) indexGreaterThanOrEqualToIndex: (unsigned int)anIndex
|
||||||
{
|
{
|
||||||
unsigned pos;
|
unsigned pos;
|
||||||
|
NSRange r;
|
||||||
|
|
||||||
if (_array == 0 || GSIArrayCount(_array) == 0)
|
if (anIndex == NSNotFound)
|
||||||
{
|
{
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
}
|
}
|
||||||
pos = posForIndex(_array, anIndex);
|
if (_array == 0 || GSIArrayCount(_array) == 0
|
||||||
if (pos >= GSIArrayCount(_array))
|
|| (pos = posForIndex(_array, anIndex)) >= GSIArrayCount(_array))
|
||||||
{
|
{
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
}
|
}
|
||||||
if (NSLocationInRange(anIndex, GSIArrayItemAtIndex(_array, pos).ext))
|
r = GSIArrayItemAtIndex(_array, pos).ext;
|
||||||
|
if (NSLocationInRange(anIndex, r))
|
||||||
{
|
{
|
||||||
return anIndex;
|
return anIndex;
|
||||||
}
|
}
|
||||||
return GSIArrayItemAtIndex(_array, pos+1).ext.location;
|
if (++pos >= GSIArrayCount(_array))
|
||||||
|
{
|
||||||
|
return NSNotFound;
|
||||||
|
}
|
||||||
|
r = GSIArrayItemAtIndex(_array, pos).ext;
|
||||||
|
return r.location;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned int) indexLessThanIndex: (unsigned int)anIndex
|
- (unsigned int) indexLessThanIndex: (unsigned int)anIndex
|
||||||
{
|
{
|
||||||
unsigned pos;
|
unsigned pos;
|
||||||
|
NSRange r;
|
||||||
|
|
||||||
if (anIndex == 0)
|
if (anIndex-- == 0)
|
||||||
{
|
{
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
}
|
}
|
||||||
if (_array == 0 || GSIArrayCount(_array) == 0)
|
if (_array == 0 || GSIArrayCount(_array) == 0
|
||||||
|
|| (pos = posForIndex(_array, anIndex)) >= GSIArrayCount(_array))
|
||||||
{
|
{
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
}
|
}
|
||||||
pos = posForIndex(_array, anIndex - 1);
|
r = GSIArrayItemAtIndex(_array, pos).ext;
|
||||||
if (pos >= GSIArrayCount(_array))
|
if (NSLocationInRange(anIndex, r))
|
||||||
|
{
|
||||||
|
return anIndex;
|
||||||
|
}
|
||||||
|
if (pos-- == 0)
|
||||||
{
|
{
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
}
|
}
|
||||||
if (NSLocationInRange(anIndex - 1, GSIArrayItemAtIndex(_array, pos).ext))
|
r = GSIArrayItemAtIndex(_array, pos).ext;
|
||||||
{
|
return NSMaxRange(r) - 1;
|
||||||
return anIndex - 1;
|
|
||||||
}
|
|
||||||
if (pos == 0)
|
|
||||||
{
|
|
||||||
return NSNotFound;
|
|
||||||
}
|
|
||||||
return NSMaxRange(GSIArrayItemAtIndex(_array, pos).ext) - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned int) indexLessThanOrEqualToIndex: (unsigned int)anIndex
|
- (unsigned int) indexLessThanOrEqualToIndex: (unsigned int)anIndex
|
||||||
{
|
{
|
||||||
unsigned pos;
|
unsigned pos;
|
||||||
|
NSRange r;
|
||||||
|
|
||||||
if (_array == 0 || GSIArrayCount(_array) == 0)
|
if (_array == 0 || GSIArrayCount(_array) == 0
|
||||||
|
|| (pos = posForIndex(_array, anIndex)) >= GSIArrayCount(_array))
|
||||||
{
|
{
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
}
|
}
|
||||||
pos = posForIndex(_array, anIndex);
|
r = GSIArrayItemAtIndex(_array, pos).ext;
|
||||||
if (pos >= GSIArrayCount(_array))
|
if (NSLocationInRange(anIndex, r))
|
||||||
{
|
|
||||||
return NSNotFound;
|
|
||||||
}
|
|
||||||
if (NSLocationInRange(anIndex, GSIArrayItemAtIndex(_array, pos).ext))
|
|
||||||
{
|
{
|
||||||
return anIndex;
|
return anIndex;
|
||||||
}
|
}
|
||||||
if (pos == 0)
|
if (pos-- == 0)
|
||||||
{
|
{
|
||||||
return NSNotFound;
|
return NSNotFound;
|
||||||
}
|
}
|
||||||
return NSMaxRange(GSIArrayItemAtIndex(_array, pos).ext) - 1;
|
r = GSIArrayItemAtIndex(_array, pos).ext;
|
||||||
|
return NSMaxRange(r) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
|
@ -403,7 +412,26 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
||||||
|
|
||||||
- (id) initWithIndexSet: (NSIndexSet*)aSet
|
- (id) initWithIndexSet: (NSIndexSet*)aSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
if (aSet == nil || [aSet isKindOfClass: [NSIndexSet class]] == NO)
|
||||||
|
{
|
||||||
|
DESTROY(self);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unsigned count = GSIArrayCount(_other);
|
||||||
|
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
_array = (GSIArray)NSZoneMalloc([self zone], sizeof(GSIArray_t));
|
||||||
|
GSIArrayInitWithZoneAndCapacity(_array, [self zone], count);
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
GSIArrayAddItem(_array, GSIArrayItemAtIndex(_other, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,8 +477,28 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
||||||
|
|
||||||
- (BOOL) isEqualToIndexSet: (NSIndexSet*)aSet
|
- (BOOL) isEqualToIndexSet: (NSIndexSet*)aSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
unsigned count = GSIArrayCount(_other);
|
||||||
return NO;
|
|
||||||
|
if (count != GSIArrayCount(_array))
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
NSRange rself = GSIArrayItemAtIndex(_array, i).ext;
|
||||||
|
NSRange rother = GSIArrayItemAtIndex(_other, i).ext;
|
||||||
|
|
||||||
|
if (NSEqualRanges(rself, rother) == NO)
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned int) lastIndex
|
- (unsigned int) lastIndex
|
||||||
|
@ -474,6 +522,9 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
||||||
|
|
||||||
@implementation NSMutableIndexSet
|
@implementation NSMutableIndexSet
|
||||||
|
|
||||||
|
#undef _other
|
||||||
|
#define _other ((GSIArray)(((NSMutableIndexSet*)aSet)->_data))
|
||||||
|
|
||||||
- (void) addIndex: (unsigned int)anIndex
|
- (void) addIndex: (unsigned int)anIndex
|
||||||
{
|
{
|
||||||
[self addIndexesInRange: NSMakeRange(anIndex, 1)];
|
[self addIndexesInRange: NSMakeRange(anIndex, 1)];
|
||||||
|
@ -481,7 +532,19 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
||||||
|
|
||||||
- (void) addIndexes: (NSIndexSet*)aSet
|
- (void) addIndexes: (NSIndexSet*)aSet
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
unsigned count = GSIArrayCount(_other);
|
||||||
|
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
NSRange r = GSIArrayItemAtIndex(_other, i).ext;
|
||||||
|
|
||||||
|
[self addIndexesInRange: r];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) addIndexesInRange: (NSRange)aRange
|
- (void) addIndexesInRange: (NSRange)aRange
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue