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:
mccallum 1996-02-22 15:11:43 +00:00
parent 72114c01b0
commit 9c3783b952
52 changed files with 1839 additions and 2931 deletions

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C Array collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -26,13 +26,19 @@
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/IndexedCollection.h> #include <objects/IndexedCollection.h>
#include <objects/OrderedCollecting.h>
@interface Array : IndexedCollection @interface ConstantArray : IndexedCollection
{ {
@public @public
int (*_comparison_function)(elt,elt); id *_contents_array;
elt *_contents_array;
unsigned int _count; unsigned int _count;
}
@end
@interface Array : ConstantArray
{
@public
unsigned int _capacity; unsigned int _capacity;
unsigned int _grow_factor; unsigned int _grow_factor;
} }
@ -40,16 +46,18 @@
+ (unsigned) defaultCapacity; + (unsigned) defaultCapacity;
+ (unsigned) defaultGrowFactor; + (unsigned) defaultGrowFactor;
- initWithType: (const char *)contentEncoding
capacity: (unsigned)aCapacity;
- initWithCapacity: (unsigned) aCapacity; - initWithCapacity: (unsigned) aCapacity;
- setCapacity: (unsigned)newCapacity; - (void) setCapacity: (unsigned)newCapacity;
- (unsigned) growFactor; - (unsigned) growFactor;
- setGrowFactor: (unsigned)aNum; - (void) setGrowFactor: (unsigned)aNum;
@end @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) \ #define FOR_ARRAY(ARRAY, ELEMENT_VAR) \
{ \ { \
unsigned _FOR_ARRAY_i; \ unsigned _FOR_ARRAY_i; \

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C Bag collection object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -25,39 +25,27 @@
#define __Bag_h_INCLUDE_GNU #define __Bag_h_INCLUDE_GNU
#include <objects/stdobjects.h> #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; unsigned int _count; // the number of elements;
} }
// INITIALIZING AND FREEING;
- initWithCapacity: (unsigned)aCapacity;
// ADDING; // ADDING;
- addObject: newObject withOccurrences: (unsigned)count; - (void) addObject: newObject withOccurrences: (unsigned)count;
// REMOVING AND REPLACING; // REMOVING AND REPLACING;
- removeObject: oldObject occurrences: (unsigned)count; - (void) removeObject: oldObject occurrences: (unsigned)count;
- removeObject: oldObject occurrences: (unsigned)count
ifAbsentCall: (id(*)(arglist_t))excFunc;
// TESTING; // TESTING;
- (unsigned) uniqueCount; - (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 @end
#endif /* __Bag_h_INCLUDE_GNU */ #endif /* __Bag_h_INCLUDE_GNU */

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C BinaryTree collection object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -35,13 +35,15 @@
/* The <BinaryTreeComprising> protocol defines the interface to an object /* The <BinaryTreeComprising> protocol defines the interface to an object
that may be an element in a BinaryTree. that may be an element in a BinaryTree.
*/ */
@protocol BinaryTreeComprising @protocol BinaryTreeComprising <NSObject>
- leftNode; - leftNode;
- rightNode; - rightNode;
- parentNode; - parentNode;
- setLeftNode: (id <BinaryTreeComprising>)aNode; - (void) setLeftNode: (id <BinaryTreeComprising>)aNode;
- setRightNode: (id <BinaryTreeComprising>)aNode; - (void) setRightNode: (id <BinaryTreeComprising>)aNode;
- setParentNode: (id <BinaryTreeComprising>)aNode; - (void) setParentNode: (id <BinaryTreeComprising>)aNode;
- binaryTree;
- (void) setBinaryTree: anObject;
@end @end
#define NODE_IS_RIGHTCHILD(NODE) (NODE == [[NODE parentNode] rightNode]) #define NODE_IS_RIGHTCHILD(NODE) (NODE == [[NODE parentNode] rightNode])

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C BinaryTreeNode object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -33,6 +33,7 @@
id _left; id _left;
id _right; id _right;
id _parent; id _parent;
id _binary_tree;
} }
@end @end

View file

@ -1,8 +1,8 @@
/* Protocol for Objective-C objects that hold collections of elements. /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -35,54 +35,61 @@
#define __Collecting_h_INCLUDE_GNU #define __Collecting_h_INCLUDE_GNU
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objc/Object.h> #include <objects/Coding.h>
#include <objects/elt.h> #include <objects/Invoking.h>
#include <objects/Enumerating.h>
@protocol ConstantCollecting @protocol ConstantCollecting
// INITIALIZING; // INITIALIZING;
- init; - init;
- initWithObjects: (id*)objc count: (unsigned)c;
- initWithObjects: firstObject, ...;
- initWithObjects: firstObject rest: (va_list)ap;
- initWithContentsOf: (id <ConstantCollecting>)aCollection; - initWithContentsOf: (id <ConstantCollecting>)aCollection;
// TESTING; // QUERYING COUNTS;
- (BOOL) isEmpty; - (BOOL) isEmpty;
- (BOOL) includesObject: anObject; - (unsigned) count;
- (BOOL) containsObject: anObject;
- (unsigned) occurrencesOfObject: anObject;
// COMPARISON WITH OTHER COLLECTIONS;
- (BOOL) isSubsetOf: (id <ConstantCollecting>)aCollection; - (BOOL) isSubsetOf: (id <ConstantCollecting>)aCollection;
- (BOOL) isDisjointFrom: (id <ConstantCollecting>)aCollection; - (BOOL) isDisjointFrom: (id <ConstantCollecting>)aCollection;
- (int) compare: anObject;
- (BOOL) isEqual: anObject; - (BOOL) isEqual: anObject;
- (int) compare: anObject;
- (BOOL) contentsEqual: (id <ConstantCollecting>)aCollection; - (BOOL) contentsEqual: (id <ConstantCollecting>)aCollection;
- (unsigned) count;
- (unsigned) occurrencesOfObject: anObject; // PROPERTIES OF CONTENTS;
- (BOOL) trueForAllObjectsByCalling: (BOOL(*)(id))aFunc; - (BOOL) trueForAllObjectsByInvoking: (id <Invoking>)anInvocation;
- (BOOL) trueForAnyObjectsByCalling: (BOOL(*)(id))aFunc; - (BOOL) trueForAnyObjectsByInvoking: (id <Invoking>)anInvocation;
- detectObjectByCalling: (BOOL(*)(id))aFunc; - detectObjectByInvoking: (id <Invoking>)anInvocation;
- detectObjectByCalling: (BOOL(*)(id))aFunc
ifNoneCall: (id(*)(arglist_t))excFunc;
- maxObject; - maxObject;
- maxObjectByCalling: (int(*)(id,id))aFunc;
- minObject; - minObject;
- minObjectByCalling: (int(*)(id,id))aFunc;
// ENUMERATING // ENUMERATING
- (void*) newEnumState; - (id <Enumerating>) objectEnumerator;
- (BOOL) getNextObject:(id *)anObjectPtr withEnumState: (void**)enumState; - (void) withObjectsInvoke: (id <Invoking>)anInvocation;
- freeEnumState: (void**)enumState; - (void) withObjectsInvoke: (id <Invoking>)anInvocation whileTrue:(BOOL *)flag;
- withObjectsCall: (void(*)(id))aFunc; - (void) makeObjectsPerform: (SEL)aSel;
- withObjectsCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag; - (void) makeObjectsPerform: (SEL)aSel withObject: argObject;
- injectObject: initialArgObject byCalling:(id(*)(id,id))aFunc;
- makeObjectsPerform: (SEL)aSel;
- makeObjectsPerform: (SEL)aSel with: argObject;
// FILTERED ENUMERATING; // FILTERED ENUMERATING;
- withObjectsTrueByCalling: (BOOL(*)(id))testFunc - (void) withObjectsTrueByInvoking: (id <Invoking>)testInvocation
call: (void(*)(id))destFunc; invoke: (id <Invoking>)anInvocation;
- withObjectsFalseByCalling: (BOOL(*)(id))testFunc - (void) withObjectsFalseByInvoking: (id <Invoking>)testInvocation
call: (void(*)(id))destFunc; invoke: (id <Invoking>)anInvocation;
- withObjectsTransformedByCalling: (id(*)(id))transFunc - (void) withObjectsTransformedByInvoking: (id <Invoking>)transInvocation
call: (void(*)(id))destFunc; invoke: (id <Invoking>)anInvocation;
// COPYING // LOW-LEVEL ENUMERATING;
- (void*) newEnumState;
- nextObjectWithEnumState: (void**)enumState;
- (void) freeEnumState: (void**)enumState;
// COPYING;
- allocCopy;
- emptyCopy; - emptyCopy;
- emptyCopyAs: (Class)aCollectionClass; - emptyCopyAs: (Class)aCollectionClass;
- shallowCopy; - shallowCopy;
@ -91,98 +98,34 @@
- copyAs: (Class)aCollectionClass; - copyAs: (Class)aCollectionClass;
- species; - 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 @end
@protocol Collecting <ConstantCollecting> @protocol Collecting <ConstantCollecting>
// ADDING; // ADDING;
- addObject: newObject; - (void) addObject: newObject;
- addObjectIfAbsent: newObject; - (void) addObjectIfAbsent: newObject;
- addContentsOf: (id <ConstantCollecting>)aCollection; - (void) addContentsOf: (id <ConstantCollecting>)aCollection;
- addContentsOfIfAbsent: (id <ConstantCollecting>)aCollection; - (void) addContentsIfAbsentOf: (id <ConstantCollecting>)aCollection;
- addObjectsCount: (unsigned)count, ...; - (void) addWithObjects: (id*)objc count: (unsigned)c;
- (void) addObjects: firstObject, ...;
- (void) addObjects: firstObject rest: (va_list)ap;
// REMOVING; // REMOVING;
- removeObject: oldObject; - (void) removeObject: oldObject;
- removeObject: oldObject ifAbsentCall: (id(*)(arglist_t))excFunc; - (void) removeAllOccurrencesOfObject: oldObject;
- removeAllOccurrencesOfObject: oldObject; - (void) removeContentsIn: (id <ConstantCollecting>)aCollection;
- removeContentsIn: (id <ConstantCollecting>)aCollection; - (void) removeContentsNotIn: (id <ConstantCollecting>)aCollection;
- removeContentsNotIn: (id <ConstantCollecting>)aCollection; - (void) uniqueContents;
- uniqueContents; - (void) empty;
- empty;
// REPLACING; // REPLACING;
- replaceObject: oldObject with: newObject; - (void) replaceObject: oldObject withObject: newObject;
- replaceObject: oldObject with: newObject - (void) replaceAllOccurrencesOfObject: oldObject withObject: 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;
@end @end
#define NO_OBJECT nil
#endif /* __Collecting_h_INCLUDE_GNU */ #endif /* __Collecting_h_INCLUDE_GNU */

View file

