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