Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Properties | Methods | Protected Attributes
IndexSet Struct Reference

#include <IndexSet.h>

Overview

Immutable collections of unique index values.

Definition at line 41 of file IndexSet.h.

Inheritance diagram for IndexSet:
Object MutableIndexSet

Properties

size_t count
 The count of indexes. More...
 
size_t * indexes
 The indexes. More...
 
Object object
 The superclass. More...
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class. More...
 

Methods

Class_IndexSet (void)
 The IndexSet archetype. More...
 
_Bool containsIndex (const IndexSet *self, size_t index)
 
IndexSetinitWithIndex (IndexSet *self, size_t index)
 Initializes this IndexSet with the specified index. More...
 
IndexSetinitWithIndexes (IndexSet *self, size_t *indexes, size_t count)
 Initializes this IndexSet with the specified indexes and count. More...
 
- Methods inherited from Object
Class_Object (void)
 The Object archetype. More...
 
Objectcopy (const Object *self)
 Creates a shallow copy of this Object. More...
 
void dealloc (Object *self)
 Frees all resources held by this Object. More...
 
Stringdescription (const Object *self)
 
int hash (const Object *self)
 
Objectinit (Object *self)
 Initializes this Object. More...
 
_Bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object. More...
 
_Bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership. More...
 

Protected Attributes

IndexSetInterface * interface
 The interface. More...
 
- Protected Attributes inherited from Object
ObjectInterface * interface
 The interface. More...
 

Property Details

◆ count

size_t IndexSet::count

The count of indexes.

Definition at line 62 of file IndexSet.h.

◆ indexes

size_t* IndexSet::indexes

The indexes.

Definition at line 57 of file IndexSet.h.

◆ interface

IndexSetInterface* IndexSet::interface
protected

The interface.

Definition at line 52 of file IndexSet.h.

◆ object

Object IndexSet::object

The superclass.

Definition at line 46 of file IndexSet.h.

Method Details

◆ _IndexSet()

Class * _IndexSet ( void  )

The IndexSet archetype.

Returns
The IndexSet Class.

Definition at line 218 of file IndexSet.c.

218 {
219 static Class *clazz;
220 static Once once;
221
222 do_once(&once, {
223 clazz = _initialize(&(const ClassDef) {
224 .name = "IndexSet",
225 .superclass = _Object(),
226 .instanceSize = sizeof(IndexSet),
227 .interfaceOffset = offsetof(IndexSet, interface),
228 .interfaceSize = sizeof(IndexSetInterface),
230 });
231 });
232
233 return clazz;
234}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void initialize(Class *clazz)
Definition: IndexSet.c:201
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
The runtime representation of a Class.
Definition: Class.h:95
Immutable collections of unique index values.
Definition: IndexSet.h:41
IndexSetInterface * interface
The interface.
Definition: IndexSet.h:52
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition: Object.h:51
Class * _Object(void)
The Object archetype.
Definition: Object.c:136

◆ containsIndex()

_Bool containsIndex ( const IndexSet self,
size_t  index 
)
Parameters
selfThe IndexSet.
indexThe index.
Returns
True if this IndexSet contains index, false otherwise.

Definition at line 155 of file IndexSet.c.

155 {
156
157 for (size_t i = 0; i < self->count; i++) {
158 if (self->indexes[i] == index) {
159 return true;
160 }
161 }
162
163 return false;
164}
size_t * indexes
The indexes.
Definition: IndexSet.h:57
size_t count
The count of indexes.
Definition: IndexSet.h:62

◆ initWithIndex()

IndexSet * initWithIndex ( IndexSet self,
size_t  index 
)

Initializes this IndexSet with the specified index.

Parameters
selfThe IndexSet.
indexThe index.
Returns
The intialized IndexSet, or NULL on error.

Definition at line 170 of file IndexSet.c.

170 {
171 return $(self, initWithIndexes, &index, 1);
172}
IndexSet * initWithIndexes(IndexSet *self, size_t *indexes, size_t count)
Initializes this IndexSet with the specified indexes and count.
Definition: IndexSet.c:178

◆ initWithIndexes()

IndexSet * initWithIndexes ( IndexSet self,
size_t *  indexes,
size_t  count 
)

Initializes this IndexSet with the specified indexes and count.

Parameters
selfThe IndexSet.
indexesThe indexes.
countThe count of indexes.
Returns
The intialized IndexSet, or NULL on error.

Definition at line 178 of file IndexSet.c.

178 {
179
180 self = (IndexSet *) super(Object, self, init);
181 if (self) {
182
183 self->count = compact(indexes, count);
184 if (self->count) {
185
186 self->indexes = calloc(sizeof(size_t), self->count);
187 assert(self->indexes);
188
189 memcpy(self->indexes, indexes, sizeof(size_t) * self->count);
190 }
191 }
192
193 return self;
194}
#define super(type, obj, method,...)
static size_t compact(size_t *indexes, size_t count)
Sorts and compacts the given array to contain only unique values.
Definition: IndexSet.c:46
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46
Object * init(Object *self)
Initializes this Object.
Definition: Object.c:83

The documentation for this struct was generated from the following files: