mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 01:31:08 +00:00
([LinkedList -insertObject:after:]): When inserting first object, set
_count to 1. ([LinkedList -insertObject:before:]): Likewise. ([LinkedList -appendObject:]): Don't claim ownership here if we're going to call -insertObject:after: later. ([LinkedList -prependObject:]): Likewise. And renamed from prependElement. ([LinkedList -insertObject:atIndex:]): Likewise. ([LinkedList -newEnumState]): New method. ([LinkedList -nextObjectWithEnumState:]): Overhauled. ([LinkedList -prevObjectWithEnumState:]): Likewise. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1044 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8e74895739
commit
bf4fd7952b
1 changed files with 38 additions and 29 deletions
|
@ -138,6 +138,7 @@
|
|||
{
|
||||
_first_link = newObject;
|
||||
_last_link = newObject;
|
||||
_count = 1;
|
||||
[newObject setNextLink: NO_OBJECT];
|
||||
[newObject setPrevLink: NO_OBJECT];
|
||||
}
|
||||
|
@ -170,6 +171,7 @@
|
|||
{
|
||||
_first_link = newObject;
|
||||
_last_link = newObject;
|
||||
_count = 1;
|
||||
[newObject setNextLink: NO_OBJECT];
|
||||
[newObject setPrevLink: NO_OBJECT];
|
||||
}
|
||||
|
@ -220,15 +222,17 @@
|
|||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setLinkedList: self];
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
/* Put it in as the only node. */
|
||||
_first_link = newObject;
|
||||
_last_link = newObject;
|
||||
_count = 1;
|
||||
[newObject setNextLink: NO_OBJECT];
|
||||
[newObject setPrevLink: NO_OBJECT];
|
||||
}
|
||||
|
@ -236,20 +240,22 @@
|
|||
[self insertObject: newObject after: _last_link];
|
||||
}
|
||||
|
||||
- prependElement: newObject
|
||||
- prependObject: newObject
|
||||
{
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setLinkedList: self];
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
/* Put it in as the only node. */
|
||||
_first_link = newObject;
|
||||
_last_link = newObject;
|
||||
_count = 1;
|
||||
[newObject setNextLink: NO_OBJECT];
|
||||
[newObject setPrevLink: NO_OBJECT];
|
||||
}
|
||||
|
@ -257,22 +263,24 @@
|
|||
[self insertObject: newObject before: _first_link];
|
||||
}
|
||||
|
||||
- insertElement: newObject atIndex: (unsigned)index
|
||||
- insertObject: newObject atIndex: (unsigned)index
|
||||
{
|
||||
CHECK_INDEX_RANGE_ERROR(index, (_count+1));
|
||||
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setLinkedList: self];
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
/* Put it in as the only node. */
|
||||
_first_link = newObject;
|
||||
_last_link = newObject;
|
||||
_count = 1;
|
||||
[newObject setNextLink: NO_OBJECT];
|
||||
[newObject setPrevLink: NO_OBJECT];
|
||||
}
|
||||
|
@ -334,31 +342,32 @@
|
|||
return [oldObject prevLink];
|
||||
}
|
||||
|
||||
- (void*) newEnumState
|
||||
{
|
||||
return _first_link;
|
||||
}
|
||||
|
||||
- nextObjectWithEnumState: (void**)enumState
|
||||
{
|
||||
/* *enumState points to the next object to be returned. */
|
||||
id ret;
|
||||
|
||||
if (*enumState == _first_link)
|
||||
return NO_OBJECT;
|
||||
else if (!(*enumState))
|
||||
*enumState = _first_link;
|
||||
ret = (id) *enumState;
|
||||
if (!*enumState)
|
||||
return nil;
|
||||
ret = *enumState;
|
||||
*enumState = [(id)(*enumState) nextLink];
|
||||
/* *enumState points to the next object to be returned. */
|
||||
return ret;
|
||||
}
|
||||
|
||||
- prevObjectWithEnumState: (void**)enumState
|
||||
{
|
||||
id ret;
|
||||
|
||||
if (*enumState == _last_link)
|
||||
return NO_OBJECT;
|
||||
else if (!(*enumState))
|
||||
*enumState = _last_link;
|
||||
ret = (id) *enumState;
|
||||
*enumState = [(id)(*enumState) prevLink];
|
||||
return ret;
|
||||
/* *enumState points to the object returned last time. */
|
||||
if (!*enumState)
|
||||
return nil;
|
||||
if (*enumState == _first_link)
|
||||
/* enumState was just initialized from -newEnumState. */
|
||||
return *enumState = _last_link;
|
||||
return (id) *enumState = [(id)(*enumState) prevLink];
|
||||
}
|
||||
|
||||
- (unsigned) count
|
||||
|
|
Loading…
Reference in a new issue