35#define VECTOR_CHUNK_SIZE 64
49 that->
elements = malloc(this->capacity * this->size);
51 memcpy(that->
elements, this->elements, this->count * this->size);
52 that->
count = this->count;
82 .length = this->count * this->size
102 if (this->count == that->
count) {
103 return memcmp(this->elements, that->
elements, this->count * this->size) == 0;
143 for (
size_t i = 0; i < self->
count; i++) {
156 for (
size_t i = 0; i < self->
count; i++) {
171 for (
size_t i = 0; i < self->
count; i++) {
186 for (
size_t i = 0; i < self->
count; i++) {
230 assert(index <= self->count);
232 $(self,
add, element);
234 for (
size_t i = self->
count - 1; i > index; i--) {
250 for (
size_t i = 0; i < self->
count; i++) {
252 $(vector,
add, result);
265 for (
size_t i = 0; i < self->
count; i++) {
279 for (
size_t i = 0; i < self->
count; i++) {
293 assert(index < self->count);
299 const size_t size = (self->
count - index - 1) * self->
size;
313 for (
size_t i = capacity; i < self->
count; i++) {
325#if defined(__APPLE__)
330static int _sort(
void *
data,
const void *a,
const void *b) {
347static int _sort(
void *
data,
const void *a,
const void *b) {
364static int _sort(
const void *a,
const void *b,
void *
data) {
394#pragma mark - Class lifecycle
436 .instanceSize =
sizeof(
Vector),
437 .interfaceOffset = offsetof(
Vector, interface),
438 .interfaceSize =
sizeof(VectorInterface),
static Array * init(Array *self)
static void destroy(Class *clazz)
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.
static bool isKindOfClass(const Object *self, const 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.
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.
static ident reduce(const Vector *self, Reducer reducer, ident accumulator, ident data)
static ident find(const Vector *self, Predicate predicate, ident data)
static void removeAt(Vector *self, size_t index)
static void add(Vector *self, const ident element)
static bool isEqual(const Object *self, const Object *other)
static void removeAll(Vector *self)
static void resize(Vector *self, size_t capacity)
static Vector * initWithSize(Vector *self, size_t size)
static void filter(Vector *self, Predicate predicate, ident data)
static Vector * initWithElements(Vector *self, size_t size, size_t count, ident elements)
static ssize_t indexOf(const Vector *self, const ident element)
static void enumerate(const Vector *self, VectorEnumerator enumerator, ident data)
static Vector * vectorWithElements(size_t size, size_t count, ident elements)
static Vector * vectorWithSize(size_t size)
static void insert(Vector *self, const ident element, size_t index)
static void dealloc(Object *self)
static Vector * mappedVector(const Vector *self, Functor functor, ident data)
static int _sort(const void *a, const void *b, void *data)
qsort_r comparator.
static Object * copy(const Object *self)
static void initialize(Class *clazz)
#define VECTOR_CHUNK_SIZE
static void sort(Vector *self, Comparator comparator)
static int hash(const Object *self)
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.
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.
Object is the root Class of The Objectively Class hierarchy.
void dealloc(Object *self)
Frees all resources held by this Object.
A location and length into contiguous collections.
ssize_t location
The location.
ident reduce(const Vector *self, Reducer reducer, ident accumulator, ident data)
Consumer destroy
Optional destructor called when an element is removed.
Vector * vectorWithSize(size_t size)
Creates a new Vector with the specified element size.
void insert(Vector *self, const ident element, size_t index)
Inserts the element at the specified index.
Vector * initWithSize(Vector *self, size_t size)
Initializes this Vector with the specified element size.
size_t count
The count of elements.
size_t capacity
The capacity.
ident elements
The elements.
size_t size
The size of each element.