@ -32,29 +32,42 @@
#include <Foundation/NSObject.h> #include <Foundation/NSObject.h>
#include <objects/Collecting.h> #include <objects/Collecting.h>
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/collhash.h>
#include <objects/Coding.h> #include <objects/Coding.h>
@interface Collection : NSObject <Collecting> @interface ConstantCollection : NSObject <ConstantCollecting>
{ - printForDebugger; /* This method will disappear later. */
}
- (void) withObjectsInvoke: anInvocation;
- printElement: (elt)anElement;
- printForDebugger;
@end @end
// #warning fix this macro @interface Collection : ConstantCollection <Collecting>
#define FOR_COLL(ACOLL, ELT) \ @end
@interface Enumerator : NSObject <Enumerating>
{
id collection;
void *enum_state;
}
@end
#define FOR_COLLECTION(ACOLL, ELT) \
{ \ { \
void *_es = [ACOLL initEnumState]; \ void *_es = [ACOLL newEnumState]; \
while ([ACOLL getNextElement:&(ELT) withEnumState:&_es]) \ 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: /* The only subclassResponsibilities in Collection are:

View file

@ -1,8 +1,8 @@
/* Collection definitions for the use of subclass implementations only /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -25,28 +25,23 @@
#define __CollectionPrivate_h_INCLUDE_GNU #define __CollectionPrivate_h_INCLUDE_GNU
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/eltfuncs.h>
@interface Collection (ArchivingHelpers) @interface ConstantCollection (ArchivingHelpers)
/* These methods should never be called except in order inside /* These methods should never be called except in order, and inside
-write: and -read: */ -encodeWithCoder: and -decodeWithCoder: */
- _writeInit: (TypedStream*)aStream;
- _readInit: (TypedStream*)aStream;
- _writeContents: (TypedStream*)aStream;
- _readContents: (TypedStream*)aStream;
/* The Coding versions of the above */
- (void) _encodeCollectionWithCoder: (id <Encoding>)aCoder; - (void) _encodeCollectionWithCoder: (id <Encoding>)aCoder;
- _initCollectionWithCoder: (id <Decoding>)aCoder; - _initCollectionWithCoder: (id <Decoding>)aCoder;
- (void) _encodeContentsWithCoder: (id <Encoding>)aCoder; - (void) _encodeContentsWithCoder: (id <Encoding>)aCoder;
- (void) _decodeContentsWithCoder: (id <Decoding>)aCoder; - (void) _decodeContentsWithCoder: (id <Decoding>)aCoder;
@end @end
@interface Collection (DeallocationHelpers) @interface ConstantCollection (DeallocationHelpers)
/* Empty the internals of a collection after the contents have /* Empty the internals of a collection after the contents have
already been released. */ already been released. */
- _empty; - (void) _collectionEmpty;
- (void) _collectionReleaseContents;
/* Deallocate the internals of a collection after the contents /* Deallocate the internals of a collection after the contents
have already been released. */ have already been released. */
@ -54,63 +49,4 @@
@end @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 */ #endif /* __CollectionPrivate_h_INCLUDE_GNU */

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C Dictionary collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -26,18 +26,14 @@
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/KeyedCollection.h> #include <objects/KeyedCollection.h>
#include <Foundation/NSMapTable.h>
@interface Dictionary : KeyedCollection @interface Dictionary : KeyedCollection
{ {
coll_cache_ptr _contents_hash; // a hashtable to hold the contents; NSMapTable *_contents_hash;
int (*_comparison_function)(elt,elt);
} }
- initWithType: (const char *)contentEncoding - initWithCapacity: (unsigned)aCapacity;
keyType: (const char *)keyEncoding
capacity: (unsigned)aCapacity;
- initWithType: (const char *)contentEncoding
capacity: (unsigned)aCapacity;
@end @end

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C Heap collection object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -28,14 +28,9 @@
#include <objects/Array.h> #include <objects/Array.h>
@interface Heap : Array @interface Heap : Array
{
}
- addElement: (elt)anElement; - (void) heapifyFromIndex: (unsigned)index;
- (elt) removeFirstElement; - (void) heapify;
- heapifyFromIndex: (unsigned)index;
- heapify;
@end @end

View file

@ -1,5 +1,5 @@
/* Protocol for Objective-C objects that hold elements accessible by index /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -36,7 +36,7 @@
#define __IndexedCollecting_h_OBJECTS_INCLUDE #define __IndexedCollecting_h_OBJECTS_INCLUDE
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/KeyedCollecting.h> #include <objects/Collecting.h>
typedef struct _IndexRange { typedef struct _IndexRange {
unsigned location; unsigned location;
@ -47,8 +47,8 @@ typedef struct _IndexRange {
({IndexRange __a=(RANGE1), __b=(RANGE2); \ ({IndexRange __a=(RANGE1), __b=(RANGE2); \
__a.start<=__b.start && __a.end>=__b.end;}) __a.start<=__b.start && __a.end>=__b.end;})
@protocol ConstantIndexedCollecting <ConstantKeyedCollecting> @protocol ConstantIndexedCollecting <ConstantCollecting>
// GETTING MEMBERS BY INDEX; // GETTING MEMBERS BY INDEX;
- objectAtIndex: (unsigned)index; - objectAtIndex: (unsigned)index;
@ -61,115 +61,53 @@ typedef struct _IndexRange {
// GETTING INDICES BY MEMBER; // GETTING INDICES BY MEMBER;
- (unsigned) indexOfObject: anObject; - (unsigned) indexOfObject: anObject;
- (unsigned) indexOfObject: anObject
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
- (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange; - (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange;
- (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
// TESTING; // TESTING;
- (BOOL) includesIndex: (unsigned)index;
- (BOOL) contentsEqualInOrder: (id <ConstantIndexedCollecting>)aColl; - (BOOL) contentsEqualInOrder: (id <ConstantIndexedCollecting>)aColl;
- (int) compareInOrderContentsOf: (id <Collecting>)aCollection;
- (unsigned) indexOfFirstDifference: (id <ConstantIndexedCollecting>)aColl; - (unsigned) indexOfFirstDifference: (id <ConstantIndexedCollecting>)aColl;
- (unsigned) indexOfFirstIn: (id <ConstantCollecting>)aColl; - (unsigned) indexOfFirstIn: (id <ConstantCollecting>)aColl;
- (unsigned) indexOfFirstNotIn: (id <ConstantCollecting>)aColl; - (unsigned) indexOfFirstNotIn: (id <ConstantCollecting>)aColl;
// ENUMERATING; // ENUMERATING;
- (BOOL) getPrevObject: (id*)anIdPtr withEnumState: (void**)enumState; - (id <Enumerating>) reverseObjectEnumerator;
- withObjectsInRange: (IndexRange)aRange call:(void(*)(id))aFunc; - (void) withObjectsInRange: (IndexRange)aRange
- withObjectsInReverseCall: (void(*)(id))aFunc; invoke: (id <Invoking>)anInvocation;
- withObjectsInReverseCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag; - (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; // LOW-LEVEL ENUMERATING;
- prevObjectWithEnumState: (void**)enumState;
// 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;
@end @end
@protocol IndexedCollecting <ConstantIndexedCollecting, KeyedCollecting>
@protocol IndexedCollecting <ConstantIndexedCollecting, Collecting>
// ADDING; // REPLACING;
- insertObject: newObject atIndex: (unsigned)index; - (void) replaceObjectAtIndex: (unsigned)index with: newObject;
- 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 AND SWAPPING // REMOVING;
- replaceObjectAtIndex: (unsigned)index with: newObject; - (void) removeObjectAtIndex: (unsigned)index;
- replaceRange: (IndexRange)aRange with: (id <ConstantCollecting>)aCollection; - (void) removeFirstObject;
- replaceRange: (IndexRange)aRange using: (id <ConstantCollecting>)aCollection; - (void) removeLastObject;
- swapAtIndeces: (unsigned)index1 : (unsigned)index2; - (void) removeRange: (IndexRange)aRange;
// REMOVING
- removeObjectAtIndex: (unsigned)index;
- removeFirstObject;
- removeLastObject;
- removeRange: (IndexRange)aRange;
// ENUMERATING WHILE CHANGING CONTENTS;
- safeWithObjectsInReverseCall: (void(*)(id))aFunc;
- safeWithObjectsInReverseCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
// SORTING; // SORTING;
- sortContents; - (void) sortContents;
- sortObjectsByCalling: (int(*)(id,id))aFunc; - (void) sortAddObject: newObject;
- 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;
@end @end
#include <limits.h>
#define NO_INDEX UINT_MAX
/* xxx Fix this comment: */
/* Most methods in the KeyedCollecting protocol that mention a key are /* Most methods in the KeyedCollecting protocol that mention a key are
duplicated in the IndexedCollecting protocol, with their names duplicated in the IndexedCollecting protocol, with their names
modified to reflect that the "key" now must be an unsigned integer, modified to reflect that the "key" now must be an unsigned integer,

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C Sequential Collection object. /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -28,12 +28,54 @@
#include <objects/KeyedCollection.h> #include <objects/KeyedCollection.h>
#include <objects/IndexedCollecting.h> #include <objects/IndexedCollecting.h>
@interface IndexedCollection : KeyedCollection @interface ConstantIndexedCollection : ConstantCollection
@end
@interface IndexedCollection : ConstantIndexedCollection
@end
@interface ReverseEnumerator : Enumerator
@end @end
/* Put this on category instead of class to avoid bogus complaint from gcc */ /* Put this on category instead of class to avoid bogus complaint from gcc */
@interface IndexedCollection (IndexedCollectionProtocol) <IndexedCollecting> @interface ConstantIndexedCollection (Protocol) <ConstantIndexedCollecting>
@end @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: /* The only subclassResponsibilities in IndexedCollection are:

View file

@ -1,5 +1,5 @@
/* Protocol for Objective-C objects holding (keyElement,contentElement) pairs. /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -38,84 +38,44 @@
@protocol ConstantKeyedCollecting <ConstantCollecting> @protocol ConstantKeyedCollecting <ConstantCollecting>
// INITIALIZING;
- initWithObjects: (id*)objects forKeys: (id*)keys count: (unsigned)c;
// GETTING ELEMENTS AND KEYS; // GETTING ELEMENTS AND KEYS;
- objectAtKey: (elt)aKey; - objectAtKey: aKey;
- keyObjectOfObject: aContentObject; - keyOfObject: aContentObject;
// TESTING; // TESTING;
- (BOOL) includesKey: (elt)aKey; - (BOOL) containsKey: aKey;
// ENUMERATIONS; // ENUMERATIONS;
- withKeyObjectsCall: (void(*)(id))aFunc; - (id <Enumerating>) keyEnumerator;
- withKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc; - withKeyObjectsInvoke: (id <Invoking>)anInvocation;
- withKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc - withKeyObjectsInvoke: (id <Invoking>)anInvocation
whileTrue: (BOOL *)flag; whileTrue: (BOOL *)flag;
// NON-OBJECT ELEMENT METHOD NAMES; // LOW-LEVEL ENUMERATING;
- nextObjectAndKey: (id*)keyPtr withEnumState: (void**)enumState;
// INITIALIZING; // COPYING;
- initWithType: (const char *)contentsEncoding - shallowCopyValuesAs: (Class)aCollectingClass;
keyType: (const char *)keyEncoding; - shallowCopyKeysAs: (Class)aCollectingClass;
- initKeyType: (const char *)keyEncoding; - copyValuesAs: (Class)aCollectingClass;
- copyKeysAs: (Class)aCollectingClass;
// 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;
@end @end
@protocol KeyedCollecting <ConstantKeyedCollecting, Collecting> @protocol KeyedCollecting <ConstantKeyedCollecting, Collecting>
// ADDING; // ADDING;
- putObject: newContentObject atKey: (elt)aKey; - (void) putObject: newContentObject atKey: aKey;
// REPLACING AND SWAPPING; // REPLACING AND SWAPPING;
- replaceObjectAtKey: (elt)aKey with: newContentObject; - (void) replaceObjectAtKey: aKey with: newContentObject;
- swapAtKeys: (elt)key1 : (elt)key2; - (void) swapObjectsAtKeys: key1 : key2;
// REMOVING; // REMOVING;
- removeObjectAtKey: (elt)aKey; - (void) removeObjectAtKey: 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;
@end @end

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C KeyedCollection collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -28,12 +28,44 @@
#include <objects/Collection.h> #include <objects/Collection.h>
#include <objects/KeyedCollecting.h> #include <objects/KeyedCollecting.h>
@interface KeyedCollection : Collection @interface ConstantKeyedCollection : Collection
@end
@interface KeyedCollection : ConstantKeyedCollection
@end @end
/* Put this on category instead of class to avoid bogus complaint from gcc */ /* Put this on category instead of class to avoid bogus complaint from gcc */
@interface KeyedCollection (KeyedCollectingProtocol) <KeyedCollecting> @interface ConstantKeyedCollection (Protocol) <ConstantKeyedCollecting>
@end @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: /* The only subclassResponsibilities in IndexedCollection are:

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C LinkedList collection object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -25,7 +25,7 @@
#define __LinkedList_h_INCLUDE_GNU #define __LinkedList_h_INCLUDE_GNU
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/IndexedCollection.h> #include <objects/OrderedCollection.h>
/* The <LinkedListComprising> protocol defines the interface to an object /* The <LinkedListComprising> protocol defines the interface to an object
that may be an element in a LinkedList. that may be an element in a LinkedList.
@ -33,13 +33,16 @@
@protocol LinkedListComprising @protocol LinkedListComprising
- nextLink; - nextLink;
- prevLink; - prevLink;
- setNextLink: (id <LinkedListComprising>)aLink; - (void) setNextLink: (id <LinkedListComprising>)aLink;
- setPrevLink: (id <LinkedListComprising>)aLink; - (void) setPrevLink: (id <LinkedListComprising>)aLink;
- linkedList;
- (void) setLinkedList: aLinkedList;
@end @end
@interface LinkedList : IndexedCollection @interface LinkedList : OrderedCollection
{ {
id _first_link; id _first_link;
id _last_link;
unsigned int _count; unsigned int _count;
} }

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C LinkedListNode object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -32,8 +32,8 @@
{ {
id <LinkedListComprising> _next; id <LinkedListComprising> _next;
id <LinkedListComprising> _prev; id <LinkedListComprising> _prev;
id _linked_list;
} }
@end @end
#endif /* __LinkedListNode_h_INCLUDE_GNU */ #endif /* __LinkedListNode_h_INCLUDE_GNU */

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C MappedCollector collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -33,7 +33,7 @@
id <KeyedCollecting> _domain; id <KeyedCollecting> _domain;
} }
- initCollection: (id <KeyedCollecting>)aDomain - initWithCollection: (id <KeyedCollecting>)aDomain
map: (id <KeyedCollecting>)aMap; map: (id <KeyedCollecting>)aMap;
@end @end

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C Queue object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -29,13 +29,9 @@
@interface Queue : CircularArray @interface Queue : CircularArray
- enqueueObject: newObject; - (void) enqueueObject: newObject;
- dequeueObject; - dequeueObject;
// NON-OBJECT MESSAGE NAMES;
- enqueueElement: (elt)newElement;
- (elt) dequeueElement;
@end @end
#endif /* __Queue_h_INCLUDE_GNU */ #endif /* __Queue_h_INCLUDE_GNU */

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C Set collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -26,24 +26,23 @@
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/Collection.h> #include <objects/Collection.h>
#include <Foundation/NSHashTable.h>
@interface Set : Collection @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; // MANAGING CAPACITY;
+ (unsigned) defaultCapacity; + (unsigned) defaultCapacity;
// INITIALIZING AND FREEING; // INITIALIZING AND FREEING;
- initWithType: (const char *)contentEncoding
capacity: (unsigned)aCapacity;
- initWithCapacity: (unsigned)aCapacity; - initWithCapacity: (unsigned)aCapacity;
// SET OPERATIONS; // SET OPERATIONS;
- intersectWithCollection: (id <Collecting>)aCollection; - (void) intersectWithCollection: (id <Collecting>)aCollection;
- unionWithCollection: (id <Collecting>)aCollection; - (void) unionWithCollection: (id <Collecting>)aCollection;
- differenceWithCollection: (id <Collecting>)aCollection; - (void) differenceWithCollection: (id <Collecting>)aCollection;
- shallowCopyIntersectWithCollection: (id <Collecting>)aCollection; - shallowCopyIntersectWithCollection: (id <Collecting>)aCollection;
- shallowCopyUnionWithCollection: (id <Collecting>)aCollection; - shallowCopyUnionWithCollection: (id <Collecting>)aCollection;

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C SplayTree collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -41,7 +41,7 @@
{ {
} }
- splayNode: aNode; - (void) splayNode: aNode;
@end @end

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C Stack object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -29,17 +29,11 @@
@interface Stack : Array @interface Stack : Array
- pushObject: anObject; - (void) pushObject: anObject;
- popObject; - popObject;
- topObject; - topObject;
- duplicateTop; - (void) duplicateTop;
- exchangeTop; - (void) exchangeTop;
// NON-OBJECT MESSAGE NAMES;
- pushElement: (elt)anElement;
- (elt) popElement;
- (elt) topElement;
@end @end

