1
/** Interface for NSSet, NSMutableSet, NSCountedSet for GNUStep
2
Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc.
4
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
7
This file is part of the GNUstep Base Library.
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Library General Public
11
License as published by the Free Software Foundation; either
12
version 2 of the License, or (at your option) any later version.
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Library General Public License for more details.
19
You should have received a copy of the GNU Library General Public
20
License along with this library; if not, write to the Free
21
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
23
AutogsdocSource: NSSet.m
24
AutogsdocSource: NSCountedSet.m
28
#ifndef _NSSet_h_GNUSTEP_BASE_INCLUDE
29
#define _NSSet_h_GNUSTEP_BASE_INCLUDE
31
#include <Foundation/NSObject.h>
33
@class NSArray, NSString, NSEnumerator, NSDictionary;
35
@interface NSSet : NSObject <NSCoding, NSCopying, NSMutableCopying>
38
+ (id) setWithArray: (NSArray*)objects;
39
+ (id) setWithObject: (id)anObject;
40
+ (id) setWithObjects: (id)firstObject, ...;
41
#ifndef STRICT_OPENSTEP
42
+ (id) setWithObjects: (id*)objects
43
count: (unsigned)count;
45
+ (id) setWithSet: (NSSet*)aSet;
47
- (NSArray*) allObjects;
49
- (BOOL) containsObject: (id)anObject;
51
- (NSString*) description;
52
- (NSString*) descriptionWithLocale: (NSDictionary*)locale;
55
- (id) initWithArray: (NSArray*)other;
56
- (id) initWithObjects: (id)firstObject, ...;
57
- (id) initWithObjects: (id*)objects
58
count: (unsigned)count;
59
- (id) initWithSet: (NSSet*)other;
60
- (id) initWithSet: (NSSet*)other copyItems: (BOOL)flag;
62
- (BOOL) intersectsSet: (NSSet*)otherSet;
63
- (BOOL) isEqualToSet: (NSSet*)other;
64
- (BOOL) isSubsetOfSet: (NSSet*)otherSet;
66
- (void) makeObjectsPerform: (SEL)aSelector;
67
- (void) makeObjectsPerform: (SEL)aSelector withObject: (id)argument;
68
#ifndef STRICT_OPENSTEP
69
- (void) makeObjectsPerformSelector: (SEL)aSelector;
70
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject: (id)argument;
72
- (id) member: (id)anObject;
73
- (NSEnumerator*) objectEnumerator;
77
@interface NSMutableSet: NSSet
79
+ (id) setWithCapacity: (unsigned)numItems;
81
- (void) addObject: (id)anObject;
82
- (void) addObjectsFromArray: (NSArray*)array;
83
- (id) initWithCapacity: (unsigned)numItems;
84
- (void) intersectSet: (NSSet*)other;
85
- (void) minusSet: (NSSet*)other;
86
- (void) removeAllObjects;
87
- (void) removeObject: (id)anObject;
88
#ifndef STRICT_OPENSTEP
89
- (void) setSet: (NSSet*)other;
91
- (void) unionSet: (NSSet*)other;
94
@interface NSCountedSet : NSMutableSet
96
- (unsigned int) countForObject: (id)anObject;
103
* Utility methods for using a counted set to handle uniquing of objects.
105
@interface NSCountedSet (GNU_Uniquing)
108
* This method removes from the set all objects whose count is
109
* less than or equal to the specified value.
112
* This is useful where a counted set is used for uniquing objects.
113
* The set can be periodically purged of objects that have only
114
* been added once - and are therefore simply wasting space.
117
- (void) purge: (int)level;
121
* If the supplied object (or one equal to it as determined by
122
* the [NSObject-isEqual:] method) is already present in the set, the
123
* count for that object is incremented, the supplied object
124
* is released, and the object in the set is retained and returned.
125
* Otherwise, the supplied object is added to the set and returned.
128
* This method is useful for uniquing objects - the init method of
129
* a class need simply end with -
131
* return [myUniquingSet unique: self];
135
- (id) unique: (id)anObject;
139
* Functions for managing a global uniquing set.
143
* GSUniquing() turns on/off the action of the GSUnique() function.
144
* if uniquing is turned off, GSUnique() simply returns its argument.
147
void GSUniquing(BOOL flag);
150
* GSUnique() returns an object that is equal to the one passed to it.
151
* If the returned object is not the same object as the object passed in,
152
* the original object is released and the returned object is retained.
153
* Thus, an -init method that wants to implement uniquing simply needs
154
* to end with 'return GSUnique(self);'
156
id GSUnique(id anObject);
159
* Management functions -
163
* GSUPurge() can be used to purge infrequently referenced objects from the
164
* set by removing any objec whose count is less than or equal to that given.
167
void GSUPurge(unsigned count);
170
* GSUSet() can be used to artificially set the count for a particular object
171
* Setting the count to zero will remove the object from the global set.
173
id GSUSet(id anObject, unsigned count);
175
#endif /* NO_GNUSTEP */