32#define _Class _MutableSet
34#define MUTABLESET_DEFAULT_CAPACITY 64
35#define MUTABLESET_GROW_FACTOR 2.0
36#define MUTABLESET_MAX_LOAD 0.75f
45 const Set *
this = (
Set *) self;
54#pragma mark - MutableSet
64 const float load =
set->
count / (float)
set->capacity;
67 size_t capacity =
set->capacity;
73 set->elements = calloc(
set->capacity,
sizeof(
ident));
74 assert(
set->elements);
76 for (
size_t i = 0; i < capacity; i++) {
161 for (
size_t i = 0; i < self->
set.capacity; i++) {
170 self->
set.elements[i] = NULL;
196 self->
set.capacity = capacity;
197 if (self->
set.capacity) {
199 self->
set.elements = calloc(self->
set.capacity,
sizeof(
ident));
200 assert(self->
set.elements);
213 for (
size_t i = 0; i < self->
set.capacity; i++) {
218 self->
set.elements[i] = NULL;
231 if (self->
set.capacity == 0) {
247 self->
set.elements[bin] = NULL;
273#pragma mark - Class lifecycle
304 .name =
"MutableSet",
305 .superclass =
_Set(),
307 .interfaceOffset = offsetof(
MutableSet, interface),
308 .interfaceSize =
sizeof(MutableSetInterface),
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Class * _initialize(const ClassDef *def)
Initializes the given Class.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
int HashForObject(int hash, const ident obj)
Accumulates the hash value of object into hash.
Utilities for calculating hash values.
#define HASH_SEED
The hash seed value.
#define MUTABLESET_GROW_FACTOR
#define MUTABLESET_DEFAULT_CAPACITY
#define MUTABLESET_MAX_LOAD
static void addObjectsFromArray_enumerator(const Array *array, ident obj, ident data)
ArrayEnumerator for addObjectsFromArray.
static void addObjectsFromSet_enumerator(const Set *set, ident obj, ident data)
SetEnumerator for addObjectsFromSet.
static void initialize(Class *clazz)
static void addObject_resize(Set *set)
A helper for resizing Sets as Objects are added to them.
void * ident
The identity type, similar to Objective-C id.
_Bool(* Predicate)(const ident obj, ident data)
The Predicate function type for filtering Objects.
#define do_once(once, block)
Executes the given block at most one time.
void enumerateObjects(const Array *self, ArrayEnumerator enumerator, ident data)
Enumerate the elements of this Array with the given function.
ssize_t indexOfObject(const Array *self, const ident obj)
_Bool containsObject(const Array *self, const ident obj)
size_t count
The count of elements.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
Condition * init(Condition *self)
Initializes this Condition.
void removeObjectAtIndex(MutableArray *self, size_t index)
Removes the Object at the specified index.
Array array
The superclass.
void filter(MutableArray *self, Predicate predicate, ident data)
Filters this MutableArray in place using predicate.
void addObject(MutableArray *self, const ident obj)
Adds the specified Object to this MutableArray.
void removeAllObjects(MutableArray *self)
Removes all Objects from this MutableArray.
void removeObject(MutableArray *self, const ident obj)
Removes the specified Object from this MutableArray.
MutableArray * array(void)
Returns a new MutableArray.
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.
MutableData * data(void)
Returns a new MutableData.
void addObjectsFromSet(MutableSet *self, const Set *set)
Adds the Objects contained in set to this Set.
MutableSet * set(void)
Returns a new MutableSet.
MutableSet * setWithCapacity(size_t capacity)
Returns a new MutableSet with the given capacity.
Class * _MutableSet(void)
The MutableSet archetype.
Object is the root Class of The Objectively Class hierarchy.
Object * copy(const Object *self)
Creates a shallow copy of this Object.
size_t count
The count of elements.
Class * _Set(void)
The Set archetype.