View file

@ -24,11 +24,9 @@
#include <objects/BinaryTree.h> #include <objects/BinaryTree.h>
#include <objects/IndexedCollectionPrivate.h> #include <objects/IndexedCollectionPrivate.h>
#include <objects/BinaryTreeNode.h> #include <objects/BinaryTreeNode.h>
#include <objects/NSString.h>
// do safety checks; /* the sentinal */
#define SAFE_BinaryTree 1
/* sentinal */
static id nilBinaryTreeNode; static id nilBinaryTreeNode;
@implementation BinaryTree @implementation BinaryTree
@ -37,7 +35,6 @@ static id nilBinaryTreeNode;
{ {
if (self == [BinaryTree class]) if (self == [BinaryTree class])
{ {
[self setVersion:0]; /* beta release */
nilBinaryTreeNode = [[BinaryTreeNode alloc] init]; nilBinaryTreeNode = [[BinaryTreeNode alloc] init];
} }
} }
@ -45,7 +42,6 @@ static id nilBinaryTreeNode;
/* This is the designated initializer of this class */ /* This is the designated initializer of this class */
- init - init
{ {
[super initWithType:@encode(id)];
_count = 0; _count = 0;
_contents_root = [self nilNode]; _contents_root = [self nilNode];
return self; return self;
@ -80,39 +76,6 @@ static id nilBinaryTreeNode;
[aCoder finishDecodingInterconnectedObjects]; [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 */ /* Empty copy must empty an allocCopy'ed version of self */
- emptyCopy - emptyCopy
{ {
@ -123,20 +86,10 @@ static id nilBinaryTreeNode;
} }
/* This must work without sending any messages to content objects */ /* This must work without sending any messages to content objects */
- _empty - (void) _empty
{ {
_count = 0; _count = 0;
_contents_root = [self nilNode]; _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 - nilNode
@ -173,64 +126,72 @@ static id nilBinaryTreeNode;
return aNode; return aNode;
} }
- (elt) firstElement - firstObject
{ {
return [self leftmostNodeFromNode: _contents_root]; 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]; return [self rightmostNodeFromNode: _contents_root];
} }
/* This is correct only is the tree is sorted. How to deal with this? */ /* This is correct only is the tree is sorted. How to deal with this? */
- (elt) maxElement - minObject
{
return [self rightmostNodeFromNode:_contents_root];
}
/* This is correct only is the tree is sorted. How to deal with this? */
- (elt) minElement
{ {
return [self leftmostNodeFromNode: _contents_root]; return [self leftmostNodeFromNode: _contents_root];
} }
// returns [self nilNode] is there is no successor; - successorOfObject: anObject
- (elt) successorOfElement: (elt)anElement
{ {
id tmp; id tmp;
/* Make sure we actually own the anObject. */
assert ([anObject binaryTree] == self);
// here tmp is the right node; // here tmp is the right node;
if ((tmp = [anElement.id_u rightNode]) != [self nilNode]) if ((tmp = [anObject rightNode]) != [self nilNode])
return [self leftmostNodeFromNode: tmp]; return [self leftmostNodeFromNode: tmp];
// here tmp is the parent; // here tmp is the parent;
tmp = [anElement.id_u parentNode]; tmp = [anObject parentNode];
while (tmp != [self nilNode] && anElement.id_u == [tmp rightNode]) while (tmp != [self nilNode] && anObject == [tmp rightNode])
{ {
anElement.id_u = tmp; anObject = tmp;
tmp = [tmp parentNode]; tmp = [tmp parentNode];
} }
if (tmp == [self nilNode])
return NO_OBJECT;
return tmp; return tmp;
} }
// I should make sure that [_contents_root parentNode] == [self nilNode]; // I should make sure that [_contents_root parentNode] == [self nilNode];
// Perhaps I should make [_contents_root parentNode] == binaryTreeObj ??; // Perhaps I should make [_contents_root parentNode] == binaryTreeObj ??;
// returns [self nilNode] is there is no predecessor; - predecessorObject: anObject
- (elt) predecessorElement: (elt)anElement
{ {
id tmp; id tmp;
/* Make sure we actually own the anObject. */
assert ([anObject binaryTree] == self);
// here tmp is the left node; // here tmp is the left node;
if ((tmp = [anElement.id_u leftNode]) != [self nilNode]) if ((tmp = [anObject leftNode]) != [self nilNode])
return [self rightmostNodeFromNode:tmp]; return [self rightmostNodeFromNode:tmp];
// here tmp is the parent; // here tmp is the parent;
tmp = [anElement.id_u parentNode]; tmp = [anObject parentNode];
while (tmp != [self nilNode] && anElement.id_u == [tmp leftNode]) while (tmp != [self nilNode] && anObject == [tmp leftNode])
{ {
anElement.id_u = tmp; anObject = tmp;
tmp = [tmp parentNode]; tmp = [tmp parentNode];
} }
if (tmp == [self nilNode])
return NO_OBJECT;
return tmp; return tmp;
} }
@ -238,6 +199,10 @@ static id nilBinaryTreeNode;
- rootFromNode: aNode - rootFromNode: aNode
{ {
id parentNode; id parentNode;
/* Make sure we actually own the aNode. */
assert ([aNode binaryTree] == self);
while ((parentNode = [aNode parentNode]) != [self nilNode]) while ((parentNode = [aNode parentNode]) != [self nilNode])
aNode = parentNode; aNode = parentNode;
return aNode; return aNode;
@ -248,6 +213,9 @@ static id nilBinaryTreeNode;
{ {
unsigned count = 0; unsigned count = 0;
/* Make sure we actually own the aNode. */
assert ([aNode binaryTree] == self);
if (aNode == nil || aNode == [self nilNode]) if (aNode == nil || aNode == [self nilNode])
[self error:"in %s, Can't find depth of nil node", sel_get_name(_cmd)]; [self error:"in %s, Can't find depth of nil node", sel_get_name(_cmd)];
do do
@ -264,6 +232,9 @@ static id nilBinaryTreeNode;
unsigned leftHeight, rightHeight; unsigned leftHeight, rightHeight;
id tmpNode; id tmpNode;
/* Make sure we actually own the aNode. */
assert ([aNode binaryTree] == self);
if (aNode == nil || aNode == [self nilNode]) if (aNode == nil || aNode == [self nilNode])
{ {
[self error:"in %s, Can't find height of nil node", sel_get_name(_cmd)]; [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) nodeCountUnderNode: aNode
{ {
unsigned count = 0; unsigned count = 0;
/* Make sure we actually own the aNode. */
assert ([aNode binaryTree] == self);
if ([aNode leftNode] != [self nilNode]) if ([aNode leftNode] != [self nilNode])
count += 1 + [self nodeCountUnderNode:[aNode leftNode]]; count += 1 + [self nodeCountUnderNode:[aNode leftNode]];
if ([aNode rightNode] != [self nilNode]) if ([aNode rightNode] != [self nilNode])
@ -299,6 +274,9 @@ static id nilBinaryTreeNode;
{ {
id y; id y;
/* Make sure we actually own the aNode. */
assert ([aNode binaryTree] == self);
y = [aNode rightNode]; y = [aNode rightNode];
if (y == [self nilNode]) if (y == [self nilNode])
return self; return self;
@ -324,6 +302,9 @@ static id nilBinaryTreeNode;
{ {
id y; id y;
/* Make sure we actually own the aNode. */
assert ([aNode binaryTree] == self);
y = [aNode leftNode]; y = [aNode leftNode];
if (y == [self nilNode]) if (y == [self nilNode])
return self; return self;
@ -345,156 +326,73 @@ static id nilBinaryTreeNode;
return self; return self;
} }
- (elt) elementAtIndex: (unsigned)index - objectAtIndex: (unsigned)index
{ {
elt ret; id ret;
CHECK_INDEX_RANGE_ERROR(index, _count); CHECK_INDEX_RANGE_ERROR(index, _count);
ret = [self firstElement]; ret = [self firstObject];
// Not very efficient; Should be rewritten; // Not very efficient; Should be rewritten;
while (index--) while (index--)
ret = [self successorOfElement:ret]; ret = [self successorOfObject: ret];
return ret; return ret;
} }
- sortAddElement: (elt)newElement byCalling: (int(*)(elt,elt))aFunc - (void) sortAddObject: newObject
{ {
id theParent, tmpChild; id theParent, tmpChild;
[newElement.id_u setLeftNode:[self nilNode]]; /* Make sure no one else already owns the newObject. */
[newElement.id_u setRightNode:[self nilNode]]; 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]; theParent = [self nilNode];
tmpChild = _contents_root; tmpChild = _contents_root;
while (tmpChild != [self nilNode]) while (tmpChild != [self nilNode])
{ {
theParent = tmpChild; theParent = tmpChild;
if ((*aFunc)(newElement,theParent) < 0) if ([newObject compare: theParent] < 0)
tmpChild = [tmpChild leftNode]; tmpChild = [tmpChild leftNode];
else else
tmpChild = [tmpChild rightNode]; tmpChild = [tmpChild rightNode];
} }
[newElement.id_u setParentNode:theParent]; [newObject setParentNode:theParent];
if (theParent == [self nilNode]) if (theParent == [self nilNode])
_contents_root = newElement.id_u; _contents_root = newObject;
else else
{ {
if (COMPARE_ELEMENTS(newElement, theParent) < 0) if ([newObject compare: theParent] < 0)
[theParent setLeftNode:newElement.id_u]; [theParent setLeftNode:newObject];
else else
[theParent setRightNode:newElement.id_u]; [theParent setRightNode:newObject];
} }
_count++; _count++;
RETAIN_ELT(newElement);
return self;
} }
- addElement: (elt)newElement - (void) addObject: newObject
{ {
// By default insert in sorted order. Is this what we want?; // By default insert in sorted order.
[self sortAddElement:newElement]; [self sortAddObject: newObject];
return self;
} }
// NOTE: This gives you the power to put elements in unsorted order; - (void) removeObject: oldObject
- 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
{ {
id x, y; id x, y;
if ([oldElement.id_u leftNode] == [self nilNode] /* Make sure we actually own the aNode. */
|| [oldElement.id_u rightNode] == [self nilNode]) assert ([oldObject binaryTree] == self);
y = oldElement.id_u;
/* Extract the oldObject and sew up the cut. */
if ([oldObject leftNode] == [self nilNode]
|| [oldObject rightNode] == [self nilNode])
y = oldObject;
else else
y = [self successorOfElement:oldElement].id_u; y = [self successorOfObject: oldObject];
if ([y leftNode] != [self nilNode]) if ([y leftNode] != [self nilNode])
x = [y leftNode]; x = [y leftNode];
@ -514,76 +412,54 @@ static id nilBinaryTreeNode;
[[y parentNode] setRightNode: x]; [[y parentNode] setRightNode: x];
} }
if (y != oldElement.id_u) if (y != oldObject)
{ {
/* put y in the place of oldElement.id_u */ /* put y in the place of oldObject */
[y setParentNode:[oldElement.id_u parentNode]]; [y setParentNode: [oldObject parentNode]];
[y setLeftNode:[oldElement.id_u leftNode]]; [y setLeftNode: [oldObject leftNode]];
[y setRightNode:[oldElement.id_u rightNode]]; [y setRightNode: [oldObject rightNode]];
if (oldElement.id_u == [[oldElement.id_u parentNode] leftNode]) if (oldObject == [[oldObject parentNode] leftNode])
[[oldElement.id_u parentNode] setLeftNode:y]; [[oldObject parentNode] setLeftNode: y];
else else
[[oldElement.id_u parentNode] setRightNode:y]; [[oldObject parentNode] setRightNode: y];
[[oldElement.id_u leftNode] setParentNode:y]; [[oldObject leftNode] setParentNode: y];
[[oldElement.id_u rightNode] 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--; _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
{ // ENUMERATING;
void traverse(id aNode)
{
if (!(*flag) || aNode == [self nilNode] || !aNode)
return;
traverse([aNode leftNode]);
(*aFunc)(aNode);
traverse([aNode rightNode]);
}
traverse(_contents_root);
return self;
}
- withElementsInReverseCall: (void(*)(elt))aFunc whileTrue: (BOOL*)flag - nextObjectWithEnumState: (void**)enumState
{
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
{ {
if (!(*enumState)) if (!(*enumState))
*enumState = [self leftmostNodeFromNode:_contents_root]; *enumState = [self leftmostNodeFromNode:_contents_root];
else else
*enumState = [self successorOfElement:*enumState].id_u; *enumState = [self successorOfObject:*enumState];
*anElementPtr = *enumState; return (id) *enumState;
if (*enumState)
return YES;
return NO;
} }
- (BOOL) getPrevElement:(elt *)anElementPtr withEnumState: (void**)enumState - prevObjectWithEnumState: (void**)enumState
{ {
if (!(*enumState)) if (!(*enumState))
*enumState = [self rightmostNodeFromNode:_contents_root]; *enumState = [self rightmostNodeFromNode:_contents_root];
else else
*enumState = [self predecessorElement:*enumState].id_u; *enumState = [self predecessorObject:*enumState];
*anElementPtr = *enumState; return (id) *enumState;
if (*enumState)
return YES;
return NO;
} }
- (unsigned) count - (unsigned) count
@ -591,14 +467,12 @@ static id nilBinaryTreeNode;
return _count; return _count;
} }
/* replace this with something better eventually */ /* replace this with something better eventually */
- _tmpPrintFromNode: aNode indent: (int)count - _tmpPrintFromNode: aNode indent: (int)count
{ {
printf("%-*s", count, ""); printf("%-*s", count, "");
if ([aNode respondsTo:@selector(printForDebugger)]) printf("%s\n", [[aNode description] cStringNoCopy]);
[aNode printForDebugger];
else
printf("?\n");
printf("%-*s.", count, ""); printf("%-*s.", count, "");
if ([aNode leftNode] != [self nilNode]) if ([aNode leftNode] != [self nilNode])
[self _tmpPrintFromNode:[aNode leftNode] indent:count+2]; [self _tmpPrintFromNode:[aNode leftNode] indent:count+2];
@ -621,3 +495,112 @@ static id nilBinaryTreeNode;
@end @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

View file

@ -45,6 +45,8 @@
[aCoder encodeObjectReference:_right withName:@"Right BinaryTree Node"]; [aCoder encodeObjectReference:_right withName:@"Right BinaryTree Node"];
[aCoder encodeObjectReference:_left withName:@"Left BinaryTree Node"]; [aCoder encodeObjectReference:_left withName:@"Left BinaryTree Node"];
[aCoder encodeObjectReference:_parent withName:@"Parent BinaryTree Node"]; [aCoder encodeObjectReference:_parent withName:@"Parent BinaryTree Node"];
[aCoder encodeObjectReference:_binary_tree
withName:@"BinaryTree"];
} }
- initWithCoder: aCoder - initWithCoder: aCoder
@ -53,6 +55,7 @@
[aCoder decodeObjectAt:&_right withName:NULL]; [aCoder decodeObjectAt:&_right withName:NULL];
[aCoder decodeObjectAt:&_left withName:NULL]; [aCoder decodeObjectAt:&_left withName:NULL];
[aCoder decodeObjectAt:&_parent withName:NULL]; [aCoder decodeObjectAt:&_parent withName:NULL];
[aCoder decodeObjectAt:&_binary_tree withName:NULL];
return self; return self;
} }
@ -71,22 +74,29 @@
return _parent; return _parent;
} }
- setLeftNode: aNode - (void) setLeftNode: aNode
{ {
_left = aNode; _left = aNode;
return self;
} }
- setRightNode: aNode - (void) setRightNode: aNode
{ {
_right = aNode; _right = aNode;
return self;
} }
- setParentNode: aNode - (void) setParentNode: aNode
{ {
_parent = aNode; _parent = aNode;
return self; }
- binaryTree
{
return _binary_tree;
}
- (void) setBinaryTree: anObject
{
_binary_tree = anObject;
} }
@end @end

View file

@ -1,8 +1,8 @@
/* Implementation for Objective-C CircularArray collection object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -27,17 +27,10 @@
@implementation CircularArray @implementation CircularArray
+ (void) initialize
{
if (self == [CircularArray class])
[self setVersion:0]; /* beta release */
}
/* This is the designated initializer of this class */ /* This is the designated initializer of this class */
- initWithType: (const char *)contentEncoding - initWithCapacity: (unsigned)aCapacity
capacity: (unsigned)aCapacity
{ {
[super initWithType:contentEncoding capacity:aCapacity]; [super initWithCapacity:aCapacity];
_start_index = 0; _start_index = 0;
return self; return self;
} }
@ -51,13 +44,6 @@
return self; return self;
} }
- _readInit: (TypedStream*)aStream
{
[super _readInit: aStream];
_start_index = 0;
return self;
}
/* Empty copy must empty an allocCopy'ed version of self */ /* Empty copy must empty an allocCopy'ed version of self */
- emptyCopy - emptyCopy
@ -67,24 +53,23 @@
return copy; return copy;
} }
- _empty - (void) _collectionEmpty
{ {
[super _empty]; [super _collectionEmpty];
_start_index = 0; _start_index = 0;
return self;
} }
/* This is the only method that changes the value of the instance /* 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; int i;
if (newCapacity > _count) { if (newCapacity > _count) {
/* This could be more efficient */ /* This could be more efficient */
OBJC_MALLOC(new_contents, elt, newCapacity); OBJC_MALLOC(new_contents, id, newCapacity);
for (i = 0; i < _count; i++) for (i = 0; i < _count; i++)
new_contents[i] = _contents_array[CIRCULAR_TO_BASIC(i)]; new_contents[i] = _contents_array[CIRCULAR_TO_BASIC(i)];
OBJC_FREE(_contents_array); OBJC_FREE(_contents_array);
@ -92,95 +77,83 @@
_start_index = 0; _start_index = 0;
_capacity = newCapacity; _capacity = newCapacity;
} }
return self;
} }
- (elt) removeElementAtIndex: (unsigned)index - (void) removeObjectAtIndex: (unsigned)index
{ {
unsigned basicIndex; unsigned basicIndex;
elt ret;
CHECK_INDEX_RANGE_ERROR(index, _count); CHECK_INDEX_RANGE_ERROR(index, _count);
basicIndex = CIRCULAR_TO_BASIC(index); basicIndex = CIRCULAR_TO_BASIC(index);
ret = _contents_array[basicIndex]; [_contents_array[basicIndex] release];
circularFillHoleAt(self, basicIndex); circularFillHoleAt(self, basicIndex);
decrementCount(self); decrementCount(self);
return AUTORELEASE_ELT(ret);
} }
- (elt) removeFirstElement - (void) removeFirstObject
{ {
elt ret; if (!_count)
return;
ret = _contents_array[_start_index]; [_contents_array[_start_index] release];
_start_index = (_start_index + 1) % _capacity; _start_index = (_start_index + 1) % _capacity;
decrementCount(self); decrementCount(self);
return AUTORELEASE_ELT(ret);
} }
- (elt) removeLastElement - (void) removeLastObject
{ {
elt ret;
if (!_count) if (!_count)
NO_ELEMENT_FOUND_ERROR(); return;
ret = _contents_array[CIRCULAR_TO_BASIC(_count-1)]; [_contents_array[CIRCULAR_TO_BASIC(_count-1)] release];
decrementCount(self); decrementCount(self);
return AUTORELEASE_ELT(ret);
} }
- (elt) elementAtIndex: (unsigned)index - objectAtIndex: (unsigned)index
{ {
CHECK_INDEX_RANGE_ERROR(index, _count); CHECK_INDEX_RANGE_ERROR(index, _count);
return _contents_array[CIRCULAR_TO_BASIC(index)]; return _contents_array[CIRCULAR_TO_BASIC(index)];
} }
- appendElement: (elt)newElement - (void) appendObject: newObject
{ {
incrementCount(self); incrementCount(self);
RETAIN_ELT(newElement); [newObject retain];
_contents_array[CIRCULAR_TO_BASIC(_count-1)] = newElement; _contents_array[CIRCULAR_TO_BASIC(_count-1)] = newObject;
return self;
} }
- prependElement: (elt)newElement - (void) prependElement: newObject
{ {
incrementCount(self); incrementCount(self);
RETAIN_ELT(newElement); [newObject retain];
_start_index = (_capacity + _start_index - 1) % _capacity; _start_index = (_capacity + _start_index - 1) % _capacity;
_contents_array[_start_index] = newElement; _contents_array[_start_index] = newObject;
return self;
} }
- insertElement: (elt)newElement atIndex: (unsigned)index - (void) insertElement: newObject atIndex: (unsigned)index
{ {
unsigned basicIndex; unsigned basicIndex;
CHECK_INDEX_RANGE_ERROR(index, _count+1); CHECK_INDEX_RANGE_ERROR(index, _count+1);
incrementCount(self); incrementCount(self);
RETAIN_ELT(newElement); [newObject retain];
basicIndex = CIRCULAR_TO_BASIC(index); basicIndex = CIRCULAR_TO_BASIC(index);
circularMakeHoleAt(self, basicIndex); circularMakeHoleAt(self, basicIndex);
_contents_array[basicIndex] = newElement; _contents_array[basicIndex] = newObject;
return self;
} }
- (elt) replaceElementAtIndex: (unsigned)index with: (elt)newElement - (void) replaceObjectAtIndex: (unsigned)index withObject: newObject
{ {
elt ret;
unsigned basicIndex; unsigned basicIndex;
CHECK_INDEX_RANGE_ERROR(index, _count); CHECK_INDEX_RANGE_ERROR(index, _count);
RETAIN_ELT(newElement); [newObject retain];
basicIndex = CIRCULAR_TO_BASIC(index); basicIndex = CIRCULAR_TO_BASIC(index);
ret = _contents_array[basicIndex]; [_contents_array[basicIndex] release];
_contents_array[basicIndex] = newElement; _contents_array[basicIndex] = newObject;
return AUTORELEASE_ELT(ret);
} }
- 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(index1, _count);
CHECK_INDEX_RANGE_ERROR(index2, _count); CHECK_INDEX_RANGE_ERROR(index2, _count);
@ -189,10 +162,10 @@
tmp = _contents_array[index1]; tmp = _contents_array[index1];
_contents_array[index1] = _contents_array[index2]; _contents_array[index1] = _contents_array[index2];
_contents_array[index2] = tmp; _contents_array[index2] = tmp;
return self;
} }
/* just temporary for debugging #if 0
/* just temporary for debugging */
- circularArrayPrintForDebugger - circularArrayPrintForDebugger
{ {
int i; int i;
@ -217,7 +190,7 @@
return self; return self;
} }
*/ #endif
@end @end

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
/* Implementation for Objective-C LinkedList collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -27,21 +27,22 @@
@implementation LinkedList @implementation LinkedList
+ (void) initialize
{
if (self == [LinkedList class])
[self setVersion:0]; /* beta release */
}
/* This is the designated initializer of this class */ /* This is the designated initializer of this class */
- init - init
{ {
[super initWithType:@encode(id)];
_count = 0; _count = 0;
_first_link = nil; _first_link = nil;
_last_link = nil;
return self; return self;
} }
- initWithObjects: (id*)objs count: (unsigned)c
{
[self init];
while (c--)
[self prependObject: objs[c]];
}
/* Archiving must mimic the above designated initializer */ /* Archiving must mimic the above designated initializer */
- _initCollectionWithCoder: aCoder - _initCollectionWithCoder: aCoder
@ -49,10 +50,11 @@
[super _initCollectionWithCoder:aCoder]; [super _initCollectionWithCoder:aCoder];
_count = 0; _count = 0;
_first_link = nil; _first_link = nil;
_last_link = nil;
return self; return self;
} }
- (void) _encodeContentsWithCoder: aCoder - (void) _encodeContentsWithCoder: (id <Encoding>)aCoder
{ {
[aCoder startEncodingInterconnectedObjects]; [aCoder startEncodingInterconnectedObjects];
[super _encodeContentsWithCoder:aCoder]; [super _encodeContentsWithCoder:aCoder];
@ -63,257 +65,302 @@
We shouldn't do an -addElement. finishEncodingInterconnectedObjects We shouldn't do an -addElement. finishEncodingInterconnectedObjects
should take care of all that. */ should take care of all that. */
- (void) _decodeContentsWithCoder: (Coder*)aCoder - (void) _decodeContentsWithCoder: (id <Decoding>)aCoder
{ {
[aCoder startDecodingInterconnectedObjects]; [aCoder startDecodingInterconnectedObjects];
[super _decodeContentsWithCoder:aCoder]; [super _decodeContentsWithCoder:aCoder];
[aCoder finishDecodingInterconnectedObjects]; [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 */ /* Empty copy must empty an allocCopy'ed version of self */
- emptyCopy - emptyCopy
{ {
LinkedList *copy = [super emptyCopy]; LinkedList *copy = [super emptyCopy];
copy->_count = 0;
copy->_first_link = nil; copy->_first_link = nil;
copy->_last_link = nil;
copy->_count = 0;
return copy; return copy;
} }
/* This must work without sending any messages to content objects */ /* This must work without sending any messages to content objects */
- _empty - (void) _empty
{ {
_count = 0; _count = 0;
_first_link = nil; _first_link = nil;
return self; _last_link = nil;
}
/* 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;
} }
/* These next four methods are the only ones that change the values of /* These next four methods are the only ones that change the values of
the instance variables _count, _first_link, except for 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) if (_count > 1)
_first_link = [oldElement.id_u nextLink]; _first_link = [oldObject nextLink];
else else
_first_link = nil; _first_link = nil;
} }
[[oldElement.id_u nextLink] setPrevLink:[oldElement.id_u prevLink]]; else
[[oldElement.id_u prevLink] setNextLink:[oldElement.id_u nextLink]]; [[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--; _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) if (_count == 0)
{ {
/* link to self */ _first_link = newObject;
_first_link = newElement.id_u; _last_link = newObject;
[newElement.id_u setNextLink:newElement.id_u]; [newObject setNextLink: NO_OBJECT];
[newElement.id_u setPrevLink:newElement.id_u]; [newObject setPrevLink: NO_OBJECT];
} }
else else
{ {
[newElement.id_u setNextLink:[oldElement.id_u nextLink]]; if (oldObject == _last_link)
[newElement.id_u setPrevLink:oldElement.id_u]; _last_link = newObject;
[[oldElement.id_u nextLink] setPrevLink:newElement.id_u]; [newObject setNextLink: [oldObject nextLink]];
[oldElement.id_u setNextLink:newElement.id_u]; [newObject setPrevLink: oldObject];
[[oldObject nextLink] setPrevLink: newObject];
[oldObject setNextLink: newObject];
} }
_count++; _count++;
return self;
} }
- insertElement: (elt)newElement before: (elt)oldElement - (void) insertObject: newObject before: oldObject
{ {
if (oldElement.id_u == _first_link) /* Make sure we actually own the oldObject. */
_first_link = newElement.id_u; 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) if (_count == 0)
{ {
/* Link to self */ _first_link = newObject;
[newElement.id_u setNextLink:newElement.id_u]; _last_link = newObject;
[newElement.id_u setPrevLink:newElement.id_u]; [newObject setNextLink: NO_OBJECT];
[newObject setPrevLink: NO_OBJECT];
} }
else else
{ {
[newElement.id_u setPrevLink:[oldElement.id_u prevLink]]; if (oldObject == _first_link)
[newElement.id_u setNextLink:oldElement.id_u]; _first_link = newObject;
[[oldElement.id_u prevLink] setNextLink:newElement.id_u]; [newObject setPrevLink: [oldObject prevLink]];
[oldElement.id_u setPrevLink:newElement.id_u]; [newObject setNextLink: oldObject];
[[oldObject prevLink] setNextLink: newObject];
[oldObject setPrevLink: newObject];
} }
_count++; _count++;
RETAIN_ELT(newElement);
return self;
} }
- (elt) replaceElement: (elt)oldElement with: (elt)newElement - (void) replaceObject: oldObject with: newObject
{ {
RETAIN_ELT(newElement); /* Make sure we actually own the oldObject. */
if (oldElement.id_u == _first_link) assert ([oldObject linkedList] == self);
_first_link = newElement.id_u;
[newElement.id_u setNextLink:[oldElement.id_u nextLink]]; /* Make sure no one else already owns the newObject. */
[newElement.id_u setPrevLink:[oldElement.id_u prevLink]]; assert ([newObject linkedList] == NO_OBJECT);
[[oldElement.id_u prevLink] setNextLink:newElement.id_u];
[[oldElement.id_u nextLink] setPrevLink:newElement.id_u]; /* Claim ownership of the newObject. */
return AUTORELEASE_ELT(oldElement); [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. */ /* End of methods that change the instance variables. */
- (void) appendObject: newObject
- appendElement: (elt)newElement
{ {
if (_count) /* Make sure no one else already owns the newObject. */
[self insertElement:newElement after:[self lastElement]]; 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 else
[self insertElement:newElement after:nil]; [self insertObject: newObject after: _last_link];
return self;
} }
- prependElement: (elt)newElement - prependElement: newObject
{ {
[self insertElement:newElement before:_first_link]; /* Make sure no one else already owns the newObject. */
return self; 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)); 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 else
[self insertElement:newElement before:[self elementAtIndex:index]]; [self insertObject:newObject before: [self objectAtIndex: index]];
return self; return self;
} }
- (elt) removeElementAtIndex: (unsigned)index - (void) removeObjectAtIndex: (unsigned)index
{ {
CHECK_INDEX_RANGE_ERROR(index, _count); 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); CHECK_INDEX_RANGE_ERROR(index, _count);
if (index < _count / 2) if (index < _count / 2)
for (aLink = _first_link; for (link = _first_link;
index; index;
aLink = [aLink nextLink], index--) link = [link nextLink], index--)
; ;
else else
for (aLink = [_first_link prevLink], index = _count - index - 1; for (link = _last_link, index = _count - index - 1;
index; index;
aLink = [aLink prevLink], index--) link = [link prevLink], index--)
; ;
return aLink; return link;
} }
- (elt) firstElement - firstObject
{ {
return _first_link; return _first_link;
} }
- (elt) lastElement - lastObject
{ {
if (_count) return _last_link;
return [_first_link prevLink];
else
return NO_ELEMENT_FOUND_ERROR();
} }
- (elt) successorOfElement: (elt)oldElement - successorOfObject: oldObject
{ {
id nextElement = [oldElement.id_u nextLink]; /* Make sure we actually own the oldObject. */
if (_first_link == nextElement) assert ([oldObject linkedList] == self);
return nil;
else return [oldObject nextLink];
return (elt)nextElement;
} }
- (elt) predecessorOfElement: (elt)oldElement - predecessorOfObject: oldObject
{ {
if (_first_link == oldElement.id_u) /* Make sure we actually own the oldObject. */
return nil; assert ([oldObject linkedList] == self);
else
return (elt)[oldElement.id_u prevLink]; 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) if (*enumState == _first_link)
return NO; return NO_OBJECT;
else if (!(*enumState)) else if (!(*enumState))
*enumState = _first_link; *enumState = _first_link;
*anElementPtr = *enumState; ret = (id) *enumState;
*enumState = [(id)(*enumState) nextLink]; *enumState = [(id)(*enumState) nextLink];
return YES; return ret;
} }
- (BOOL) getPrevElement:(elt *)anElementPtr withEnumState: (void**)enumState - prevObjectWithEnumState: (void**)enumState
{ {
if (*enumState == _first_link) id ret;
return NO;
if (!(*enumState)) if (*enumState == _last_link)
*enumState = _first_link; return NO_OBJECT;
else if (!(*enumState))
*enumState = _last_link;
ret = (id) *enumState;
*enumState = [(id)(*enumState) prevLink]; *enumState = [(id)(*enumState) prevLink];
*anElementPtr = *enumState; return ret;
return YES;
} }
- 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 - (unsigned) count
{ {
return _count; return _count;

View file

@ -1,8 +1,8 @@
/* Implementation for Objective-C LinkedListNode object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -44,6 +44,7 @@
[super encodeWithCoder:aCoder]; [super encodeWithCoder:aCoder];
[aCoder encodeObjectReference:_next withName:@"Next LinkedList Node"]; [aCoder encodeObjectReference:_next withName:@"Next LinkedList Node"];
[aCoder encodeObjectReference:_prev withName:@"Prev LinkedList Node"]; [aCoder encodeObjectReference:_prev withName:@"Prev LinkedList Node"];
[aCoder encodeObjectReference:_linked_list withName:@"LinkedList"];
} }
- initWithCoder: aCoder - initWithCoder: aCoder
@ -51,6 +52,7 @@
[super initWithCoder:aCoder]; [super initWithCoder:aCoder];
[aCoder decodeObjectAt:&_next withName:NULL]; [aCoder decodeObjectAt:&_next withName:NULL];
[aCoder decodeObjectAt:&_prev withName:NULL]; [aCoder decodeObjectAt:&_prev withName:NULL];
[aCoder decodeObjectAt:&_linked_list withName:NULL];
return self; return self;
} }
@ -64,17 +66,24 @@
return _prev; return _prev;
} }
- setNextLink: (id <LinkedListComprising>)aLink - (void) setNextLink: (id <LinkedListComprising>)aLink
{ {
_next = aLink; _next = aLink;
return self;
} }
- setPrevLink: (id <LinkedListComprising>)aLink - (void) setPrevLink: (id <LinkedListComprising>)aLink
{ {
_prev = aLink; _prev = aLink;
return self; }
- linkedList
{
return _linked_list;
}
- (void) setLinkedList: anObject;
{
_linked_list = anObject;
} }
@end @end

View file

@ -1,8 +1,8 @@
/* Implementation for Objective-C MappedCollector collection object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -28,13 +28,9 @@
@implementation MappedCollector @implementation MappedCollector
/* This is the designated initializer for this class */ /* This is the designated initializer for this class */
- initCollection: (id <KeyedCollecting>)aDomain - initWithCollection: (id <KeyedCollecting>)aDomain
map: (id <KeyedCollecting>)aMap 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; _map = aMap;
_domain = aDomain; _domain = aDomain;
return self; return self;
@ -53,20 +49,10 @@
return self; return self;
} }
- _writeInit: (TypedStream*)aStream /* Override our superclass' designated initializer */
- initWithObjects: (id*)objects forKeys: (id*)keys count: (unsigned)c
{ {
[super _writeInit: aStream]; [self notImplemented: _cmd];
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;
} }
/* Empty copy must empty an allocCopy'ed version of self */ /* Empty copy must empty an allocCopy'ed version of self */
@ -79,83 +65,56 @@
} }
/* This must work without sending any messages to content objects */ /* This must work without sending any messages to content objects */
- empty - (void) empty
{ {
[_domain empty]; [_domain empty];
}
- objectAtKey: aKey
{
return [_domain objectAtKey: [_map objectAtKey: aKey]];
}
- keyOfObject: aContentObject
{
[self notImplemented: _cmd];
return self; 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] id mapContent;
with:newElement]; id domainKey;
}
- putElement: (elt)newElement atKey: (elt)aKey while ((mapContent = [_map nextObjectAndKey:keyPtr withEnumState:enumState])
{
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])
&& &&
(![_domain includesKey:(domainKey = [_map elementAtKey:*aKeyPtr])])) (![_domain containsKey: (domainKey = [_map objectAtKey:*keyPtr])]))
; ;
if (!ret) if (mapContent == NO_OBJECT)
return NO; return NO_OBJECT;
*anElementPtr = [_domain elementAtKey:domainKey]; return [_domain objectAtKey: domainKey];
return YES;
} }
- species - species

