mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-20 20:26:42 +00:00
Overhaul for new collection class scheme to improve distributed objects and NeXT-compatibility.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@940 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
72114c01b0
commit
9c3783b952
52 changed files with 1839 additions and 2931 deletions
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C Array collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -26,13 +26,19 @@
|
|||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/IndexedCollection.h>
|
||||
#include <objects/OrderedCollecting.h>
|
||||
|
||||
@interface Array : IndexedCollection
|
||||
@interface ConstantArray : IndexedCollection
|
||||
{
|
||||
@public
|
||||
int (*_comparison_function)(elt,elt);
|
||||
elt *_contents_array;
|
||||
id *_contents_array;
|
||||
unsigned int _count;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface Array : ConstantArray
|
||||
{
|
||||
@public
|
||||
unsigned int _capacity;
|
||||
unsigned int _grow_factor;
|
||||
}
|
||||
|
@ -40,16 +46,18 @@
|
|||
+ (unsigned) defaultCapacity;
|
||||
+ (unsigned) defaultGrowFactor;
|
||||
|
||||
- initWithType: (const char *)contentEncoding
|
||||
capacity: (unsigned)aCapacity;
|
||||
- initWithCapacity: (unsigned) aCapacity;
|
||||
|
||||
- setCapacity: (unsigned)newCapacity;
|
||||
- (void) setCapacity: (unsigned)newCapacity;
|
||||
- (unsigned) growFactor;
|
||||
- setGrowFactor: (unsigned)aNum;
|
||||
- (void) setGrowFactor: (unsigned)aNum;
|
||||
|
||||
@end
|
||||
|
||||
/* Put this on category instead of class to avoid bogus complaint from gcc */
|
||||
@interface Array (Ordering) <OrderedCollecting>
|
||||
@end
|
||||
|
||||
#define FOR_ARRAY(ARRAY, ELEMENT_VAR) \
|
||||
{ \
|
||||
unsigned _FOR_ARRAY_i; \
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C Bag collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -25,39 +25,27 @@
|
|||
#define __Bag_h_INCLUDE_GNU
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/Set.h>
|
||||
#include <objects/Collection.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
|
||||
@interface Bag : Set
|
||||
@interface Bag : Collection
|
||||
{
|
||||
NSMapTable *_contents_map;
|
||||
unsigned int _count; // the number of elements;
|
||||
}
|
||||
|
||||
// INITIALIZING AND FREEING;
|
||||
- initWithCapacity: (unsigned)aCapacity;
|
||||
|
||||
// ADDING;
|
||||
- addObject: newObject withOccurrences: (unsigned)count;
|
||||
- (void) addObject: newObject withOccurrences: (unsigned)count;
|
||||
|
||||
// REMOVING AND REPLACING;
|
||||
- removeObject: oldObject occurrences: (unsigned)count;
|
||||
- removeObject: oldObject occurrences: (unsigned)count
|
||||
ifAbsentCall: (id(*)(arglist_t))excFunc;
|
||||
- (void) removeObject: oldObject occurrences: (unsigned)count;
|
||||
|
||||
// TESTING;
|
||||
- (unsigned) uniqueCount;
|
||||
|
||||
|
||||
// NON-OBJECT ELEMENT METHOD NAMES;
|
||||
|
||||
// INITIALIZING AND FREEING;
|
||||
- initWithType: (const char *)contentEncoding
|
||||
capacity: (unsigned)aCapacity;
|
||||
|
||||
// ADDING;
|
||||
- addElement: (elt)newElement withOccurrences: (unsigned)count;
|
||||
|
||||
// REMOVING AND REPLACING;
|
||||
- (elt) removeElement:(elt)oldElement occurrences: (unsigned)count;
|
||||
- (elt) removeElement:(elt)oldElement occurrences: (unsigned)count
|
||||
ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* __Bag_h_INCLUDE_GNU */
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C BinaryTree collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -35,13 +35,15 @@
|
|||
/* The <BinaryTreeComprising> protocol defines the interface to an object
|
||||
that may be an element in a BinaryTree.
|
||||
*/
|
||||
@protocol BinaryTreeComprising
|
||||
@protocol BinaryTreeComprising <NSObject>
|
||||
- leftNode;
|
||||
- rightNode;
|
||||
- parentNode;
|
||||
- setLeftNode: (id <BinaryTreeComprising>)aNode;
|
||||
- setRightNode: (id <BinaryTreeComprising>)aNode;
|
||||
- setParentNode: (id <BinaryTreeComprising>)aNode;
|
||||
- (void) setLeftNode: (id <BinaryTreeComprising>)aNode;
|
||||
- (void) setRightNode: (id <BinaryTreeComprising>)aNode;
|
||||
- (void) setParentNode: (id <BinaryTreeComprising>)aNode;
|
||||
- binaryTree;
|
||||
- (void) setBinaryTree: anObject;
|
||||
@end
|
||||
|
||||
#define NODE_IS_RIGHTCHILD(NODE) (NODE == [[NODE parentNode] rightNode])
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C BinaryTreeNode object
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
|||
id _left;
|
||||
id _right;
|
||||
id _parent;
|
||||
id _binary_tree;
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Protocol for Objective-C objects that hold collections of elements.
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -35,54 +35,61 @@
|
|||
#define __Collecting_h_INCLUDE_GNU
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objc/Object.h>
|
||||
#include <objects/elt.h>
|
||||
#include <objects/Coding.h>
|
||||
#include <objects/Invoking.h>
|
||||
#include <objects/Enumerating.h>
|
||||
|
||||
@protocol ConstantCollecting
|
||||
|
||||
// INITIALIZING;
|
||||
- init;
|
||||
- initWithObjects: (id*)objc count: (unsigned)c;
|
||||
- initWithObjects: firstObject, ...;
|
||||
- initWithObjects: firstObject rest: (va_list)ap;
|
||||
- initWithContentsOf: (id <ConstantCollecting>)aCollection;
|
||||
|
||||
// TESTING;
|
||||
// QUERYING COUNTS;
|
||||
- (BOOL) isEmpty;
|
||||
- (BOOL) includesObject: anObject;
|
||||
- (unsigned) count;
|
||||
- (BOOL) containsObject: anObject;
|
||||
- (unsigned) occurrencesOfObject: anObject;
|
||||
|
||||
// COMPARISON WITH OTHER COLLECTIONS;
|
||||
- (BOOL) isSubsetOf: (id <ConstantCollecting>)aCollection;
|
||||
- (BOOL) isDisjointFrom: (id <ConstantCollecting>)aCollection;
|
||||
- (int) compare: anObject;
|
||||
- (BOOL) isEqual: anObject;
|
||||
- (int) compare: anObject;
|
||||
- (BOOL) contentsEqual: (id <ConstantCollecting>)aCollection;
|
||||
- (unsigned) count;
|
||||
- (unsigned) occurrencesOfObject: anObject;
|
||||
- (BOOL) trueForAllObjectsByCalling: (BOOL(*)(id))aFunc;
|
||||
- (BOOL) trueForAnyObjectsByCalling: (BOOL(*)(id))aFunc;
|
||||
- detectObjectByCalling: (BOOL(*)(id))aFunc;
|
||||
- detectObjectByCalling: (BOOL(*)(id))aFunc
|
||||
ifNoneCall: (id(*)(arglist_t))excFunc;
|
||||
|
||||
// PROPERTIES OF CONTENTS;
|
||||
- (BOOL) trueForAllObjectsByInvoking: (id <Invoking>)anInvocation;
|
||||
- (BOOL) trueForAnyObjectsByInvoking: (id <Invoking>)anInvocation;
|
||||
- detectObjectByInvoking: (id <Invoking>)anInvocation;
|
||||
- maxObject;
|
||||
- maxObjectByCalling: (int(*)(id,id))aFunc;
|
||||
- minObject;
|
||||
- minObjectByCalling: (int(*)(id,id))aFunc;
|
||||
|
||||
// ENUMERATING
|
||||
- (void*) newEnumState;
|
||||
- (BOOL) getNextObject:(id *)anObjectPtr withEnumState: (void**)enumState;
|
||||
- freeEnumState: (void**)enumState;
|
||||
- withObjectsCall: (void(*)(id))aFunc;
|
||||
- withObjectsCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
|
||||
- injectObject: initialArgObject byCalling:(id(*)(id,id))aFunc;
|
||||
- makeObjectsPerform: (SEL)aSel;
|
||||
- makeObjectsPerform: (SEL)aSel with: argObject;
|
||||
- (id <Enumerating>) objectEnumerator;
|
||||
- (void) withObjectsInvoke: (id <Invoking>)anInvocation;
|
||||
- (void) withObjectsInvoke: (id <Invoking>)anInvocation whileTrue:(BOOL *)flag;
|
||||
- (void) makeObjectsPerform: (SEL)aSel;
|
||||
- (void) makeObjectsPerform: (SEL)aSel withObject: argObject;
|
||||
|
||||
// FILTERED ENUMERATING;
|
||||
- withObjectsTrueByCalling: (BOOL(*)(id))testFunc
|
||||
call: (void(*)(id))destFunc;
|
||||
- withObjectsFalseByCalling: (BOOL(*)(id))testFunc
|
||||
call: (void(*)(id))destFunc;
|
||||
- withObjectsTransformedByCalling: (id(*)(id))transFunc
|
||||
call: (void(*)(id))destFunc;
|
||||
- (void) withObjectsTrueByInvoking: (id <Invoking>)testInvocation
|
||||
invoke: (id <Invoking>)anInvocation;
|
||||
- (void) withObjectsFalseByInvoking: (id <Invoking>)testInvocation
|
||||
invoke: (id <Invoking>)anInvocation;
|
||||
- (void) withObjectsTransformedByInvoking: (id <Invoking>)transInvocation
|
||||
invoke: (id <Invoking>)anInvocation;
|
||||
|
||||
// COPYING
|
||||
// LOW-LEVEL ENUMERATING;
|
||||
- (void*) newEnumState;
|
||||
- nextObjectWithEnumState: (void**)enumState;
|
||||
- (void) freeEnumState: (void**)enumState;
|
||||
|
||||
// COPYING;
|
||||
- allocCopy;
|
||||
- emptyCopy;
|
||||
- emptyCopyAs: (Class)aCollectionClass;
|
||||
- shallowCopy;
|
||||
|
@ -91,98 +98,34 @@
|
|||
- copyAs: (Class)aCollectionClass;
|
||||
- species;
|
||||
|
||||
// NON-OBJECT ELEMENT METHOD NAMES;
|
||||
|
||||
// INITIALIZING;
|
||||
- initWithType:(const char *)contentEncoding;
|
||||
|
||||
// TESTING;
|
||||
- (BOOL) includesElement: (elt)anElement;
|
||||
- (unsigned) occurrencesOfElement: (elt)anElement;
|
||||
- (elt) detectElementByCalling: (BOOL(*)(elt))aFunc;
|
||||
- (elt) detectElementByCalling: (BOOL(*)(elt))aFunc
|
||||
ifNoneCall: (elt(*)(arglist_t))excFunc;
|
||||
- (elt) maxElement;
|
||||
- (elt) maxElementByCalling: (int(*)(elt,elt))aFunc;
|
||||
- (elt) minElement;
|
||||
- (elt) minElementByCalling: (int(*)(elt,elt))aFunc;
|
||||
- (BOOL) trueForAllElementsByCalling: (BOOL(*)(elt))aFunc;
|
||||
- (BOOL) trueForAnyElementsByCalling: (BOOL(*)(elt))aFunc;
|
||||
- (const char *) contentType;
|
||||
- (BOOL) contentsAreObjects;
|
||||
- (int(*)(elt,elt)) comparisonFunction;
|
||||
|
||||
// ENUMERATING;
|
||||
- (BOOL) getNextElement:(elt *)anElementPtr withEnumState: (void**)enumState;
|
||||
- withElementsCall: (void(*)(elt))aFunc;
|
||||
- withElementsCall: (void(*)(elt))aFunc whileTrue: (BOOL*)flag;
|
||||
- (elt) injectElement: (elt)initialElement byCalling: (elt(*)(elt,elt))aFunc;
|
||||
|
||||
// FILTERED ENUMERATING;
|
||||
- withElementsTrueByCalling: (BOOL(*)(elt))testFunc
|
||||
call: (void(*)(elt))destFunc;
|
||||
- withElementsFalseByCalling: (BOOL(*)(elt))testFunc
|
||||
call: (void(*)(elt))destFunc;
|
||||
- withElementsTransformedByCalling: (elt(*)(elt))transFunc
|
||||
call: (void(*)(elt))destFunc;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@protocol Collecting <ConstantCollecting>
|
||||
|
||||
// ADDING;
|
||||
- addObject: newObject;
|
||||
- addObjectIfAbsent: newObject;
|
||||
- addContentsOf: (id <ConstantCollecting>)aCollection;
|
||||
- addContentsOfIfAbsent: (id <ConstantCollecting>)aCollection;
|
||||
- addObjectsCount: (unsigned)count, ...;
|
||||
- (void) addObject: newObject;
|
||||
- (void) addObjectIfAbsent: newObject;
|
||||
- (void) addContentsOf: (id <ConstantCollecting>)aCollection;
|
||||
- (void) addContentsIfAbsentOf: (id <ConstantCollecting>)aCollection;
|
||||
- (void) addWithObjects: (id*)objc count: (unsigned)c;
|
||||
- (void) addObjects: firstObject, ...;
|
||||
- (void) addObjects: firstObject rest: (va_list)ap;
|
||||
|
||||
// REMOVING;
|
||||
- removeObject: oldObject;
|
||||
- removeObject: oldObject ifAbsentCall: (id(*)(arglist_t))excFunc;
|
||||
- removeAllOccurrencesOfObject: oldObject;
|
||||
- removeContentsIn: (id <ConstantCollecting>)aCollection;
|
||||
- removeContentsNotIn: (id <ConstantCollecting>)aCollection;
|
||||
- uniqueContents;
|
||||
- empty;
|
||||
- (void) removeObject: oldObject;
|
||||
- (void) removeAllOccurrencesOfObject: oldObject;
|
||||
- (void) removeContentsIn: (id <ConstantCollecting>)aCollection;
|
||||
- (void) removeContentsNotIn: (id <ConstantCollecting>)aCollection;
|
||||
- (void) uniqueContents;
|
||||
- (void) empty;
|
||||
|
||||
// REPLACING;
|
||||
- replaceObject: oldObject with: newObject;
|
||||
- replaceObject: oldObject with: newObject
|
||||
ifAbsentCall:(id(*)(arglist_t))excFunc;
|
||||
- replaceAllOccurrencesOfObject: oldObject with: newObject;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeMakeObjectsPerform: (SEL)aSel;
|
||||
- safeMakeObjectsPerform: (SEL)aSel with: argObject;
|
||||
- safeWithObjectsCall: (void(*)(id))aFunc;
|
||||
- safeWithObjectsCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
|
||||
|
||||
|
||||
// NON-OBJECT ELEMENT METHOD NAMES;
|
||||
|
||||
// ADDING;
|
||||
- addElement: (elt)newElement;
|
||||
- addElementIfAbsent: (elt)newElement;
|
||||
- addElementsCount: (unsigned)count, ...;
|
||||
|
||||
// REMOVING;
|
||||
- (elt) removeElement: (elt)oldElement;
|
||||
- (elt) removeElement: (elt)oldElement
|
||||
ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
- removeAllOccurrencesOfElement: (elt)oldElement;
|
||||
|
||||
// REPLACING;
|
||||
- (elt) replaceElement: (elt)oldElement with: (elt)newElement;
|
||||
- (elt) replaceElement: (elt)oldElement with: (elt)newElement
|
||||
ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
- replaceAllOccurrencesOfElement: (elt)oldElement with: (elt)newElement;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeWithElementsCall: (void(*)(elt))aFunc;
|
||||
- safeWithElementsCall: (void(*)(elt))aFunc whileTrue: (BOOL*)flag;
|
||||
- (void) replaceObject: oldObject withObject: newObject;
|
||||
- (void) replaceAllOccurrencesOfObject: oldObject withObject: newObject;
|
||||
|
||||
@end
|
||||
|
||||
#define NO_OBJECT nil
|
||||
|
||||
#endif /* __Collecting_h_INCLUDE_GNU */
|
||||
|
|
|
@ -32,29 +32,42 @@
|
|||
#include <Foundation/NSObject.h>
|
||||
#include <objects/Collecting.h>
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/collhash.h>
|
||||
#include <objects/Coding.h>
|
||||
|
||||
@interface Collection : NSObject <Collecting>
|
||||
{
|
||||
}
|
||||
|
||||
- (void) withObjectsInvoke: anInvocation;
|
||||
- printElement: (elt)anElement;
|
||||
- printForDebugger;
|
||||
|
||||
@interface ConstantCollection : NSObject <ConstantCollecting>
|
||||
- printForDebugger; /* This method will disappear later. */
|
||||
@end
|
||||
|
||||
// #warning fix this macro
|
||||
#define FOR_COLL(ACOLL, ELT) \
|
||||
@interface Collection : ConstantCollection <Collecting>
|
||||
@end
|
||||
|
||||
@interface Enumerator : NSObject <Enumerating>
|
||||
{
|
||||
id collection;
|
||||
void *enum_state;
|
||||
}
|
||||
@end
|
||||
|
||||
#define FOR_COLLECTION(ACOLL, ELT) \
|
||||
{ \
|
||||
void *_es = [ACOLL initEnumState]; \
|
||||
while ([ACOLL getNextElement:&(ELT) withEnumState:&_es]) \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while ((ELT = [ACOLL nextObjectWithEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define FOR_COLL_END \
|
||||
#define END_FOR_COLLECTION(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState:_es]; \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
#define FOR_COLLECTION_WHILE_TRUE(ACOLL, ELT, FLAG) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while (FLAG && (ELT = [ACOLL nextObjectWithEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_COLLECTION_WHILE_TRUE(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
/* The only subclassResponsibilities in Collection are:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Collection definitions for the use of subclass implementations only
|
||||
Copyright (C) 1993,1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993,1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -25,28 +25,23 @@
|
|||
#define __CollectionPrivate_h_INCLUDE_GNU
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/eltfuncs.h>
|
||||
|
||||
@interface Collection (ArchivingHelpers)
|
||||
/* These methods should never be called except in order inside
|
||||
-write: and -read: */
|
||||
- _writeInit: (TypedStream*)aStream;
|
||||
- _readInit: (TypedStream*)aStream;
|
||||
- _writeContents: (TypedStream*)aStream;
|
||||
- _readContents: (TypedStream*)aStream;
|
||||
|
||||
/* The Coding versions of the above */
|
||||
@interface ConstantCollection (ArchivingHelpers)
|
||||
/* These methods should never be called except in order, and inside
|
||||
-encodeWithCoder: and -decodeWithCoder: */
|
||||
- (void) _encodeCollectionWithCoder: (id <Encoding>)aCoder;
|
||||
- _initCollectionWithCoder: (id <Decoding>)aCoder;
|
||||
- (void) _encodeContentsWithCoder: (id <Encoding>)aCoder;
|
||||
- (void) _decodeContentsWithCoder: (id <Decoding>)aCoder;
|
||||
@end
|
||||
|
||||
@interface Collection (DeallocationHelpers)
|
||||
@interface ConstantCollection (DeallocationHelpers)
|
||||
|
||||
/* Empty the internals of a collection after the contents have
|
||||
already been released. */
|
||||
- _empty;
|
||||
- (void) _collectionEmpty;
|
||||
|
||||
- (void) _collectionReleaseContents;
|
||||
|
||||
/* Deallocate the internals of a collection after the contents
|
||||
have already been released. */
|
||||
|
@ -54,63 +49,4 @@
|
|||
|
||||
@end
|
||||
|
||||
|
||||
/* To be used inside methods for getting the element comparison function.
|
||||
This macro could be redefined when the comparison function is an
|
||||
instance variable or is fixed.
|
||||
I'm wondering if I should put _comparison_function back as an instance
|
||||
variable in Collection. */
|
||||
#define COMPARISON_FUNCTION [self comparisonFunction]
|
||||
|
||||
/* Use this for comparing elements in your implementation. */
|
||||
#define COMPARE_ELEMENTS(ELT1, ELT2) \
|
||||
((*COMPARISON_FUNCTION)(ELT1, ELT2))
|
||||
|
||||
#define ELEMENTS_EQUAL(ELT1, ELT2) \
|
||||
(COMPARE_ELEMENTS(ELT1, ELT2) == 0)
|
||||
|
||||
#define ENCODING_IS_OBJECT(ENCODING) \
|
||||
((*(ENCODING) == _C_ID) || (*(ENCODING) == _C_CLASS))
|
||||
|
||||
/* To be used inside a method for determining if the contents are objects */
|
||||
#define CONTAINS_OBJECTS \
|
||||
(ENCODING_IS_OBJECT([self contentType]))
|
||||
|
||||
/* Used inside a method for sending "-retain" if necessary */
|
||||
#define RETAIN_ELT(ELT) \
|
||||
if (CONTAINS_OBJECTS) [ELT.id_u retain]
|
||||
|
||||
/* Used inside a method for sending "-release" if necessary */
|
||||
#define RELEASE_ELT(ELT) \
|
||||
if (CONTAINS_OBJECTS) [ELT.id_u release]
|
||||
|
||||
/* Used inside a method for sending "-autorelease" if necessary */
|
||||
#define AUTORELEASE_ELT(ELT) \
|
||||
((CONTAINS_OBJECTS) ? ((elt)[ELT.id_u autorelease]) : ELT)
|
||||
|
||||
|
||||
/* Error Handling */
|
||||
|
||||
#define RETURN_BY_CALLING_EXCEPTION_FUNCTION(FUNC) \
|
||||
return (*FUNC)(__builtin_apply_args())
|
||||
|
||||
|
||||
/* To be used inside a method for making sure the contents are objects.
|
||||
typeof(DEFAULT_ERROR_RETURN) must be the same type as the method
|
||||
returns. */
|
||||
#define CHECK_CONTAINS_OBJECTS_ERROR() \
|
||||
({if (!(CONTAINS_OBJECTS)) \
|
||||
{ \
|
||||
[self error:"in %s, requires object contents", sel_get_name(_cmd)]; \
|
||||
}})
|
||||
|
||||
/* To be used inside a method whenever a particular element isn't found */
|
||||
#define ELEMENT_NOT_FOUND_ERROR(AN_ELEMENT) \
|
||||
([self error:"in %s, element not found.", sel_get_name(_cmd)])
|
||||
|
||||
/* To be used inside a method whenever there is no element matching the
|
||||
needed criteria */
|
||||
#define NO_ELEMENT_FOUND_ERROR() \
|
||||
([self error:"in %s, no element found.", sel_get_name(_cmd)])
|
||||
|
||||
#endif /* __CollectionPrivate_h_INCLUDE_GNU */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C Dictionary collection object
|
||||
Copyright (C) 1993,1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -26,18 +26,14 @@
|
|||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/KeyedCollection.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
|
||||
@interface Dictionary : KeyedCollection
|
||||
{
|
||||
coll_cache_ptr _contents_hash; // a hashtable to hold the contents;
|
||||
int (*_comparison_function)(elt,elt);
|
||||
NSMapTable *_contents_hash;
|
||||
}
|
||||
|
||||
- initWithType: (const char *)contentEncoding
|
||||
keyType: (const char *)keyEncoding
|
||||
capacity: (unsigned)aCapacity;
|
||||
- initWithType: (const char *)contentEncoding
|
||||
capacity: (unsigned)aCapacity;
|
||||
- initWithCapacity: (unsigned)aCapacity;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C Heap collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -28,14 +28,9 @@
|
|||
#include <objects/Array.h>
|
||||
|
||||
@interface Heap : Array
|
||||
{
|
||||
}
|
||||
|
||||
- addElement: (elt)anElement;
|
||||
- (elt) removeFirstElement;
|
||||
|
||||
- heapifyFromIndex: (unsigned)index;
|
||||
- heapify;
|
||||
- (void) heapifyFromIndex: (unsigned)index;
|
||||
- (void) heapify;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Protocol for Objective-C objects that hold elements accessible by index
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -36,7 +36,7 @@
|
|||
#define __IndexedCollecting_h_OBJECTS_INCLUDE
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/KeyedCollecting.h>
|
||||
#include <objects/Collecting.h>
|
||||
|
||||
typedef struct _IndexRange {
|
||||
unsigned location;
|
||||
|
@ -47,8 +47,8 @@ typedef struct _IndexRange {
|
|||
({IndexRange __a=(RANGE1), __b=(RANGE2); \
|
||||
__a.start<=__b.start && __a.end>=__b.end;})
|
||||
|
||||
|
||||
@protocol ConstantIndexedCollecting <ConstantKeyedCollecting>
|
||||
|
||||
@protocol ConstantIndexedCollecting <ConstantCollecting>
|
||||
|
||||
// GETTING MEMBERS BY INDEX;
|
||||
- objectAtIndex: (unsigned)index;
|
||||
|
@ -61,115 +61,53 @@ typedef struct _IndexRange {
|
|||
|
||||
// GETTING INDICES BY MEMBER;
|
||||
- (unsigned) indexOfObject: anObject;
|
||||
- (unsigned) indexOfObject: anObject
|
||||
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
|
||||
- (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange;
|
||||
- (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange
|
||||
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
|
||||
|
||||
// TESTING;
|
||||
- (BOOL) includesIndex: (unsigned)index;
|
||||
- (BOOL) contentsEqualInOrder: (id <ConstantIndexedCollecting>)aColl;
|
||||
- (int) compareInOrderContentsOf: (id <Collecting>)aCollection;
|
||||
- (unsigned) indexOfFirstDifference: (id <ConstantIndexedCollecting>)aColl;
|
||||
- (unsigned) indexOfFirstIn: (id <ConstantCollecting>)aColl;
|
||||
- (unsigned) indexOfFirstNotIn: (id <ConstantCollecting>)aColl;
|
||||
|
||||
// ENUMERATING;
|
||||
- (BOOL) getPrevObject: (id*)anIdPtr withEnumState: (void**)enumState;
|
||||
- withObjectsInRange: (IndexRange)aRange call:(void(*)(id))aFunc;
|
||||
- withObjectsInReverseCall: (void(*)(id))aFunc;
|
||||
- withObjectsInReverseCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
|
||||
- (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;
|
||||
|
||||
// NON-OBJECT MESSAGE NAMES;
|
||||
|
||||
// GETTING ELEMENTS BY INDEX;
|
||||
- (elt) elementAtIndex: (unsigned)index;
|
||||
- (elt) firstElement;
|
||||
- (elt) lastElement;
|
||||
|
||||
// GETTING MEMBERS BY NEIGHBOR;
|
||||
- (elt) successorOfElement: (elt)anElement;
|
||||
- (elt) predecessorOfElement: (elt)anElement;
|
||||
|
||||
// GETTING INDICES BY MEMBER;
|
||||
- (unsigned) indexOfElement: (elt)anElement;
|
||||
- (unsigned) indexOfElement: (elt)anElement
|
||||
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
|
||||
- (unsigned) indexOfElement: (elt)anElement inRange: (IndexRange)aRange;
|
||||
- (unsigned) indexOfElement: (elt)anElement inRange: (IndexRange)aRange
|
||||
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
|
||||
|
||||
// ENUMERATING;
|
||||
- (BOOL) getPrevElement:(elt*)anElementPtr withEnumState: (void**)enumState;
|
||||
- withElementsInRange: (IndexRange)aRange call:(void(*)(elt))aFunc;
|
||||
- withElementsInReverseCall: (void(*)(elt))aFunc;
|
||||
- withElementsInReverseCall: (void(*)(elt))aFunc whileTrue:(BOOL *)flag;
|
||||
// LOW-LEVEL ENUMERATING;
|
||||
- prevObjectWithEnumState: (void**)enumState;
|
||||
|
||||
@end
|
||||
|
||||
@protocol IndexedCollecting <ConstantIndexedCollecting, KeyedCollecting>
|
||||
|
||||
@protocol IndexedCollecting <ConstantIndexedCollecting, Collecting>
|
||||
|
||||
// ADDING;
|
||||
- insertObject: newObject atIndex: (unsigned)index;
|
||||
- insertObject: newObject before: oldObject;
|
||||
- insertObject: newObject after: oldObject;
|
||||
- insertContentsOf: (id <ConstantCollecting>)aCollection
|
||||
atIndex: (unsigned)index;
|
||||
- appendObject: newObject;
|
||||
- prependObject: newObject;
|
||||
- appendContentsOf: (id <ConstantCollecting>)aCollection;
|
||||
- prependContentsOf: (id <ConstantCollecting>)aCollection;
|
||||
// REPLACING;
|
||||
- (void) replaceObjectAtIndex: (unsigned)index with: newObject;
|
||||
|
||||
// REPLACING AND SWAPPING
|
||||
- replaceObjectAtIndex: (unsigned)index with: newObject;
|
||||
- replaceRange: (IndexRange)aRange with: (id <ConstantCollecting>)aCollection;
|
||||
- replaceRange: (IndexRange)aRange using: (id <ConstantCollecting>)aCollection;
|
||||
- swapAtIndeces: (unsigned)index1 : (unsigned)index2;
|
||||
|
||||
// REMOVING
|
||||
- removeObjectAtIndex: (unsigned)index;
|
||||
- removeFirstObject;
|
||||
- removeLastObject;
|
||||
- removeRange: (IndexRange)aRange;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeWithObjectsInReverseCall: (void(*)(id))aFunc;
|
||||
- safeWithObjectsInReverseCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
|
||||
// REMOVING;
|
||||
- (void) removeObjectAtIndex: (unsigned)index;
|
||||
- (void) removeFirstObject;
|
||||
- (void) removeLastObject;
|
||||
- (void) removeRange: (IndexRange)aRange;
|
||||
|
||||
// SORTING;
|
||||
- sortContents;
|
||||
- sortObjectsByCalling: (int(*)(id,id))aFunc;
|
||||
- sortAddObject: newObject;
|
||||
- sortAddObject: newObject byCalling: (int(*)(id,id))aFunc;
|
||||
|
||||
|
||||
// NON-OBJECT MESSAGE NAMES;
|
||||
|
||||
// ADDING;
|
||||
- appendElement: (elt)newElement;
|
||||
- prependElement: (elt)newElement;
|
||||
- insertElement: (elt)newElement atIndex: (unsigned)index;
|
||||
- insertElement: (elt)newElement before: (elt)oldElement;
|
||||
- insertElement: (elt)newElement after: (elt)oldElement;
|
||||
|
||||
// REMOVING AND REPLACING;
|
||||
- (elt) removeElementAtIndex: (unsigned)index;
|
||||
- (elt) removeFirstElement;
|
||||
- (elt) removeLastElement;
|
||||
- (elt) replaceElementAtIndex: (unsigned)index with: (elt)newElement;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeWithElementsInRange: (IndexRange)aRange call:(void(*)(elt))aFunc;
|
||||
- safeWithElementsInReverseCall: (void(*)(elt))aFunc;
|
||||
- safeWithElementsInReverseCall: (void(*)(elt))aFunc whileTrue:(BOOL *)flag;
|
||||
|
||||
// SORTING;
|
||||
- sortElementsByCalling: (int(*)(elt,elt))aFunc;
|
||||
- sortAddElement: (elt)newElement;
|
||||
- sortAddElement: (elt)newElement byCalling: (int(*)(elt,elt))aFunc;
|
||||
- (void) sortContents;
|
||||
- (void) sortAddObject: newObject;
|
||||
|
||||
@end
|
||||
|
||||
#include <limits.h>
|
||||
#define NO_INDEX UINT_MAX
|
||||
|
||||
/* xxx Fix this comment: */
|
||||
|
||||
/* 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,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C Sequential Collection object.
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -28,12 +28,54 @@
|
|||
#include <objects/KeyedCollection.h>
|
||||
#include <objects/IndexedCollecting.h>
|
||||
|
||||
@interface IndexedCollection : KeyedCollection
|
||||
@interface ConstantIndexedCollection : ConstantCollection
|
||||
@end
|
||||
|
||||
@interface IndexedCollection : ConstantIndexedCollection
|
||||
@end
|
||||
|
||||
@interface ReverseEnumerator : Enumerator
|
||||
@end
|
||||
|
||||
/* Put this on category instead of class to avoid bogus complaint from gcc */
|
||||
@interface IndexedCollection (IndexedCollectionProtocol) <IndexedCollecting>
|
||||
@interface ConstantIndexedCollection (Protocol) <ConstantIndexedCollecting>
|
||||
@end
|
||||
@interface IndexedCollection (Protocol) <IndexedCollecting>
|
||||
@end
|
||||
|
||||
#define FOR_INDEXED_COLLECTION(ACOLL, ELT) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while ((ELT = [ACOLL nextObjectWithEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_INDEXED_COLLECTION(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
#define FOR_INDEXED_COLLECTION_REVERSE(ACOLL, ELT) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while ((ELT = [ACOLL prevObjectWithEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_INDEXED_COLLECTION_REVERSE(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
#define FOR_INDEXED_COLLECTION_WHILE_TRUE(ACOLL, ELT, FLAG) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while (FLAG && (ELT = [ACOLL nextObjectWithEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_INDEXED_COLLECTION_WHILE_TRUE(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
|
||||
/* The only subclassResponsibilities in IndexedCollection are:
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Protocol for Objective-C objects holding (keyElement,contentElement) pairs.
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -38,84 +38,44 @@
|
|||
|
||||
@protocol ConstantKeyedCollecting <ConstantCollecting>
|
||||
|
||||
// INITIALIZING;
|
||||
- initWithObjects: (id*)objects forKeys: (id*)keys count: (unsigned)c;
|
||||
|
||||
// GETTING ELEMENTS AND KEYS;
|
||||
- objectAtKey: (elt)aKey;
|
||||
- keyObjectOfObject: aContentObject;
|
||||
- objectAtKey: aKey;
|
||||
- keyOfObject: aContentObject;
|
||||
|
||||
// TESTING;
|
||||
- (BOOL) includesKey: (elt)aKey;
|
||||
- (BOOL) containsKey: aKey;
|
||||
|
||||
// ENUMERATIONS;
|
||||
- withKeyObjectsCall: (void(*)(id))aFunc;
|
||||
- withKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc;
|
||||
- withKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc
|
||||
- (id <Enumerating>) keyEnumerator;
|
||||
- withKeyObjectsInvoke: (id <Invoking>)anInvocation;
|
||||
- withKeyObjectsInvoke: (id <Invoking>)anInvocation
|
||||
whileTrue: (BOOL *)flag;
|
||||
|
||||
// NON-OBJECT ELEMENT METHOD NAMES;
|
||||
// LOW-LEVEL ENUMERATING;
|
||||
- nextObjectAndKey: (id*)keyPtr withEnumState: (void**)enumState;
|
||||
|
||||
// INITIALIZING;
|
||||
- initWithType: (const char *)contentsEncoding
|
||||
keyType: (const char *)keyEncoding;
|
||||
- initKeyType: (const char *)keyEncoding;
|
||||
|
||||
// GETTING ELEMENTS AND KEYS;
|
||||
- (elt) elementAtKey: (elt)aKey;
|
||||
- (elt) elementAtKey: (elt)aKey ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
- (elt) keyElementOfElement: (elt)aContentObject;
|
||||
- (elt) keyElementOfElement: (elt)aContentObject
|
||||
ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
|
||||
// TESTING;
|
||||
- (const char *) keyType;
|
||||
|
||||
// ENUMERATING;
|
||||
- (BOOL) getNextKey: (elt*)aKeyPtr content: (elt*)anElementPtr
|
||||
withEnumState: (void**)enumState;
|
||||
- withKeyElementsCall: (void(*)(elt))aFunc;
|
||||
- withKeyElementsAndContentElementsCall: (void(*)(elt,elt))aFunc;
|
||||
- withKeyElementsAndContentElementsCall: (void(*)(elt,elt))aFunc
|
||||
whileTrue: (BOOL *)flag;
|
||||
// COPYING;
|
||||
- shallowCopyValuesAs: (Class)aCollectingClass;
|
||||
- shallowCopyKeysAs: (Class)aCollectingClass;
|
||||
- copyValuesAs: (Class)aCollectingClass;
|
||||
- copyKeysAs: (Class)aCollectingClass;
|
||||
|
||||
@end
|
||||
|
||||
@protocol KeyedCollecting <ConstantKeyedCollecting, Collecting>
|
||||
|
||||
// ADDING;
|
||||
- putObject: newContentObject atKey: (elt)aKey;
|
||||
- (void) putObject: newContentObject atKey: aKey;
|
||||
|
||||
// REPLACING AND SWAPPING;
|
||||
- replaceObjectAtKey: (elt)aKey with: newContentObject;
|
||||
- swapAtKeys: (elt)key1 : (elt)key2;
|
||||
- (void) replaceObjectAtKey: aKey with: newContentObject;
|
||||
- (void) swapObjectsAtKeys: key1 : key2;
|
||||
|
||||
// REMOVING;
|
||||
- removeObjectAtKey: (elt)aKey;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeWithKeyObjectsCall: (void(*)(id))aFunc;
|
||||
- safeWithKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc;
|
||||
- safeWithKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc
|
||||
whileTrue: (BOOL *)flag;
|
||||
|
||||
|
||||
// NON-OBJECT ELEMENT METHOD NAMES;
|
||||
|
||||
// ADDING;
|
||||
- putElement: (elt)newContentElement atKey: (elt)aKey;
|
||||
|
||||
// REPLACING;
|
||||
- (elt) replaceElementAtKey: (elt)aKey with: (elt)newContentElement;
|
||||
- (elt) replaceElementAtKey: (elt)aKey with: (elt)newContentElement
|
||||
ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
|
||||
// REMOVING;
|
||||
- (elt) removeElementAtKey: (elt)aKey;
|
||||
- (elt) removeElementAtKey: (elt)aKey ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeWithKeyElementsCall: (void(*)(elt))aFunc;
|
||||
- safeWithKeyElementsAndContentElementsCall: (void(*)(elt,elt))aFunc;
|
||||
- safeWithKeyElementsAndContentElementsCall: (void(*)(elt,elt))aFunc
|
||||
whileTrue: (BOOL *)flag;
|
||||
- (void) removeObjectAtKey: aKey;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C KeyedCollection collection object
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -28,12 +28,44 @@
|
|||
#include <objects/Collection.h>
|
||||
#include <objects/KeyedCollecting.h>
|
||||
|
||||
@interface KeyedCollection : Collection
|
||||
@interface ConstantKeyedCollection : Collection
|
||||
@end
|
||||
|
||||
@interface KeyedCollection : ConstantKeyedCollection
|
||||
@end
|
||||
|
||||
/* Put this on category instead of class to avoid bogus complaint from gcc */
|
||||
@interface KeyedCollection (KeyedCollectingProtocol) <KeyedCollecting>
|
||||
@interface ConstantKeyedCollection (Protocol) <ConstantKeyedCollecting>
|
||||
@end
|
||||
@interface KeyedCollection (Protocol) <KeyedCollecting>
|
||||
@end
|
||||
|
||||
@interface KeyEnumerator : Enumerator
|
||||
@end
|
||||
|
||||
#define FOR_KEYED_COLLECTION(ACOLL, ELT, KEY) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while ((ELT = [ACOLL nextObjectAndKey: &(KEY) withEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_KEYED_COLLECTION(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
#define FOR_KEYED_COLLECTION_WHILE_TRUE(ACOLL, ELT, KEY, FLAG) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while (FLAG && (ELT = [ACOLL nextObjectAndKey: &(KEY) \
|
||||
withEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_KEYED_COLLECTION_WHILE_TRUE(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
|
||||
/* The only subclassResponsibilities in IndexedCollection are:
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C LinkedList collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
#define __LinkedList_h_INCLUDE_GNU
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/IndexedCollection.h>
|
||||
#include <objects/OrderedCollection.h>
|
||||
|
||||
/* The <LinkedListComprising> protocol defines the interface to an object
|
||||
that may be an element in a LinkedList.
|
||||
|
@ -33,13 +33,16 @@
|
|||
@protocol LinkedListComprising
|
||||
- nextLink;
|
||||
- prevLink;
|
||||
- setNextLink: (id <LinkedListComprising>)aLink;
|
||||
- setPrevLink: (id <LinkedListComprising>)aLink;
|
||||
- (void) setNextLink: (id <LinkedListComprising>)aLink;
|
||||
- (void) setPrevLink: (id <LinkedListComprising>)aLink;
|
||||
- linkedList;
|
||||
- (void) setLinkedList: aLinkedList;
|
||||
@end
|
||||
|
||||
@interface LinkedList : IndexedCollection
|
||||
@interface LinkedList : OrderedCollection
|
||||
{
|
||||
id _first_link;
|
||||
id _last_link;
|
||||
unsigned int _count;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C LinkedListNode object
|
||||
Copyright (C) 1993,1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -32,8 +32,8 @@
|
|||
{
|
||||
id <LinkedListComprising> _next;
|
||||
id <LinkedListComprising> _prev;
|
||||
id _linked_list;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif /* __LinkedListNode_h_INCLUDE_GNU */
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C MappedCollector collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -33,7 +33,7 @@
|
|||
id <KeyedCollecting> _domain;
|
||||
}
|
||||
|
||||
- initCollection: (id <KeyedCollecting>)aDomain
|
||||
- initWithCollection: (id <KeyedCollecting>)aDomain
|
||||
map: (id <KeyedCollecting>)aMap;
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C Queue object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -29,13 +29,9 @@
|
|||
|
||||
@interface Queue : CircularArray
|
||||
|
||||
- enqueueObject: newObject;
|
||||
- (void) enqueueObject: newObject;
|
||||
- dequeueObject;
|
||||
|
||||
// NON-OBJECT MESSAGE NAMES;
|
||||
- enqueueElement: (elt)newElement;
|
||||
- (elt) dequeueElement;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* __Queue_h_INCLUDE_GNU */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C Set collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993,1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -26,24 +26,23 @@
|
|||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/Collection.h>
|
||||
#include <Foundation/NSHashTable.h>
|
||||
|
||||
@interface Set : Collection
|
||||
{
|
||||
coll_cache_ptr _contents_hash; // a hashtable to hold the contents;
|
||||
NSHashTable *_contents_hash; // a hashtable to hold the contents;
|
||||
}
|
||||
|
||||
// MANAGING CAPACITY;
|
||||
+ (unsigned) defaultCapacity;
|
||||
|
||||
// INITIALIZING AND FREEING;
|
||||
- initWithType: (const char *)contentEncoding
|
||||
capacity: (unsigned)aCapacity;
|
||||
- initWithCapacity: (unsigned)aCapacity;
|
||||
|
||||
// SET OPERATIONS;
|
||||
- intersectWithCollection: (id <Collecting>)aCollection;
|
||||
- unionWithCollection: (id <Collecting>)aCollection;
|
||||
- differenceWithCollection: (id <Collecting>)aCollection;
|
||||
- (void) intersectWithCollection: (id <Collecting>)aCollection;
|
||||
- (void) unionWithCollection: (id <Collecting>)aCollection;
|
||||
- (void) differenceWithCollection: (id <Collecting>)aCollection;
|
||||
|
||||
- shallowCopyIntersectWithCollection: (id <Collecting>)aCollection;
|
||||
- shallowCopyUnionWithCollection: (id <Collecting>)aCollection;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C SplayTree collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
{
|
||||
}
|
||||
|
||||
- splayNode: aNode;
|
||||
- (void) splayNode: aNode;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C Stack object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -29,17 +29,11 @@
|
|||
|
||||
@interface Stack : Array
|
||||
|
||||
- pushObject: anObject;
|
||||
- (void) pushObject: anObject;
|
||||
- popObject;
|
||||
- topObject;
|
||||
- duplicateTop;
|
||||
- exchangeTop;
|
||||
|
||||
// NON-OBJECT MESSAGE NAMES;
|
||||
- pushElement: (elt)anElement;
|
||||
- (elt) popElement;
|
||||
- (elt) topElement;
|
||||
|
||||
- (void) duplicateTop;
|
||||
- (void) exchangeTop;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -24,11 +24,9 @@
|
|||
#include <objects/BinaryTree.h>
|
||||
#include <objects/IndexedCollectionPrivate.h>
|
||||
#include <objects/BinaryTreeNode.h>
|
||||
#include <objects/NSString.h>
|
||||
|
||||
// do safety checks;
|
||||
#define SAFE_BinaryTree 1
|
||||
|
||||
/* sentinal */
|
||||
/* the sentinal */
|
||||
static id nilBinaryTreeNode;
|
||||
|
||||
@implementation BinaryTree
|
||||
|
@ -37,7 +35,6 @@ static id nilBinaryTreeNode;
|
|||
{
|
||||
if (self == [BinaryTree class])
|
||||
{
|
||||
[self setVersion:0]; /* beta release */
|
||||
nilBinaryTreeNode = [[BinaryTreeNode alloc] init];
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +42,6 @@ static id nilBinaryTreeNode;
|
|||
/* This is the designated initializer of this class */
|
||||
- init
|
||||
{
|
||||
[super initWithType:@encode(id)];
|
||||
_count = 0;
|
||||
_contents_root = [self nilNode];
|
||||
return self;
|
||||
|
@ -80,39 +76,6 @@ static id nilBinaryTreeNode;
|
|||
[aCoder finishDecodingInterconnectedObjects];
|
||||
}
|
||||
|
||||
- _readInit: (TypedStream*)aStream
|
||||
{
|
||||
[super _readInit:aStream];
|
||||
_count = 0;
|
||||
_contents_root = [self nilNode];
|
||||
return self;
|
||||
}
|
||||
|
||||
- _writeContents: (TypedStream*)aStream
|
||||
{
|
||||
void archiveElement(elt e)
|
||||
{
|
||||
objc_write_object(aStream, e.id_u);
|
||||
}
|
||||
objc_write_type(aStream, @encode(unsigned int), &_count);
|
||||
[self withElementsCall:archiveElement];
|
||||
// We rely on the nodes to archive their children and parent ptrs;
|
||||
objc_write_object_reference(aStream, _contents_root);
|
||||
return self;
|
||||
}
|
||||
|
||||
- _readContents: (TypedStream*)aStream
|
||||
{
|
||||
int i;
|
||||
|
||||
objc_read_type(aStream, @encode(unsigned int), &_count);
|
||||
for (i = 0; i < _count; i++)
|
||||
objc_read_object(aStream, &_contents_root);
|
||||
// We rely on the nodes to have archived their children and parent ptrs;
|
||||
objc_read_object(aStream, &_contents_root);
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Empty copy must empty an allocCopy'ed version of self */
|
||||
- emptyCopy
|
||||
{
|
||||
|
@ -123,20 +86,10 @@ static id nilBinaryTreeNode;
|
|||
}
|
||||
|
||||
/* This must work without sending any messages to content objects */
|
||||
- _empty
|
||||
- (void) _empty
|
||||
{
|
||||
_count = 0;
|
||||
_contents_root = [self nilNode];
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Override the designated initializer for our superclass IndexedCollection
|
||||
to make sure we have object contents */
|
||||
- initWithType: (const char *)contentEncoding
|
||||
{
|
||||
if (!ENCODING_IS_OBJECT(contentEncoding))
|
||||
[self error:"BinaryTree contents must be objects."];
|
||||
return [self init];
|
||||
}
|
||||
|
||||
- nilNode
|
||||
|
@ -173,64 +126,72 @@ static id nilBinaryTreeNode;
|
|||
return aNode;
|
||||
}
|
||||
|
||||
- (elt) firstElement
|
||||
- firstObject
|
||||
{
|
||||
return [self leftmostNodeFromNode: _contents_root];
|
||||
}
|
||||
|
||||
- (elt) lastElement
|
||||
- lastObject
|
||||
{
|
||||
return [self rightmostNodeFromNode: _contents_root];
|
||||
}
|
||||
|
||||
/* This is correct only if the tree is sorted. How to deal with this? */
|
||||
- maxObject
|
||||
{
|
||||
return [self rightmostNodeFromNode: _contents_root];
|
||||
}
|
||||
|
||||
/* This is correct only is the tree is sorted. How to deal with this? */
|
||||
- (elt) maxElement
|
||||
{
|
||||
return [self rightmostNodeFromNode:_contents_root];
|
||||
}
|
||||
|
||||
/* This is correct only is the tree is sorted. How to deal with this? */
|
||||
- (elt) minElement
|
||||
- minObject
|
||||
{
|
||||
return [self leftmostNodeFromNode: _contents_root];
|
||||
}
|
||||
|
||||
// returns [self nilNode] is there is no successor;
|
||||
- (elt) successorOfElement: (elt)anElement
|
||||
- successorOfObject: anObject
|
||||
{
|
||||
id tmp;
|
||||
|
||||
/* Make sure we actually own the anObject. */
|
||||
assert ([anObject binaryTree] == self);
|
||||
|
||||
// here tmp is the right node;
|
||||
if ((tmp = [anElement.id_u rightNode]) != [self nilNode])
|
||||
if ((tmp = [anObject rightNode]) != [self nilNode])
|
||||
return [self leftmostNodeFromNode: tmp];
|
||||
// here tmp is the parent;
|
||||
tmp = [anElement.id_u parentNode];
|
||||
while (tmp != [self nilNode] && anElement.id_u == [tmp rightNode])
|
||||
tmp = [anObject parentNode];
|
||||
while (tmp != [self nilNode] && anObject == [tmp rightNode])
|
||||
{
|
||||
anElement.id_u = tmp;
|
||||
anObject = tmp;
|
||||
tmp = [tmp parentNode];
|
||||
}
|
||||
if (tmp == [self nilNode])
|
||||
return NO_OBJECT;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// I should make sure that [_contents_root parentNode] == [self nilNode];
|
||||
// Perhaps I should make [_contents_root parentNode] == binaryTreeObj ??;
|
||||
|
||||
// returns [self nilNode] is there is no predecessor;
|
||||
- (elt) predecessorElement: (elt)anElement
|
||||
- predecessorObject: anObject
|
||||
{
|
||||
id tmp;
|
||||
|
||||
/* Make sure we actually own the anObject. */
|
||||
assert ([anObject binaryTree] == self);
|
||||
|
||||
// here tmp is the left node;
|
||||
if ((tmp = [anElement.id_u leftNode]) != [self nilNode])
|
||||
if ((tmp = [anObject leftNode]) != [self nilNode])
|
||||
return [self rightmostNodeFromNode:tmp];
|
||||
// here tmp is the parent;
|
||||
tmp = [anElement.id_u parentNode];
|
||||
while (tmp != [self nilNode] && anElement.id_u == [tmp leftNode])
|
||||
tmp = [anObject parentNode];
|
||||
while (tmp != [self nilNode] && anObject == [tmp leftNode])
|
||||
{
|
||||
anElement.id_u = tmp;
|
||||
anObject = tmp;
|
||||
tmp = [tmp parentNode];
|
||||
}
|
||||
if (tmp == [self nilNode])
|
||||
return NO_OBJECT;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
@ -238,6 +199,10 @@ static id nilBinaryTreeNode;
|
|||
- rootFromNode: aNode
|
||||
{
|
||||
id parentNode;
|
||||
|
||||
/* Make sure we actually own the aNode. */
|
||||
assert ([aNode binaryTree] == self);
|
||||
|
||||
while ((parentNode = [aNode parentNode]) != [self nilNode])
|
||||
aNode = parentNode;
|
||||
return aNode;
|
||||
|
@ -248,6 +213,9 @@ static id nilBinaryTreeNode;
|
|||
{
|
||||
unsigned count = 0;
|
||||
|
||||
/* Make sure we actually own the aNode. */
|
||||
assert ([aNode binaryTree] == self);
|
||||
|
||||
if (aNode == nil || aNode == [self nilNode])
|
||||
[self error:"in %s, Can't find depth of nil node", sel_get_name(_cmd)];
|
||||
do
|
||||
|
@ -264,6 +232,9 @@ static id nilBinaryTreeNode;
|
|||
unsigned leftHeight, rightHeight;
|
||||
id tmpNode;
|
||||
|
||||
/* Make sure we actually own the aNode. */
|
||||
assert ([aNode binaryTree] == self);
|
||||
|
||||
if (aNode == nil || aNode == [self nilNode])
|
||||
{
|
||||
[self error:"in %s, Can't find height of nil node", sel_get_name(_cmd)];
|
||||
|
@ -288,6 +259,10 @@ static id nilBinaryTreeNode;
|
|||
- (unsigned) nodeCountUnderNode: aNode
|
||||
{
|
||||
unsigned count = 0;
|
||||
|
||||
/* Make sure we actually own the aNode. */
|
||||
assert ([aNode binaryTree] == self);
|
||||
|
||||
if ([aNode leftNode] != [self nilNode])
|
||||
count += 1 + [self nodeCountUnderNode:[aNode leftNode]];
|
||||
if ([aNode rightNode] != [self nilNode])
|
||||
|
@ -299,6 +274,9 @@ static id nilBinaryTreeNode;
|
|||
{
|
||||
id y;
|
||||
|
||||
/* Make sure we actually own the aNode. */
|
||||
assert ([aNode binaryTree] == self);
|
||||
|
||||
y = [aNode rightNode];
|
||||
if (y == [self nilNode])
|
||||
return self;
|
||||
|
@ -324,6 +302,9 @@ static id nilBinaryTreeNode;
|
|||
{
|
||||
id y;
|
||||
|
||||
/* Make sure we actually own the aNode. */
|
||||
assert ([aNode binaryTree] == self);
|
||||
|
||||
y = [aNode leftNode];
|
||||
if (y == [self nilNode])
|
||||
return self;
|
||||
|
@ -345,156 +326,73 @@ static id nilBinaryTreeNode;
|
|||
return self;
|
||||
}
|
||||
|
||||
- (elt) elementAtIndex: (unsigned)index
|
||||
- objectAtIndex: (unsigned)index
|
||||
{
|
||||
elt ret;
|
||||
id ret;
|
||||
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
ret = [self firstElement];
|
||||
ret = [self firstObject];
|
||||
// Not very efficient; Should be rewritten;
|
||||
while (index--)
|
||||
ret = [self successorOfElement:ret];
|
||||
ret = [self successorOfObject: ret];
|
||||
return ret;
|
||||
}
|
||||
|
||||
- sortAddElement: (elt)newElement byCalling: (int(*)(elt,elt))aFunc
|
||||
- (void) sortAddObject: newObject
|
||||
{
|
||||
id theParent, tmpChild;
|
||||
|
||||
[newElement.id_u setLeftNode:[self nilNode]];
|
||||
[newElement.id_u setRightNode:[self nilNode]];
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject binaryTree] == NO_OBJECT);
|
||||
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setBinaryTree: self];
|
||||
|
||||
[newObject setLeftNode:[self nilNode]];
|
||||
[newObject setRightNode:[self nilNode]];
|
||||
theParent = [self nilNode];
|
||||
tmpChild = _contents_root;
|
||||
while (tmpChild != [self nilNode])
|
||||
{
|
||||
theParent = tmpChild;
|
||||
if ((*aFunc)(newElement,theParent) < 0)
|
||||
if ([newObject compare: theParent] < 0)
|
||||
tmpChild = [tmpChild leftNode];
|
||||
else
|
||||
tmpChild = [tmpChild rightNode];
|
||||
}
|
||||
[newElement.id_u setParentNode:theParent];
|
||||
[newObject setParentNode:theParent];
|
||||
if (theParent == [self nilNode])
|
||||
_contents_root = newElement.id_u;
|
||||
_contents_root = newObject;
|
||||
else
|
||||
{
|
||||
if (COMPARE_ELEMENTS(newElement, theParent) < 0)
|
||||
[theParent setLeftNode:newElement.id_u];
|
||||
if ([newObject compare: theParent] < 0)
|
||||
[theParent setLeftNode:newObject];
|
||||
else
|
||||
[theParent setRightNode:newElement.id_u];
|
||||
[theParent setRightNode:newObject];
|
||||
}
|
||||
_count++;
|
||||
RETAIN_ELT(newElement);
|
||||
return self;
|
||||
}
|
||||
|
||||
- addElement: (elt)newElement
|
||||
- (void) addObject: newObject
|
||||
{
|
||||
// By default insert in sorted order. Is this what we want?;
|
||||
[self sortAddElement:newElement];
|
||||
return self;
|
||||
// By default insert in sorted order.
|
||||
[self sortAddObject: newObject];
|
||||
}
|
||||
|
||||
// NOTE: This gives you the power to put elements in unsorted order;
|
||||
- insertElement: (elt)newElement before: (elt)oldElement
|
||||
{
|
||||
id tmp;
|
||||
|
||||
#if SAFE_BinaryTree
|
||||
if ([self rootFromNode:oldElement.id_u] != _contents_root)
|
||||
[self error:"in %s, oldElement not in tree!!", sel_get_name(_cmd)];
|
||||
#endif
|
||||
|
||||
[newElement.id_u setRightNode:[self nilNode]];
|
||||
[newElement.id_u setLeftNode:[self nilNode]];
|
||||
if ((tmp = [oldElement.id_u leftNode]) != [self nilNode])
|
||||
{
|
||||
[(tmp = [self rightmostNodeFromNode:tmp]) setRightNode:newElement.id_u];
|
||||
[newElement.id_u setParentNode:tmp];
|
||||
}
|
||||
else if (newElement.id_u != [self nilNode])
|
||||
{
|
||||
[oldElement.id_u setLeftNode:newElement.id_u];
|
||||
[newElement.id_u setParentNode:oldElement.id_u];
|
||||
}
|
||||
else
|
||||
{
|
||||
_contents_root = newElement.id_u;
|
||||
[newElement.id_u setParentNode:[self nilNode]];
|
||||
}
|
||||
_count++;
|
||||
RETAIN_ELT(newElement);
|
||||
return self;
|
||||
}
|
||||
|
||||
// NOTE: This gives you the power to put elements in unsorted order;
|
||||
- insertElement: (elt)newElement after: (elt)oldElement
|
||||
{
|
||||
id tmp;
|
||||
|
||||
#if SAFE_BinaryTree
|
||||
if ([self rootFromNode:oldElement.id_u] != _contents_root)
|
||||
[self error:"in %s, !!!!!!!!", sel_get_name(_cmd)];
|
||||
#endif
|
||||
|
||||
[newElement.id_u setRightNode:[self nilNode]];
|
||||
[newElement.id_u setLeftNode:[self nilNode]];
|
||||
if ((tmp = [oldElement.id_u rightNode]) != [self nilNode])
|
||||
{
|
||||
[(tmp = [self leftmostNodeFromNode:tmp]) setLeftNode:newElement.id_u];
|
||||
[newElement.id_u setParentNode:tmp];
|
||||
}
|
||||
else if (newElement.id_u != [self nilNode])
|
||||
{
|
||||
[oldElement.id_u setRightNode:newElement.id_u];
|
||||
[newElement.id_u setParentNode:oldElement.id_u];
|
||||
}
|
||||
else
|
||||
{
|
||||
_contents_root = newElement.id_u;
|
||||
[newElement.id_u setParentNode:[self nilNode]];
|
||||
}
|
||||
_count++;
|
||||
RETAIN_ELT(newElement);
|
||||
return self;
|
||||
}
|
||||
|
||||
// NOTE: This gives you the power to put elements in unsorted order;
|
||||
- insertElement: (elt)newElement atIndex: (unsigned)index
|
||||
{
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count+1);
|
||||
if (index == _count)
|
||||
[self appendElement:newElement];
|
||||
else
|
||||
[self insertElement:newElement before:[self elementAtIndex:index]];
|
||||
return self;
|
||||
}
|
||||
|
||||
// NOTE: This gives you the power to put elements in unsorted order;
|
||||
- appendElement: (elt)newElement
|
||||
{
|
||||
if (_count == 0)
|
||||
{
|
||||
_contents_root = newElement.id_u;
|
||||
_count = 1;
|
||||
[newElement.id_u setLeftNode:[self nilNode]];
|
||||
[newElement.id_u setRightNode:[self nilNode]];
|
||||
[newElement.id_u setParentNode:[self nilNode]];
|
||||
}
|
||||
else
|
||||
[self insertElement:newElement after:[self lastElement]];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (elt) removeElement: (elt)oldElement
|
||||
- (void) removeObject: oldObject
|
||||
{
|
||||
id x, y;
|
||||
|
||||
if ([oldElement.id_u leftNode] == [self nilNode]
|
||||
|| [oldElement.id_u rightNode] == [self nilNode])
|
||||
y = oldElement.id_u;
|
||||
/* Make sure we actually own the aNode. */
|
||||
assert ([oldObject binaryTree] == self);
|
||||
|
||||
/* Extract the oldObject and sew up the cut. */
|
||||
if ([oldObject leftNode] == [self nilNode]
|
||||
|| [oldObject rightNode] == [self nilNode])
|
||||
y = oldObject;
|
||||
else
|
||||
y = [self successorOfElement:oldElement].id_u;
|
||||
y = [self successorOfObject: oldObject];
|
||||
|
||||
if ([y leftNode] != [self nilNode])
|
||||
x = [y leftNode];
|
||||
|
@ -514,76 +412,54 @@ static id nilBinaryTreeNode;
|
|||
[[y parentNode] setRightNode: x];
|
||||
}
|
||||
|
||||
if (y != oldElement.id_u)
|
||||
if (y != oldObject)
|
||||
{
|
||||
/* put y in the place of oldElement.id_u */
|
||||
[y setParentNode:[oldElement.id_u parentNode]];
|
||||
[y setLeftNode:[oldElement.id_u leftNode]];
|
||||
[y setRightNode:[oldElement.id_u rightNode]];
|
||||
if (oldElement.id_u == [[oldElement.id_u parentNode] leftNode])
|
||||
[[oldElement.id_u parentNode] setLeftNode:y];
|
||||
/* put y in the place of oldObject */
|
||||
[y setParentNode: [oldObject parentNode]];
|
||||
[y setLeftNode: [oldObject leftNode]];
|
||||
[y setRightNode: [oldObject rightNode]];
|
||||
if (oldObject == [[oldObject parentNode] leftNode])
|
||||
[[oldObject parentNode] setLeftNode: y];
|
||||
else
|
||||
[[oldElement.id_u parentNode] setRightNode:y];
|
||||
[[oldElement.id_u leftNode] setParentNode:y];
|
||||
[[oldElement.id_u rightNode] setParentNode:y];
|
||||
[[oldObject parentNode] setRightNode: y];
|
||||
[[oldObject leftNode] setParentNode: y];
|
||||
[[oldObject rightNode] setParentNode: y];
|
||||
}
|
||||
[oldElement.id_u setRightNode:[self nilNode]];
|
||||
[oldElement.id_u setLeftNode:[self nilNode]];
|
||||
[oldElement.id_u setParentNode:[self nilNode]];
|
||||
_count--;
|
||||
return AUTORELEASE_ELT(oldElement);
|
||||
|
||||
/* Release ownership of the object. */
|
||||
#if 0
|
||||
[oldObject setRightNode: [self nilNode]];
|
||||
[oldObject setLeftNode: [self nilNode]];
|
||||
[oldObject setParentNode: [self nilNode]];
|
||||
#else
|
||||
[oldObject setLeftNode: NO_OBJECT];
|
||||
[oldObject setRightNode: NO_OBJECT];
|
||||
[oldObject setParentNode: NO_OBJECT];
|
||||
#endif
|
||||
[oldObject setBinaryTree: NO_OBJECT];
|
||||
[oldObject release];
|
||||
}
|
||||
|
||||
- withElementsCall: (void(*)(elt))aFunc whileTrue: (BOOL*)flag
|
||||
{
|
||||
void traverse(id aNode)
|
||||
{
|
||||
if (!(*flag) || aNode == [self nilNode] || !aNode)
|
||||
return;
|
||||
traverse([aNode leftNode]);
|
||||
(*aFunc)(aNode);
|
||||
traverse([aNode rightNode]);
|
||||
}
|
||||
traverse(_contents_root);
|
||||
return self;
|
||||
}
|
||||
|
||||
// ENUMERATING;
|
||||
|
||||
- withElementsInReverseCall: (void(*)(elt))aFunc whileTrue: (BOOL*)flag
|
||||
{
|
||||
void traverse(id aNode)
|
||||
{
|
||||
if (*flag || aNode == [self nilNode] || !aNode)
|
||||
return;
|
||||
traverse([aNode rightNode]);
|
||||
(*aFunc)(aNode);
|
||||
traverse([aNode leftNode]);
|
||||
}
|
||||
traverse(_contents_root);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) getNextElement:(elt *)anElementPtr withEnumState: (void**)enumState
|
||||
- nextObjectWithEnumState: (void**)enumState
|
||||
{
|
||||
if (!(*enumState))
|
||||
*enumState = [self leftmostNodeFromNode:_contents_root];
|
||||
else
|
||||
*enumState = [self successorOfElement:*enumState].id_u;
|
||||
*anElementPtr = *enumState;
|
||||
if (*enumState)
|
||||
return YES;
|
||||
return NO;
|
||||
*enumState = [self successorOfObject:*enumState];
|
||||
return (id) *enumState;
|
||||
}
|
||||
|
||||
- (BOOL) getPrevElement:(elt *)anElementPtr withEnumState: (void**)enumState
|
||||
- prevObjectWithEnumState: (void**)enumState
|
||||
{
|
||||
if (!(*enumState))
|
||||
*enumState = [self rightmostNodeFromNode:_contents_root];
|
||||
else
|
||||
*enumState = [self predecessorElement:*enumState].id_u;
|
||||
*anElementPtr = *enumState;
|
||||
if (*enumState)
|
||||
return YES;
|
||||
return NO;
|
||||
*enumState = [self predecessorObject:*enumState];
|
||||
return (id) *enumState;
|
||||
}
|
||||
|
||||
- (unsigned) count
|
||||
|
@ -591,14 +467,12 @@ static id nilBinaryTreeNode;
|
|||
return _count;
|
||||
}
|
||||
|
||||
|
||||
/* replace this with something better eventually */
|
||||
- _tmpPrintFromNode: aNode indent: (int)count
|
||||
{
|
||||
printf("%-*s", count, "");
|
||||
if ([aNode respondsTo:@selector(printForDebugger)])
|
||||
[aNode printForDebugger];
|
||||
else
|
||||
printf("?\n");
|
||||
printf("%s\n", [[aNode description] cStringNoCopy]);
|
||||
printf("%-*s.", count, "");
|
||||
if ([aNode leftNode] != [self nilNode])
|
||||
[self _tmpPrintFromNode:[aNode leftNode] indent:count+2];
|
||||
|
@ -621,3 +495,112 @@ static id nilBinaryTreeNode;
|
|||
@end
|
||||
|
||||
|
||||
|
||||
/* These methods removed because they belong to an
|
||||
OrderedCollection implementation, not an IndexedCollection
|
||||
implementation. */
|
||||
|
||||
#if 0
|
||||
// NOTE: This gives you the power to put elements in unsorted order;
|
||||
- insertObject: newObject before: oldObject
|
||||
{
|
||||
id tmp;
|
||||
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setBinaryTree: self];
|
||||
|
||||
[newObject setRightNode:[self nilNode]];
|
||||
[newObject setLeftNode:[self nilNode]];
|
||||
if ((tmp = [oldObject leftNode]) != [self nilNode])
|
||||
{
|
||||
[(tmp = [self rightmostNodeFromNode:tmp]) setRightNode:newObject];
|
||||
[newObject setParentNode:tmp];
|
||||
}
|
||||
else if (newObject != [self nilNode])
|
||||
{
|
||||
[oldObject setLeftNode:newObject];
|
||||
[newObject setParentNode:oldObject];
|
||||
}
|
||||
else
|
||||
{
|
||||
_contents_root = newObject;
|
||||
[newObject setParentNode:[self nilNode]];
|
||||
}
|
||||
_count++;
|
||||
RETAIN_ELT(newObject);
|
||||
return self;
|
||||
}
|
||||
|
||||
// NOTE: This gives you the power to put elements in unsorted order;
|
||||
- insertObject: newObject after: oldObject
|
||||
{
|
||||
id tmp;
|
||||
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setBinaryTree: self];
|
||||
|
||||
[newObject setRightNode:[self nilNode]];
|
||||
[newObject setLeftNode:[self nilNode]];
|
||||
if ((tmp = [oldObject rightNode]) != [self nilNode])
|
||||
{
|
||||
[(tmp = [self leftmostNodeFromNode:tmp]) setLeftNode:newObject];
|
||||
[newObject setParentNode:tmp];
|
||||
}
|
||||
else if (newObject != [self nilNode])
|
||||
{
|
||||
[oldObject setRightNode:newObject];
|
||||
[newObject setParentNode:oldObject];
|
||||
}
|
||||
else
|
||||
{
|
||||
_contents_root = newObject;
|
||||
[newObject setParentNode:[self nilNode]];
|
||||
}
|
||||
_count++;
|
||||
RETAIN_ELT(newObject);
|
||||
return self;
|
||||
}
|
||||
|
||||
// NOTE: This gives you the power to put elements in unsorted order;
|
||||
- insertObject: newObject atIndex: (unsigned)index
|
||||
{
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count+1);
|
||||
|
||||
if (index == _count)
|
||||
[self appendObject:newObject];
|
||||
else
|
||||
[self insertObject:newObject before:[self ObjectAtIndex:index]];
|
||||
return self;
|
||||
}
|
||||
|
||||
// NOTE: This gives you the power to put elements in unsorted order;
|
||||
- appendObject: newObject
|
||||
{
|
||||
if (_count == 0)
|
||||
{
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setBinaryTree: self];
|
||||
|
||||
_contents_root = newObject;
|
||||
_count = 1;
|
||||
[newObject setLeftNode:[self nilNode]];
|
||||
[newObject setRightNode:[self nilNode]];
|
||||
[newObject setParentNode:[self nilNode]];
|
||||
}
|
||||
else
|
||||
[self insertObject:newObject after:[self lastObject]];
|
||||
return self;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
[aCoder encodeObjectReference:_right withName:@"Right BinaryTree Node"];
|
||||
[aCoder encodeObjectReference:_left withName:@"Left BinaryTree Node"];
|
||||
[aCoder encodeObjectReference:_parent withName:@"Parent BinaryTree Node"];
|
||||
[aCoder encodeObjectReference:_binary_tree
|
||||
withName:@"BinaryTree"];
|
||||
}
|
||||
|
||||
- initWithCoder: aCoder
|
||||
|
@ -53,6 +55,7 @@
|
|||
[aCoder decodeObjectAt:&_right withName:NULL];
|
||||
[aCoder decodeObjectAt:&_left withName:NULL];
|
||||
[aCoder decodeObjectAt:&_parent withName:NULL];
|
||||
[aCoder decodeObjectAt:&_binary_tree withName:NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -71,22 +74,29 @@
|
|||
return _parent;
|
||||
}
|
||||
|
||||
- setLeftNode: aNode
|
||||
- (void) setLeftNode: aNode
|
||||
{
|
||||
_left = aNode;
|
||||
return self;
|
||||
}
|
||||
|
||||
- setRightNode: aNode
|
||||
- (void) setRightNode: aNode
|
||||
{
|
||||
_right = aNode;
|
||||
return self;
|
||||
}
|
||||
|
||||
- setParentNode: aNode
|
||||
- (void) setParentNode: aNode
|
||||
{
|
||||
_parent = aNode;
|
||||
return self;
|
||||
}
|
||||
|
||||
- binaryTree
|
||||
{
|
||||
return _binary_tree;
|
||||
}
|
||||
|
||||
- (void) setBinaryTree: anObject
|
||||
{
|
||||
_binary_tree = anObject;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Implementation for Objective-C CircularArray collection object
|
||||
Copyright (C) 1993,1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -27,17 +27,10 @@
|
|||
|
||||
@implementation CircularArray
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [CircularArray class])
|
||||
[self setVersion:0]; /* beta release */
|
||||
}
|
||||
|
||||
/* This is the designated initializer of this class */
|
||||
- initWithType: (const char *)contentEncoding
|
||||
capacity: (unsigned)aCapacity
|
||||
- initWithCapacity: (unsigned)aCapacity
|
||||
{
|
||||
[super initWithType:contentEncoding capacity:aCapacity];
|
||||
[super initWithCapacity:aCapacity];
|
||||
_start_index = 0;
|
||||
return self;
|
||||
}
|
||||
|
@ -51,13 +44,6 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- _readInit: (TypedStream*)aStream
|
||||
{
|
||||
[super _readInit: aStream];
|
||||
_start_index = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Empty copy must empty an allocCopy'ed version of self */
|
||||
|
||||
- emptyCopy
|
||||
|
@ -67,24 +53,23 @@
|
|||
return copy;
|
||||
}
|
||||
|
||||
- _empty
|
||||
- (void) _collectionEmpty
|
||||
{
|
||||
[super _empty];
|
||||
[super _collectionEmpty];
|
||||
_start_index = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* This is the only method that changes the value of the instance
|
||||
variable _capacity, except for "-initDescription:capacity:" */
|
||||
variable _capacity, except for "-initWithCapacity:" */
|
||||
|
||||
- setCapacity: (unsigned)newCapacity
|
||||
- (void) setCapacity: (unsigned)newCapacity
|
||||
{
|
||||
elt *new_contents;
|
||||
id *new_contents;
|
||||
int i;
|
||||
|
||||
if (newCapacity > _count) {
|
||||
/* This could be more efficient */
|
||||
OBJC_MALLOC(new_contents, elt, newCapacity);
|
||||
OBJC_MALLOC(new_contents, id, newCapacity);
|
||||
for (i = 0; i < _count; i++)
|
||||
new_contents[i] = _contents_array[CIRCULAR_TO_BASIC(i)];
|
||||
OBJC_FREE(_contents_array);
|
||||
|
@ -92,95 +77,83 @@
|
|||
_start_index = 0;
|
||||
_capacity = newCapacity;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (elt) removeElementAtIndex: (unsigned)index
|
||||
- (void) removeObjectAtIndex: (unsigned)index
|
||||
{
|
||||
unsigned basicIndex;
|
||||
elt ret;
|
||||
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
basicIndex = CIRCULAR_TO_BASIC(index);
|
||||
ret = _contents_array[basicIndex];
|
||||
[_contents_array[basicIndex] release];
|
||||
circularFillHoleAt(self, basicIndex);
|
||||
decrementCount(self);
|
||||
return AUTORELEASE_ELT(ret);
|
||||
}
|
||||
|
||||
- (elt) removeFirstElement
|
||||
- (void) removeFirstObject
|
||||
{
|
||||
elt ret;
|
||||
|
||||
ret = _contents_array[_start_index];
|
||||
if (!_count)
|
||||
return;
|
||||
[_contents_array[_start_index] release];
|
||||
_start_index = (_start_index + 1) % _capacity;
|
||||
decrementCount(self);
|
||||
return AUTORELEASE_ELT(ret);
|
||||
}
|
||||
|
||||
- (elt) removeLastElement
|
||||
- (void) removeLastObject
|
||||
{
|
||||
elt ret;
|
||||
|
||||
if (!_count)
|
||||
NO_ELEMENT_FOUND_ERROR();
|
||||
ret = _contents_array[CIRCULAR_TO_BASIC(_count-1)];
|
||||
return;
|
||||
[_contents_array[CIRCULAR_TO_BASIC(_count-1)] release];
|
||||
decrementCount(self);
|
||||
return AUTORELEASE_ELT(ret);
|
||||
}
|
||||
|
||||
- (elt) elementAtIndex: (unsigned)index
|
||||
- objectAtIndex: (unsigned)index
|
||||
{
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
return _contents_array[CIRCULAR_TO_BASIC(index)];
|
||||
}
|
||||
|
||||
- appendElement: (elt)newElement
|
||||
- (void) appendObject: newObject
|
||||
{
|
||||
incrementCount(self);
|
||||
RETAIN_ELT(newElement);
|
||||
_contents_array[CIRCULAR_TO_BASIC(_count-1)] = newElement;
|
||||
return self;
|
||||
[newObject retain];
|
||||
_contents_array[CIRCULAR_TO_BASIC(_count-1)] = newObject;
|
||||
}
|
||||
|
||||
- prependElement: (elt)newElement
|
||||
- (void) prependElement: newObject
|
||||
{
|
||||
incrementCount(self);
|
||||
RETAIN_ELT(newElement);
|
||||
[newObject retain];
|
||||
_start_index = (_capacity + _start_index - 1) % _capacity;
|
||||
_contents_array[_start_index] = newElement;
|
||||
return self;
|
||||
_contents_array[_start_index] = newObject;
|
||||
}
|
||||
|
||||
- insertElement: (elt)newElement atIndex: (unsigned)index
|
||||
- (void) insertElement: newObject atIndex: (unsigned)index
|
||||
{
|
||||
unsigned basicIndex;
|
||||
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count+1);
|
||||
incrementCount(self);
|
||||
RETAIN_ELT(newElement);
|
||||
[newObject retain];
|
||||
basicIndex = CIRCULAR_TO_BASIC(index);
|
||||
circularMakeHoleAt(self, basicIndex);
|
||||
_contents_array[basicIndex] = newElement;
|
||||
return self;
|
||||
_contents_array[basicIndex] = newObject;
|
||||
}
|
||||
|
||||
- (elt) replaceElementAtIndex: (unsigned)index with: (elt)newElement
|
||||
- (void) replaceObjectAtIndex: (unsigned)index withObject: newObject
|
||||
{
|
||||
elt ret;
|
||||
unsigned basicIndex;
|
||||
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
RETAIN_ELT(newElement);
|
||||
[newObject retain];
|
||||
basicIndex = CIRCULAR_TO_BASIC(index);
|
||||
ret = _contents_array[basicIndex];
|
||||
_contents_array[basicIndex] = newElement;
|
||||
return AUTORELEASE_ELT(ret);
|
||||
[_contents_array[basicIndex] release];
|
||||
_contents_array[basicIndex] = newObject;
|
||||
}
|
||||
|
||||
- swapAtIndeces: (unsigned)index1 : (unsigned)index2
|
||||
- (void) swapAtIndeces: (unsigned)index1 : (unsigned)index2
|
||||
{
|
||||
elt tmp;
|
||||
id tmp;
|
||||
|
||||
CHECK_INDEX_RANGE_ERROR(index1, _count);
|
||||
CHECK_INDEX_RANGE_ERROR(index2, _count);
|
||||
|
@ -189,10 +162,10 @@
|
|||
tmp = _contents_array[index1];
|
||||
_contents_array[index1] = _contents_array[index2];
|
||||
_contents_array[index2] = tmp;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* just temporary for debugging
|
||||
#if 0
|
||||
/* just temporary for debugging */
|
||||
- circularArrayPrintForDebugger
|
||||
{
|
||||
int i;
|
||||
|
@ -217,7 +190,7 @@
|
|||
|
||||
return self;
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
|
|
1614
Source/Collection.m
1614
Source/Collection.m
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
|||
/* Implementation for Objective-C LinkedList collection object
|
||||
Copyright (C) 1993,1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -27,21 +27,22 @@
|
|||
|
||||
@implementation LinkedList
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [LinkedList class])
|
||||
[self setVersion:0]; /* beta release */
|
||||
}
|
||||
|
||||
/* This is the designated initializer of this class */
|
||||
- init
|
||||
{
|
||||
[super initWithType:@encode(id)];
|
||||
_count = 0;
|
||||
_first_link = nil;
|
||||
_last_link = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
- initWithObjects: (id*)objs count: (unsigned)c
|
||||
{
|
||||
[self init];
|
||||
while (c--)
|
||||
[self prependObject: objs[c]];
|
||||
}
|
||||
|
||||
/* Archiving must mimic the above designated initializer */
|
||||
|
||||
- _initCollectionWithCoder: aCoder
|
||||
|
@ -49,10 +50,11 @@
|
|||
[super _initCollectionWithCoder:aCoder];
|
||||
_count = 0;
|
||||
_first_link = nil;
|
||||
_last_link = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) _encodeContentsWithCoder: aCoder
|
||||
- (void) _encodeContentsWithCoder: (id <Encoding>)aCoder
|
||||
{
|
||||
[aCoder startEncodingInterconnectedObjects];
|
||||
[super _encodeContentsWithCoder:aCoder];
|
||||
|
@ -63,257 +65,302 @@
|
|||
We shouldn't do an -addElement. finishEncodingInterconnectedObjects
|
||||
should take care of all that. */
|
||||
|
||||
- (void) _decodeContentsWithCoder: (Coder*)aCoder
|
||||
- (void) _decodeContentsWithCoder: (id <Decoding>)aCoder
|
||||
{
|
||||
[aCoder startDecodingInterconnectedObjects];
|
||||
[super _decodeContentsWithCoder:aCoder];
|
||||
[aCoder finishDecodingInterconnectedObjects];
|
||||
}
|
||||
|
||||
- _readInit: (TypedStream*)aStream
|
||||
{
|
||||
[super _readInit:aStream];
|
||||
_count = 0;
|
||||
_first_link = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Empty copy must empty an allocCopy'ed version of self */
|
||||
- emptyCopy
|
||||
{
|
||||
LinkedList *copy = [super emptyCopy];
|
||||
copy->_count = 0;
|
||||
copy->_first_link = nil;
|
||||
copy->_last_link = nil;
|
||||
copy->_count = 0;
|
||||
return copy;
|
||||
}
|
||||
|
||||
/* This must work without sending any messages to content objects */
|
||||
- _empty
|
||||
- (void) _empty
|
||||
{
|
||||
_count = 0;
|
||||
_first_link = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Override the designated initializer for our superclass IndexedCollection
|
||||
to make sure we have object values. */
|
||||
- initWithType: (const char *)contentEncoding
|
||||
{
|
||||
if (!ENCODING_IS_OBJECT(contentEncoding))
|
||||
[self error:"LinkedList contents must be objects conforming to "
|
||||
"<LinkedListComprising> protocol"];
|
||||
[self init];
|
||||
return self;
|
||||
_last_link = nil;
|
||||
}
|
||||
|
||||
/* These next four methods are the only ones that change the values of
|
||||
the instance variables _count, _first_link, except for
|
||||
"-initDescription:". */
|
||||
"-init". */
|
||||
|
||||
- (elt) removeElement: (elt)oldElement
|
||||
- (void) removeObject: oldObject
|
||||
{
|
||||
if (_first_link == oldElement.id_u)
|
||||
assert ([oldObject linkedList] == self);
|
||||
if (_first_link == oldObject)
|
||||
{
|
||||
if (_count > 1)
|
||||
_first_link = [oldElement.id_u nextLink];
|
||||
_first_link = [oldObject nextLink];
|
||||
else
|
||||
_first_link = nil;
|
||||
}
|
||||
[[oldElement.id_u nextLink] setPrevLink:[oldElement.id_u prevLink]];
|
||||
[[oldElement.id_u prevLink] setNextLink:[oldElement.id_u nextLink]];
|
||||
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]];
|
||||
_count--;
|
||||
return AUTORELEASE_ELT(oldElement);
|
||||
[oldObject setNextLink: NO_OBJECT];
|
||||
[oldObject setPrevLink: NO_OBJECT];
|
||||
[oldObject release];
|
||||
}
|
||||
|
||||
- insertElement: (elt)newElement after: (elt)oldElement
|
||||
- (void) insertObject: newObject after: oldObject
|
||||
{
|
||||
/* Make sure we actually own the oldObject. */
|
||||
assert ([oldObject linkedList] == self);
|
||||
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setLinkedList: self];
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
/* link to self */
|
||||
_first_link = newElement.id_u;
|
||||
[newElement.id_u setNextLink:newElement.id_u];
|
||||
[newElement.id_u setPrevLink:newElement.id_u];
|
||||
_first_link = newObject;
|
||||
_last_link = newObject;
|
||||
[newObject setNextLink: NO_OBJECT];
|
||||
[newObject setPrevLink: NO_OBJECT];
|
||||
}
|
||||
else
|
||||
{
|
||||
[newElement.id_u setNextLink:[oldElement.id_u nextLink]];
|
||||
[newElement.id_u setPrevLink:oldElement.id_u];
|
||||
[[oldElement.id_u nextLink] setPrevLink:newElement.id_u];
|
||||
[oldElement.id_u setNextLink:newElement.id_u];
|
||||
if (oldObject == _last_link)
|
||||
_last_link = newObject;
|
||||
[newObject setNextLink: [oldObject nextLink]];
|
||||
[newObject setPrevLink: oldObject];
|
||||
[[oldObject nextLink] setPrevLink: newObject];
|
||||
[oldObject setNextLink: newObject];
|
||||
}
|
||||
_count++;
|
||||
return self;
|
||||
}
|
||||
|
||||
- insertElement: (elt)newElement before: (elt)oldElement
|
||||
- (void) insertObject: newObject before: oldObject
|
||||
{
|
||||
if (oldElement.id_u == _first_link)
|
||||
_first_link = newElement.id_u;
|
||||
/* Make sure we actually own the oldObject. */
|
||||
assert ([oldObject linkedList] == self);
|
||||
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setLinkedList: self];
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
/* Link to self */
|
||||
[newElement.id_u setNextLink:newElement.id_u];
|
||||
[newElement.id_u setPrevLink:newElement.id_u];
|
||||
_first_link = newObject;
|
||||
_last_link = newObject;
|
||||
[newObject setNextLink: NO_OBJECT];
|
||||
[newObject setPrevLink: NO_OBJECT];
|
||||
}
|
||||
else
|
||||
{
|
||||
[newElement.id_u setPrevLink:[oldElement.id_u prevLink]];
|
||||
[newElement.id_u setNextLink:oldElement.id_u];
|
||||
[[oldElement.id_u prevLink] setNextLink:newElement.id_u];
|
||||
[oldElement.id_u setPrevLink:newElement.id_u];
|
||||
if (oldObject == _first_link)
|
||||
_first_link = newObject;
|
||||
[newObject setPrevLink: [oldObject prevLink]];
|
||||
[newObject setNextLink: oldObject];
|
||||
[[oldObject prevLink] setNextLink: newObject];
|
||||
[oldObject setPrevLink: newObject];
|
||||
}
|
||||
_count++;
|
||||
RETAIN_ELT(newElement);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (elt) replaceElement: (elt)oldElement with: (elt)newElement
|
||||
- (void) replaceObject: oldObject with: newObject
|
||||
{
|
||||
RETAIN_ELT(newElement);
|
||||
if (oldElement.id_u == _first_link)
|
||||
_first_link = newElement.id_u;
|
||||
[newElement.id_u setNextLink:[oldElement.id_u nextLink]];
|
||||
[newElement.id_u setPrevLink:[oldElement.id_u prevLink]];
|
||||
[[oldElement.id_u prevLink] setNextLink:newElement.id_u];
|
||||
[[oldElement.id_u nextLink] setPrevLink:newElement.id_u];
|
||||
return AUTORELEASE_ELT(oldElement);
|
||||
/* Make sure we actually own the oldObject. */
|
||||
assert ([oldObject linkedList] == self);
|
||||
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* 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];
|
||||
}
|
||||
|
||||
/* End of methods that change the instance variables. */
|
||||
|
||||
|
||||
|
||||
- appendElement: (elt)newElement
|
||||
- (void) appendObject: newObject
|
||||
{
|
||||
if (_count)
|
||||
[self insertElement:newElement after:[self lastElement]];
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setLinkedList: self];
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
_first_link = newObject;
|
||||
_last_link = newObject;
|
||||
[newObject setNextLink: NO_OBJECT];
|
||||
[newObject setPrevLink: NO_OBJECT];
|
||||
}
|
||||
else
|
||||
[self insertElement:newElement after:nil];
|
||||
return self;
|
||||
[self insertObject: newObject after: _last_link];
|
||||
}
|
||||
|
||||
- prependElement: (elt)newElement
|
||||
- prependElement: newObject
|
||||
{
|
||||
[self insertElement:newElement before:_first_link];
|
||||
return self;
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setLinkedList: self];
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
_first_link = newObject;
|
||||
_last_link = newObject;
|
||||
[newObject setNextLink: NO_OBJECT];
|
||||
[newObject setPrevLink: NO_OBJECT];
|
||||
}
|
||||
else
|
||||
[self insertObject: newObject before: _first_link];
|
||||
}
|
||||
|
||||
- insertElement: (elt)newElement atIndex: (unsigned)index
|
||||
- insertElement: newObject atIndex: (unsigned)index
|
||||
{
|
||||
CHECK_INDEX_RANGE_ERROR(index, (_count+1));
|
||||
if (index == _count)
|
||||
[self insertElement:newElement after:[self lastElement]];
|
||||
|
||||
/* Make sure no one else already owns the newObject. */
|
||||
assert ([newObject linkedList] == NO_OBJECT);
|
||||
|
||||
/* Claim ownership of the newObject. */
|
||||
[newObject retain];
|
||||
[newObject setLinkedList: self];
|
||||
|
||||
/* Insert it. */
|
||||
if (_count == 0)
|
||||
{
|
||||
_first_link = newObject;
|
||||
_last_link = newObject;
|
||||
[newObject setNextLink: NO_OBJECT];
|
||||
[newObject setPrevLink: NO_OBJECT];
|
||||
}
|
||||
else if (index == _count)
|
||||
[self insertObject: newObject after: _last_link];
|
||||
else
|
||||
[self insertElement:newElement before:[self elementAtIndex:index]];
|
||||
[self insertObject:newObject before: [self objectAtIndex: index]];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (elt) removeElementAtIndex: (unsigned)index
|
||||
- (void) removeObjectAtIndex: (unsigned)index
|
||||
{
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
return [self removeElement:[self elementAtIndex:index]];
|
||||
[self removeObject: [self objectAtIndex: index]];
|
||||
}
|
||||
|
||||
- (elt) elementAtIndex: (unsigned)index
|
||||
- objectAtIndex: (unsigned)index
|
||||
{
|
||||
id <LinkedListComprising> aLink;
|
||||
id <LinkedListComprising> link;
|
||||
|
||||
CHECK_INDEX_RANGE_ERROR(index, _count);
|
||||
|
||||
if (index < _count / 2)
|
||||
for (aLink = _first_link;
|
||||
for (link = _first_link;
|
||||
index;
|
||||
aLink = [aLink nextLink], index--)
|
||||
link = [link nextLink], index--)
|
||||
;
|
||||
else
|
||||
for (aLink = [_first_link prevLink], index = _count - index - 1;
|
||||
for (link = _last_link, index = _count - index - 1;
|
||||
index;
|
||||
aLink = [aLink prevLink], index--)
|
||||
link = [link prevLink], index--)
|
||||
;
|
||||
return aLink;
|
||||
return link;
|
||||
}
|
||||
|
||||
- (elt) firstElement
|
||||
- firstObject
|
||||
{
|
||||
return _first_link;
|
||||
}
|
||||
|
||||
- (elt) lastElement
|
||||
- lastObject
|
||||
{
|
||||
if (_count)
|
||||
return [_first_link prevLink];
|
||||
else
|
||||
return NO_ELEMENT_FOUND_ERROR();
|
||||
return _last_link;
|
||||
}
|
||||
|
||||
- (elt) successorOfElement: (elt)oldElement
|
||||
- successorOfObject: oldObject
|
||||
{
|
||||
id nextElement = [oldElement.id_u nextLink];
|
||||
if (_first_link == nextElement)
|
||||
return nil;
|
||||
else
|
||||
return (elt)nextElement;
|
||||
/* Make sure we actually own the oldObject. */
|
||||
assert ([oldObject linkedList] == self);
|
||||
|
||||
return [oldObject nextLink];
|
||||
}
|
||||
|
||||
- (elt) predecessorOfElement: (elt)oldElement
|
||||
- predecessorOfObject: oldObject
|
||||
{
|
||||
if (_first_link == oldElement.id_u)
|
||||
return nil;
|
||||
else
|
||||
return (elt)[oldElement.id_u prevLink];
|
||||
/* Make sure we actually own the oldObject. */
|
||||
assert ([oldObject linkedList] == self);
|
||||
|
||||
return [oldObject prevLink];
|
||||
}
|
||||
|
||||
- (BOOL) getNextElement:(elt *)anElementPtr withEnumState: (void**)enumState
|
||||
- nextObjectWithEnumState: (void**)enumState
|
||||
{
|
||||
/* *enumState points to the next object to be returned. */
|
||||
id ret;
|
||||
|
||||
if (*enumState == _first_link)
|
||||
return NO;
|
||||
return NO_OBJECT;
|
||||
else if (!(*enumState))
|
||||
*enumState = _first_link;
|
||||
*anElementPtr = *enumState;
|
||||
ret = (id) *enumState;
|
||||
*enumState = [(id)(*enumState) nextLink];
|
||||
return YES;
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (BOOL) getPrevElement:(elt *)anElementPtr withEnumState: (void**)enumState
|
||||
- prevObjectWithEnumState: (void**)enumState
|
||||
{
|
||||
if (*enumState == _first_link)
|
||||
return NO;
|
||||
if (!(*enumState))
|
||||
*enumState = _first_link;
|
||||
id ret;
|
||||
|
||||
if (*enumState == _last_link)
|
||||
return NO_OBJECT;
|
||||
else if (!(*enumState))
|
||||
*enumState = _last_link;
|
||||
ret = (id) *enumState;
|
||||
*enumState = [(id)(*enumState) prevLink];
|
||||
*anElementPtr = *enumState;
|
||||
return YES;
|
||||
return ret;
|
||||
}
|
||||
|
||||
- withElementsCall: (void(*)(elt))aFunc whileTrue:(BOOL *)flag
|
||||
{
|
||||
id link;
|
||||
unsigned i;
|
||||
|
||||
for (link = _first_link, i = 0;
|
||||
*flag && i < _count;
|
||||
link = [link nextLink], i++)
|
||||
{
|
||||
(*aFunc)(link);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- withElementsInReverseCall: (void(*)(elt))aFunc whileTrue:(BOOL *)flag
|
||||
{
|
||||
id link;
|
||||
unsigned i;
|
||||
|
||||
if (!_first_link)
|
||||
return self;
|
||||
for (link = [_first_link prevLink], i = 0;
|
||||
*flag && i < _count;
|
||||
link = [link prevLink], i++)
|
||||
{
|
||||
(*aFunc)(link);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (unsigned) count
|
||||
{
|
||||
return _count;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Implementation for Objective-C LinkedListNode object
|
||||
Copyright (C) 1993,1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -44,6 +44,7 @@
|
|||
[super encodeWithCoder:aCoder];
|
||||
[aCoder encodeObjectReference:_next withName:@"Next LinkedList Node"];
|
||||
[aCoder encodeObjectReference:_prev withName:@"Prev LinkedList Node"];
|
||||
[aCoder encodeObjectReference:_linked_list withName:@"LinkedList"];
|
||||
}
|
||||
|
||||
- initWithCoder: aCoder
|
||||
|
@ -51,6 +52,7 @@
|
|||
[super initWithCoder:aCoder];
|
||||
[aCoder decodeObjectAt:&_next withName:NULL];
|
||||
[aCoder decodeObjectAt:&_prev withName:NULL];
|
||||
[aCoder decodeObjectAt:&_linked_list withName:NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -64,17 +66,24 @@
|
|||
return _prev;
|
||||
}
|
||||
|
||||
- setNextLink: (id <LinkedListComprising>)aLink
|
||||
- (void) setNextLink: (id <LinkedListComprising>)aLink
|
||||
{
|
||||
_next = aLink;
|
||||
return self;
|
||||
}
|
||||
|
||||
- setPrevLink: (id <LinkedListComprising>)aLink
|
||||
- (void) setPrevLink: (id <LinkedListComprising>)aLink
|
||||
{
|
||||
_prev = aLink;
|
||||
return self;
|
||||
}
|
||||
|
||||
- linkedList
|
||||
{
|
||||
return _linked_list;
|
||||
}
|
||||
|
||||
- (void) setLinkedList: anObject;
|
||||
{
|
||||
_linked_list = anObject;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Implementation for Objective-C MappedCollector collection object
|
||||
Copyright (C) 1993,1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -28,13 +28,9 @@
|
|||
@implementation MappedCollector
|
||||
|
||||
/* This is the designated initializer for this class */
|
||||
- initCollection: (id <KeyedCollecting>)aDomain
|
||||
- initWithCollection: (id <KeyedCollecting>)aDomain
|
||||
map: (id <KeyedCollecting>)aMap
|
||||
{
|
||||
if (strcmp([aMap contentType], [aDomain keyType]))
|
||||
[self error:"map's contents are not the same as domain's keys"];
|
||||
[super initWithType:[aDomain contentType]
|
||||
keyType:[aMap keyType]];
|
||||
_map = aMap;
|
||||
_domain = aDomain;
|
||||
return self;
|
||||
|
@ -53,20 +49,10 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- _writeInit: (TypedStream*)aStream
|
||||
/* Override our superclass' designated initializer */
|
||||
- initWithObjects: (id*)objects forKeys: (id*)keys count: (unsigned)c
|
||||
{
|
||||
[super _writeInit: aStream];
|
||||
objc_write_object(aStream, _map);
|
||||
objc_write_object(aStream, _domain);
|
||||
return self;
|
||||
}
|
||||
|
||||
- _readInit: (TypedStream*)aStream
|
||||
{
|
||||
[super _readInit: aStream];
|
||||
objc_read_object(aStream, &_map);
|
||||
objc_read_object(aStream, &_domain);
|
||||
return self;
|
||||
[self notImplemented: _cmd];
|
||||
}
|
||||
|
||||
/* Empty copy must empty an allocCopy'ed version of self */
|
||||
|
@ -79,83 +65,56 @@
|
|||
}
|
||||
|
||||
/* This must work without sending any messages to content objects */
|
||||
- empty
|
||||
- (void) empty
|
||||
{
|
||||
[_domain empty];
|
||||
}
|
||||
|
||||
- objectAtKey: aKey
|
||||
{
|
||||
return [_domain objectAtKey: [_map objectAtKey: aKey]];
|
||||
}
|
||||
|
||||
- keyOfObject: aContentObject
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (const char *) contentType
|
||||
- (void) replaceObjectAtKey: aKey with: newObject
|
||||
{
|
||||
return [_domain contentType];
|
||||
return [_domain replaceObjectAtKey: [_map objectAtKey: aKey]
|
||||
with: newObject];
|
||||
}
|
||||
|
||||
- (const char *) keyType
|
||||
- (void) putObject: newObject atKey: aKey
|
||||
{
|
||||
return [_map keyType];
|
||||
return [_domain putObject: newObject
|
||||
atKey: [_map objectAtKey:aKey]];
|
||||
}
|
||||
|
||||
- (int(*)(elt,elt)) comparisonFunction
|
||||
- (void) removeObjectAtKey: aKey
|
||||
{
|
||||
return [_domain comparisonFunction];
|
||||
return [_domain removeObjectAtKey: [_map objectAtKey: aKey]];
|
||||
}
|
||||
|
||||
- (elt) elementAtKey: (elt)aKey
|
||||
- (BOOL) containsKey: aKey
|
||||
{
|
||||
return [_domain elementAtKey:[_map elementAtKey:aKey]];
|
||||
return [_domain containsKey: [_map objectAtKey:aKey]];
|
||||
}
|
||||
|
||||
- (elt) replaceElementAtKey: (elt)aKey with: (elt)newElement
|
||||
- nextObjectAndKey: (id*)keyPtr withEnumState: (void**)enumState
|
||||
{
|
||||
return [_domain replaceElementAtKey:[_map elementAtKey:aKey]
|
||||
with:newElement];
|
||||
}
|
||||
id mapContent;
|
||||
id domainKey;
|
||||
|
||||
- putElement: (elt)newElement atKey: (elt)aKey
|
||||
{
|
||||
return [_domain putElement:newElement
|
||||
atKey:[_map elementAtKey:aKey]];
|
||||
}
|
||||
|
||||
- (elt) removeElementAtKey: (elt)aKey
|
||||
{
|
||||
return [_domain removeElementAtKey:[_map elementAtKey:aKey]];
|
||||
}
|
||||
|
||||
- (BOOL) includesKey: (elt)aKey
|
||||
{
|
||||
return [_domain includesKey:[_map elementAtKey:aKey]];
|
||||
}
|
||||
|
||||
- withKeyElementsAndContentElementsCall: (void(*)(const elt,elt))aFunc
|
||||
whileTrue: (BOOL *)flag
|
||||
{
|
||||
void doIt(elt e)
|
||||
{
|
||||
elt domainKey = [_map elementAtKey:e];
|
||||
if ([_domain includesKey:domainKey])
|
||||
(*aFunc)(e, [_domain elementAtKey:domainKey]);
|
||||
}
|
||||
[_map withKeyElementsCall:doIt];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) getNextKey: (elt*)aKeyPtr content: (elt*)anElementPtr
|
||||
withEnumState: (void**)enumState;
|
||||
{
|
||||
BOOL ret;
|
||||
elt mapContent;
|
||||
elt domainKey;
|
||||
|
||||
while ((ret = [_map getNextKey:aKeyPtr content:&mapContent
|
||||
withEnumState:enumState])
|
||||
while ((mapContent = [_map nextObjectAndKey:keyPtr withEnumState:enumState])
|
||||
&&
|
||||
(![_domain includesKey:(domainKey = [_map elementAtKey:*aKeyPtr])]))
|
||||
(![_domain containsKey: (domainKey = [_map objectAtKey:*keyPtr])]))
|
||||
;
|
||||
if (!ret)
|
||||
return NO;
|
||||
*anElementPtr = [_domain elementAtKey:domainKey];
|
||||
return YES;
|
||||
if (mapContent == NO_OBJECT)
|
||||
return NO_OBJECT;
|
||||
return [_domain objectAtKey: domainKey];
|
||||
}
|
||||
|
||||
- species
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Implementation for Objective-C Queue object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -26,40 +26,22 @@
|
|||
|
||||
@implementation Queue
|
||||
|
||||
+ (void) initialize
|
||||
- (void) enqueueObject: newObject
|
||||
{
|
||||
if (self == [Queue class])
|
||||
[self setVersion:0]; /* beta release */
|
||||
}
|
||||
|
||||
- enqueueElement: (elt)newElement
|
||||
{
|
||||
[self prependElement:newElement];
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Overriding */
|
||||
- addElement: (elt)anElement
|
||||
{
|
||||
[self enqueueElement:anElement];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (elt) dequeueElement
|
||||
{
|
||||
return [self removeLastElement];
|
||||
}
|
||||
|
||||
// OBJECT-COMPATIBLE MESSAGE NAMES;
|
||||
|
||||
- enqueueObject: newObject
|
||||
{
|
||||
return [self enqueueElement:newObject];
|
||||
[self prependObject: newObject];
|
||||
}
|
||||
|
||||
- dequeueObject
|
||||
{
|
||||
return [self dequeueElement].id_u;
|
||||
id ret = [[self lastObject] retain];
|
||||
[self removeLastObject];
|
||||
return [ret autorelease];
|
||||
}
|
||||
|
||||
/* Overriding */
|
||||
- (void) addObject: newObject
|
||||
{
|
||||
[self enqueueObject: newObject];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
142
Source/RBTree.m
142
Source/RBTree.m
|
@ -1,5 +1,5 @@
|
|||
/* Implementation for Objective-C Red-Black Tree collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -37,7 +37,6 @@ static id nilRBNode;
|
|||
{
|
||||
if (self == [RBTree class])
|
||||
{
|
||||
[self setVersion:0]; /* beta release */
|
||||
nilRBNode = [[RBTreeNode alloc] init];
|
||||
[nilRBNode setBlack];
|
||||
}
|
||||
|
@ -48,68 +47,67 @@ static id nilRBNode;
|
|||
return nilRBNode;
|
||||
}
|
||||
|
||||
- sortAddElement: (elt)newElement byCalling: (int(*)(elt,elt))aFunc
|
||||
- (void) sortAddObject: newObject
|
||||
{
|
||||
id y;
|
||||
|
||||
[super sortAddElement:newElement byCalling:aFunc];
|
||||
[newElement.id_u setRed];
|
||||
while (newElement.id_u != _contents_root
|
||||
&& [[newElement.id_u parentNode] isRed])
|
||||
[super sortAddObject: newObject];
|
||||
[newObject setRed];
|
||||
while (newObject != _contents_root
|
||||
&& [[newObject parentNode] isRed])
|
||||
{
|
||||
if ([newElement.id_u parentNode] ==
|
||||
[[[newElement.id_u parentNode] parentNode] leftNode])
|
||||
if ([newObject parentNode] ==
|
||||
[[[newObject parentNode] parentNode] leftNode])
|
||||
{
|
||||
y = [[[newElement.id_u parentNode] parentNode] leftNode];
|
||||
y = [[[newObject parentNode] parentNode] leftNode];
|
||||
if ([y isRed])
|
||||
{
|
||||
[[newElement.id_u parentNode] setBlack];
|
||||
[[newObject parentNode] setBlack];
|
||||
[y setBlack];
|
||||
[[[newElement.id_u parentNode] parentNode] setRed];
|
||||
newElement.id_u = [[newElement.id_u parentNode] parentNode];
|
||||
[[[newObject parentNode] parentNode] setRed];
|
||||
newObject = [[newObject parentNode] parentNode];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newElement.id_u == [[newElement.id_u parentNode] rightNode])
|
||||
if (newObject == [[newObject parentNode] rightNode])
|
||||
{
|
||||
newElement.id_u = [newElement.id_u parentNode];
|
||||
[self leftRotateAroundNode:newElement.id_u];
|
||||
newObject = [newObject parentNode];
|
||||
[self leftRotateAroundNode:newObject];
|
||||
}
|
||||
[[newElement.id_u parentNode] setBlack];
|
||||
[[[newElement.id_u parentNode] parentNode] setRed];
|
||||
[[newObject parentNode] setBlack];
|
||||
[[[newObject parentNode] parentNode] setRed];
|
||||
[self rightRotateAroundNode:
|
||||
[[newElement.id_u parentNode] parentNode]];
|
||||
[[newObject parentNode] parentNode]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
y = [[[newElement.id_u parentNode] parentNode] rightNode];
|
||||
y = [[[newObject parentNode] parentNode] rightNode];
|
||||
if ([y isRed])
|
||||
{
|
||||
[[newElement.id_u parentNode] setBlack];
|
||||
[[newObject parentNode] setBlack];
|
||||
[y setBlack];
|
||||
[[[newElement.id_u parentNode] parentNode] setRed];
|
||||
newElement.id_u = [[newElement.id_u parentNode] parentNode];
|
||||
[[[newObject parentNode] parentNode] setRed];
|
||||
newObject = [[newObject parentNode] parentNode];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newElement.id_u == [[newElement.id_u parentNode] leftNode])
|
||||
if (newObject == [[newObject parentNode] leftNode])
|
||||
{
|
||||
newElement.id_u = [newElement.id_u parentNode];
|
||||
[self rightRotateAroundNode:newElement.id_u];
|
||||
newObject = [newObject parentNode];
|
||||
[self rightRotateAroundNode:newObject];
|
||||
}
|
||||
[[newElement.id_u parentNode] setBlack];
|
||||
[[[newElement.id_u parentNode] parentNode] setRed];
|
||||
[[newObject parentNode] setBlack];
|
||||
[[[newObject parentNode] parentNode] setRed];
|
||||
[self leftRotateAroundNode:
|
||||
[[newElement.id_u parentNode] parentNode]];
|
||||
[[newObject parentNode] parentNode]];
|
||||
}
|
||||
}
|
||||
}
|
||||
[_contents_root setBlack];
|
||||
return self;
|
||||
}
|
||||
|
||||
- _RBTreeDeleteFixup: x
|
||||
- (void) _RBTreeDeleteFixup: x
|
||||
{
|
||||
id w;
|
||||
|
||||
|
@ -185,18 +183,17 @@ static id nilRBNode;
|
|||
}
|
||||
}
|
||||
[x setBlack];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (elt) removeElement: (elt)oldElement
|
||||
- (void) removeObject: oldObject
|
||||
{
|
||||
id x, y;
|
||||
|
||||
if ([oldElement.id_u leftNode] == [self nilNode]
|
||||
|| [oldElement.id_u rightNode] == [self nilNode])
|
||||
y = oldElement.id_u;
|
||||
if ([oldObject leftNode] == [self nilNode]
|
||||
|| [oldObject rightNode] == [self nilNode])
|
||||
y = oldObject;
|
||||
else
|
||||
y = [self successorOfElement:oldElement].id_u;
|
||||
y = [self successorOfObject: oldObject];
|
||||
|
||||
if ([y leftNode] != [self nilNode])
|
||||
x = [y leftNode];
|
||||
|
@ -215,63 +212,38 @@ static id nilRBNode;
|
|||
[[y parentNode] setRightNode:x];
|
||||
}
|
||||
|
||||
if (y != oldElement.id_u)
|
||||
if (y != oldObject)
|
||||
{
|
||||
/* put y in the place of oldElement.id_u */
|
||||
[y setParentNode:[oldElement.id_u parentNode]];
|
||||
[y setLeftNode:[oldElement.id_u leftNode]];
|
||||
[y setRightNode:[oldElement.id_u rightNode]];
|
||||
if (oldElement.id_u == [[oldElement.id_u parentNode] leftNode])
|
||||
[[oldElement.id_u parentNode] setLeftNode:y];
|
||||
/* put y in the place of oldObject */
|
||||
[y setParentNode:[oldObject parentNode]];
|
||||
[y setLeftNode:[oldObject leftNode]];
|
||||
[y setRightNode:[oldObject rightNode]];
|
||||
if (oldObject == [[oldObject parentNode] leftNode])
|
||||
[[oldObject parentNode] setLeftNode:y];
|
||||
else
|
||||
[[oldElement.id_u parentNode] setRightNode:oldElement.id_u];
|
||||
[[oldElement.id_u leftNode] setParentNode:y];
|
||||
[[oldElement.id_u rightNode] setParentNode:y];
|
||||
[[oldObject parentNode] setRightNode:oldObject];
|
||||
[[oldObject leftNode] setParentNode:y];
|
||||
[[oldObject rightNode] setParentNode:y];
|
||||
}
|
||||
|
||||
if (NODE_IS_BLACK(y))
|
||||
[self _RBTreeDeleteFixup:x];
|
||||
|
||||
[oldElement.id_u setRightNode:[self nilNode]];
|
||||
[oldElement.id_u setLeftNode:[self nilNode]];
|
||||
[oldElement.id_u setParentNode:[self nilNode]];
|
||||
_count--;
|
||||
return AUTORELEASE_ELT(oldElement);
|
||||
|
||||
/* Release ownership of the object. */
|
||||
#if 0
|
||||
[oldObject setRightNode: [self nilNode]];
|
||||
[oldObject setLeftNode: [self nilNode]];
|
||||
[oldObject setParentNode: [self nilNode]];
|
||||
#else
|
||||
[oldObject setLeftNode: NO_OBJECT];
|
||||
[oldObject setRightNode: NO_OBJECT];
|
||||
[oldObject setParentNode: NO_OBJECT];
|
||||
#endif
|
||||
[oldObject setBinaryTree: NO_OBJECT];
|
||||
[oldObject release];
|
||||
}
|
||||
|
||||
/* Override methods that could violate assumptions of RBTree structure.
|
||||
Perhaps I shouldn't DISALLOW this, let users have the power to do
|
||||
whatever they want. I mention this in the QUESTIONS section of the
|
||||
TODO file. */
|
||||
|
||||
/***
|
||||
Or perhaps instead of calling INSERTION_ERROR we could fix up the RB
|
||||
property of the tree.
|
||||
|
||||
- insertElement: (elt)newElement before: (elt)oldElement
|
||||
{
|
||||
INSERTION_ERROR();
|
||||
return self;
|
||||
}
|
||||
|
||||
- insertElement: (elt)newElement after: (elt)oldElement
|
||||
{
|
||||
INSERTION_ERROR();
|
||||
return self;
|
||||
}
|
||||
|
||||
- insertElement: (elt)newElement atIndex: (unsigned)index
|
||||
{
|
||||
INSERTION_ERROR();
|
||||
return self;
|
||||
}
|
||||
|
||||
- appendElement: (elt)newElement
|
||||
{
|
||||
INSERTION_ERROR();
|
||||
return self;
|
||||
}
|
||||
****/
|
||||
|
||||
@end
|
||||
|
||||
|
|
225
Source/Set.m
225
Source/Set.m
|
@ -24,17 +24,12 @@
|
|||
#include <objects/Set.h>
|
||||
#include <objects/CollectionPrivate.h>
|
||||
#include <objects/Coder.h>
|
||||
#include <Foundation/NSHashTable.h>
|
||||
|
||||
#define DEFAULT_SET_CAPACITY 32
|
||||
|
||||
@implementation Set
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [Set class])
|
||||
[self setVersion:0]; /* beta release */
|
||||
}
|
||||
|
||||
// MANAGING CAPACITY;
|
||||
|
||||
/* Eventually we will want to have better capacity management,
|
||||
|
@ -48,75 +43,28 @@
|
|||
// INITIALIZING AND FREEING;
|
||||
|
||||
/* This is the designated initializer of this class */
|
||||
- initWithType:(const char *)encoding
|
||||
capacity: (unsigned)aCapacity
|
||||
- initWithCapacity: (unsigned)cap
|
||||
{
|
||||
[super initWithType:encoding];
|
||||
_contents_hash =
|
||||
coll_hash_new(POWER_OF_TWO(aCapacity),
|
||||
elt_get_hash_function(encoding),
|
||||
elt_get_comparison_function(encoding));
|
||||
_contents_hash = NSCreateHashTable(NSObjectsHashCallBacks, cap);
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Override Collection's designated initializer */
|
||||
- initWithObjects: (id*)objs count: (unsigned)count
|
||||
{
|
||||
[self initWithCapacity: count];
|
||||
while (count--)
|
||||
[self addObject: objs[count]];
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Archiving must mimic the above designated initializer */
|
||||
|
||||
- (void) _encodeCollectionWithCoder: (Coder*) aCoder
|
||||
{
|
||||
const char *enc = [self contentType];
|
||||
|
||||
[super _encodeCollectionWithCoder:aCoder];
|
||||
[aCoder encodeValueOfCType:@encode(char*)
|
||||
at:&enc
|
||||
withName:@"Set contents encoding"];
|
||||
[aCoder encodeValueOfCType:@encode(unsigned)
|
||||
at:&(_contents_hash->size)
|
||||
withName:@"Set contents capacity"];
|
||||
return;
|
||||
}
|
||||
|
||||
- _initCollectionWithCoder: aCoder
|
||||
{
|
||||
char *encoding;
|
||||
unsigned size;
|
||||
|
||||
[super _initCollectionWithCoder:aCoder];
|
||||
[aCoder decodeValueOfCType:@encode(char*)
|
||||
at:&encoding
|
||||
withName:NULL];
|
||||
[aCoder decodeValueOfCType:@encode(unsigned)
|
||||
at:&size
|
||||
withName:NULL];
|
||||
_contents_hash =
|
||||
coll_hash_new(size,
|
||||
elt_get_hash_function(encoding),
|
||||
elt_get_comparison_function(encoding));
|
||||
return self;
|
||||
}
|
||||
|
||||
- _writeInit: (TypedStream*)aStream
|
||||
{
|
||||
const char *encoding = [self contentType];
|
||||
|
||||
[super _writeInit:aStream];
|
||||
/* This implicitly archives the key's comparison and hash functions */
|
||||
objc_write_type(aStream, @encode(char*), &encoding);
|
||||
objc_write_type(aStream, @encode(unsigned int), &(_contents_hash->size));
|
||||
return self;
|
||||
}
|
||||
|
||||
- _readInit: (TypedStream*)aStream
|
||||
{
|
||||
char *encoding;
|
||||
unsigned int size;
|
||||
|
||||
[super _readInit:aStream];
|
||||
objc_read_type(aStream, @encode(char*), &encoding);
|
||||
objc_read_type(aStream, @encode(unsigned int), &size);
|
||||
_contents_hash =
|
||||
coll_hash_new(size,
|
||||
elt_get_hash_function(encoding),
|
||||
elt_get_comparison_function(encoding));
|
||||
_contents_hash = NSCreateHashTable(NSObjectsHashCallBacks,
|
||||
DEFAULT_SET_CAPACITY);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -125,52 +73,38 @@
|
|||
{
|
||||
Set *copy = [super emptyCopy];
|
||||
copy->_contents_hash =
|
||||
coll_hash_new(_contents_hash->size,
|
||||
_contents_hash->hash_func,
|
||||
_contents_hash->compare_func);
|
||||
NSCreateHashTable (NSObjectsHashCallBacks, 0);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/* Override designated initializer of superclass */
|
||||
- initWithType:(const char *)contentEncoding
|
||||
- (void) dealloc
|
||||
{
|
||||
return [self initWithType:contentEncoding
|
||||
capacity:[[self class] defaultCapacity]];
|
||||
}
|
||||
|
||||
- initWithCapacity: (unsigned)aCapacity
|
||||
{
|
||||
return [self initWithType:@encode(id) capacity:aCapacity];
|
||||
}
|
||||
|
||||
- (void) _collectionDealloc
|
||||
{
|
||||
coll_hash_delete(_contents_hash);
|
||||
NSFreeHashTable (_contents_hash);
|
||||
[super _collectionDealloc];
|
||||
}
|
||||
|
||||
// SET OPERATIONS;
|
||||
|
||||
- intersectWithCollection: (id <Collecting>)aCollection
|
||||
- (void) intersectWithCollection: (id <Collecting>)aCollection
|
||||
{
|
||||
[self removeContentsNotIn: aCollection];
|
||||
return self;
|
||||
}
|
||||
|
||||
- unionWithCollection: (id <Collecting>)aCollection
|
||||
- (void) unionWithCollection: (id <Collecting>)aCollection
|
||||
{
|
||||
[self addContentsOfIfAbsent:aCollection];
|
||||
return self;
|
||||
[self addContentsIfAbsentOf: aCollection];
|
||||
}
|
||||
|
||||
- differenceWithCollection: (id <Collecting>)aCollection
|
||||
- (void) differenceWithCollection: (id <Collecting>)aCollection
|
||||
{
|
||||
[self removeContentsIn: aCollection];
|
||||
return self;
|
||||
}
|
||||
|
||||
- shallowCopyIntersectWithCollection: (id <Collecting>)aCollection
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
#if 0
|
||||
id newColl = [self emptyCopyAs:[self species]];
|
||||
void doIt(elt e)
|
||||
{
|
||||
|
@ -179,18 +113,25 @@
|
|||
}
|
||||
[self withElementsCall:doIt];
|
||||
return newColl;
|
||||
#endif
|
||||
}
|
||||
|
||||
- shallowCopyUnionWithCollection: (id <Collecting>)aCollection
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
#if 0
|
||||
id newColl = [self shallowCopy];
|
||||
|
||||
[newColl addContentsOf:aCollection];
|
||||
return newColl;
|
||||
#endif
|
||||
}
|
||||
|
||||
- shallowCopyDifferenceWithCollection: (id <Collecting>)aCollection
|
||||
{
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
#if 0
|
||||
id newColl = [self emptyCopyAs:[self species]];
|
||||
void doIt(elt e)
|
||||
{
|
||||
|
@ -199,128 +140,78 @@
|
|||
}
|
||||
[self withElementsCall:doIt];
|
||||
return newColl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ADDING;
|
||||
|
||||
- addElement: (elt)anElement
|
||||
- (void) addObject: newObject
|
||||
{
|
||||
if (coll_hash_value_for_key(_contents_hash, anElement).void_ptr_u == 0)
|
||||
coll_hash_add(&_contents_hash, anElement, 1);
|
||||
RETAIN_ELT(anElement);
|
||||
return self;
|
||||
NSHashInsert (_contents_hash, newObject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// REMOVING AND REPLACING;
|
||||
|
||||
- (elt) removeElement: (elt)oldElement ifAbsentCall: (elt(*)(arglist_t))excFunc
|
||||
- (void) removeObject: oldObject
|
||||
{
|
||||
if (coll_hash_value_for_key(_contents_hash, oldElement).void_ptr_u == 0)
|
||||
coll_hash_remove(_contents_hash, oldElement);
|
||||
else
|
||||
RETURN_BY_CALLING_EXCEPTION_FUNCTION(excFunc);
|
||||
return AUTORELEASE_ELT(oldElement);
|
||||
NSHashRemove (_contents_hash, oldObject);
|
||||
}
|
||||
|
||||
/* This must work without sending any messages to content objects */
|
||||
- _empty
|
||||
- (void) _collectionEmpty
|
||||
{
|
||||
coll_hash_empty(_contents_hash);
|
||||
return self;
|
||||
NSResetHashTable (_contents_hash);
|
||||
}
|
||||
|
||||
- uniqueContents
|
||||
- (void) uniqueContents
|
||||
{
|
||||
return self;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TESTING;
|
||||
|
||||
- (int(*)(elt,elt)) comparisonFunction
|
||||
- (BOOL) containsObject: anObject
|
||||
{
|
||||
return _contents_hash->compare_func;
|
||||
}
|
||||
|
||||
- (const char *) contentType
|
||||
{
|
||||
return elt_get_encoding(_contents_hash->compare_func);
|
||||
}
|
||||
|
||||
- (BOOL) includesElement: (elt)anElement
|
||||
{
|
||||
if (coll_hash_value_for_key(_contents_hash, anElement).void_ptr_u != 0)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
return (NSHashGet (_contents_hash, anObject) ? 1 : 0);
|
||||
}
|
||||
|
||||
- (unsigned) count
|
||||
{
|
||||
return _contents_hash->used;
|
||||
return NSCountHashTable (_contents_hash);
|
||||
}
|
||||
|
||||
- (unsigned) occurrencesOfElement: (elt)anElement
|
||||
- (unsigned) occurrencesOfObject: anObject
|
||||
{
|
||||
if ([self includesElement:anElement])
|
||||
if ([self containsObject: anObject])
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ENUMERATING;
|
||||
|
||||
- (BOOL) getNextElement:(elt *)anElementPtr withEnumState: (void**)enumState
|
||||
- nextObjectWithEnumState: (void**)enumState
|
||||
{
|
||||
coll_node_ptr node = coll_hash_next(_contents_hash, enumState);
|
||||
if (node)
|
||||
{
|
||||
*anElementPtr = node->key;
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
return NSNextHashEnumeratorItem (((NSHashEnumerator*)enumState));
|
||||
}
|
||||
|
||||
- (void*) newEnumState
|
||||
{
|
||||
return (void*)0;
|
||||
void *es;
|
||||
|
||||
OBJC_MALLOC (es, NSMapEnumerator, 1);
|
||||
*((NSHashEnumerator*)es) = NSEnumerateHashTable (_contents_hash);
|
||||
return es;
|
||||
}
|
||||
|
||||
- freeEnumState: (void**)enumState
|
||||
- (void) freeEnumState: (void**)enumState
|
||||
{
|
||||
/* Yipes, this interface is ugly. collhash:coll_hash_next malloc'ed this */
|
||||
if (*enumState)
|
||||
OBJC_FREE (*enumState);
|
||||
return self;
|
||||
}
|
||||
|
||||
- withElementsCall: (void(*)(elt))aFunc whileTrue:(BOOL *)flag
|
||||
{
|
||||
void *state = 0;
|
||||
coll_node_ptr node;
|
||||
|
||||
while (*flag && (node = coll_hash_next(_contents_hash, &state)))
|
||||
{
|
||||
(*aFunc)(node->key);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- withElementsCall: (void(*)(elt))aFunc
|
||||
{
|
||||
void *state = 0;
|
||||
coll_node_ptr node = 0;
|
||||
|
||||
while ((node = coll_hash_next(_contents_hash, &state)))
|
||||
{
|
||||
(*aFunc)(node->key);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Implementation for Objective-C SplayTree collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -26,14 +26,8 @@
|
|||
|
||||
@implementation SplayTree
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [SplayTree class])
|
||||
[self setVersion:0]; /* beta release */
|
||||
}
|
||||
|
||||
/* Make this a function ? */
|
||||
- _doSplayOperationOnNode: aNode
|
||||
- (void) _doSplayOperationOnNode: aNode
|
||||
{
|
||||
id parent = [aNode parentNode];
|
||||
id parentRightChild =
|
||||
|
@ -41,7 +35,7 @@
|
|||
|
||||
if (aNode == _contents_root || aNode == [self nilNode])
|
||||
{
|
||||
return self;
|
||||
return;
|
||||
}
|
||||
else if (aNode == parentRightChild)
|
||||
{
|
||||
|
@ -80,53 +74,28 @@
|
|||
[self leftRotateAroundNode:[aNode parentNode]];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- splayNode: aNode
|
||||
- (void) splayNode: aNode
|
||||
{
|
||||
while (aNode != _contents_root)
|
||||
[self _doSplayOperationOnNode:aNode];
|
||||
return self;
|
||||
}
|
||||
|
||||
/* We could make this a little more efficient by doing the splay as
|
||||
we search down the tree for the correct insertion point. */
|
||||
- sortAddElement: (elt)newElement byCalling: (int(*)(elt,elt))aFunc
|
||||
- (void) sortAddObject: newObject
|
||||
{
|
||||
[super sortAddElement:newElement byCalling:aFunc];
|
||||
[self splayNode:newElement.id_u];
|
||||
return self;
|
||||
[super sortAddObject: newObject];
|
||||
[self splayNode: newObject];
|
||||
}
|
||||
|
||||
- insertElement: (elt)newElement before: (elt)oldElement
|
||||
- (void) removeObject: anObject
|
||||
{
|
||||
[super insertElement:newElement before:oldElement];
|
||||
// ?? [self splayNode:newElement.id_u];
|
||||
return self;
|
||||
}
|
||||
|
||||
- insertElement: (elt)newElement after: (elt)oldElement
|
||||
{
|
||||
[super insertElement:newElement after:oldElement];
|
||||
// ?? [self splayNode:newElement.id_u];
|
||||
return self;
|
||||
}
|
||||
|
||||
- insertElement: (elt)newElement atIndex: (unsigned)index
|
||||
{
|
||||
[super insertElement:newElement atIndex:index];
|
||||
// ?? [self splayNode:newElement.id_u];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (elt) removeElement: (elt)anElement
|
||||
{
|
||||
id parent = [anElement.id_u parentNode];
|
||||
[super removeElement:anElement];
|
||||
id parent = [anObject parentNode];
|
||||
[super removeObject: anObject];
|
||||
if (parent && parent != [self nilNode])
|
||||
[self splayNode:parent];
|
||||
return AUTORELEASE_ELT(anElement);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Implementation for Objective-C Stack object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -26,65 +26,40 @@
|
|||
|
||||
@implementation Stack
|
||||
|
||||
+ (void) initialize
|
||||
- (void) pushObject: newObject
|
||||
{
|
||||
if (self == [Stack class])
|
||||
[self setVersion:0]; /* beta release */
|
||||
}
|
||||
|
||||
- pushElement: (elt)anElement
|
||||
{
|
||||
[self appendElement:anElement];
|
||||
return self;
|
||||
[self appendObject: newObject];
|
||||
}
|
||||
|
||||
/* Overriding */
|
||||
- addElement: (elt)anElement
|
||||
- (void) addObject: newObject
|
||||
{
|
||||
[self pushElement:anElement];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (elt) popElement
|
||||
{
|
||||
return [self removeLastElement];
|
||||
}
|
||||
|
||||
- (elt) topElement
|
||||
{
|
||||
return [self lastElement];
|
||||
}
|
||||
|
||||
/* Yipes. What copying semantics do we want here? */
|
||||
- duplicateTop
|
||||
{
|
||||
[self pushElement:[self topElement]];
|
||||
return self;
|
||||
}
|
||||
|
||||
- exchangeTop
|
||||
{
|
||||
if (_count <= 1)
|
||||
return nil;
|
||||
[self swapAtIndeces:_count-1 :_count-2];
|
||||
return self;
|
||||
}
|
||||
|
||||
// OBJECT-COMPATIBLE MESSAGE NAMES;
|
||||
|
||||
- pushObject: anObject
|
||||
{
|
||||
return [self pushElement:anObject];
|
||||
[self pushObject: newObject];
|
||||
}
|
||||
|
||||
- popObject
|
||||
{
|
||||
return [self popElement].id_u;
|
||||
id ret;
|
||||
ret = [[self lastObject] retain];
|
||||
[self removeLastObject];
|
||||
return [ret autorelease];
|
||||
}
|
||||
|
||||
- topObject
|
||||
{
|
||||
return [self topElement].id_u;
|
||||
return [self lastObject];
|
||||
}
|
||||
|
||||
/* xxx Yipes. What copying semantics do we want here? */
|
||||
- (void) duplicateTop
|
||||
{
|
||||
[self pushObject: [self topObject]];
|
||||
}
|
||||
|
||||
- (void) exchangeTop
|
||||
{
|
||||
if (_count > 1)
|
||||
[self swapAtIndeces:_count-1 :_count-2];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C Array collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -26,13 +26,19 @@
|
|||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/IndexedCollection.h>
|
||||
#include <objects/OrderedCollecting.h>
|
||||
|
||||
@interface Array : IndexedCollection
|
||||
@interface ConstantArray : IndexedCollection
|
||||
{
|
||||
@public
|
||||
int (*_comparison_function)(elt,elt);
|
||||
elt *_contents_array;
|
||||
id *_contents_array;
|
||||
unsigned int _count;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface Array : ConstantArray
|
||||
{
|
||||
@public
|
||||
unsigned int _capacity;
|
||||
unsigned int _grow_factor;
|
||||
}
|
||||
|
@ -40,16 +46,18 @@
|
|||
+ (unsigned) defaultCapacity;
|
||||
+ (unsigned) defaultGrowFactor;
|
||||
|
||||
- initWithType: (const char *)contentEncoding
|
||||
capacity: (unsigned)aCapacity;
|
||||
- initWithCapacity: (unsigned) aCapacity;
|
||||
|
||||
- setCapacity: (unsigned)newCapacity;
|
||||
- (void) setCapacity: (unsigned)newCapacity;
|
||||
- (unsigned) growFactor;
|
||||
- setGrowFactor: (unsigned)aNum;
|
||||
- (void) setGrowFactor: (unsigned)aNum;
|
||||
|
||||
@end
|
||||
|
||||
/* Put this on category instead of class to avoid bogus complaint from gcc */
|
||||
@interface Array (Ordering) <OrderedCollecting>
|
||||
@end
|
||||
|
||||
#define FOR_ARRAY(ARRAY, ELEMENT_VAR) \
|
||||
{ \
|
||||
unsigned _FOR_ARRAY_i; \
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C Bag collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -25,39 +25,27 @@
|
|||
#define __Bag_h_INCLUDE_GNU
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/Set.h>
|
||||
#include <objects/Collection.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
|
||||
@interface Bag : Set
|
||||
@interface Bag : Collection
|
||||
{
|
||||
NSMapTable *_contents_map;
|
||||
unsigned int _count; // the number of elements;
|
||||
}
|
||||
|
||||
// INITIALIZING AND FREEING;
|
||||
- initWithCapacity: (unsigned)aCapacity;
|
||||
|
||||
// ADDING;
|
||||
- addObject: newObject withOccurrences: (unsigned)count;
|
||||
- (void) addObject: newObject withOccurrences: (unsigned)count;
|
||||
|
||||
// REMOVING AND REPLACING;
|
||||
- removeObject: oldObject occurrences: (unsigned)count;
|
||||
- removeObject: oldObject occurrences: (unsigned)count
|
||||
ifAbsentCall: (id(*)(arglist_t))excFunc;
|
||||
- (void) removeObject: oldObject occurrences: (unsigned)count;
|
||||
|
||||
// TESTING;
|
||||
- (unsigned) uniqueCount;
|
||||
|
||||
|
||||
// NON-OBJECT ELEMENT METHOD NAMES;
|
||||
|
||||
// INITIALIZING AND FREEING;
|
||||
- initWithType: (const char *)contentEncoding
|
||||
capacity: (unsigned)aCapacity;
|
||||
|
||||
// ADDING;
|
||||
- addElement: (elt)newElement withOccurrences: (unsigned)count;
|
||||
|
||||
// REMOVING AND REPLACING;
|
||||
- (elt) removeElement:(elt)oldElement occurrences: (unsigned)count;
|
||||
- (elt) removeElement:(elt)oldElement occurrences: (unsigned)count
|
||||
ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* __Bag_h_INCLUDE_GNU */
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C BinaryTree collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -35,13 +35,15 @@
|
|||
/* The <BinaryTreeComprising> protocol defines the interface to an object
|
||||
that may be an element in a BinaryTree.
|
||||
*/
|
||||
@protocol BinaryTreeComprising
|
||||
@protocol BinaryTreeComprising <NSObject>
|
||||
- leftNode;
|
||||
- rightNode;
|
||||
- parentNode;
|
||||
- setLeftNode: (id <BinaryTreeComprising>)aNode;
|
||||
- setRightNode: (id <BinaryTreeComprising>)aNode;
|
||||
- setParentNode: (id <BinaryTreeComprising>)aNode;
|
||||
- (void) setLeftNode: (id <BinaryTreeComprising>)aNode;
|
||||
- (void) setRightNode: (id <BinaryTreeComprising>)aNode;
|
||||
- (void) setParentNode: (id <BinaryTreeComprising>)aNode;
|
||||
- binaryTree;
|
||||
- (void) setBinaryTree: anObject;
|
||||
@end
|
||||
|
||||
#define NODE_IS_RIGHTCHILD(NODE) (NODE == [[NODE parentNode] rightNode])
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C BinaryTreeNode object
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
|||
id _left;
|
||||
id _right;
|
||||
id _parent;
|
||||
id _binary_tree;
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Protocol for Objective-C objects that hold collections of elements.
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -35,54 +35,61 @@
|
|||
#define __Collecting_h_INCLUDE_GNU
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objc/Object.h>
|
||||
#include <objects/elt.h>
|
||||
#include <objects/Coding.h>
|
||||
#include <objects/Invoking.h>
|
||||
#include <objects/Enumerating.h>
|
||||
|
||||
@protocol ConstantCollecting
|
||||
|
||||
// INITIALIZING;
|
||||
- init;
|
||||
- initWithObjects: (id*)objc count: (unsigned)c;
|
||||
- initWithObjects: firstObject, ...;
|
||||
- initWithObjects: firstObject rest: (va_list)ap;
|
||||
- initWithContentsOf: (id <ConstantCollecting>)aCollection;
|
||||
|
||||
// TESTING;
|
||||
// QUERYING COUNTS;
|
||||
- (BOOL) isEmpty;
|
||||
- (BOOL) includesObject: anObject;
|
||||
- (unsigned) count;
|
||||
- (BOOL) containsObject: anObject;
|
||||
- (unsigned) occurrencesOfObject: anObject;
|
||||
|
||||
// COMPARISON WITH OTHER COLLECTIONS;
|
||||
- (BOOL) isSubsetOf: (id <ConstantCollecting>)aCollection;
|
||||
- (BOOL) isDisjointFrom: (id <ConstantCollecting>)aCollection;
|
||||
- (int) compare: anObject;
|
||||
- (BOOL) isEqual: anObject;
|
||||
- (int) compare: anObject;
|
||||
- (BOOL) contentsEqual: (id <ConstantCollecting>)aCollection;
|
||||
- (unsigned) count;
|
||||
- (unsigned) occurrencesOfObject: anObject;
|
||||
- (BOOL) trueForAllObjectsByCalling: (BOOL(*)(id))aFunc;
|
||||
- (BOOL) trueForAnyObjectsByCalling: (BOOL(*)(id))aFunc;
|
||||
- detectObjectByCalling: (BOOL(*)(id))aFunc;
|
||||
- detectObjectByCalling: (BOOL(*)(id))aFunc
|
||||
ifNoneCall: (id(*)(arglist_t))excFunc;
|
||||
|
||||
// PROPERTIES OF CONTENTS;
|
||||
- (BOOL) trueForAllObjectsByInvoking: (id <Invoking>)anInvocation;
|
||||
- (BOOL) trueForAnyObjectsByInvoking: (id <Invoking>)anInvocation;
|
||||
- detectObjectByInvoking: (id <Invoking>)anInvocation;
|
||||
- maxObject;
|
||||
- maxObjectByCalling: (int(*)(id,id))aFunc;
|
||||
- minObject;
|
||||
- minObjectByCalling: (int(*)(id,id))aFunc;
|
||||
|
||||
// ENUMERATING
|
||||
- (void*) newEnumState;
|
||||
- (BOOL) getNextObject:(id *)anObjectPtr withEnumState: (void**)enumState;
|
||||
- freeEnumState: (void**)enumState;
|
||||
- withObjectsCall: (void(*)(id))aFunc;
|
||||
- withObjectsCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
|
||||
- injectObject: initialArgObject byCalling:(id(*)(id,id))aFunc;
|
||||
- makeObjectsPerform: (SEL)aSel;
|
||||
- makeObjectsPerform: (SEL)aSel with: argObject;
|
||||
- (id <Enumerating>) objectEnumerator;
|
||||
- (void) withObjectsInvoke: (id <Invoking>)anInvocation;
|
||||
- (void) withObjectsInvoke: (id <Invoking>)anInvocation whileTrue:(BOOL *)flag;
|
||||
- (void) makeObjectsPerform: (SEL)aSel;
|
||||
- (void) makeObjectsPerform: (SEL)aSel withObject: argObject;
|
||||
|
||||
// FILTERED ENUMERATING;
|
||||
- withObjectsTrueByCalling: (BOOL(*)(id))testFunc
|
||||
call: (void(*)(id))destFunc;
|
||||
- withObjectsFalseByCalling: (BOOL(*)(id))testFunc
|
||||
call: (void(*)(id))destFunc;
|
||||
- withObjectsTransformedByCalling: (id(*)(id))transFunc
|
||||
call: (void(*)(id))destFunc;
|
||||
- (void) withObjectsTrueByInvoking: (id <Invoking>)testInvocation
|
||||
invoke: (id <Invoking>)anInvocation;
|
||||
- (void) withObjectsFalseByInvoking: (id <Invoking>)testInvocation
|
||||
invoke: (id <Invoking>)anInvocation;
|
||||
- (void) withObjectsTransformedByInvoking: (id <Invoking>)transInvocation
|
||||
invoke: (id <Invoking>)anInvocation;
|
||||
|
||||
// COPYING
|
||||
// LOW-LEVEL ENUMERATING;
|
||||
- (void*) newEnumState;
|
||||
- nextObjectWithEnumState: (void**)enumState;
|
||||
- (void) freeEnumState: (void**)enumState;
|
||||
|
||||
// COPYING;
|
||||
- allocCopy;
|
||||
- emptyCopy;
|
||||
- emptyCopyAs: (Class)aCollectionClass;
|
||||
- shallowCopy;
|
||||
|
@ -91,98 +98,34 @@
|
|||
- copyAs: (Class)aCollectionClass;
|
||||
- species;
|
||||
|
||||
// NON-OBJECT ELEMENT METHOD NAMES;
|
||||
|
||||
// INITIALIZING;
|
||||
- initWithType:(const char *)contentEncoding;
|
||||
|
||||
// TESTING;
|
||||
- (BOOL) includesElement: (elt)anElement;
|
||||
- (unsigned) occurrencesOfElement: (elt)anElement;
|
||||
- (elt) detectElementByCalling: (BOOL(*)(elt))aFunc;
|
||||
- (elt) detectElementByCalling: (BOOL(*)(elt))aFunc
|
||||
ifNoneCall: (elt(*)(arglist_t))excFunc;
|
||||
- (elt) maxElement;
|
||||
- (elt) maxElementByCalling: (int(*)(elt,elt))aFunc;
|
||||
- (elt) minElement;
|
||||
- (elt) minElementByCalling: (int(*)(elt,elt))aFunc;
|
||||
- (BOOL) trueForAllElementsByCalling: (BOOL(*)(elt))aFunc;
|
||||
- (BOOL) trueForAnyElementsByCalling: (BOOL(*)(elt))aFunc;
|
||||
- (const char *) contentType;
|
||||
- (BOOL) contentsAreObjects;
|
||||
- (int(*)(elt,elt)) comparisonFunction;
|
||||
|
||||
// ENUMERATING;
|
||||
- (BOOL) getNextElement:(elt *)anElementPtr withEnumState: (void**)enumState;
|
||||
- withElementsCall: (void(*)(elt))aFunc;
|
||||
- withElementsCall: (void(*)(elt))aFunc whileTrue: (BOOL*)flag;
|
||||
- (elt) injectElement: (elt)initialElement byCalling: (elt(*)(elt,elt))aFunc;
|
||||
|
||||
// FILTERED ENUMERATING;
|
||||
- withElementsTrueByCalling: (BOOL(*)(elt))testFunc
|
||||
call: (void(*)(elt))destFunc;
|
||||
- withElementsFalseByCalling: (BOOL(*)(elt))testFunc
|
||||
call: (void(*)(elt))destFunc;
|
||||
- withElementsTransformedByCalling: (elt(*)(elt))transFunc
|
||||
call: (void(*)(elt))destFunc;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@protocol Collecting <ConstantCollecting>
|
||||
|
||||
// ADDING;
|
||||
- addObject: newObject;
|
||||
- addObjectIfAbsent: newObject;
|
||||
- addContentsOf: (id <ConstantCollecting>)aCollection;
|
||||
- addContentsOfIfAbsent: (id <ConstantCollecting>)aCollection;
|
||||
- addObjectsCount: (unsigned)count, ...;
|
||||
- (void) addObject: newObject;
|
||||
- (void) addObjectIfAbsent: newObject;
|
||||
- (void) addContentsOf: (id <ConstantCollecting>)aCollection;
|
||||
- (void) addContentsIfAbsentOf: (id <ConstantCollecting>)aCollection;
|
||||
- (void) addWithObjects: (id*)objc count: (unsigned)c;
|
||||
- (void) addObjects: firstObject, ...;
|
||||
- (void) addObjects: firstObject rest: (va_list)ap;
|
||||
|
||||
// REMOVING;
|
||||
- removeObject: oldObject;
|
||||
- removeObject: oldObject ifAbsentCall: (id(*)(arglist_t))excFunc;
|
||||
- removeAllOccurrencesOfObject: oldObject;
|
||||
- removeContentsIn: (id <ConstantCollecting>)aCollection;
|
||||
- removeContentsNotIn: (id <ConstantCollecting>)aCollection;
|
||||
- uniqueContents;
|
||||
- empty;
|
||||
- (void) removeObject: oldObject;
|
||||
- (void) removeAllOccurrencesOfObject: oldObject;
|
||||
- (void) removeContentsIn: (id <ConstantCollecting>)aCollection;
|
||||
- (void) removeContentsNotIn: (id <ConstantCollecting>)aCollection;
|
||||
- (void) uniqueContents;
|
||||
- (void) empty;
|
||||
|
||||
// REPLACING;
|
||||
- replaceObject: oldObject with: newObject;
|
||||
- replaceObject: oldObject with: newObject
|
||||
ifAbsentCall:(id(*)(arglist_t))excFunc;
|
||||
- replaceAllOccurrencesOfObject: oldObject with: newObject;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeMakeObjectsPerform: (SEL)aSel;
|
||||
- safeMakeObjectsPerform: (SEL)aSel with: argObject;
|
||||
- safeWithObjectsCall: (void(*)(id))aFunc;
|
||||
- safeWithObjectsCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
|
||||
|
||||
|
||||
// NON-OBJECT ELEMENT METHOD NAMES;
|
||||
|
||||
// ADDING;
|
||||
- addElement: (elt)newElement;
|
||||
- addElementIfAbsent: (elt)newElement;
|
||||
- addElementsCount: (unsigned)count, ...;
|
||||
|
||||
// REMOVING;
|
||||
- (elt) removeElement: (elt)oldElement;
|
||||
- (elt) removeElement: (elt)oldElement
|
||||
ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
- removeAllOccurrencesOfElement: (elt)oldElement;
|
||||
|
||||
// REPLACING;
|
||||
- (elt) replaceElement: (elt)oldElement with: (elt)newElement;
|
||||
- (elt) replaceElement: (elt)oldElement with: (elt)newElement
|
||||
ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
- replaceAllOccurrencesOfElement: (elt)oldElement with: (elt)newElement;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeWithElementsCall: (void(*)(elt))aFunc;
|
||||
- safeWithElementsCall: (void(*)(elt))aFunc whileTrue: (BOOL*)flag;
|
||||
- (void) replaceObject: oldObject withObject: newObject;
|
||||
- (void) replaceAllOccurrencesOfObject: oldObject withObject: newObject;
|
||||
|
||||
@end
|
||||
|
||||
#define NO_OBJECT nil
|
||||
|
||||
#endif /* __Collecting_h_INCLUDE_GNU */
|
||||
|
|
|
@ -32,29 +32,42 @@
|
|||
#include <Foundation/NSObject.h>
|
||||
#include <objects/Collecting.h>
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/collhash.h>
|
||||
#include <objects/Coding.h>
|
||||
|
||||
@interface Collection : NSObject <Collecting>
|
||||
{
|
||||
}
|
||||
|
||||
- (void) withObjectsInvoke: anInvocation;
|
||||
- printElement: (elt)anElement;
|
||||
- printForDebugger;
|
||||
|
||||
@interface ConstantCollection : NSObject <ConstantCollecting>
|
||||
- printForDebugger; /* This method will disappear later. */
|
||||
@end
|
||||
|
||||
// #warning fix this macro
|
||||
#define FOR_COLL(ACOLL, ELT) \
|
||||
@interface Collection : ConstantCollection <Collecting>
|
||||
@end
|
||||
|
||||
@interface Enumerator : NSObject <Enumerating>
|
||||
{
|
||||
id collection;
|
||||
void *enum_state;
|
||||
}
|
||||
@end
|
||||
|
||||
#define FOR_COLLECTION(ACOLL, ELT) \
|
||||
{ \
|
||||
void *_es = [ACOLL initEnumState]; \
|
||||
while ([ACOLL getNextElement:&(ELT) withEnumState:&_es]) \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while ((ELT = [ACOLL nextObjectWithEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define FOR_COLL_END \
|
||||
#define END_FOR_COLLECTION(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState:_es]; \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
#define FOR_COLLECTION_WHILE_TRUE(ACOLL, ELT, FLAG) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while (FLAG && (ELT = [ACOLL nextObjectWithEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_COLLECTION_WHILE_TRUE(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
/* The only subclassResponsibilities in Collection are:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Collection definitions for the use of subclass implementations only
|
||||
Copyright (C) 1993,1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993,1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -25,28 +25,23 @@
|
|||
#define __CollectionPrivate_h_INCLUDE_GNU
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/eltfuncs.h>
|
||||
|
||||
@interface Collection (ArchivingHelpers)
|
||||
/* These methods should never be called except in order inside
|
||||
-write: and -read: */
|
||||
- _writeInit: (TypedStream*)aStream;
|
||||
- _readInit: (TypedStream*)aStream;
|
||||
- _writeContents: (TypedStream*)aStream;
|
||||
- _readContents: (TypedStream*)aStream;
|
||||
|
||||
/* The Coding versions of the above */
|
||||
@interface ConstantCollection (ArchivingHelpers)
|
||||
/* These methods should never be called except in order, and inside
|
||||
-encodeWithCoder: and -decodeWithCoder: */
|
||||
- (void) _encodeCollectionWithCoder: (id <Encoding>)aCoder;
|
||||
- _initCollectionWithCoder: (id <Decoding>)aCoder;
|
||||
- (void) _encodeContentsWithCoder: (id <Encoding>)aCoder;
|
||||
- (void) _decodeContentsWithCoder: (id <Decoding>)aCoder;
|
||||
@end
|
||||
|
||||
@interface Collection (DeallocationHelpers)
|
||||
@interface ConstantCollection (DeallocationHelpers)
|
||||
|
||||
/* Empty the internals of a collection after the contents have
|
||||
already been released. */
|
||||
- _empty;
|
||||
- (void) _collectionEmpty;
|
||||
|
||||
- (void) _collectionReleaseContents;
|
||||
|
||||
/* Deallocate the internals of a collection after the contents
|
||||
have already been released. */
|
||||
|
@ -54,63 +49,4 @@
|
|||
|
||||
@end
|
||||
|
||||
|
||||
/* To be used inside methods for getting the element comparison function.
|
||||
This macro could be redefined when the comparison function is an
|
||||
instance variable or is fixed.
|
||||
I'm wondering if I should put _comparison_function back as an instance
|
||||
variable in Collection. */
|
||||
#define COMPARISON_FUNCTION [self comparisonFunction]
|
||||
|
||||
/* Use this for comparing elements in your implementation. */
|
||||
#define COMPARE_ELEMENTS(ELT1, ELT2) \
|
||||
((*COMPARISON_FUNCTION)(ELT1, ELT2))
|
||||
|
||||
#define ELEMENTS_EQUAL(ELT1, ELT2) \
|
||||
(COMPARE_ELEMENTS(ELT1, ELT2) == 0)
|
||||
|
||||
#define ENCODING_IS_OBJECT(ENCODING) \
|
||||
((*(ENCODING) == _C_ID) || (*(ENCODING) == _C_CLASS))
|
||||
|
||||
/* To be used inside a method for determining if the contents are objects */
|
||||
#define CONTAINS_OBJECTS \
|
||||
(ENCODING_IS_OBJECT([self contentType]))
|
||||
|
||||
/* Used inside a method for sending "-retain" if necessary */
|
||||
#define RETAIN_ELT(ELT) \
|
||||
if (CONTAINS_OBJECTS) [ELT.id_u retain]
|
||||
|
||||
/* Used inside a method for sending "-release" if necessary */
|
||||
#define RELEASE_ELT(ELT) \
|
||||
if (CONTAINS_OBJECTS) [ELT.id_u release]
|
||||
|
||||
/* Used inside a method for sending "-autorelease" if necessary */
|
||||
#define AUTORELEASE_ELT(ELT) \
|
||||
((CONTAINS_OBJECTS) ? ((elt)[ELT.id_u autorelease]) : ELT)
|
||||
|
||||
|
||||
/* Error Handling */
|
||||
|
||||
#define RETURN_BY_CALLING_EXCEPTION_FUNCTION(FUNC) \
|
||||
return (*FUNC)(__builtin_apply_args())
|
||||
|
||||
|
||||
/* To be used inside a method for making sure the contents are objects.
|
||||
typeof(DEFAULT_ERROR_RETURN) must be the same type as the method
|
||||
returns. */
|
||||
#define CHECK_CONTAINS_OBJECTS_ERROR() \
|
||||
({if (!(CONTAINS_OBJECTS)) \
|
||||
{ \
|
||||
[self error:"in %s, requires object contents", sel_get_name(_cmd)]; \
|
||||
}})
|
||||
|
||||
/* To be used inside a method whenever a particular element isn't found */
|
||||
#define ELEMENT_NOT_FOUND_ERROR(AN_ELEMENT) \
|
||||
([self error:"in %s, element not found.", sel_get_name(_cmd)])
|
||||
|
||||
/* To be used inside a method whenever there is no element matching the
|
||||
needed criteria */
|
||||
#define NO_ELEMENT_FOUND_ERROR() \
|
||||
([self error:"in %s, no element found.", sel_get_name(_cmd)])
|
||||
|
||||
#endif /* __CollectionPrivate_h_INCLUDE_GNU */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C Dictionary collection object
|
||||
Copyright (C) 1993,1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -26,18 +26,14 @@
|
|||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/KeyedCollection.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
|
||||
@interface Dictionary : KeyedCollection
|
||||
{
|
||||
coll_cache_ptr _contents_hash; // a hashtable to hold the contents;
|
||||
int (*_comparison_function)(elt,elt);
|
||||
NSMapTable *_contents_hash;
|
||||
}
|
||||
|
||||
- initWithType: (const char *)contentEncoding
|
||||
keyType: (const char *)keyEncoding
|
||||
capacity: (unsigned)aCapacity;
|
||||
- initWithType: (const char *)contentEncoding
|
||||
capacity: (unsigned)aCapacity;
|
||||
- initWithCapacity: (unsigned)aCapacity;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C Heap collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -28,14 +28,9 @@
|
|||
#include <objects/Array.h>
|
||||
|
||||
@interface Heap : Array
|
||||
{
|
||||
}
|
||||
|
||||
- addElement: (elt)anElement;
|
||||
- (elt) removeFirstElement;
|
||||
|
||||
- heapifyFromIndex: (unsigned)index;
|
||||
- heapify;
|
||||
- (void) heapifyFromIndex: (unsigned)index;
|
||||
- (void) heapify;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Protocol for Objective-C objects that hold elements accessible by index
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -36,7 +36,7 @@
|
|||
#define __IndexedCollecting_h_OBJECTS_INCLUDE
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/KeyedCollecting.h>
|
||||
#include <objects/Collecting.h>
|
||||
|
||||
typedef struct _IndexRange {
|
||||
unsigned location;
|
||||
|
@ -47,8 +47,8 @@ typedef struct _IndexRange {
|
|||
({IndexRange __a=(RANGE1), __b=(RANGE2); \
|
||||
__a.start<=__b.start && __a.end>=__b.end;})
|
||||
|
||||
|
||||
@protocol ConstantIndexedCollecting <ConstantKeyedCollecting>
|
||||
|
||||
@protocol ConstantIndexedCollecting <ConstantCollecting>
|
||||
|
||||
// GETTING MEMBERS BY INDEX;
|
||||
- objectAtIndex: (unsigned)index;
|
||||
|
@ -61,115 +61,53 @@ typedef struct _IndexRange {
|
|||
|
||||
// GETTING INDICES BY MEMBER;
|
||||
- (unsigned) indexOfObject: anObject;
|
||||
- (unsigned) indexOfObject: anObject
|
||||
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
|
||||
- (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange;
|
||||
- (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange
|
||||
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
|
||||
|
||||
// TESTING;
|
||||
- (BOOL) includesIndex: (unsigned)index;
|
||||
- (BOOL) contentsEqualInOrder: (id <ConstantIndexedCollecting>)aColl;
|
||||
- (int) compareInOrderContentsOf: (id <Collecting>)aCollection;
|
||||
- (unsigned) indexOfFirstDifference: (id <ConstantIndexedCollecting>)aColl;
|
||||
- (unsigned) indexOfFirstIn: (id <ConstantCollecting>)aColl;
|
||||
- (unsigned) indexOfFirstNotIn: (id <ConstantCollecting>)aColl;
|
||||
|
||||
// ENUMERATING;
|
||||
- (BOOL) getPrevObject: (id*)anIdPtr withEnumState: (void**)enumState;
|
||||
- withObjectsInRange: (IndexRange)aRange call:(void(*)(id))aFunc;
|
||||
- withObjectsInReverseCall: (void(*)(id))aFunc;
|
||||
- withObjectsInReverseCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
|
||||
- (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;
|
||||
|
||||
// NON-OBJECT MESSAGE NAMES;
|
||||
|
||||
// GETTING ELEMENTS BY INDEX;
|
||||
- (elt) elementAtIndex: (unsigned)index;
|
||||
- (elt) firstElement;
|
||||
- (elt) lastElement;
|
||||
|
||||
// GETTING MEMBERS BY NEIGHBOR;
|
||||
- (elt) successorOfElement: (elt)anElement;
|
||||
- (elt) predecessorOfElement: (elt)anElement;
|
||||
|
||||
// GETTING INDICES BY MEMBER;
|
||||
- (unsigned) indexOfElement: (elt)anElement;
|
||||
- (unsigned) indexOfElement: (elt)anElement
|
||||
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
|
||||
- (unsigned) indexOfElement: (elt)anElement inRange: (IndexRange)aRange;
|
||||
- (unsigned) indexOfElement: (elt)anElement inRange: (IndexRange)aRange
|
||||
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
|
||||
|
||||
// ENUMERATING;
|
||||
- (BOOL) getPrevElement:(elt*)anElementPtr withEnumState: (void**)enumState;
|
||||
- withElementsInRange: (IndexRange)aRange call:(void(*)(elt))aFunc;
|
||||
- withElementsInReverseCall: (void(*)(elt))aFunc;
|
||||
- withElementsInReverseCall: (void(*)(elt))aFunc whileTrue:(BOOL *)flag;
|
||||
// LOW-LEVEL ENUMERATING;
|
||||
- prevObjectWithEnumState: (void**)enumState;
|
||||
|
||||
@end
|
||||
|
||||
@protocol IndexedCollecting <ConstantIndexedCollecting, KeyedCollecting>
|
||||
|
||||
@protocol IndexedCollecting <ConstantIndexedCollecting, Collecting>
|
||||
|
||||
// ADDING;
|
||||
- insertObject: newObject atIndex: (unsigned)index;
|
||||
- insertObject: newObject before: oldObject;
|
||||
- insertObject: newObject after: oldObject;
|
||||
- insertContentsOf: (id <ConstantCollecting>)aCollection
|
||||
atIndex: (unsigned)index;
|
||||
- appendObject: newObject;
|
||||
- prependObject: newObject;
|
||||
- appendContentsOf: (id <ConstantCollecting>)aCollection;
|
||||
- prependContentsOf: (id <ConstantCollecting>)aCollection;
|
||||
// REPLACING;
|
||||
- (void) replaceObjectAtIndex: (unsigned)index with: newObject;
|
||||
|
||||
// REPLACING AND SWAPPING
|
||||
- replaceObjectAtIndex: (unsigned)index with: newObject;
|
||||
- replaceRange: (IndexRange)aRange with: (id <ConstantCollecting>)aCollection;
|
||||
- replaceRange: (IndexRange)aRange using: (id <ConstantCollecting>)aCollection;
|
||||
- swapAtIndeces: (unsigned)index1 : (unsigned)index2;
|
||||
|
||||
// REMOVING
|
||||
- removeObjectAtIndex: (unsigned)index;
|
||||
- removeFirstObject;
|
||||
- removeLastObject;
|
||||
- removeRange: (IndexRange)aRange;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeWithObjectsInReverseCall: (void(*)(id))aFunc;
|
||||
- safeWithObjectsInReverseCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
|
||||
// REMOVING;
|
||||
- (void) removeObjectAtIndex: (unsigned)index;
|
||||
- (void) removeFirstObject;
|
||||
- (void) removeLastObject;
|
||||
- (void) removeRange: (IndexRange)aRange;
|
||||
|
||||
// SORTING;
|
||||
- sortContents;
|
||||
- sortObjectsByCalling: (int(*)(id,id))aFunc;
|
||||
- sortAddObject: newObject;
|
||||
- sortAddObject: newObject byCalling: (int(*)(id,id))aFunc;
|
||||
|
||||
|
||||
// NON-OBJECT MESSAGE NAMES;
|
||||
|
||||
// ADDING;
|
||||
- appendElement: (elt)newElement;
|
||||
- prependElement: (elt)newElement;
|
||||
- insertElement: (elt)newElement atIndex: (unsigned)index;
|
||||
- insertElement: (elt)newElement before: (elt)oldElement;
|
||||
- insertElement: (elt)newElement after: (elt)oldElement;
|
||||
|
||||
// REMOVING AND REPLACING;
|
||||
- (elt) removeElementAtIndex: (unsigned)index;
|
||||
- (elt) removeFirstElement;
|
||||
- (elt) removeLastElement;
|
||||
- (elt) replaceElementAtIndex: (unsigned)index with: (elt)newElement;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeWithElementsInRange: (IndexRange)aRange call:(void(*)(elt))aFunc;
|
||||
- safeWithElementsInReverseCall: (void(*)(elt))aFunc;
|
||||
- safeWithElementsInReverseCall: (void(*)(elt))aFunc whileTrue:(BOOL *)flag;
|
||||
|
||||
// SORTING;
|
||||
- sortElementsByCalling: (int(*)(elt,elt))aFunc;
|
||||
- sortAddElement: (elt)newElement;
|
||||
- sortAddElement: (elt)newElement byCalling: (int(*)(elt,elt))aFunc;
|
||||
- (void) sortContents;
|
||||
- (void) sortAddObject: newObject;
|
||||
|
||||
@end
|
||||
|
||||
#include <limits.h>
|
||||
#define NO_INDEX UINT_MAX
|
||||
|
||||
/* xxx Fix this comment: */
|
||||
|
||||
/* 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,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C Sequential Collection object.
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -28,12 +28,54 @@
|
|||
#include <objects/KeyedCollection.h>
|
||||
#include <objects/IndexedCollecting.h>
|
||||
|
||||
@interface IndexedCollection : KeyedCollection
|
||||
@interface ConstantIndexedCollection : ConstantCollection
|
||||
@end
|
||||
|
||||
@interface IndexedCollection : ConstantIndexedCollection
|
||||
@end
|
||||
|
||||
@interface ReverseEnumerator : Enumerator
|
||||
@end
|
||||
|
||||
/* Put this on category instead of class to avoid bogus complaint from gcc */
|
||||
@interface IndexedCollection (IndexedCollectionProtocol) <IndexedCollecting>
|
||||
@interface ConstantIndexedCollection (Protocol) <ConstantIndexedCollecting>
|
||||
@end
|
||||
@interface IndexedCollection (Protocol) <IndexedCollecting>
|
||||
@end
|
||||
|
||||
#define FOR_INDEXED_COLLECTION(ACOLL, ELT) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while ((ELT = [ACOLL nextObjectWithEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_INDEXED_COLLECTION(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
#define FOR_INDEXED_COLLECTION_REVERSE(ACOLL, ELT) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while ((ELT = [ACOLL prevObjectWithEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_INDEXED_COLLECTION_REVERSE(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
#define FOR_INDEXED_COLLECTION_WHILE_TRUE(ACOLL, ELT, FLAG) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while (FLAG && (ELT = [ACOLL nextObjectWithEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_INDEXED_COLLECTION_WHILE_TRUE(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
|
||||
/* The only subclassResponsibilities in IndexedCollection are:
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Protocol for Objective-C objects holding (keyElement,contentElement) pairs.
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -38,84 +38,44 @@
|
|||
|
||||
@protocol ConstantKeyedCollecting <ConstantCollecting>
|
||||
|
||||
// INITIALIZING;
|
||||
- initWithObjects: (id*)objects forKeys: (id*)keys count: (unsigned)c;
|
||||
|
||||
// GETTING ELEMENTS AND KEYS;
|
||||
- objectAtKey: (elt)aKey;
|
||||
- keyObjectOfObject: aContentObject;
|
||||
- objectAtKey: aKey;
|
||||
- keyOfObject: aContentObject;
|
||||
|
||||
// TESTING;
|
||||
- (BOOL) includesKey: (elt)aKey;
|
||||
- (BOOL) containsKey: aKey;
|
||||
|
||||
// ENUMERATIONS;
|
||||
- withKeyObjectsCall: (void(*)(id))aFunc;
|
||||
- withKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc;
|
||||
- withKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc
|
||||
- (id <Enumerating>) keyEnumerator;
|
||||
- withKeyObjectsInvoke: (id <Invoking>)anInvocation;
|
||||
- withKeyObjectsInvoke: (id <Invoking>)anInvocation
|
||||
whileTrue: (BOOL *)flag;
|
||||
|
||||
// NON-OBJECT ELEMENT METHOD NAMES;
|
||||
// LOW-LEVEL ENUMERATING;
|
||||
- nextObjectAndKey: (id*)keyPtr withEnumState: (void**)enumState;
|
||||
|
||||
// INITIALIZING;
|
||||
- initWithType: (const char *)contentsEncoding
|
||||
keyType: (const char *)keyEncoding;
|
||||
- initKeyType: (const char *)keyEncoding;
|
||||
|
||||
// GETTING ELEMENTS AND KEYS;
|
||||
- (elt) elementAtKey: (elt)aKey;
|
||||
- (elt) elementAtKey: (elt)aKey ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
- (elt) keyElementOfElement: (elt)aContentObject;
|
||||
- (elt) keyElementOfElement: (elt)aContentObject
|
||||
ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
|
||||
// TESTING;
|
||||
- (const char *) keyType;
|
||||
|
||||
// ENUMERATING;
|
||||
- (BOOL) getNextKey: (elt*)aKeyPtr content: (elt*)anElementPtr
|
||||
withEnumState: (void**)enumState;
|
||||
- withKeyElementsCall: (void(*)(elt))aFunc;
|
||||
- withKeyElementsAndContentElementsCall: (void(*)(elt,elt))aFunc;
|
||||
- withKeyElementsAndContentElementsCall: (void(*)(elt,elt))aFunc
|
||||
whileTrue: (BOOL *)flag;
|
||||
// COPYING;
|
||||
- shallowCopyValuesAs: (Class)aCollectingClass;
|
||||
- shallowCopyKeysAs: (Class)aCollectingClass;
|
||||
- copyValuesAs: (Class)aCollectingClass;
|
||||
- copyKeysAs: (Class)aCollectingClass;
|
||||
|
||||
@end
|
||||
|
||||
@protocol KeyedCollecting <ConstantKeyedCollecting, Collecting>
|
||||
|
||||
// ADDING;
|
||||
- putObject: newContentObject atKey: (elt)aKey;
|
||||
- (void) putObject: newContentObject atKey: aKey;
|
||||
|
||||
// REPLACING AND SWAPPING;
|
||||
- replaceObjectAtKey: (elt)aKey with: newContentObject;
|
||||
- swapAtKeys: (elt)key1 : (elt)key2;
|
||||
- (void) replaceObjectAtKey: aKey with: newContentObject;
|
||||
- (void) swapObjectsAtKeys: key1 : key2;
|
||||
|
||||
// REMOVING;
|
||||
- removeObjectAtKey: (elt)aKey;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeWithKeyObjectsCall: (void(*)(id))aFunc;
|
||||
- safeWithKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc;
|
||||
- safeWithKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc
|
||||
whileTrue: (BOOL *)flag;
|
||||
|
||||
|
||||
// NON-OBJECT ELEMENT METHOD NAMES;
|
||||
|
||||
// ADDING;
|
||||
- putElement: (elt)newContentElement atKey: (elt)aKey;
|
||||
|
||||
// REPLACING;
|
||||
- (elt) replaceElementAtKey: (elt)aKey with: (elt)newContentElement;
|
||||
- (elt) replaceElementAtKey: (elt)aKey with: (elt)newContentElement
|
||||
ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
|
||||
// REMOVING;
|
||||
- (elt) removeElementAtKey: (elt)aKey;
|
||||
- (elt) removeElementAtKey: (elt)aKey ifAbsentCall: (elt(*)(arglist_t))excFunc;
|
||||
|
||||
// ENUMERATING WHILE CHANGING CONTENTS;
|
||||
- safeWithKeyElementsCall: (void(*)(elt))aFunc;
|
||||
- safeWithKeyElementsAndContentElementsCall: (void(*)(elt,elt))aFunc;
|
||||
- safeWithKeyElementsAndContentElementsCall: (void(*)(elt,elt))aFunc
|
||||
whileTrue: (BOOL *)flag;
|
||||
- (void) removeObjectAtKey: aKey;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C KeyedCollection collection object
|
||||
Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -28,12 +28,44 @@
|
|||
#include <objects/Collection.h>
|
||||
#include <objects/KeyedCollecting.h>
|
||||
|
||||
@interface KeyedCollection : Collection
|
||||
@interface ConstantKeyedCollection : Collection
|
||||
@end
|
||||
|
||||
@interface KeyedCollection : ConstantKeyedCollection
|
||||
@end
|
||||
|
||||
/* Put this on category instead of class to avoid bogus complaint from gcc */
|
||||
@interface KeyedCollection (KeyedCollectingProtocol) <KeyedCollecting>
|
||||
@interface ConstantKeyedCollection (Protocol) <ConstantKeyedCollecting>
|
||||
@end
|
||||
@interface KeyedCollection (Protocol) <KeyedCollecting>
|
||||
@end
|
||||
|
||||
@interface KeyEnumerator : Enumerator
|
||||
@end
|
||||
|
||||
#define FOR_KEYED_COLLECTION(ACOLL, ELT, KEY) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while ((ELT = [ACOLL nextObjectAndKey: &(KEY) withEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_KEYED_COLLECTION(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
#define FOR_KEYED_COLLECTION_WHILE_TRUE(ACOLL, ELT, KEY, FLAG) \
|
||||
{ \
|
||||
void *_es = [ACOLL newEnumState]; \
|
||||
while (FLAG && (ELT = [ACOLL nextObjectAndKey: &(KEY) \
|
||||
withEnumState: &_es])) \
|
||||
{
|
||||
|
||||
#define END_FOR_KEYED_COLLECTION_WHILE_TRUE(ACOLL) \
|
||||
} \
|
||||
[ACOLL freeEnumState: &_es]; \
|
||||
}
|
||||
|
||||
|
||||
/* The only subclassResponsibilities in IndexedCollection are:
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C LinkedList collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
#define __LinkedList_h_INCLUDE_GNU
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/IndexedCollection.h>
|
||||
#include <objects/OrderedCollection.h>
|
||||
|
||||
/* The <LinkedListComprising> protocol defines the interface to an object
|
||||
that may be an element in a LinkedList.
|
||||
|
@ -33,13 +33,16 @@
|
|||
@protocol LinkedListComprising
|
||||
- nextLink;
|
||||
- prevLink;
|
||||
- setNextLink: (id <LinkedListComprising>)aLink;
|
||||
- setPrevLink: (id <LinkedListComprising>)aLink;
|
||||
- (void) setNextLink: (id <LinkedListComprising>)aLink;
|
||||
- (void) setPrevLink: (id <LinkedListComprising>)aLink;
|
||||
- linkedList;
|
||||
- (void) setLinkedList: aLinkedList;
|
||||
@end
|
||||
|
||||
@interface LinkedList : IndexedCollection
|
||||
@interface LinkedList : OrderedCollection
|
||||
{
|
||||
id _first_link;
|
||||
id _last_link;
|
||||
unsigned int _count;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C LinkedListNode object
|
||||
Copyright (C) 1993,1994, 1995 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -32,8 +32,8 @@
|
|||
{
|
||||
id <LinkedListComprising> _next;
|
||||
id <LinkedListComprising> _prev;
|
||||
id _linked_list;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif /* __LinkedListNode_h_INCLUDE_GNU */
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C MappedCollector collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -33,7 +33,7 @@
|
|||
id <KeyedCollecting> _domain;
|
||||
}
|
||||
|
||||
- initCollection: (id <KeyedCollecting>)aDomain
|
||||
- initWithCollection: (id <KeyedCollecting>)aDomain
|
||||
map: (id <KeyedCollecting>)aMap;
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C Queue object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -29,13 +29,9 @@
|
|||
|
||||
@interface Queue : CircularArray
|
||||
|
||||
- enqueueObject: newObject;
|
||||
- (void) enqueueObject: newObject;
|
||||
- dequeueObject;
|
||||
|
||||
// NON-OBJECT MESSAGE NAMES;
|
||||
- enqueueElement: (elt)newElement;
|
||||
- (elt) dequeueElement;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* __Queue_h_INCLUDE_GNU */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C Set collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993,1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -26,24 +26,23 @@
|
|||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <objects/Collection.h>
|
||||
#include <Foundation/NSHashTable.h>
|
||||
|
||||
@interface Set : Collection
|
||||
{
|
||||
coll_cache_ptr _contents_hash; // a hashtable to hold the contents;
|
||||
NSHashTable *_contents_hash; // a hashtable to hold the contents;
|
||||
}
|
||||
|
||||
// MANAGING CAPACITY;
|
||||
+ (unsigned) defaultCapacity;
|
||||
|
||||
// INITIALIZING AND FREEING;
|
||||
- initWithType: (const char *)contentEncoding
|
||||
capacity: (unsigned)aCapacity;
|
||||
- initWithCapacity: (unsigned)aCapacity;
|
||||
|
||||
// SET OPERATIONS;
|
||||
- intersectWithCollection: (id <Collecting>)aCollection;
|
||||
- unionWithCollection: (id <Collecting>)aCollection;
|
||||
- differenceWithCollection: (id <Collecting>)aCollection;
|
||||
- (void) intersectWithCollection: (id <Collecting>)aCollection;
|
||||
- (void) unionWithCollection: (id <Collecting>)aCollection;
|
||||
- (void) differenceWithCollection: (id <Collecting>)aCollection;
|
||||
|
||||
- shallowCopyIntersectWithCollection: (id <Collecting>)aCollection;
|
||||
- shallowCopyUnionWithCollection: (id <Collecting>)aCollection;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Interface for Objective-C SplayTree collection object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
{
|
||||
}
|
||||
|
||||
- splayNode: aNode;
|
||||
- (void) splayNode: aNode;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Interface for Objective-C Stack object
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
||||
Date: May 1993
|
||||
Created: May 1993
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
|
@ -29,17 +29,11 @@
|
|||
|
||||
@interface Stack : Array
|
||||
|
||||
- pushObject: anObject;
|
||||
- (void) pushObject: anObject;
|
||||
- popObject;
|
||||
- topObject;
|
||||
- duplicateTop;
|
||||
- exchangeTop;
|
||||
|
||||
// NON-OBJECT MESSAGE NAMES;
|
||||
- pushElement: (elt)anElement;
|
||||
- (elt) popElement;
|
||||
- (elt) topElement;
|
||||
|
||||
- (void) duplicateTop;
|
||||
- (void) exchangeTop;
|
||||
|
||||
@end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue