42 qsort_r(base, count, size, comparator,
_quicksort);
55 qsort_s(base, count, size,
_quicksort, comparator);
68 qsort_r(base, count, size,
_quicksort, comparator);
73#define _Class _MutableArray
75#define ARRAY_CHUNK_SIZE 64
93#pragma mark - MutableArray
106 if (
array->elements) {
107 array->elements = realloc(
array->elements, self->capacity *
sizeof(
ident));
109 array->elements = calloc(self->capacity,
sizeof(
ident));
112 assert(
array->elements);
130 object = va_arg(args,
ident);
175 for (
size_t i = 0; i < self->
array.
count; i++) {
176 if (predicate(self->
array.elements[i],
data) ==
false) {
200 self->capacity = capacity;
201 if (self->capacity) {
203 self->
array.elements = calloc(self->capacity,
sizeof(
ident));
204 assert(self->
array.elements);
221 for (
size_t i = self->
array.
count - 1; i > index; i--) {
222 self->
array.elements[i] = self->
array.elements[i - 1];
288 for (
size_t i = index; i < self->
array.
count - 1; i++) {
289 self->
array.elements[i] = self->
array.elements[i + 1];
318#pragma mark - Class lifecycle
355 .name =
"MutableArray",
359 .interfaceSize =
sizeof(MutableArrayInterface),
void(* ArrayEnumerator)(const Array *array, ident obj, ident data)
A function pointer for Array enumeration (iteration).
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.
ident retain(ident obj)
Atomically increment the given Object's reference count.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
void quicksort(ident base, size_t count, size_t size, Comparator comparator, ident data)
A portability wrapper around reentrant qsort.
static int _quicksort(const void *a, const void *b, void *data)
GNU qsort_r.
static void initialize(Class *clazz)
void * ident
The identity type, similar to Objective-C id.
_Bool(* Predicate)(const ident obj, ident data)
The Predicate function type for filtering Objects.
Order(* Comparator)(const ident obj1, const ident obj2)
The Comparator function type for ordering Objects.
#define do_once(once, block)
Executes the given block at most one time.
Class * _Array(void)
The Array archetype.
ident lastObject(const Array *self)
ssize_t indexOfObject(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 removeAllObjectsWithEnumerator(MutableArray *self, ArrayEnumerator enumerator, ident data)
Removes all Objects from this MutableArray, invoking enumerator for each Object.
void removeObjectAtIndex(MutableArray *self, size_t index)
Removes the Object at the specified index.
void removeLastObject(MutableArray *self)
Removes the last Object from this MutableArray.
Array array
The superclass.
void filter(MutableArray *self, Predicate predicate, ident data)
Filters this MutableArray in place using predicate.
void setObjectAtIndex(MutableArray *self, const ident obj, size_t index)
Replaces the Object at the specified index.
MutableArray * arrayWithCapacity(size_t capacity)
Returns a new MutableArray with the given capacity.
void addObjects(MutableArray *self, const ident obj,...)
Adds the specified objects to this Array.
void addObject(MutableArray *self, const ident obj)
Adds the specified Object to this MutableArray.
void insertObjectAtIndex(MutableArray *self, ident obj, size_t index)
Inserts the Object at the specified index.
void sort(MutableArray *self, Comparator comparator)
Sorts this MutableArray in place using comparator.
void removeAllObjects(MutableArray *self)
Removes all Objects from this MutableArray.
void removeObject(MutableArray *self, const ident obj)
Removes the specified Object from this MutableArray.
Class * _MutableArray(void)
The MutableArray archetype.
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.
Object is the root Class of The Objectively Class hierarchy.
Object * copy(const Object *self)
Creates a shallow copy of this Object.