View file

@ -1,8 +1,8 @@
/* Implementation for Objective-C Queue object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -26,40 +26,22 @@
@implementation Queue @implementation Queue
+ (void) initialize - (void) enqueueObject: newObject
{ {
if (self == [Queue class]) [self prependObject: newObject];
[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];
} }
- dequeueObject - dequeueObject
{ {
return [self dequeueElement].id_u; id ret = [[self lastObject] retain];
[self removeLastObject];
return [ret autorelease];
}
/* Overriding */
- (void) addObject: newObject
{
[self enqueueObject: newObject];
} }
@end @end

View file

@ -1,5 +1,5 @@
/* Implementation for Objective-C Red-Black Tree collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -37,7 +37,6 @@ static id nilRBNode;
{ {
if (self == [RBTree class]) if (self == [RBTree class])
{ {
[self setVersion:0]; /* beta release */
nilRBNode = [[RBTreeNode alloc] init]; nilRBNode = [[RBTreeNode alloc] init];
[nilRBNode setBlack]; [nilRBNode setBlack];
} }
@ -48,68 +47,67 @@ static id nilRBNode;
return nilRBNode; return nilRBNode;
} }
- sortAddElement: (elt)newElement byCalling: (int(*)(elt,elt))aFunc - (void) sortAddObject: newObject
{ {
id y; id y;
[super sortAddElement:newElement byCalling:aFunc]; [super sortAddObject: newObject];
[newElement.id_u setRed]; [newObject setRed];
while (newElement.id_u != _contents_root while (newObject != _contents_root
&& [[newElement.id_u parentNode] isRed]) && [[newObject parentNode] isRed])
{ {
if ([newElement.id_u parentNode] == if ([newObject parentNode] ==
[[[newElement.id_u parentNode] parentNode] leftNode]) [[[newObject parentNode] parentNode] leftNode])
{ {
y = [[[newElement.id_u parentNode] parentNode] leftNode]; y = [[[newObject parentNode] parentNode] leftNode];
if ([y isRed]) if ([y isRed])
{ {
[[newElement.id_u parentNode] setBlack]; [[newObject parentNode] setBlack];
[y setBlack]; [y setBlack];
[[[newElement.id_u parentNode] parentNode] setRed]; [[[newObject parentNode] parentNode] setRed];
newElement.id_u = [[newElement.id_u parentNode] parentNode]; newObject = [[newObject parentNode] parentNode];
} }
else else
{ {
if (newElement.id_u == [[newElement.id_u parentNode] rightNode]) if (newObject == [[newObject parentNode] rightNode])
{ {
newElement.id_u = [newElement.id_u parentNode]; newObject = [newObject parentNode];
[self leftRotateAroundNode:newElement.id_u]; [self leftRotateAroundNode:newObject];
} }
[[newElement.id_u parentNode] setBlack]; [[newObject parentNode] setBlack];
[[[newElement.id_u parentNode] parentNode] setRed]; [[[newObject parentNode] parentNode] setRed];
[self rightRotateAroundNode: [self rightRotateAroundNode:
[[newElement.id_u parentNode] parentNode]]; [[newObject parentNode] parentNode]];
} }
} }
else else
{ {
y = [[[newElement.id_u parentNode] parentNode] rightNode]; y = [[[newObject parentNode] parentNode] rightNode];
if ([y isRed]) if ([y isRed])
{ {
[[newElement.id_u parentNode] setBlack]; [[newObject parentNode] setBlack];
[y setBlack]; [y setBlack];
[[[newElement.id_u parentNode] parentNode] setRed]; [[[newObject parentNode] parentNode] setRed];
newElement.id_u = [[newElement.id_u parentNode] parentNode]; newObject = [[newObject parentNode] parentNode];
} }
else else
{ {
if (newElement.id_u == [[newElement.id_u parentNode] leftNode]) if (newObject == [[newObject parentNode] leftNode])
{ {
newElement.id_u = [newElement.id_u parentNode]; newObject = [newObject parentNode];
[self rightRotateAroundNode:newElement.id_u]; [self rightRotateAroundNode:newObject];
} }
[[newElement.id_u parentNode] setBlack]; [[newObject parentNode] setBlack];
[[[newElement.id_u parentNode] parentNode] setRed]; [[[newObject parentNode] parentNode] setRed];
[self leftRotateAroundNode: [self leftRotateAroundNode:
[[newElement.id_u parentNode] parentNode]]; [[newObject parentNode] parentNode]];
} }
} }
} }
[_contents_root setBlack]; [_contents_root setBlack];
return self;
} }
- _RBTreeDeleteFixup: x - (void) _RBTreeDeleteFixup: x
{ {
id w; id w;
@ -185,18 +183,17 @@ static id nilRBNode;
} }
} }
[x setBlack]; [x setBlack];
return self;
} }
- (elt) removeElement: (elt)oldElement - (void) removeObject: oldObject
{ {
id x, y; id x, y;
if ([oldElement.id_u leftNode] == [self nilNode] if ([oldObject leftNode] == [self nilNode]
|| [oldElement.id_u rightNode] == [self nilNode]) || [oldObject rightNode] == [self nilNode])
y = oldElement.id_u; y = oldObject;
else else
y = [self successorOfElement:oldElement].id_u; y = [self successorOfObject: oldObject];
if ([y leftNode] != [self nilNode]) if ([y leftNode] != [self nilNode])
x = [y leftNode]; x = [y leftNode];
@ -215,63 +212,38 @@ static id nilRBNode;
[[y parentNode] setRightNode:x]; [[y parentNode] setRightNode:x];
} }
if (y != oldElement.id_u) if (y != oldObject)
{ {
/* put y in the place of oldElement.id_u */ /* put y in the place of oldObject */
[y setParentNode:[oldElement.id_u parentNode]]; [y setParentNode:[oldObject parentNode]];
[y setLeftNode:[oldElement.id_u leftNode]]; [y setLeftNode:[oldObject leftNode]];
[y setRightNode:[oldElement.id_u rightNode]]; [y setRightNode:[oldObject rightNode]];
if (oldElement.id_u == [[oldElement.id_u parentNode] leftNode]) if (oldObject == [[oldObject parentNode] leftNode])
[[oldElement.id_u parentNode] setLeftNode:y]; [[oldObject parentNode] setLeftNode:y];
else else
[[oldElement.id_u parentNode] setRightNode:oldElement.id_u]; [[oldObject parentNode] setRightNode:oldObject];
[[oldElement.id_u leftNode] setParentNode:y]; [[oldObject leftNode] setParentNode:y];
[[oldElement.id_u rightNode] setParentNode:y]; [[oldObject rightNode] setParentNode:y];
} }
if (NODE_IS_BLACK(y)) if (NODE_IS_BLACK(y))
[self _RBTreeDeleteFixup:x]; [self _RBTreeDeleteFixup:x];
[oldElement.id_u setRightNode:[self nilNode]];
[oldElement.id_u setLeftNode:[self nilNode]];
[oldElement.id_u setParentNode:[self nilNode]];
_count--; _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 @end

