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

#include <MutableIndexSet.h>

Overview

Mutable collections of unique index values.

Definition at line 41 of file MutableIndexSet.h.

Inheritance diagram for MutableIndexSet:
IndexSet Object

Properties

size_t capacity
 The capacity. More...
 
IndexSet indexSet
 The superclass. More...
 
- Properties inherited from IndexSet
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_MutableIndexSet (void)
 The MutableIndexSet archetype. More...
 
void addIndex (MutableIndexSet *self, size_t index)
 Adds the specified index to this MutableIndexSet. More...
 
void addIndexes (MutableIndexSet *self, size_t *indexes, size_t count)
 Adds the specified indexes to this MutableIndexSet. More...
 
void addIndexesInRange (MutableIndexSet *self, const Range range)
 Adds indexes in the specified Range to this MutableIndexSet. More...
 
MutableIndexSetinit (MutableIndexSet *self)
 Initializes this MutableIndexSet. More...
 
MutableIndexSetinitWithCapacity (MutableIndexSet *self, size_t capacity)
 Initializes this MutableIndexSet with the specified capacity. More...
 
void removeAllIndexes (MutableIndexSet *self)
 Removes all indexes from this MutableIndexSet. More...
 
void removeIndex (MutableIndexSet *self, size_t index)
 Removes the specified index from this MutableIndexSet. More...
 
void removeIndexes (MutableIndexSet *self, size_t *indexes, size_t count)
 Removes the specified indexes from this MutableIndexSet. More...
 
void removeIndexesInRange (MutableIndexSet *self, const Range range)
 Removes indexes in the specified Range from this MutableIndexSet. More...
 
- Methods inherited from IndexSet
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

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

Property Details

◆ capacity

size_t MutableIndexSet::capacity

The capacity.

Definition at line 57 of file MutableIndexSet.h.

◆ indexSet

IndexSet MutableIndexSet::indexSet

The superclass.

Definition at line 46 of file MutableIndexSet.h.

◆ interface

MutableIndexSetInterface* MutableIndexSet::interface
protected

The interface.

Definition at line 52 of file MutableIndexSet.h.

Method Details

◆ _MutableIndexSet()

Class * _MutableIndexSet ( void  )

The MutableIndexSet archetype.

Returns
The MutableIndexSet Class.

Definition at line 211 of file MutableIndexSet.c.

211 {
212 static Class *clazz;
213 static Once once;
214
215 do_once(&once, {
216 clazz = _initialize(&(const ClassDef) {
217 .name = "MutableIndexSet",
218 .superclass = _IndexSet(),
219 .instanceSize = sizeof(MutableIndexSet),
220 .interfaceOffset = offsetof(MutableIndexSet, interface),
221 .interfaceSize = sizeof(MutableIndexSetInterface),
223 });
224 });
225
226 return clazz;
227}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void initialize(Class *clazz)
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
Class * _IndexSet(void)
The IndexSet archetype.
Definition: IndexSet.c:218
Mutable collections of unique index values.
MutableIndexSetInterface * interface
The interface.
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition: Object.h:51

◆ addIndex()

void addIndex ( MutableIndexSet self,
size_t  index 
)

Adds the specified index to this MutableIndexSet.

Parameters
selfThe MutableIndexSet.
indexThe index to add.

Definition at line 51 of file MutableIndexSet.c.

51 {
52
53 IndexSet *this = &self->indexSet;
54
55 size_t i;
56 for (i = 0; i < this->count; i++) {
57 if (this->indexes[i] == index) {
58 return;
59 }
60 if (this->indexes[i] > index) {
61 break;
62 }
63 }
64
65 if (this->count == self->capacity) {
67
68 this->indexes = realloc(this->indexes, self->capacity * sizeof(size_t));
69 assert(this->indexes);
70 }
71
72 for (size_t j = this->count; j > i; j--) {
73 this->indexes[j] = this->indexes[j - 1];
74 }
75
76 this->indexes[i] = index;
77 this->count++;
78}
#define INDEX_SET_CHUNK_SIZE
Immutable collections of unique index values.
Definition: IndexSet.h:41
size_t * indexes
The indexes.
Definition: IndexSet.h:57
size_t count
The count of indexes.
Definition: IndexSet.h:62
size_t capacity
The capacity.
IndexSet indexSet
The superclass.

◆ addIndexes()

void addIndexes ( MutableIndexSet self,
size_t *  indexes,
size_t  count 
)

