#include <assert.h>
#include <stdarg.h>
#include <stdlib.h>
#include "Hash.h"
#include "MutableArray.h"
#include "MutableSet.h"
Go to the source code of this file.
|
Class * | _MutableSet (void) |
|
static void | addObject (MutableSet *self, const ident obj) |
|
static void | addObject_resize (Set *set) |
| A helper for resizing Sets as Objects are added to them. More...
|
|
static void | addObjectsFromArray (MutableSet *self, const Array *array) |
|
static void | addObjectsFromArray_enumerator (const Array *array, ident obj, ident data) |
| ArrayEnumerator for addObjectsFromArray. More...
|
|
static void | addObjectsFromSet (MutableSet *self, const Set *set) |
|
static void | addObjectsFromSet_enumerator (const Set *set, ident obj, ident data) |
| SetEnumerator for addObjectsFromSet. More...
|
|
static Object * | copy (const Object *self) |
|
static void | filter (MutableSet *self, Predicate predicate, ident data) |
|
static MutableSet * | init (MutableSet *self) |
|
static void | initialize (Class *clazz) |
|
static MutableSet * | initWithCapacity (MutableSet *self, size_t capacity) |
|
static void | removeAllObjects (MutableSet *self) |
|
static void | removeObject (MutableSet *self, const ident obj) |
|
static MutableSet * | set (void) |
|
static MutableSet * | setWithCapacity (size_t capacity) |
|
◆ _Class
◆ MUTABLESET_DEFAULT_CAPACITY
#define MUTABLESET_DEFAULT_CAPACITY 64 |
◆ MUTABLESET_GROW_FACTOR
#define MUTABLESET_GROW_FACTOR 2.0 |
◆ MUTABLESET_MAX_LOAD
#define MUTABLESET_MAX_LOAD 0.75f |
◆ _MutableSet()
Class * _MutableSet |
( |
void |
| ) |
|
Definition at line 298 of file MutableSet.c.
298 {
301
304 .name = "MutableSet",
305 .superclass =
_Set(),
307 .interfaceOffset = offsetof(
MutableSet, interface),
308 .interfaceSize = sizeof(MutableSetInterface),
310 });
311 });
312
313 return clazz;
314}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
static void initialize(Class *clazz)
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
Class * _Set(void)
The Set archetype.
◆ addObject()
Definition at line 96 of file MutableSet.c.
96 {
97
99
101
103
107 }
108
112 }
113}
#define alloc(type)
Allocate and initialize and instance of type.
int HashForObject(int hash, const ident obj)
Accumulates the hash value of object into hash.
#define HASH_SEED
The hash seed value.
static void addObject_resize(Set *set)
A helper for resizing Sets as Objects are added to them.
_Bool containsObject(const Array *self, const ident obj)
Condition * init(Condition *self)
Initializes this Condition.
void addObject(MutableArray *self, const ident obj)
Adds the specified Object to this MutableArray.
MutableArray * array(void)
Returns a new MutableArray.
MutableSet * set(void)
Returns a new MutableSet.
size_t count
The count of elements.
◆ addObject_resize()
static void addObject_resize |
( |
Set * |
set | ) |
|
|
static |
A helper for resizing Sets as Objects are added to them.
Definition at line 60 of file MutableSet.c.
60 {
61
63
64 const float load =
set->
count / (float)
set->capacity;
66
67 size_t capacity =
set->capacity;
69
72
73 set->elements = calloc(
set->capacity,
sizeof(
ident));
74 assert(
set->elements);
75
76 for (size_t i = 0; i < capacity; i++) {
77
82 }
83 }
84
85 free(elements);
86 }
87 } else {
89 }
90}
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
#define MUTABLESET_GROW_FACTOR
#define MUTABLESET_DEFAULT_CAPACITY
#define MUTABLESET_MAX_LOAD
void * ident
The identity type, similar to Objective-C id.
MutableArray * initWithCapacity(MutableArray *self, size_t capacity)
Initializes this MutableArray with the specified capacity.
void addObjectsFromArray(MutableArray *self, const Array *array)
Adds the Objects contained in array to this MutableArray.
◆ addObjectsFromArray()
Definition at line 126 of file MutableSet.c.
126 {
127
130 }
131}
static void addObjectsFromArray_enumerator(const Array *array, ident obj, ident data)
ArrayEnumerator for addObjectsFromArray.
void enumerateObjects(const Array *self, ArrayEnumerator enumerator, ident data)
Enumerate the elements of this Array with the given function.
◆ addObjectsFromArray_enumerator()
static void addObjectsFromArray_enumerator |
( |
const Array * |
array, |
|
|
ident |
obj, |
|
|
ident |
data |
|
) |
| |
|
static |
ArrayEnumerator for addObjectsFromArray.
Definition at line 118 of file MutableSet.c.
118 {
120}
MutableData * data(void)
Returns a new MutableData.
◆ addObjectsFromSet()
static void addObjectsFromSet |
( |
MutableSet * |
self, |
|
|
const Set * |
set |
|
) |
| |
|
static |
Definition at line 144 of file MutableSet.c.
144 {
145
148 }
149}
static void addObjectsFromSet_enumerator(const Set *set, ident obj, ident data)
SetEnumerator for addObjectsFromSet.
◆ addObjectsFromSet_enumerator()
static void addObjectsFromSet_enumerator |
( |
const Set * |
set, |
|
|
ident |
obj, |
|
|
ident |
data |
|
) |
| |
|
static |
SetEnumerator for addObjectsFromSet.
Definition at line 136 of file MutableSet.c.
◆ copy()
- See also
- Object::copy(const Object *)
Definition at line 43 of file MutableSet.c.
43 {
44
45 const Set *
this = (
Set *) self;
46
48
50
52}
void addObjectsFromSet(MutableSet *self, const Set *set)
Adds the Objects contained in set to this Set.
Object is the root Class of The Objectively Class hierarchy.
Object * copy(const Object *self)
Creates a shallow copy of this Object.
◆ filter()
Definition at line 155 of file MutableSet.c.
155 {
156
157 assert(predicate);
158
160
161 for (
size_t i = 0; i < self->
set.capacity; i++) {
162
165
167
170 self->
set.elements[i] = NULL;
171 } else {
173 }
174 }
175 }
176}
size_t count
The count of elements.
Array array
The superclass.
void filter(MutableArray *self, Predicate predicate, ident data)
Filters this MutableArray in place using predicate.
◆ init()
◆ initialize()
static void initialize |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::initialize(Class *)
Definition at line 278 of file MutableSet.c.
278 {
279
281
292}
ident interface
The interface of the Class.
void removeAllObjects(MutableArray *self)
Removes all Objects from this MutableArray.
void removeObject(MutableArray *self, const ident obj)
Removes the specified Object from this MutableArray.
MutableSet * setWithCapacity(size_t capacity)
Returns a new MutableSet with the given capacity.
◆ initWithCapacity()
Definition at line 191 of file MutableSet.c.
191 {
192
194 if (self) {
195
196 self->
set.capacity = capacity;
197 if (self->
set.capacity) {
198
199 self->
set.elements = calloc(self->
set.capacity,
sizeof(
ident));
200 assert(self->
set.elements);
201 }
202 }
203
204 return self;
205}
#define super(type, obj, method,...)
◆ removeAllObjects()
Definition at line 211 of file MutableSet.c.
211 {
212
213 for (
size_t i = 0; i < self->
set.capacity; i++) {
214
218 self->
set.elements[i] = NULL;
219 }
220 }
221
223}
◆ removeObject()
Definition at line 229 of file MutableSet.c.
229 {
230
231 if (self->
set.capacity == 0) {
232 return;
233 }
234
236
239
241 if (index > -1) {
242
244
247 self->
set.elements[bin] = NULL;
248 }
249
251 }
252 }
253}
ssize_t indexOfObject(const Array *self, const ident obj)
void removeObjectAtIndex(MutableArray *self, size_t index)
Removes the Object at the specified index.
◆ set()
◆ setWithCapacity()
static MutableSet * setWithCapacity |
( |
size_t |
capacity | ) |
|
|
static |