View file

@ -24,17 +24,12 @@
#include <objects/Set.h> #include <objects/Set.h>
#include <objects/CollectionPrivate.h> #include <objects/CollectionPrivate.h>
#include <objects/Coder.h> #include <objects/Coder.h>
#include <Foundation/NSHashTable.h>
#define DEFAULT_SET_CAPACITY 32 #define DEFAULT_SET_CAPACITY 32
@implementation Set @implementation Set
+ (void) initialize
{
if (self == [Set class])
[self setVersion:0]; /* beta release */
}
// MANAGING CAPACITY; // MANAGING CAPACITY;
/* Eventually we will want to have better capacity management, /* Eventually we will want to have better capacity management,
@ -48,75 +43,28 @@
// INITIALIZING AND FREEING; // INITIALIZING AND FREEING;
/* This is the designated initializer of this class */ /* This is the designated initializer of this class */
- initWithType:(const char *)encoding - initWithCapacity: (unsigned)cap
capacity: (unsigned)aCapacity
{ {
[super initWithType:encoding]; _contents_hash = NSCreateHashTable(NSObjectsHashCallBacks, cap);
_contents_hash = return self;
coll_hash_new(POWER_OF_TWO(aCapacity), }
elt_get_hash_function(encoding),
elt_get_comparison_function(encoding)); /* Override Collection's designated initializer */
- initWithObjects: (id*)objs count: (unsigned)count
{
[self initWithCapacity: count];
while (count--)
[self addObject: objs[count]];
return self; return self;
} }
/* Archiving must mimic the above designated initializer */ /* 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 - _initCollectionWithCoder: aCoder
{ {
char *encoding;
unsigned size;
[super _initCollectionWithCoder:aCoder]; [super _initCollectionWithCoder:aCoder];
[aCoder decodeValueOfCType:@encode(char*) _contents_hash = NSCreateHashTable(NSObjectsHashCallBacks,
at:&encoding DEFAULT_SET_CAPACITY);
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));
return self; return self;
} }
@ -125,52 +73,38 @@
{ {
Set *copy = [super emptyCopy]; Set *copy = [super emptyCopy];
copy->_contents_hash = copy->_contents_hash =
coll_hash_new(_contents_hash->size, NSCreateHashTable (NSObjectsHashCallBacks, 0);
_contents_hash->hash_func,
_contents_hash->compare_func);
return copy; return copy;
} }
/* Override designated initializer of superclass */ - (void) dealloc
- initWithType:(const char *)contentEncoding
{ {
return [self initWithType:contentEncoding NSFreeHashTable (_contents_hash);
capacity:[[self class] defaultCapacity]];
}
- initWithCapacity: (unsigned)aCapacity
{
return [self initWithType:@encode(id) capacity:aCapacity];
}
- (void) _collectionDealloc
{
coll_hash_delete(_contents_hash);
[super _collectionDealloc]; [super _collectionDealloc];
} }
// SET OPERATIONS; // SET OPERATIONS;
- intersectWithCollection: (id <Collecting>)aCollection - (void) intersectWithCollection: (id <Collecting>)aCollection
{ {
[self removeContentsNotIn: aCollection]; [self removeContentsNotIn: aCollection];
return self;
} }
- unionWithCollection: (id <Collecting>)aCollection - (void) unionWithCollection: (id <Collecting>)aCollection
{ {
[self addContentsOfIfAbsent:aCollection]; [self addContentsIfAbsentOf: aCollection];
return self;
} }
- differenceWithCollection: (id <Collecting>)aCollection - (void) differenceWithCollection: (id <Collecting>)aCollection
{ {
[self removeContentsIn: aCollection]; [self removeContentsIn: aCollection];
return self;
} }
- shallowCopyIntersectWithCollection: (id <Collecting>)aCollection - shallowCopyIntersectWithCollection: (id <Collecting>)aCollection
{ {
[self notImplemented: _cmd];
return nil;
#if 0
id newColl = [self emptyCopyAs:[self species]]; id newColl = [self emptyCopyAs:[self species]];
void doIt(elt e) void doIt(elt e)
{ {
@ -179,18 +113,25 @@
} }
[self withElementsCall:doIt]; [self withElementsCall:doIt];
return newColl; return newColl;
#endif
} }
- shallowCopyUnionWithCollection: (id <Collecting>)aCollection - shallowCopyUnionWithCollection: (id <Collecting>)aCollection
{ {
[self notImplemented: _cmd];
return nil;
#if 0
id newColl = [self shallowCopy]; id newColl = [self shallowCopy];
[newColl addContentsOf:aCollection]; [newColl addContentsOf:aCollection];
return newColl; return newColl;
#endif
} }
- shallowCopyDifferenceWithCollection: (id <Collecting>)aCollection - shallowCopyDifferenceWithCollection: (id <Collecting>)aCollection
{ {
[self notImplemented: _cmd];
return nil;
#if 0
id newColl = [self emptyCopyAs:[self species]]; id newColl = [self emptyCopyAs:[self species]];
void doIt(elt e) void doIt(elt e)
{ {
@ -199,128 +140,78 @@
} }
[self withElementsCall:doIt]; [self withElementsCall:doIt];
return newColl; return newColl;
#endif
} }
// ADDING; // ADDING;
- addElement: (elt)anElement - (void) addObject: newObject
{ {
if (coll_hash_value_for_key(_contents_hash, anElement).void_ptr_u == 0) NSHashInsert (_contents_hash, newObject);
coll_hash_add(&_contents_hash, anElement, 1);
RETAIN_ELT(anElement);
return self;
} }
// REMOVING AND REPLACING; // 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) NSHashRemove (_contents_hash, oldObject);
coll_hash_remove(_contents_hash, oldElement);
else
RETURN_BY_CALLING_EXCEPTION_FUNCTION(excFunc);
return AUTORELEASE_ELT(oldElement);
} }
/* This must work without sending any messages to content objects */ /* This must work without sending any messages to content objects */
- _empty - (void) _collectionEmpty
{ {
coll_hash_empty(_contents_hash); NSResetHashTable (_contents_hash);
return self;
} }
- uniqueContents - (void) uniqueContents
{ {
return self; return;
} }
// TESTING; // TESTING;
- (int(*)(elt,elt)) comparisonFunction - (BOOL) containsObject: anObject
{ {
return _contents_hash->compare_func; return (NSHashGet (_contents_hash, anObject) ? 1 : 0);
}
- (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;
} }
- (unsigned) count - (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; return 1;
else else
return 0; return 0;
} }
// ENUMERATING; // ENUMERATING;
- (BOOL) getNextElement:(elt *)anElementPtr withEnumState: (void**)enumState - nextObjectWithEnumState: (void**)enumState
{ {
coll_node_ptr node = coll_hash_next(_contents_hash, enumState); return NSNextHashEnumeratorItem (((NSHashEnumerator*)enumState));
if (node)
{
*anElementPtr = node->key;
return YES;
}
return NO;
} }
- (void*) newEnumState - (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); 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 @end

