35#define VECTOR_CHUNK_SIZE 64
48 copy->elements = malloc(this->capacity * this->size);
49 memcpy(
copy->elements, this->elements, this->count * this->size);
75 .length = this->count * this->size
95 if (this->count == that->
count) {
96 return memcmp(this->elements, that->
elements, this->count * this->size) == 0;
136 for (
size_t i = 0; i < self->
count; i++) {
149 for (
size_t i = 0; i < self->
count; i++) {
164 for (
size_t i = 0; i < self->
count; i++) {
179 for (
size_t i = 0; i < self->
count; i++) {
223 assert(index <= self->count);
227 for (
size_t i = self->
count - 1; i > index; i--) {
242 for (
size_t i = 0; i < self->
count; i++) {
263 assert(index < self->count);
265 const size_t size = (self->
count - index) * self->
size;
285#if defined(__APPLE__)
290static int _sort(
void *
data,
const void *a,
const void *b) {
307static int _sort(
void *
data,
const void *a,
const void *b) {
324static int _sort(
const void *a,
const void *b,
void *
data) {
354#pragma mark - Class lifecycle
395 .instanceSize =
sizeof(
Vector),
396 .interfaceOffset = offsetof(
Vector, interface),
397 .interfaceSize =
sizeof(VectorInterface),
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 HashForBytes(int hash, const uint8_t *bytes, const Range range)
Accumulates the hash value of bytes 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(* Reducer)(const ident obj, ident accumulator, ident data)
The Reducer function type for reducing collections.
static int _sort(const void *a, const void *b, void *data)
qsort_r comparator.
static void initialize(Class *clazz)
#define VECTOR_CHUNK_SIZE
Mutable contiguous storage for C types.
void(* VectorEnumerator)(const Vector *vector, ident obj, ident data)
The VectorEnumerator function type.
#define do_once(once, block)
Executes the given block at most one time.
ident reduce(const Array *self, Reducer reducer, ident accumulator, ident data)
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 sort(MutableArray *self, Comparator comparator)
Sorts this MutableArray in place using comparator.
MutableData * data(void)
Returns a new MutableData.
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.
_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.
A location and length into contiguous collections.
ssize_t location
The location.
void removeElementAtIndex(Vector *self, size_t index)
Removes the element at the specified index.
ident findElement(const Vector *self, Predicate predicate, ident data)
void addElement(Vector *self, const ident element)
Adds the specified element to this Vector.
void resize(Vector *self, size_t capacity)
Resizes this Vector to the specified capacity.
Vector * vectorWithSize(size_t size)
Creates a new Vector with the specified element size.
Class * _Vector(void)
The Vector archetype.
Vector * vectorWithElements(size_t size, size_t count, ident elements)
Creates a new Vector with the specified elements.
Vector * initWithElements(Vector *self, size_t size, size_t count, ident elements)
Initializes this Vector with the specified elements.
Vector * initWithSize(Vector *self, size_t size)
Initializes this Vector with the specified element size.
void removeAllElements(Vector *self)
Removes all elements from this Vector without modifying its capacity.
size_t count
The count of elements.
void insertElementAtIndex(Vector *self, const ident element, size_t index)
Inserts the element at the specified index.
size_t capacity
The capacity.
ssize_t indexOfElement(const Vector *self, const ident element)
ident elements
The elements.
void filterElements(Vector *self, Predicate predicate, ident data)
size_t size
The size of each element.
void enumerateElements(const Vector *self, VectorEnumerator enumerator, ident data)
Enumerates the elements of this Vector with the given function.