Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Set.h
Go to the documentation of this file.
1/*
2 * Objectively: Ultra-lightweight object oriented framework for GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <Objectively/Array.h>
27#include <Objectively/Object.h>
28
39typedef struct Set Set;
40typedef struct SetInterface SetInterface;
41
48typedef void (*SetEnumerator)(const Set *set, ident obj, ident data);
49
55struct Set {
56
61
66 SetInterface *interface;
67
72 size_t capacity;
73
77 size_t count;
78
83 ident *elements;
84};
85
86typedef struct MutableSet MutableSet;
87
91struct SetInterface {
92
96 ObjectInterface objectInterface;
97
104 Array *(*allObjects)(const Set *self);
105
113 _Bool (*containsObject)(const Set *self, const ident obj);
114
123 _Bool (*containsObjectMatching)(const Set *self, Predicate predicate, ident data);
124
134 void (*enumerateObjects)(const Set *self, SetEnumerator enumerator, ident data);
135
145 Set *(*filteredSet)(const Set *self, Predicate predicate, ident data);
146
155 Set *(*initWithArray)(Set *self, const Array *array);
156
164 Set *(*initWithObjects)(Set *self, ...);
165
174 Set *(*initWithSet)(Set *self, const Set *set);
175
185 Set *(*mappedSet)(const Set *self, Functor functor, ident data);
186
193 MutableSet *(*mutableCopy)(const Set *self);
194
204 ident (*reduce)(const Set *self, Reducer reducer, ident accumulator, ident data);
205
214 Set *(*setWithArray)(const Array *array);
215
224 Set *(*setWithObjects)(ident obj, ...);
225
234 Set *(*setWithSet)(const Set *set);
235};
236
static ident reduce(const Array *self, Reducer reducer, ident accumulator, ident data)
Definition: Array.c:405
static _Bool containsObject(const Array *self, const ident obj)
Definition: Array.c:208
static void enumerateObjects(const Array *self, ArrayEnumerator enumerator, ident data)
Definition: Array.c:217
Immutable arrays.
#define obj
static MutableArray * array(void)
Definition: MutableArray.c:153
static MutableData * data(void)
Definition: MutableData.c:75
static MutableSet * set(void)
Definition: MutableSet.c:259
Object is the root Class of The Objectively Class hierarchy.
static _Bool containsObjectMatching(const Set *self, Predicate predicate, ident data)
Definition: Set.c:173
void(* SetEnumerator)(const Set *set, ident obj, ident data)
A function pointer for Set enumeration (iteration).
Definition: Set.h:48
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
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
Immutable arrays.
Definition: Array.h:56
The runtime representation of a Class.
Definition: Class.h:95
MutableData * data(void)
Returns a new MutableData.
Definition: MutableData.c:75
Mutable sets.
Definition: MutableSet.h:40
MutableSet * set(void)
Returns a new MutableSet.
Definition: MutableSet.c:259
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46
Immutable sets.
Definition: Set.h:55
Object object
The superclass.
Definition: Set.h:60
size_t count
The count of elements.
Definition: Set.h:77
SetInterface * interface
The interface.
Definition: Set.h:66
Class * _Set(void)
The Set archetype.
Definition: Set.c:454