Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
Vector.h File Reference

Mutable contiguous storage for C types. More...

#include <stdarg.h>
#include <Objectively/Object.h>

Go to the source code of this file.

Data Structures

struct  Vector
 Vectors. More...
 

Macros

#define VectorElement(vector, type, index)    (((type *) vector->elements) + (index))
 Access the typed element of Vector at the specified index.
 
#define VectorValue(vector, type, index)    *(VectorElement(vector, type, index))
 Access the typed value of a Vector at the specified index.
 

Typedefs

typedef void(* VectorEnumerator) (const Vector *vector, ident obj, ident data)
 The VectorEnumerator function type.
 

Functions

OBJECTIVELY_EXPORT Class_Vector (void)
 

Detailed Description

Mutable contiguous storage for C types.

Definition in file Vector.h.

Macro Definition Documentation

◆ VectorElement

#define VectorElement (   vector,
  type,
  index 
)     (((type *) vector->elements) + (index))

Access the typed element of Vector at the specified index.

Definition at line 96 of file Vector.h.

107 {
108
112 ObjectInterface objectInterface;
113
121 void (*add)(Vector *self, const ident element);
122
131 void (*enumerate)(const Vector *self, VectorEnumerator enumerator, ident data);
132
141 void (*filter)(Vector *self, Predicate predicate, ident data);
142
151 ident (*find)(const Vector *self, Predicate predicate, ident data);
152
160 ssize_t (*indexOf)(const Vector *self, const ident element);
161
172 Vector *(*initWithElements)(Vector *self, size_t size, size_t count, ident elements);
173
182 Vector *(*initWithSize)(Vector *self, size_t size);
183
192 void (*insert)(Vector *self, const ident element, size_t index);
193
203 Vector *(*mappedVector)(const Vector *self, Functor functor, ident data);
204
214 ident (*reduce)(const Vector *self, Reducer reducer, ident accumulator, ident data);
215
222 void (*removeAll)(Vector *self);
223
231 void (*removeAt)(Vector *self, size_t index);
232
240 void (*resize)(Vector *self, size_t capacity);
241
249 void (*sort)(Vector *self, Comparator comparator);
250
261 Vector *(*vectorWithElements)(size_t size, size_t count, ident elements);
262
271 Vector *(*vectorWithSize)(size_t size);
272};
273
static void filter(Array *self, Predicate predicate, ident data)
Definition Array.c:347
static ident find(const Array *self, Predicate predicate, ident data)
Definition Array.c:377
static ident reduce(const Array *self, Reducer reducer, ident accumulator, ident data)
Definition Array.c:589
static void enumerate(const Array *self, ArrayEnumerator enumerator, ident data)
Definition Array.c:334
static void sort(Array *self, Comparator comparator)
Definition Array.c:686
static Data * data(void)
Definition Data.c:286
static void resize(HashTable *self, size_t capacity)
Rehashes all entries into a new bucket array of the given capacity.
Definition HashTable.c:251
static void removeAll(HashTable *self)
Definition HashTable.c:227
static void add(PointerArray *self, ident pointer)
static void removeAt(PointerArray *self, size_t index)
void * ident
The identity type, similar to Objective-C id.
Definition Types.h:49
#define OBJECTIVELY_EXPORT
Definition Types.h:36
bool(* Predicate)(const ident obj, ident data)
The Predicate function type for filtering Objects.
Definition Types.h:111
Order(* Comparator)(const ident obj1, const ident obj2)
The Comparator function type for ordering Objects.
Definition Types.h:82
ident(* Functor)(const ident obj, ident data)
The Functor function type for transforming Objects.
Definition Types.h:103
ident(* Reducer)(const ident obj, ident accumulator, ident data)
The Reducer function type for reducing collections.
Definition Types.h:127
static ssize_t indexOf(const Vector *self, const ident element)
Definition Vector.c:184
static void insert(Vector *self, const ident element, size_t index)
Definition Vector.c:228
void(* VectorEnumerator)(const Vector *vector, ident obj, ident data)
The VectorEnumerator function type.
Definition Vector.h:44
OBJECTIVELY_EXPORT Class * _Vector(void)
Definition Vector.c:428
The runtime representation of a Class.
Definition Class.h:95
Vectors.
Definition Vector.h:51

◆ VectorValue

#define VectorValue (   vector,
  type,
  index 
)     *(VectorElement(vector, type, index))

Access the typed value of a Vector at the specified index.

Definition at line 102 of file Vector.h.

Typedef Documentation

◆ VectorEnumerator

typedef void(* VectorEnumerator) (const Vector *vector, ident obj, ident data)

The VectorEnumerator function type.

Parameters
vectorThe Vector.
objThe Object or element to enumerate.
dataUser data.

Definition at line 44 of file Vector.h.

Function Documentation

◆ _Vector()

OBJECTIVELY_EXPORT Class * _Vector ( void  )

Definition at line 428 of file Vector.c.

428 {
429 static Class *clazz;
430 static Once once;
431
432 do_once(&once, {
433 clazz = _initialize(&(const ClassDef) {
434 .name = "Vector",
435 .superclass = _Object(),
436 .instanceSize = sizeof(Vector),
437 .interfaceOffset = offsetof(Vector, interface),
438 .interfaceSize = sizeof(VectorInterface),
440 });
441 });
442
443 return clazz;
444}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition Class.c:86
Class * _Object(void)
Definition Object.c:136
static void initialize(Class *clazz)
Definition Vector.c:399
long Once
The Once type.
Definition Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition Class.h:41