View file

@ -1,5 +1,5 @@
/* Implementation for Objective-C SplayTree collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -26,14 +26,8 @@
@implementation SplayTree @implementation SplayTree
+ (void) initialize
{
if (self == [SplayTree class])
[self setVersion:0]; /* beta release */
}
/* Make this a function ? */ /* Make this a function ? */
- _doSplayOperationOnNode: aNode - (void) _doSplayOperationOnNode: aNode
{ {
id parent = [aNode parentNode]; id parent = [aNode parentNode];
id parentRightChild = id parentRightChild =
@ -41,7 +35,7 @@
if (aNode == _contents_root || aNode == [self nilNode]) if (aNode == _contents_root || aNode == [self nilNode])
{ {
return self; return;
} }
else if (aNode == parentRightChild) else if (aNode == parentRightChild)
{ {
@ -80,53 +74,28 @@
[self leftRotateAroundNode:[aNode parentNode]]; [self leftRotateAroundNode:[aNode parentNode]];
} }
} }
return self;
} }
- splayNode: aNode - (void) splayNode: aNode
{ {
while (aNode != _contents_root) while (aNode != _contents_root)
[self _doSplayOperationOnNode:aNode]; [self _doSplayOperationOnNode:aNode];
return self;
} }
/* We could make this a little more efficient by doing the splay as /* We could make this a little more efficient by doing the splay as
we search down the tree for the correct insertion point. */ 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]; [super sortAddObject: newObject];
[self splayNode:newElement.id_u]; [self splayNode: newObject];
return self;
} }
- insertElement: (elt)newElement before: (elt)oldElement - (void) removeObject: anObject
{ {
[super insertElement:newElement before:oldElement]; id parent = [anObject parentNode];
// ?? [self splayNode:newElement.id_u]; [super removeObject: anObject];
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];
if (parent && parent != [self nilNode]) if (parent && parent != [self nilNode])
[self splayNode:parent]; [self splayNode:parent];
return AUTORELEASE_ELT(anElement);
} }
@end @end

View file

