34#define SET_DEFAULT_CAPACITY 64
35#define SET_GROW_FACTOR 2.0
36#define SET_MAX_LOAD 0.75f
45 const Set *
this = (
Set *) self;
61 for (
size_t i = 0; i < this->capacity; i++) {
85 const Set *
this = (
Set *) self;
89 for (
size_t i = 0; i < this->capacity; i++) {
90 if (this->elements[i]) {
109 const Set *
this = (
Set *) self;
110 const Set *that = (
Set *) other;
112 if (this->count == that->
count) {
116 for (
size_t i = 0; i < objects->
count; i++) {
143 const float load =
set->
count / (float)
set->capacity;
146 size_t capacity =
set->capacity;
152 set->elements = calloc(
set->capacity,
sizeof(
ident));
153 assert(
set->elements);
155 for (
size_t i = 0; i < capacity; i++) {
254 if (self->capacity) {
274 for (
size_t i = 0; i < self->capacity; i++) {
298 for (
size_t i = 0; i < self->capacity; i++) {
320 for (
size_t i = 0; i < self->capacity; i++) {
329 self->elements[i] = NULL;
347 for (
size_t i = 0; i < self->capacity; i++) {
406 self->capacity = capacity;
407 if (self->capacity) {
409 self->elements = calloc(self->capacity,
sizeof(
ident));
410 assert(self->elements);
427 va_start(args, self);
479 for (
size_t i = 0; i < self->capacity; i++) {
506 for (
size_t i = 0; i < self->capacity; i++) {
512 accumulator = reducer(
array->elements[j], accumulator,
data);
526 for (
size_t i = 0; i < self->capacity; i++) {
531 self->elements[i] = NULL;
544 if (self->capacity == 0) {
560 self->elements[bin] = NULL;
627#pragma mark - Class lifecycle
677 .instanceSize =
sizeof(
Set),
678 .interfaceOffset = offsetof(
Set, interface),
679 .interfaceSize =
sizeof(SetInterface),
static void removeObjectAtIndex(Array *self, size_t index)
static ident objectAtIndex(const Array *self, size_t index)
static void enumerate(const Array *self, ArrayEnumerator enumerator, ident data)
static Array * array(void)
static ssize_t indexOfObject(const Array *self, const ident obj)
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.
#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.
static Set * mappedSet(const Set *self, Functor functor, ident data)
static Set * filteredSet(const Set *self, Predicate predicate, ident data)
static void initWithArray_enumerator(const Array *array, ident obj, ident data)
ArrayEnumerator for initWithArray.
static void addObjectsFromArray(Set *self, const Array *array)
static void allObjects_enumerator(const Set *set, ident obj, ident data)
SetEnumerator for allObjects.
static Set * initWithCapacity(Set *self, size_t capacity)
static void addObjectsFromSet(Set *self, const Set *set)
static bool containsObject(const Set *self, const ident obj)
static Array * allObjects(const Set *self)
static bool isEqual(const Object *self, const Object *other)
static Set * setWithObjects(ident obj,...)
static void filter(Set *self, Predicate predicate, ident data)
static void addObject(Set *self, const ident obj)
static String * description(const Object *self)
static void addObjectsFromArray_enumerator(const Array *array, ident obj, ident data)
ArrayEnumerator for addObjectsFromArray.
#define SET_DEFAULT_CAPACITY
static ident reduce(const Set *self, Reducer reducer, ident accumulator, ident data)
static Set * setWithArray(const Array *array)
static void dealloc(Object *self)
static void removeObject(Set *self, const ident obj)
static Set * initWithObjects(Set *self,...)
static Object * copy(const Object *self)
static void addObjectsFromSet_enumerator(const Set *set, ident obj, ident data)
SetEnumerator for addObjectsFromSet.
static void initialize(Class *clazz)
static void initWithSet_enumerator(const Set *set, ident obj, ident data)
SetEnumerator for initWithSet.
static Set * initWithSet(Set *self, const Set *set)
static Set * init(Set *self)
static Set * initWithArray(Set *self, const Array *array)
static void addObject_resize(Set *set)
A helper for resizing Sets as Objects are added to them.
static void removeAllObjects(Set *self)
static bool containsObjectMatching(const Set *self, Predicate predicate, ident data)
static Set * setWithSet(const Set *set)
static void enumerateObjects(const Set *self, SetEnumerator enumerator, ident data)
static Set * setWithCapacity(size_t capacity)
static int hash(const Object *self)
void(* SetEnumerator)(const Set *set, ident obj, ident data)
A function pointer for Set enumeration (iteration).
void * ident
The identity type, similar to Objective-C id.
bool(* Predicate)(const ident obj, ident data)
The Predicate function type for filtering 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.
bool containsObject(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.
Object is the root Class of The Objectively Class hierarchy.
Class * clazz
Every instance of Object begins with a pointer to its Class.
int hash(const Object *self)
void dealloc(Object *self)
Frees all resources held by this Object.
Set * setWithSet(const Set *set)
Returns a new Set with the contents of set.
size_t count
The count of elements.
Set * initWithObjects(Set *self,...)
Initializes this Set with the specified objects.
Set * init(Set *self)
Initializes this Set.
Set * mappedSet(const Set *self, Functor functor, ident data)
Transforms the elements in this Set by functor.
Set * initWithArray(Set *self, const Array *array)
Initializes this Set to contain the Objects in array.
Set * setWithCapacity(size_t capacity)
Returns a new Set with the given capacity.
Set * initWithSet(Set *self, const Set *set)
Initializes this Set to contain the Objects in set.
Set * setWithObjects(ident obj,...)
Returns a new Set containing the specified Objects.
Set * setWithArray(const Array *array)
Returns a new Set with the contents of array.
ident reduce(const Set *self, Reducer reducer, ident accumulator, ident data)
Set * initWithCapacity(Set *self, size_t capacity)
Initializes this Set with the specified capacity.