1994-11-04 16:29:24 +00:00
|
|
|
|
/* Implementation for Objective-C LinkedList collection object
|
1996-02-22 15:11:43 +00:00
|
|
|
|
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
Date: May 1993
|
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
|
#include <config.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
|
#include <base/LinkedList.h>
|
|
|
|
|
#include <base/IndexedCollectionPrivate.h>
|
|
|
|
|
#include <base/Coder.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
@implementation LinkedList
|
|
|
|
|
|
|
|
|
|
/* This is the designated initializer of this class */
|
|
|
|
|
- init
|
|
|
|
|
{
|
|
|
|
|
_count = 0;
|
|
|
|
|
_first_link = nil;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
_last_link = nil;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- initWithObjects: (id*)objs count: (unsigned)c
|
|
|
|
|
{
|
|
|
|
|
[self init];
|
|
|
|
|
while (c--)
|
|
|
|
|
[self prependObject: objs[c]];
|
1996-03-18 13:51:44 +00:00
|
|
|
|
return self;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
/* Archiving must mimic the above designated initializer */
|
|
|
|
|
|
1996-04-14 16:00:07 +00:00
|
|
|
|
- (void) encodeWithCoder: coder
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-04-14 16:00:07 +00:00
|
|
|
|
id l;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-04-14 16:00:07 +00:00
|
|
|
|
[super encodeWithCoder: coder];
|
|
|
|
|
[coder encodeValueOfCType: @encode (typeof (_count))
|
|
|
|
|
at: &_count
|
|
|
|
|
withName: @"LinkedList count"];
|
|
|
|
|
FOR_COLLECTION (self, l)
|
|
|
|
|
{
|
|
|
|
|
[coder encodeObject: l
|
|
|
|
|
withName: @"LinkedList element"];
|
|
|
|
|
}
|
|
|
|
|
END_FOR_COLLECTION (self);
|
|
|
|
|
[coder encodeObjectReference: _first_link
|
|
|
|
|
withName: @"LinkedList first link"];
|
|
|
|
|
[coder encodeObjectReference: _last_link
|
|
|
|
|
withName: @"LinkedList last link"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-04-14 16:00:07 +00:00
|
|
|
|
- initWithCoder: coder
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-04-14 16:00:07 +00:00
|
|
|
|
int i;
|
|
|
|
|
// id link;
|
|
|
|
|
|
|
|
|
|
self = [super initWithCoder: coder];
|
|
|
|
|
[coder decodeValueOfCType: @encode (typeof (_count))
|
|
|
|
|
at: &_count
|
|
|
|
|
withName: NULL];
|
|
|
|
|
/* We don't really care about storing the elements decoded, because
|
|
|
|
|
we access them through their own link pointers. */
|
|
|
|
|
for (i = 0; i < _count; i++)
|
|
|
|
|
[coder decodeObjectAt: NULL
|
|
|
|
|
withName: NULL];
|
|
|
|
|
[coder decodeObjectAt: &_first_link
|
|
|
|
|
withName: NULL];
|
|
|
|
|
[coder decodeObjectAt: &_last_link
|
|
|
|
|
withName: NULL];
|
|
|
|
|
#if 0
|
|
|
|
|
/* xxx Not necessary, since the links encode this?
|
|
|
|
|
But should we rely on the links encoding this?
|
|
|
|
|
BUT! Look out: the next link pointers may not be set until
|
|
|
|
|
the last finishDecoding... method is run... */
|
|
|
|
|
FOR_COLLECTION (self, link)
|
1996-04-12 21:10:15 +00:00
|
|
|
|
{
|
1996-04-14 16:00:07 +00:00
|
|
|
|
[link setLinkedList: self];
|
1996-04-12 21:10:15 +00:00
|
|
|
|
}
|
|
|
|
|
END_FOR_COLLECTION (self);
|
1996-04-14 16:00:07 +00:00
|
|
|
|
#endif
|
|
|
|
|
return self;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Empty copy must empty an allocCopy'ed version of self */
|
|
|
|
|
- emptyCopy
|
|
|
|
|
{
|
|
|
|
|
LinkedList *copy = [super emptyCopy];
|
|
|
|
|
copy->_first_link = nil;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
copy->_last_link = nil;
|
|
|
|
|
copy->_count = 0;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This must work without sending any messages to content objects */
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- (void) _empty
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
_count = 0;
|
|
|
|
|
_first_link = nil;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
_last_link = nil;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* These next four methods are the only ones that change the values of
|
|
|
|
|
the instance variables _count, _first_link, except for
|
1996-02-22 15:11:43 +00:00
|
|
|
|
"-init". */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- (void) removeObject: oldObject
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([oldObject linkedList] == self, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
if (_first_link == oldObject)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (_count > 1)
|
1996-02-22 15:11:43 +00:00
|
|
|
|
_first_link = [oldObject nextLink];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
else
|
|
|
|
|
_first_link = nil;
|
|
|
|
|
}
|
1996-02-22 15:11:43 +00:00
|
|
|
|
else
|
|
|
|
|
[[oldObject prevLink] setNextLink:[oldObject nextLink]];
|
|
|
|
|
if (_last_link == oldObject)
|
|
|
|
|
{
|
|
|
|
|
if (_count > 1)
|
|
|
|
|
_last_link = [oldObject prevLink];
|
|
|
|
|
else
|
|
|
|
|
_first_link = nil;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
[[oldObject nextLink] setPrevLink:[oldObject prevLink]];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
_count--;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
[oldObject setNextLink: NO_OBJECT];
|
|
|
|
|
[oldObject setPrevLink: NO_OBJECT];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
[oldObject setLinkedList: NO_OBJECT];
|
1996-02-22 15:11:43 +00:00
|
|
|
|
[oldObject release];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- (void) insertObject: newObject after: oldObject
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
/* Make sure we actually own the oldObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([oldObject linkedList] == self, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure no one else already owns the newObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([newObject linkedList] == NO_OBJECT, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
/* Claim ownership of the newObject. */
|
|
|
|
|
[newObject retain];
|
|
|
|
|
[newObject setLinkedList: self];
|
|
|
|
|
|
|
|
|
|
/* Insert it. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if (_count == 0)
|
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
_first_link = newObject;
|
|
|
|
|
_last_link = newObject;
|
1996-03-03 01:36:41 +00:00
|
|
|
|
_count = 1;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
[newObject setNextLink: NO_OBJECT];
|
|
|
|
|
[newObject setPrevLink: NO_OBJECT];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
if (oldObject == _last_link)
|
|
|
|
|
_last_link = newObject;
|
|
|
|
|
[newObject setNextLink: [oldObject nextLink]];
|
|
|
|
|
[newObject setPrevLink: oldObject];
|
|
|
|
|
[[oldObject nextLink] setPrevLink: newObject];
|
|
|
|
|
[oldObject setNextLink: newObject];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
_count++;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- (void) insertObject: newObject before: oldObject
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
/* Make sure we actually own the oldObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([oldObject linkedList] == self, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure no one else already owns the newObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([newObject linkedList] == NO_OBJECT, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
/* Claim ownership of the newObject. */
|
|
|
|
|
[newObject retain];
|
|
|
|
|
[newObject setLinkedList: self];
|
|
|
|
|
|
|
|
|
|
/* Insert it. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if (_count == 0)
|
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
_first_link = newObject;
|
|
|
|
|
_last_link = newObject;
|
1996-03-03 01:36:41 +00:00
|
|
|
|
_count = 1;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
[newObject setNextLink: NO_OBJECT];
|
|
|
|
|
[newObject setPrevLink: NO_OBJECT];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
if (oldObject == _first_link)
|
|
|
|
|
_first_link = newObject;
|
|
|
|
|
[newObject setPrevLink: [oldObject prevLink]];
|
|
|
|
|
[newObject setNextLink: oldObject];
|
|
|
|
|
[[oldObject prevLink] setNextLink: newObject];
|
|
|
|
|
[oldObject setPrevLink: newObject];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
_count++;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- (void) replaceObject: oldObject with: newObject
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
/* Make sure we actually own the oldObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([oldObject linkedList] == self, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure no one else already owns the newObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([newObject linkedList] == NO_OBJECT, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
/* Claim ownership of the newObject. */
|
|
|
|
|
[newObject retain];
|
|
|
|
|
[newObject setLinkedList: self];
|
|
|
|
|
|
|
|
|
|
/* Do the replacement. */
|
|
|
|
|
if (oldObject == _first_link)
|
|
|
|
|
_first_link = newObject;
|
|
|
|
|
[newObject setNextLink:[oldObject nextLink]];
|
|
|
|
|
[newObject setPrevLink:[oldObject prevLink]];
|
|
|
|
|
[[oldObject prevLink] setNextLink:newObject];
|
|
|
|
|
[[oldObject nextLink] setPrevLink:newObject];
|
|
|
|
|
|
|
|
|
|
/* Release ownership of the oldObject. */
|
|
|
|
|
[oldObject setNextLink: NO_OBJECT];
|
|
|
|
|
[oldObject setPrevLink: NO_OBJECT];
|
|
|
|
|
[oldObject setLinkedList: NO_OBJECT];
|
|
|
|
|
[oldObject release];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* End of methods that change the instance variables. */
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- (void) appendObject: newObject
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
/* Make sure no one else already owns the newObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([newObject linkedList] == NO_OBJECT, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
/* Insert it. */
|
|
|
|
|
if (_count == 0)
|
|
|
|
|
{
|
1996-03-03 01:36:41 +00:00
|
|
|
|
/* Claim ownership of the newObject. */
|
|
|
|
|
[newObject retain];
|
|
|
|
|
[newObject setLinkedList: self];
|
|
|
|
|
|
|
|
|
|
/* Put it in as the only node. */
|
1996-02-22 15:11:43 +00:00
|
|
|
|
_first_link = newObject;
|
|
|
|
|
_last_link = newObject;
|
1996-03-03 01:36:41 +00:00
|
|
|
|
_count = 1;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
[newObject setNextLink: NO_OBJECT];
|
|
|
|
|
[newObject setPrevLink: NO_OBJECT];
|
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
|
else
|
1996-02-22 15:11:43 +00:00
|
|
|
|
[self insertObject: newObject after: _last_link];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-06 14:09:55 +00:00
|
|
|
|
- (void) prependObject: newObject
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
/* Make sure no one else already owns the newObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([newObject linkedList] == NO_OBJECT, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
/* Insert it. */
|
|
|
|
|
if (_count == 0)
|
|
|
|
|
{
|
1996-03-03 01:36:41 +00:00
|
|
|
|
/* Claim ownership of the newObject. */
|
|
|
|
|
[newObject retain];
|
|
|
|
|
[newObject setLinkedList: self];
|
|
|
|
|
|
|
|
|
|
/* Put it in as the only node. */
|
1996-02-22 15:11:43 +00:00
|
|
|
|
_first_link = newObject;
|
|
|
|
|
_last_link = newObject;
|
1996-03-03 01:36:41 +00:00
|
|
|
|
_count = 1;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
[newObject setNextLink: NO_OBJECT];
|
|
|
|
|
[newObject setPrevLink: NO_OBJECT];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
[self insertObject: newObject before: _first_link];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-06 14:09:55 +00:00
|
|
|
|
- (void) insertObject: newObject atIndex: (unsigned)index
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
CHECK_INDEX_RANGE_ERROR(index, (_count+1));
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure no one else already owns the newObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([newObject linkedList] == NO_OBJECT, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
/* Insert it. */
|
|
|
|
|
if (_count == 0)
|
|
|
|
|
{
|
1996-03-03 01:36:41 +00:00
|
|
|
|
/* Claim ownership of the newObject. */
|
|
|
|
|
[newObject retain];
|
|
|
|
|
[newObject setLinkedList: self];
|
|
|
|
|
|
|
|
|
|
/* Put it in as the only node. */
|
1996-02-22 15:11:43 +00:00
|
|
|
|
_first_link = newObject;
|
|
|
|
|
_last_link = newObject;
|
1996-03-03 01:36:41 +00:00
|
|
|
|
_count = 1;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
[newObject setNextLink: NO_OBJECT];
|
|
|
|
|
[newObject setPrevLink: NO_OBJECT];
|
|
|
|
|
}
|
|
|
|
|
else if (index == _count)
|
|
|
|
|
[self insertObject: newObject after: _last_link];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
else
|
1996-02-22 15:11:43 +00:00
|
|
|
|
[self insertObject:newObject before: [self objectAtIndex: index]];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- (void) removeObjectAtIndex: (unsigned)index
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
CHECK_INDEX_RANGE_ERROR(index, _count);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
[self removeObject: [self objectAtIndex: index]];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- objectAtIndex: (unsigned)index
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
id <LinkedListComprising> link;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
CHECK_INDEX_RANGE_ERROR(index, _count);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
if (index < _count / 2)
|
1996-02-22 15:11:43 +00:00
|
|
|
|
for (link = _first_link;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
index;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
link = [link nextLink], index--)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
;
|
|
|
|
|
else
|
1996-02-22 15:11:43 +00:00
|
|
|
|
for (link = _last_link, index = _count - index - 1;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
index;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
link = [link prevLink], index--)
|
1994-11-04 16:29:24 +00:00
|
|
|
|
;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
return link;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- firstObject
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
return _first_link;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- lastObject
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
return _last_link;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- successorOfObject: oldObject
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
/* Make sure we actually own the oldObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([oldObject linkedList] == self, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
return [oldObject nextLink];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- predecessorOfObject: oldObject
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
/* Make sure we actually own the oldObject. */
|
1998-11-19 21:26:27 +00:00
|
|
|
|
NSAssert([oldObject linkedList] == self, NSInternalInconsistencyException);
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
return [oldObject prevLink];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-03 01:36:41 +00:00
|
|
|
|
- (void*) newEnumState
|
|
|
|
|
{
|
|
|
|
|
return _first_link;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- nextObjectWithEnumState: (void**)enumState
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-02-22 15:11:43 +00:00
|
|
|
|
id ret;
|
|
|
|
|
|
1996-03-03 01:36:41 +00:00
|
|
|
|
if (!*enumState)
|
|
|
|
|
return nil;
|
|
|
|
|
ret = *enumState;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
*enumState = [(id)(*enumState) nextLink];
|
1996-03-03 01:36:41 +00:00
|
|
|
|
/* *enumState points to the next object to be returned. */
|
1996-02-22 15:11:43 +00:00
|
|
|
|
return ret;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- prevObjectWithEnumState: (void**)enumState
|
1994-11-04 16:29:24 +00:00
|
|
|
|
{
|
1996-03-03 01:36:41 +00:00
|
|
|
|
/* *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];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned) count
|
|
|
|
|
{
|
|
|
|
|
return _count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|