@ -1,8 +1,8 @@
/* Implementation for Objective-C Stack object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -26,65 +26,40 @@
@implementation Stack @implementation Stack
+ (void) initialize - (void) pushObject: newObject
{ {
if (self == [Stack class]) [self appendObject: newObject];
[self setVersion:0]; /* beta release */
}
- pushElement: (elt)anElement
{
[self appendElement:anElement];
return self;
} }
/* Overriding */ /* Overriding */
- addElement: (elt)anElement - (void) addObject: newObject
{ {
[self pushElement:anElement]; [self pushObject: newObject];
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];
} }
- popObject - popObject
{ {
return [self popElement].id_u; id ret;
ret = [[self lastObject] retain];
[self removeLastObject];
return [ret autorelease];
} }
- topObject - 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 @end

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C Array collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -26,13 +26,19 @@
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/IndexedCollection.h> #include <objects/IndexedCollection.h>
#include <objects/OrderedCollecting.h>
@interface Array : IndexedCollection @interface ConstantArray : IndexedCollection
{ {
@public @public
int (*_comparison_function)(elt,elt); id *_contents_array;
elt *_contents_array;
unsigned int _count; unsigned int _count;
}
@end
@interface Array : ConstantArray
{
@public
unsigned int _capacity; unsigned int _capacity;
unsigned int _grow_factor; unsigned int _grow_factor;
} }
@ -40,16 +46,18 @@
+ (unsigned) defaultCapacity; + (unsigned) defaultCapacity;
+ (unsigned) defaultGrowFactor; + (unsigned) defaultGrowFactor;
- initWithType: (const char *)contentEncoding
capacity: (unsigned)aCapacity;
- initWithCapacity: (unsigned) aCapacity; - initWithCapacity: (unsigned) aCapacity;
- setCapacity: (unsigned)newCapacity; - (void) setCapacity: (unsigned)newCapacity;
- (unsigned) growFactor; - (unsigned) growFactor;
- setGrowFactor: (unsigned)aNum; - (void) setGrowFactor: (unsigned)aNum;
@end @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) \ #define FOR_ARRAY(ARRAY, ELEMENT_VAR) \
{ \ { \
unsigned _FOR_ARRAY_i; \ unsigned _FOR_ARRAY_i; \

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C Bag collection object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -25,39 +25,27 @@
#define __Bag_h_INCLUDE_GNU #define __Bag_h_INCLUDE_GNU
#include <objects/stdobjects.h> #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; unsigned int _count; // the number of elements;
} }
// INITIALIZING AND FREEING;
- initWithCapacity: (unsigned)aCapacity;
// ADDING; // ADDING;
- addObject: newObject withOccurrences: (unsigned)count; - (void) addObject: newObject withOccurrences: (unsigned)count;
// REMOVING AND REPLACING; // REMOVING AND REPLACING;
- removeObject: oldObject occurrences: (unsigned)count; - (void) removeObject: oldObject occurrences: (unsigned)count;
- removeObject: oldObject occurrences: (unsigned)count
ifAbsentCall: (id(*)(arglist_t))excFunc;
// TESTING; // TESTING;
- (unsigned) uniqueCount; - (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 @end
#endif /* __Bag_h_INCLUDE_GNU */ #endif /* __Bag_h_INCLUDE_GNU */

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C BinaryTree collection object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -35,13 +35,15 @@
/* The <BinaryTreeComprising> protocol defines the interface to an object /* The <BinaryTreeComprising> protocol defines the interface to an object
that may be an element in a BinaryTree. that may be an element in a BinaryTree.
*/ */
@protocol BinaryTreeComprising @protocol BinaryTreeComprising <NSObject>
- leftNode; - leftNode;
- rightNode; - rightNode;
- parentNode; - parentNode;
- setLeftNode: (id <BinaryTreeComprising>)aNode; - (void) setLeftNode: (id <BinaryTreeComprising>)aNode;
- setRightNode: (id <BinaryTreeComprising>)aNode; - (void) setRightNode: (id <BinaryTreeComprising>)aNode;
- setParentNode: (id <BinaryTreeComprising>)aNode; - (void) setParentNode: (id <BinaryTreeComprising>)aNode;
- binaryTree;
- (void) setBinaryTree: anObject;
@end @end
#define NODE_IS_RIGHTCHILD(NODE) (NODE == [[NODE parentNode] rightNode]) #define NODE_IS_RIGHTCHILD(NODE) (NODE == [[NODE parentNode] rightNode])

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C BinaryTreeNode object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -33,6 +33,7 @@
id _left; id _left;
id _right; id _right;
id _parent; id _parent;
id _binary_tree;
} }
@end @end

View file

@ -1,8 +1,8 @@
/* Protocol for Objective-C objects that hold collections of elements. /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -35,54 +35,61 @@
#define __Collecting_h_INCLUDE_GNU #define __Collecting_h_INCLUDE_GNU
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objc/Object.h> #include <objects/Coding.h>
#include <objects/elt.h> #include <objects/Invoking.h>
#include <objects/Enumerating.h>
@protocol ConstantCollecting @protocol ConstantCollecting
// INITIALIZING; // INITIALIZING;
- init; - init;
- initWithObjects: (id*)objc count: (unsigned)c;
- initWithObjects: firstObject, ...;
- initWithObjects: firstObject rest: (va_list)ap;
- initWithContentsOf: (id <ConstantCollecting>)aCollection; - initWithContentsOf: (id <ConstantCollecting>)aCollection;
// TESTING; // QUERYING COUNTS;
- (BOOL) isEmpty; - (BOOL) isEmpty;
- (BOOL) includesObject: anObject; - (unsigned) count;
- (BOOL) containsObject: anObject;
- (unsigned) occurrencesOfObject: anObject;
// COMPARISON WITH OTHER COLLECTIONS;
- (BOOL) isSubsetOf: (id <ConstantCollecting>)aCollection; - (BOOL) isSubsetOf: (id <ConstantCollecting>)aCollection;
- (BOOL) isDisjointFrom: (id <ConstantCollecting>)aCollection; - (BOOL) isDisjointFrom: (id <ConstantCollecting>)aCollection;
- (int) compare: anObject;
- (BOOL) isEqual: anObject; - (BOOL) isEqual: anObject;
- (int) compare: anObject;
- (BOOL) contentsEqual: (id <ConstantCollecting>)aCollection; - (BOOL) contentsEqual: (id <ConstantCollecting>)aCollection;
- (unsigned) count;
- (unsigned) occurrencesOfObject: anObject; // PROPERTIES OF CONTENTS;
- (BOOL) trueForAllObjectsByCalling: (BOOL(*)(id))aFunc; - (BOOL) trueForAllObjectsByInvoking: (id <Invoking>)anInvocation;
- (BOOL) trueForAnyObjectsByCalling: (BOOL(*)(id))aFunc; - (BOOL) trueForAnyObjectsByInvoking: (id <Invoking>)anInvocation;
- detectObjectByCalling: (BOOL(*)(id))aFunc; - detectObjectByInvoking: (id <Invoking>)anInvocation;
- detectObjectByCalling: (BOOL(*)(id))aFunc
ifNoneCall: (id(*)(arglist_t))excFunc;
- maxObject; - maxObject;
- maxObjectByCalling: (int(*)(id,id))aFunc;
- minObject; - minObject;
- minObjectByCalling: (int(*)(id,id))aFunc;
// ENUMERATING // ENUMERATING
- (void*) newEnumState; - (id <Enumerating>) objectEnumerator;
- (BOOL) getNextObject:(id *)anObjectPtr withEnumState: (void**)enumState; - (void) withObjectsInvoke: (id <Invoking>)anInvocation;
- freeEnumState: (void**)enumState; - (void) withObjectsInvoke: (id <Invoking>)anInvocation whileTrue:(BOOL *)flag;
- withObjectsCall: (void(*)(id))aFunc; - (void) makeObjectsPerform: (SEL)aSel;
- withObjectsCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag; - (void) makeObjectsPerform: (SEL)aSel withObject: argObject;
- injectObject: initialArgObject byCalling:(id(*)(id,id))aFunc;
- makeObjectsPerform: (SEL)aSel;
- makeObjectsPerform: (SEL)aSel with: argObject;
// FILTERED ENUMERATING; // FILTERED ENUMERATING;
- withObjectsTrueByCalling: (BOOL(*)(id))testFunc - (void) withObjectsTrueByInvoking: (id <Invoking>)testInvocation
call: (void(*)(id))destFunc; invoke: (id <Invoking>)anInvocation;
- withObjectsFalseByCalling: (BOOL(*)(id))testFunc - (void) withObjectsFalseByInvoking: (id <Invoking>)testInvocation
call: (void(*)(id))destFunc; invoke: (id <Invoking>)anInvocation;
- withObjectsTransformedByCalling: (id(*)(id))transFunc - (void) withObjectsTransformedByInvoking: (id <Invoking>)transInvocation
call: (void(*)(id))destFunc; invoke: (id <Invoking>)anInvocation;
// COPYING // LOW-LEVEL ENUMERATING;
- (void*) newEnumState;
- nextObjectWithEnumState: (void**)enumState;
- (void) freeEnumState: (void**)enumState;
// COPYING;
- allocCopy;
- emptyCopy; - emptyCopy;
- emptyCopyAs: (Class)aCollectionClass; - emptyCopyAs: (Class)aCollectionClass;
- shallowCopy; - shallowCopy;
@ -91,98 +98,34 @@
- copyAs: (Class)aCollectionClass; - copyAs: (Class)aCollectionClass;
- species; - 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 @end
@protocol Collecting <ConstantCollecting> @protocol Collecting <ConstantCollecting>
// ADDING; // ADDING;
- addObject: newObject; - (void) addObject: newObject;
- addObjectIfAbsent: newObject; - (void) addObjectIfAbsent: newObject;
- addContentsOf: (id <ConstantCollecting>)aCollection; - (void) addContentsOf: (id <ConstantCollecting>)aCollection;
- addContentsOfIfAbsent: (id <ConstantCollecting>)aCollection; - (void) addContentsIfAbsentOf: (id <ConstantCollecting>)aCollection;
- addObjectsCount: (unsigned)count, ...; - (void) addWithObjects: (id*)objc count: (unsigned)c;
- (void) addObjects: firstObject, ...;
- (void) addObjects: firstObject rest: (va_list)ap;
// REMOVING; // REMOVING;
- removeObject: oldObject; - (void) removeObject: oldObject;
- removeObject: oldObject ifAbsentCall: (id(*)(arglist_t))excFunc; - (void) removeAllOccurrencesOfObject: oldObject;
- removeAllOccurrencesOfObject: oldObject; - (void) removeContentsIn: (id <ConstantCollecting>)aCollection;
- removeContentsIn: (id <ConstantCollecting>)aCollection; - (void) removeContentsNotIn: (id <ConstantCollecting>)aCollection;
- removeContentsNotIn: (id <ConstantCollecting>)aCollection; - (void) uniqueContents;
- uniqueContents; - (void) empty;
- empty;
// REPLACING; // REPLACING;
- replaceObject: oldObject with: newObject; - (void) replaceObject: oldObject withObject: newObject;
- replaceObject: oldObject with: newObject - (void) replaceAllOccurrencesOfObject: oldObject withObject: 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;
@end @end
#define NO_OBJECT nil
#endif /* __Collecting_h_INCLUDE_GNU */ #endif /* __Collecting_h_INCLUDE_GNU */

View file