Adds the specified indexes to this MutableIndexSet.

Parameters
selfThe MutableIndexSet.
indexesThe indexes to add.
countThe count of indexes.

Definition at line 84 of file MutableIndexSet.c.

84 {
85
86 for (size_t i = 0; i < count; i++) {
87 $(self, addIndex, indexes[i]);
88 }
89}
void addIndex(MutableIndexSet *self, size_t index)
Adds the specified index to this MutableIndexSet.

◆ addIndexesInRange()

void addIndexesInRange ( MutableIndexSet self,
const Range  range 
)

Adds indexes in the specified Range to this MutableIndexSet.

Parameters
selfThe MutableIndexSet.
rangeThe Range of indexes to add.

Definition at line 98 of file MutableIndexSet.c.

98 {
99
100 for (size_t i = range.location; i < range.length; i++) {
101 $(self, addIndex, i);
102 }
103}
ssize_t location
The location.
Definition: Types.h:59
size_t length
The length.
Definition: Types.h:64

◆ init()

MutableIndexSet * init ( MutableIndexSet self)

Initializes this MutableIndexSet.

Parameters
selfThe MutableIndexSet.
Returns
The initialized MutableIndexSet, or NULL on error.

Definition at line 109 of file MutableIndexSet.c.

109 {
110 return $(self, initWithCapacity, INDEX_SET_CHUNK_SIZE);
111}
MutableIndexSet * initWithCapacity(MutableIndexSet *self, size_t capacity)
Initializes this MutableIndexSet with the specified capacity.

◆ initWithCapacity()

MutableIndexSet * initWithCapacity ( MutableIndexSet self,
size_t  capacity 
)

Initializes this MutableIndexSet with the specified capacity.

Parameters
selfThe MutableIndexSet.
capacityThe capacity.
Returns
The initialized MutableIndexSet, or NULL on error.

Definition at line 117 of file MutableIndexSet.c.

117 {
118
119 self = (MutableIndexSet *) super(Object, self, init);
120 if (self) {
121 self->capacity = capacity;
122
123 IndexSet *this = & self->indexSet;
124
125 this->indexes = malloc(self->capacity * sizeof(size_t));
126 assert(this->indexes);
127 }
128
129 return self;
130}
#define super(type, obj, method,...)
MutableIndexSet * init(MutableIndexSet *self)
Initializes this MutableIndexSet.
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46

◆ removeAllIndexes()

void removeAllIndexes ( MutableIndexSet self)

Removes all indexes from this MutableIndexSet.

Parameters
selfThe MutableIndexSet.

Definition at line 136 of file MutableIndexSet.c.

136 {
137
138 IndexSet *this = &self->indexSet;
139
140 free(this->indexes);
141 this->indexes = NULL;
142
143 this->count = 0;
144 self->capacity = 0;
145}

◆ removeIndex()

void removeIndex ( MutableIndexSet self,
size_t  index 
)

Removes the specified index from this MutableIndexSet.

Parameters
selfThe MutableIndexSet.
indexThe index to remove.

Definition at line 151 of file MutableIndexSet.c.

151 {
152
153 IndexSet *this = &self->indexSet;
154 for (size_t i = 0; i < this->count; i++) {
155 if (this->indexes[i] == index) {
156 this->count--;
157 for (size_t j = i; j < this->count; j++) {
158 this->indexes[j] = this->indexes[j + 1];
159 }
160 return;
161 }
162 }
163}

◆ removeIndexes()

void removeIndexes ( MutableIndexSet self,
size_t *  indexes,
size_t  count 
)

Removes the specified indexes from this MutableIndexSet.

Parameters
selfThe MutableIndexSet.
indexesThe indexes to remove.
countThe count of indexes.

Definition at line 169 of file MutableIndexSet.c.

169 {
170
171 for (size_t i = 0; i < count; i++) {
172 $(self, removeIndex, indexes[i]);
173 }
174}
void removeIndex(MutableIndexSet *self, size_t index)
Removes the specified index from this MutableIndexSet.

◆ removeIndexesInRange()

void removeIndexesInRange ( MutableIndexSet self,
const Range  range 
)

Removes indexes in the specified Range from this MutableIndexSet.

Parameters
selfThe MutableIndexSet.
rangeThe Range of indexes to remove.

Definition at line 180 of file MutableIndexSet.c.

180 {
181
182 for (size_t i = range.location; i < range.length; i++) {
183 $(self, removeIndex, i);
184 }
185}

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