1994-11-04 16:29:24 +00:00
|
|
|
|
/* Protocol for Objective-C objects that hold elements accessible by index
|
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
|
|
|
|
|
|
|
|
|
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
|
Date: May 1993
|
|
|
|
|
|
|
|
|
|
This file is part of the GNU Objective C Class Library.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* The <IndexedCollecting> protocol inherits from the
|
|
|
|
|
<KeyedCollecting> protocol.
|
|
|
|
|
|
|
|
|
|
The <IndexedCollecting> protocol defines the interface to a
|
|
|
|
|
collection of elements that are accessible by a key that is an index,
|
|
|
|
|
where the indeces in a collection are a contiguous series of unsigned
|
|
|
|
|
integers beginning at 0. This is the root of the protocol heirarchy
|
|
|
|
|
for all collections that hold their elements in some order. Elements
|
|
|
|
|
may be accessed, inserted, replaced and removed by their index.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __IndexedCollecting_h_OBJECTS_INCLUDE
|
|
|
|
|
#define __IndexedCollecting_h_OBJECTS_INCLUDE
|
|
|
|
|
|
|
|
|
|
#include <objects/stdobjects.h>
|
1996-02-22 15:11:43 +00:00
|
|
|
|
#include <objects/Collecting.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
typedef struct _IndexRange {
|
1995-03-12 20:05:21 +00:00
|
|
|
|
unsigned location;
|
|
|
|
|
unsigned length;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
} IndexRange;
|
|
|
|
|
|
|
|
|
|
#define IndexRangeInside(RANGE1,RANGE2) \
|
|
|
|
|
({IndexRange __a=(RANGE1), __b=(RANGE2); \
|
|
|
|
|
__a.start<=__b.start && __a.end>=__b.end;})
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
@protocol ConstantIndexedCollecting <ConstantCollecting>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
// GETTING MEMBERS BY INDEX;
|
|
|
|
|
- objectAtIndex: (unsigned)index;
|
|
|
|
|
- firstObject;
|
|
|
|
|
- lastObject;
|
|
|
|
|
|
|
|
|
|
// GETTING MEMBERS BY NEIGHBOR;
|
|
|
|
|
- successorOfObject: anObject;
|
|
|
|
|
- predecessorOfObject: anObject;
|
|
|
|
|
|
|
|
|
|
// GETTING INDICES BY MEMBER;
|
|
|
|
|
- (unsigned) indexOfObject: anObject;
|
|
|
|
|
- (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange;
|
|
|
|
|
|
|
|
|
|
// TESTING;
|
1995-04-09 01:38:21 +00:00
|
|
|
|
- (BOOL) contentsEqualInOrder: (id <ConstantIndexedCollecting>)aColl;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- (int) compareInOrderContentsOf: (id <Collecting>)aCollection;
|
1995-04-09 01:38:21 +00:00
|
|
|
|
- (unsigned) indexOfFirstDifference: (id <ConstantIndexedCollecting>)aColl;
|
|
|
|
|
- (unsigned) indexOfFirstIn: (id <ConstantCollecting>)aColl;
|
|
|
|
|
- (unsigned) indexOfFirstNotIn: (id <ConstantCollecting>)aColl;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
// ENUMERATING;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- (id <Enumerating>) reverseObjectEnumerator;
|
|
|
|
|
- (void) withObjectsInRange: (IndexRange)aRange
|
|
|
|
|
invoke: (id <Invoking>)anInvocation;
|
|
|
|
|
- (void) withObjectsInReverseInvoke: (id <Invoking>)anInvocation;
|
|
|
|
|
- (void) withObjectsInReverseInvoke: (id <Invoking>)anInvocation
|
|
|
|
|
whileTrue:(BOOL *)flag;
|
|
|
|
|
- (void) makeObjectsPerformInReverse: (SEL)aSel;
|
|
|
|
|
- (void) makeObjectsPerformInReverse: (SEL)aSel withObject: argObject;
|
|
|
|
|
|
|
|
|
|
// LOW-LEVEL ENUMERATING;
|
|
|
|
|
- prevObjectWithEnumState: (void**)enumState;
|
1995-04-08 17:05:21 +00:00
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
|
|
|
|
|
@protocol IndexedCollecting <ConstantIndexedCollecting, Collecting>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
// REPLACING;
|
|
|
|
|
- (void) replaceObjectAtIndex: (unsigned)index with: newObject;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
// REMOVING;
|
|
|
|
|
- (void) removeObjectAtIndex: (unsigned)index;
|
|
|
|
|
- (void) removeFirstObject;
|
|
|
|
|
- (void) removeLastObject;
|
|
|
|
|
- (void) removeRange: (IndexRange)aRange;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
// SORTING;
|
1996-02-22 15:11:43 +00:00
|
|
|
|
- (void) sortContents;
|
|
|
|
|
- (void) sortAddObject: newObject;
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
1996-02-22 15:11:43 +00:00
|
|
|
|
#include <limits.h>
|
|
|
|
|
#define NO_INDEX UINT_MAX
|
|
|
|
|
|
|
|
|
|
/* xxx Fix this comment: */
|
|
|
|
|
|
1994-11-04 16:29:24 +00:00
|
|
|
|
/* Most methods in the KeyedCollecting protocol that mention a key are
|
|
|
|
|
duplicated in the IndexedCollecting protocol, with their names
|
|
|
|
|
modified to reflect that the "key" now must be an unsigned integer,
|
|
|
|
|
(an "index"). The programmer should be able to use either of the
|
|
|
|
|
corresponding method names to the same effect.
|
|
|
|
|
|
|
|
|
|
The new methods are provided in the IndexedCollecting protocol for:
|
|
|
|
|
1) Better type checking for when an unsigned int is required.
|
|
|
|
|
2) More intuitive method names.
|
|
|
|
|
|
|
|
|
|
IndexedCollecting KeyedCollecting
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
insertObject:atIndex insertObject:atKey:
|
|
|
|
|
replaceObjectAtIndex:with: replaceObjectAtKey:with:
|
|
|
|
|
removeObjectAtIndex: removeObjectAtKey:
|
|
|
|
|
objectAtIndex: objectAtKey:
|
|
|
|
|
includesIndex: includesKey:
|
|
|
|
|
|
|
|
|
|
insertElement:atIndex insertElement:atKey:
|
|
|
|
|
replaceElementAtIndex:with: replaceElementAtKey:with:
|
|
|
|
|
removeElementAtIndex: removeElementAtKey:
|
|
|
|
|
elementAtIndex: elementAtKey:
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endif /* __IndexedCollecting_h_OBJECTS_INCLUDE */
|