54 for (
size_t i = 0; i < this->count; i++) {
86 for (
size_t i = 0; i < this->count; i++) {
107 if (this->count == that->
count) {
109 for (
size_t i = 0; i < this->count; i++) {
111 const Object *thisObject = this->elements[i];
112 const Object *thatObject = that->elements[i];
114 if ($(thisObject,
isEqual, thatObject) ==
false) {
151 assert(
array->elements);
180 for (
size_t i = 0; i < self->
count; i++) {
187 if (i < self->count - 1) {
221 for (
size_t i = 0; i < self->
count; i++) {
222 enumerator(self, self->elements[i],
data);
249 for (
size_t i = 0; i < self->
count; i++) {
250 if (predicate(self->elements[i],
data)) {
251 return self->elements[i];
275 for (
size_t i = 0; i < self->
count; i++) {
296 self->elements = calloc(self->
count,
sizeof(
ident));
297 assert(self->elements);
299 for (
size_t i = 0; i < self->
count; i++) {
315 va_start(args, self);
334 self->elements = realloc(self->elements, ++self->
count *
sizeof(
ident));
335 assert(self->elements);
338 element = va_arg(args,
ident);
365 for (
size_t i = 0; i < self->
count; i++) {
396 assert(index < self->count);
398 return self->elements[index];
409 for (
size_t i = 0; i < self->
count; i++) {
410 accumulator = reducer(self->elements[i], accumulator,
data);
431#pragma mark - Class lifecycle
478 .instanceSize =
sizeof(
Array),
479 .interfaceOffset = offsetof(
Array, interface),
480 .interfaceSize =
sizeof(ArrayInterface),
static void initialize(Class *clazz)
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,...)
int HashForInteger(int hash, const long integer)
Accumulates the hash value of integer into hash.
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.
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.
ident(* Functor)(const ident obj, ident data)
The Functor function type for transforming Objects.
ident(* Reducer)(const ident obj, ident accumulator, ident data)
The Reducer function type for reducing collections.
#define do_once(once, block)
Executes the given block at most one time.
Array * initWithObjects(Array *self,...)
Initializes this Array to contain the Objects in the NULL-terminated arguments list.
Class * _Array(void)
The Array archetype.
ident reduce(const Array *self, Reducer reducer, ident accumulator, ident data)
String * componentsJoinedByString(const Array *self, const String *string)
Returns the components of this Array joined by the specified String.
ident findObject(const Array *self, Predicate predicate, ident data)
String * componentsJoinedByCharacters(const Array *self, const char *chars)
Returns the components of this Array joined by chars.
Array * mappedArray(const Array *self, Functor functor, ident data)
Transforms the elements in this Array by functor.
MutableArray * mutableCopy(const Array *self)
Array * arrayWithObjects(ident obj,...)
Returns a new Array containing the given Objects.
void enumerateObjects(const Array *self, ArrayEnumerator enumerator, ident data)
Enumerate the elements of this Array with the given function.
Array * initWithArray(Array *self, const Array *array)
Initializes this Array to contain the Objects in array.
Array * initWithVaList(Array *self, va_list args)
Initializes this Array to contain the Objects in the NULL-terminated va_list.
Array * filteredArray(const Array *self, Predicate predicate, ident data)
Creates a new Array with elements that pass predicate.
ident lastObject(const Array *self)
ssize_t indexOfObject(const Array *self, const ident obj)
Array * sortedArray(const Array *self, Comparator comparator)
ident objectAtIndex(const Array *self, int index)
_Bool containsObject(const Array *self, const ident obj)
Array * arrayWithVaList(va_list args)
Returns a new Array containing the Objects in the given va_list.
size_t count
The count of elements.
Array * arrayWithArray(const Array *array)
Returns a new Array containing the contents of array.
ident firstObject(const Array *self)
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 filter(MutableArray *self, Predicate predicate, ident data)
Filters this MutableArray in place using predicate.
MutableArray * arrayWithCapacity(size_t capacity)
Returns a new MutableArray with the given capacity.
void addObject(MutableArray *self, const ident obj)
Adds the specified Object to this MutableArray.
void sort(MutableArray *self, Comparator comparator)
Sorts this MutableArray in place using comparator.
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 appendString(MutableString *self, const String *string)
Appends the specified String to this MutableString.
MutableString * string(void)
Returns a new MutableString.
void appendCharacters(MutableString *self, const char *chars)
Appends the specified UTF-8 encoded C string.
Object is the root Class of The Objectively Class hierarchy.
Class * _Object(void)
The Object archetype.
Object * copy(const Object *self)
Creates a shallow copy of this Object.
_Bool isKindOfClass(const Object *self, const Class *clazz)
Tests for Class hierarchy membership.
String * description(const Object *self)
_Bool isEqual(const Object *self, const Object *other)
Tests equality of the other Object.
int hash(const Object *self)
void dealloc(Object *self)
Frees all resources held by this Object.
char * chars
The backing null-terminated UTF-8 encoded character array.