API  0.9.10
CPMutableSet.j
Go to the documentation of this file.
1 
8 @implementation CPMutableSet : CPSet
9 {
10  id __doxygen__;
11 }
12 
17 - (id)initWithCapacity:(unsigned)aCapacity
18 {
19  return [self init];
20 }
21 
26 + (id)setWithCapacity:(CPUInteger)aCapacity
27 {
28  return [[self alloc] initWithCapacity:aCapacity];
29 }
30 - (void)filterUsingPredicate:(CPPredicate)aPredicate
35 {
36  var object,
37  objectEnumerator = [self objectEnumerator];
38 
39  while ((object = [objectEnumerator nextObject]) !== nil)
40  if (![aPredicate evaluateWithObject:object])
41  [self removeObject:object];
42 }
43 
48 - (void)removeObject:(id)anObject
49 {
50  _CPRaiseInvalidAbstractInvocation(self, _cmd);
51 }
52 
57 - (void)removeObjectsInArray:(CPArray)anArray
58 {
59  var index = 0,
60  count = [anArray count];
61 
62  for (; index < count; ++index)
63  [self removeObject:[anArray objectAtIndex:index]];
64 }
65 
70 {
71  var object,
72  objectEnumerator = [self objectEnumerator];
73 
74  while ((object = [objectEnumerator nextObject]) !== nil)
75  [self removeObject:object];
76 }
77 
82 - (void)addObjectsFromArray:(CPArray)objects
83 {
84  var count = [objects count];
85 
86  while (count--)
87  [self addObject:objects[count]];
88 }
89 
94 - (void)unionSet:(CPSet)aSet
95 {
96  var object,
97  objectEnumerator = [aSet objectEnumerator];
98 
99  while ((object = [objectEnumerator nextObject]) !== nil)
100  [self addObject:object];
101 }
102 
107 - (void)minusSet:(CPSet)aSet
108 {
109  var object,
110  objectEnumerator = [aSet objectEnumerator];
111 
112  while ((object = [objectEnumerator nextObject]) !== nil)
113  [self removeObject:object];
114 }
115 
120 - (void)intersectSet:(CPSet)aSet
121 {
122  var object,
123  objectEnumerator = [self objectEnumerator],
124  objectsToRemove = [];
125 
126  while ((object = [objectEnumerator nextObject]) !== nil)
127  if (![aSet containsObject:object])
128  objectsToRemove.push(object);
129 
130  var count = [objectsToRemove count];
131 
132  while (count--)
133  [self removeObject:objectsToRemove[count]];
134 }
135 
140 - (void)setSet:(CPSet)aSet
141 {
142  [self removeAllObjects];
143  [self unionSet:aSet];
144 }
145 
146 @end
147 
void unionSet:(CPSet aSet)
Definition: CPMutableSet.j:94
void removeObject:(id anObject)
Definition: CPMutableSet.j:48
void removeAllObjects()
Definition: CPMutableSet.j:69