#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "Hash.h"
#include "IndexSet.h"
#include "MutableString.h"
Go to the source code of this file.
◆ _Class
◆ _IndexSet()
Class * _IndexSet |
( |
void |
| ) |
|
Definition at line 218 of file IndexSet.c.
218 {
221
224 .name = "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.
static void initialize(Class *clazz)
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
Immutable collections of unique index values.
Class * _Object(void)
The Object archetype.
◆ compact()
static size_t compact |
( |
size_t * |
indexes, |
|
|
size_t |
count |
|
) |
| |
|
static |
Sorts and compacts the given array to contain only unique values.
Definition at line 46 of file IndexSet.c.
46 {
47
48 size_t size = 0;
49
50 if (count) {
51 qsort(indexes, count,
sizeof(
size_t),
compare);
52
53 for (size_t i = 1; i < count; i++) {
54 if (indexes[i] != indexes[size]) {
55 indexes[++size] = indexes[i];
56 }
57 }
58
59 size++;
60 }
61
62 return size;
63}
static int compare(const void *a, const void *b)
qsort comparator for indexes.
◆ compare()
static int compare |
( |
const void * |
a, |
|
|
const void * |
b |
|
) |
| |
|
static |
qsort comparator for indexes.
Definition at line 35 of file IndexSet.c.
35 {
36
37 const size_t sa = *(size_t *) a;
38 const size_t sb = *(size_t *) b;
39
40 return sa < sb ? -1 : sa > sb ? 1 : 0;
41}
◆ containsIndex()
static _Bool containsIndex |
( |
const IndexSet * |
self, |
|
|
size_t |
index |
|
) |
| |
|
static |
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.
size_t count
The count of indexes.
◆ copy()
- See also
- Object::copy(const Object *)
Definition at line 72 of file IndexSet.c.
72 {
73
76
78}
#define alloc(type)
Allocate and initialize and instance of type.
IndexPath * initWithIndexes(IndexPath *self, size_t *indexes, size_t length)
Initializes this IndexPath with the specified indexes and length.
Object is the root Class of The Objectively Class hierarchy.
◆ dealloc()
static void dealloc |
( |
Object * |
self | ) |
|
|
static |
- See also
- Object::dealloc(Object *)
Definition at line 83 of file IndexSet.c.
83 {
84
86
87 free(this->indexes);
88
90}
#define super(type, obj, method,...)
void dealloc(Object *self)
Frees all resources held by this Object.
◆ description()
- See also
- Object::description(const Object *)
Definition at line 95 of file IndexSet.c.
95 {
96
99
100 for (size_t i = 0; i < this->count; i++) {
102 if (i < this->count - 1) {
104 }
105 }
106
109}
void appendFormat(MutableString *self, const char *fmt,...)
Appends the specified formatted string.
void appendCharacters(MutableString *self, const char *chars)
Appends the specified UTF-8 encoded C string.
OBJECTIVELY_EXPORT MutableString * mstr(const char *fmt,...)
A convenience function for instantiating MutableStrings.
◆ hash()
static int hash |
( |
const Object * |
self | ) |
|
|
static |
- See also
- Object::hash(const Object *)
Definition at line 114 of file IndexSet.c.
114 {
115
117
119
120 for (size_t i = 0; i < this->count; i++) {
122 }
123
125}
int HashForInteger(int hash, const long integer)
Accumulates the hash value of integer into hash.
#define HASH_SEED
The hash seed value.
int hash(const Object *self)
◆ initialize()
static void initialize |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::initialize(Class *)
Definition at line 201 of file IndexSet.c.
201 {
202
208
212}
ident interface
The interface of the Class.
IndexPath * initWithIndex(IndexPath *self, size_t index)
Initializes this IndexPath with the specified index.
_Bool containsIndex(const IndexSet *self, size_t index)
Object * copy(const Object *self)
Creates a shallow copy of this Object.
String * description(const Object *self)
_Bool isEqual(const Object *self, const Object *other)
Tests equality of the other Object.
◆ initWithIndex()
◆ initWithIndexes()
static IndexSet * initWithIndexes |
( |
IndexSet * |
self, |
|
|
size_t * |
indexes, |
|
|
size_t |
count |
|
) |
| |
|
static |
Definition at line 178 of file IndexSet.c.
178 {
179
181 if (self) {
182
185
188
189 memcpy(self->
indexes, indexes,
sizeof(
size_t) * self->
count);
190 }
191 }
192
193 return self;
194}
static size_t compact(size_t *indexes, size_t count)
Sorts and compacts the given array to contain only unique values.
Condition * init(Condition *self)
Initializes this Condition.
◆ isEqual()
static _Bool isEqual |
( |
const Object * |
self, |
|
|
const Object * |
other |
|
) |
| |
|
static |
- See also
- Object::isEqual(const Object *, const Object *)
Definition at line 130 of file IndexSet.c.
130 {
131
133 return true;
134 }
135
137
140
141 if (this->count == that->
count) {
142 return memcmp(this->indexes, that->
indexes, this->count *
sizeof(
size_t)) == 0;
143 }
144 }
145
146 return false;
147}
Class * _IndexSet(void)
The IndexSet archetype.
_Bool isKindOfClass(const Object *self, const Class *clazz)
Tests for Class hierarchy membership.