@ -32,29 +32,42 @@
#include <Foundation/NSObject.h> #include <Foundation/NSObject.h>
#include <objects/Collecting.h> #include <objects/Collecting.h>
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/collhash.h>
#include <objects/Coding.h> #include <objects/Coding.h>
@interface Collection : NSObject <Collecting> @interface ConstantCollection : NSObject <ConstantCollecting>
{ - printForDebugger; /* This method will disappear later. */
}
- (void) withObjectsInvoke: anInvocation;
- printElement: (elt)anElement;
- printForDebugger;
@end @end
// #warning fix this macro @interface Collection : ConstantCollection <Collecting>
#define FOR_COLL(ACOLL, ELT) \ @end
@interface Enumerator : NSObject <Enumerating>
{
id collection;
void *enum_state;
}
@end
#define FOR_COLLECTION(ACOLL, ELT) \
{ \ { \
void *_es = [ACOLL initEnumState]; \ void *_es = [ACOLL newEnumState]; \
while ([ACOLL getNextElement:&(ELT) withEnumState:&_es]) \ 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: /* The only subclassResponsibilities in Collection are:

View file

@ -1,8 +1,8 @@
/* Collection definitions for the use of subclass implementations only /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -25,28 +25,23 @@
#define __CollectionPrivate_h_INCLUDE_GNU #define __CollectionPrivate_h_INCLUDE_GNU
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/eltfuncs.h>
@interface Collection (ArchivingHelpers) @interface ConstantCollection (ArchivingHelpers)
/* These methods should never be called except in order inside /* These methods should never be called except in order, and inside
-write: and -read: */ -encodeWithCoder: and -decodeWithCoder: */
- _writeInit: (TypedStream*)aStream;
- _readInit: (TypedStream*)aStream;
- _writeContents: (TypedStream*)aStream;
- _readContents: (TypedStream*)aStream;
/* The Coding versions of the above */
- (void) _encodeCollectionWithCoder: (id <Encoding>)aCoder; - (void) _encodeCollectionWithCoder: (id <Encoding>)aCoder;
- _initCollectionWithCoder: (id <Decoding>)aCoder; - _initCollectionWithCoder: (id <Decoding>)aCoder;
- (void) _encodeContentsWithCoder: (id <Encoding>)aCoder; - (void) _encodeContentsWithCoder: (id <Encoding>)aCoder;
- (void) _decodeContentsWithCoder: (id <Decoding>)aCoder; - (void) _decodeContentsWithCoder: (id <Decoding>)aCoder;
@end @end
@interface Collection (DeallocationHelpers) @interface ConstantCollection (DeallocationHelpers)
/* Empty the internals of a collection after the contents have /* Empty the internals of a collection after the contents have
already been released. */ already been released. */
- _empty; - (void) _collectionEmpty;
- (void) _collectionReleaseContents;
/* Deallocate the internals of a collection after the contents /* Deallocate the internals of a collection after the contents
have already been released. */ have already been released. */
@ -54,63 +49,4 @@
@end @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 */ #endif /* __CollectionPrivate_h_INCLUDE_GNU */

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C Dictionary collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -26,18 +26,14 @@
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/KeyedCollection.h> #include <objects/KeyedCollection.h>
#include <Foundation/NSMapTable.h>
@interface Dictionary : KeyedCollection @interface Dictionary : KeyedCollection
{ {
coll_cache_ptr _contents_hash; // a hashtable to hold the contents; NSMapTable *_contents_hash;
int (*_comparison_function)(elt,elt);
} }
- initWithType: (const char *)contentEncoding - initWithCapacity: (unsigned)aCapacity;
keyType: (const char *)keyEncoding
capacity: (unsigned)aCapacity;
- initWithType: (const char *)contentEncoding
capacity: (unsigned)aCapacity;
@end @end

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C Heap collection object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -28,14 +28,9 @@
#include <objects/Array.h> #include <objects/Array.h>
@interface Heap : Array @interface Heap : Array
{
}
- addElement: (elt)anElement; - (void) heapifyFromIndex: (unsigned)index;
- (elt) removeFirstElement; - (void) heapify;
- heapifyFromIndex: (unsigned)index;
- heapify;
@end @end

View file

@ -1,5 +1,5 @@
/* Protocol for Objective-C objects that hold elements accessible by index /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -36,7 +36,7 @@
#define __IndexedCollecting_h_OBJECTS_INCLUDE #define __IndexedCollecting_h_OBJECTS_INCLUDE
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/KeyedCollecting.h> #include <objects/Collecting.h>
typedef struct _IndexRange { typedef struct _IndexRange {
unsigned location; unsigned location;
@ -47,8 +47,8 @@ typedef struct _IndexRange {
({IndexRange __a=(RANGE1), __b=(RANGE2); \ ({IndexRange __a=(RANGE1), __b=(RANGE2); \
__a.start<=__b.start && __a.end>=__b.end;}) __a.start<=__b.start && __a.end>=__b.end;})
@protocol ConstantIndexedCollecting <ConstantKeyedCollecting> @protocol ConstantIndexedCollecting <ConstantCollecting>
// GETTING MEMBERS BY INDEX; // GETTING MEMBERS BY INDEX;
- objectAtIndex: (unsigned)index; - objectAtIndex: (unsigned)index;
@ -61,115 +61,53 @@ typedef struct _IndexRange {
// GETTING INDICES BY MEMBER; // GETTING INDICES BY MEMBER;
- (unsigned) indexOfObject: anObject; - (unsigned) indexOfObject: anObject;
- (unsigned) indexOfObject: anObject
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
- (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange; - (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange;
- (unsigned) indexOfObject: anObject inRange: (IndexRange)aRange
ifAbsentCall: (unsigned(*)(arglist_t))excFunc;
// TESTING; // TESTING;
- (BOOL) includesIndex: (unsigned)index;
- (BOOL) contentsEqualInOrder: (id <ConstantIndexedCollecting>)aColl; - (BOOL) contentsEqualInOrder: (id <ConstantIndexedCollecting>)aColl;
- (int) compareInOrderContentsOf: (id <Collecting>)aCollection;
- (unsigned) indexOfFirstDifference: (id <ConstantIndexedCollecting>)aColl; - (unsigned) indexOfFirstDifference: (id <ConstantIndexedCollecting>)aColl;
- (unsigned) indexOfFirstIn: (id <ConstantCollecting>)aColl; - (unsigned) indexOfFirstIn: (id <ConstantCollecting>)aColl;
- (unsigned) indexOfFirstNotIn: (id <ConstantCollecting>)aColl; - (unsigned) indexOfFirstNotIn: (id <ConstantCollecting>)aColl;
// ENUMERATING; // ENUMERATING;
- (BOOL) getPrevObject: (id*)anIdPtr withEnumState: (void**)enumState; - (id <Enumerating>) reverseObjectEnumerator;
- withObjectsInRange: (IndexRange)aRange call:(void(*)(id))aFunc; - (void) withObjectsInRange: (IndexRange)aRange
- withObjectsInReverseCall: (void(*)(id))aFunc; invoke: (id <Invoking>)anInvocation;
- withObjectsInReverseCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag; - (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; // LOW-LEVEL ENUMERATING;
- prevObjectWithEnumState: (void**)enumState;
// 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;
@end @end
@protocol IndexedCollecting <ConstantIndexedCollecting, KeyedCollecting>
@protocol IndexedCollecting <ConstantIndexedCollecting, Collecting>
// ADDING; // REPLACING;
- insertObject: newObject atIndex: (unsigned)index; - (void) replaceObjectAtIndex: (unsigned)index with: newObject;
- 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 AND SWAPPING // REMOVING;
- replaceObjectAtIndex: (unsigned)index with: newObject; - (void) removeObjectAtIndex: (unsigned)index;
- replaceRange: (IndexRange)aRange with: (id <ConstantCollecting>)aCollection; - (void) removeFirstObject;
- replaceRange: (IndexRange)aRange using: (id <ConstantCollecting>)aCollection; - (void) removeLastObject;
- swapAtIndeces: (unsigned)index1 : (unsigned)index2; - (void) removeRange: (IndexRange)aRange;
// REMOVING
- removeObjectAtIndex: (unsigned)index;
- removeFirstObject;
- removeLastObject;
- removeRange: (IndexRange)aRange;
// ENUMERATING WHILE CHANGING CONTENTS;
- safeWithObjectsInReverseCall: (void(*)(id))aFunc;
- safeWithObjectsInReverseCall: (void(*)(id))aFunc whileTrue:(BOOL *)flag;
// SORTING; // SORTING;
- sortContents; - (void) sortContents;
- sortObjectsByCalling: (int(*)(id,id))aFunc; - (void) sortAddObject: newObject;
- 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;
@end @end
#include <limits.h>
#define NO_INDEX UINT_MAX
/* xxx Fix this comment: */
/* Most methods in the KeyedCollecting protocol that mention a key are /* Most methods in the KeyedCollecting protocol that mention a key are
duplicated in the IndexedCollecting protocol, with their names duplicated in the IndexedCollecting protocol, with their names
modified to reflect that the "key" now must be an unsigned integer, modified to reflect that the "key" now must be an unsigned integer,

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C Sequential Collection object. /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -28,12 +28,54 @@
#include <objects/KeyedCollection.h> #include <objects/KeyedCollection.h>
#include <objects/IndexedCollecting.h> #include <objects/IndexedCollecting.h>
@interface IndexedCollection : KeyedCollection @interface ConstantIndexedCollection : ConstantCollection
@end
@interface IndexedCollection : ConstantIndexedCollection
@end
@interface ReverseEnumerator : Enumerator
@end @end
/* Put this on category instead of class to avoid bogus complaint from gcc */ /* Put this on category instead of class to avoid bogus complaint from gcc */
@interface IndexedCollection (IndexedCollectionProtocol) <IndexedCollecting> @interface ConstantIndexedCollection (Protocol) <ConstantIndexedCollecting>
@end @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: /* The only subclassResponsibilities in IndexedCollection are:

View file

@ -1,5 +1,5 @@
/* Protocol for Objective-C objects holding (keyElement,contentElement) pairs. /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -38,84 +38,44 @@
@protocol ConstantKeyedCollecting <ConstantCollecting> @protocol ConstantKeyedCollecting <ConstantCollecting>
// INITIALIZING;
- initWithObjects: (id*)objects forKeys: (id*)keys count: (unsigned)c;
// GETTING ELEMENTS AND KEYS; // GETTING ELEMENTS AND KEYS;
- objectAtKey: (elt)aKey; - objectAtKey: aKey;
- keyObjectOfObject: aContentObject; - keyOfObject: aContentObject;
// TESTING; // TESTING;
- (BOOL) includesKey: (elt)aKey; - (BOOL) containsKey: aKey;
// ENUMERATIONS; // ENUMERATIONS;
- withKeyObjectsCall: (void(*)(id))aFunc; - (id <Enumerating>) keyEnumerator;
- withKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc; - withKeyObjectsInvoke: (id <Invoking>)anInvocation;
- withKeyObjectsAndContentObjectsCall: (void(*)(id,id))aFunc - withKeyObjectsInvoke: (id <Invoking>)anInvocation
whileTrue: (BOOL *)flag; whileTrue: (BOOL *)flag;
// NON-OBJECT ELEMENT METHOD NAMES; // LOW-LEVEL ENUMERATING;
- nextObjectAndKey: (id*)keyPtr withEnumState: (void**)enumState;
// INITIALIZING; // COPYING;
- initWithType: (const char *)contentsEncoding - shallowCopyValuesAs: (Class)aCollectingClass;
keyType: (const char *)keyEncoding; - shallowCopyKeysAs: (Class)aCollectingClass;
- initKeyType: (const char *)keyEncoding; - copyValuesAs: (Class)aCollectingClass;
- copyKeysAs: (Class)aCollectingClass;
// 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;
@end @end
@protocol KeyedCollecting <ConstantKeyedCollecting, Collecting> @protocol KeyedCollecting <ConstantKeyedCollecting, Collecting>
// ADDING; // ADDING;
- putObject: newContentObject atKey: (elt)aKey; - (void) putObject: newContentObject atKey: aKey;
// REPLACING AND SWAPPING; // REPLACING AND SWAPPING;
- replaceObjectAtKey: (elt)aKey with: newContentObject; - (void) replaceObjectAtKey: aKey with: newContentObject;
- swapAtKeys: (elt)key1 : (elt)key2; - (void) swapObjectsAtKeys: key1 : key2;
// REMOVING; // REMOVING;
- removeObjectAtKey: (elt)aKey; - (void) removeObjectAtKey: 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;
@end @end

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C KeyedCollection collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -28,12 +28,44 @@
#include <objects/Collection.h> #include <objects/Collection.h>
#include <objects/KeyedCollecting.h> #include <objects/KeyedCollecting.h>
@interface KeyedCollection : Collection @interface ConstantKeyedCollection : Collection
@end
@interface KeyedCollection : ConstantKeyedCollection
@end @end
/* Put this on category instead of class to avoid bogus complaint from gcc */ /* Put this on category instead of class to avoid bogus complaint from gcc */
@interface KeyedCollection (KeyedCollectingProtocol) <KeyedCollecting> @interface ConstantKeyedCollection (Protocol) <ConstantKeyedCollecting>
@end @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: /* The only subclassResponsibilities in IndexedCollection are:

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C LinkedList collection object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -25,7 +25,7 @@
#define __LinkedList_h_INCLUDE_GNU #define __LinkedList_h_INCLUDE_GNU
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/IndexedCollection.h> #include <objects/OrderedCollection.h>
/* The <LinkedListComprising> protocol defines the interface to an object /* The <LinkedListComprising> protocol defines the interface to an object
that may be an element in a LinkedList. that may be an element in a LinkedList.
@ -33,13 +33,16 @@
@protocol LinkedListComprising @protocol LinkedListComprising
- nextLink; - nextLink;
- prevLink; - prevLink;
- setNextLink: (id <LinkedListComprising>)aLink; - (void) setNextLink: (id <LinkedListComprising>)aLink;
- setPrevLink: (id <LinkedListComprising>)aLink; - (void) setPrevLink: (id <LinkedListComprising>)aLink;
- linkedList;
- (void) setLinkedList: aLinkedList;
@end @end
@interface LinkedList : IndexedCollection @interface LinkedList : OrderedCollection
{ {
id _first_link; id _first_link;
id _last_link;
unsigned int _count; unsigned int _count;
} }

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C LinkedListNode object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -32,8 +32,8 @@
{ {
id <LinkedListComprising> _next; id <LinkedListComprising> _next;
id <LinkedListComprising> _prev; id <LinkedListComprising> _prev;
id _linked_list;
} }
@end @end
#endif /* __LinkedListNode_h_INCLUDE_GNU */ #endif /* __LinkedListNode_h_INCLUDE_GNU */

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C MappedCollector collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -33,7 +33,7 @@
id <KeyedCollecting> _domain; id <KeyedCollecting> _domain;
} }
- initCollection: (id <KeyedCollecting>)aDomain - initWithCollection: (id <KeyedCollecting>)aDomain
map: (id <KeyedCollecting>)aMap; map: (id <KeyedCollecting>)aMap;
@end @end

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C Queue object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -29,13 +29,9 @@
@interface Queue : CircularArray @interface Queue : CircularArray
- enqueueObject: newObject; - (void) enqueueObject: newObject;
- dequeueObject; - dequeueObject;
// NON-OBJECT MESSAGE NAMES;
- enqueueElement: (elt)newElement;
- (elt) dequeueElement;
@end @end
#endif /* __Queue_h_INCLUDE_GNU */ #endif /* __Queue_h_INCLUDE_GNU */

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C Set collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -26,24 +26,23 @@
#include <objects/stdobjects.h> #include <objects/stdobjects.h>
#include <objects/Collection.h> #include <objects/Collection.h>
#include <Foundation/NSHashTable.h>
@interface Set : Collection @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; // MANAGING CAPACITY;
+ (unsigned) defaultCapacity; + (unsigned) defaultCapacity;
// INITIALIZING AND FREEING; // INITIALIZING AND FREEING;
- initWithType: (const char *)contentEncoding
capacity: (unsigned)aCapacity;
- initWithCapacity: (unsigned)aCapacity; - initWithCapacity: (unsigned)aCapacity;
// SET OPERATIONS; // SET OPERATIONS;
- intersectWithCollection: (id <Collecting>)aCollection; - (void) intersectWithCollection: (id <Collecting>)aCollection;
- unionWithCollection: (id <Collecting>)aCollection; - (void) unionWithCollection: (id <Collecting>)aCollection;
- differenceWithCollection: (id <Collecting>)aCollection; - (void) differenceWithCollection: (id <Collecting>)aCollection;
- shallowCopyIntersectWithCollection: (id <Collecting>)aCollection; - shallowCopyIntersectWithCollection: (id <Collecting>)aCollection;
- shallowCopyUnionWithCollection: (id <Collecting>)aCollection; - shallowCopyUnionWithCollection: (id <Collecting>)aCollection;

View file

@ -1,5 +1,5 @@
/* Interface for Objective-C SplayTree collection object /* 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> Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: May 1993 Date: May 1993
@ -41,7 +41,7 @@
{ {
} }
- splayNode: aNode; - (void) splayNode: aNode;
@end @end

View file

@ -1,8 +1,8 @@
/* Interface for Objective-C Stack object /* 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> 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. This file is part of the GNU Objective C Class Library.
@ -29,17 +29,11 @@
@interface Stack : Array @interface Stack : Array
- pushObject: anObject; - (void) pushObject: anObject;
- popObject; - popObject;
- topObject; - topObject;
- duplicateTop; - (void) duplicateTop;
- exchangeTop; - (void) exchangeTop;
// NON-OBJECT MESSAGE NAMES;
- pushElement: (elt)anElement;
- (elt) popElement;
- (elt) topElement;
@end @end