35static int compare(
const void *a,
const void *b) {
37 const size_t sa = *(
size_t *) a;
38 const size_t sb = *(
size_t *) b;
40 return sa < sb ? -1 : sa > sb ? 1 : 0;
46static size_t compact(
size_t *indexes,
size_t count) {
51 qsort(indexes, count,
sizeof(
size_t),
compare);
53 for (
size_t i = 1; i < count; i++) {
54 if (indexes[i] != indexes[size]) {
55 indexes[++size] = indexes[i];
65#define _Class _IndexSet
100 for (
size_t i = 0; i < this->count; i++) {
102 if (i < this->count - 1) {
120 for (
size_t i = 0; i < this->count; i++) {
141 if (this->count == that->
count) {
142 return memcmp(this->indexes, that->
indexes, this->count *
sizeof(
size_t)) == 0;
149#pragma mark - IndexSet
157 for (
size_t i = 0; i < self->
count; i++) {
158 if (self->
indexes[i] == index) {
189 memcpy(self->
indexes, indexes,
sizeof(
size_t) * self->
count);
196#pragma mark - Class lifecycle
227 .interfaceOffset = offsetof(
IndexSet, interface),
228 .interfaceSize =
sizeof(IndexSetInterface),
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.
Utilities for calculating hash values.
#define HASH_SEED
The hash seed value.
static int compare(const void *a, const void *b)
qsort comparator for indexes.
static size_t compact(size_t *indexes, size_t count)
Sorts and compacts the given array to contain only unique values.
static void initialize(Class *clazz)
Immutable collections of unique index values.
#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.
ident interface
The interface of the Class.
Condition * init(Condition *self)
Initializes this Condition.
IndexPath * initWithIndexes(IndexPath *self, size_t *indexes, size_t length)
Initializes this IndexPath with the specified indexes and length.
IndexPath * initWithIndex(IndexPath *self, size_t index)
Initializes this IndexPath with the specified index.
Immutable collections of unique index values.
size_t * indexes
The indexes.
Class * _IndexSet(void)
The IndexSet archetype.
size_t count
The count of indexes.
_Bool containsIndex(const IndexSet *self, size_t index)
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.
Object is the root Class of The Objectively Class hierarchy.
Class * _Object(void)
The Object archetype.
Object * copy(const Object *self)
Creates a shallow copy of this Object.
_Bool isKindOfClass(const Object *self, const Class *clazz)
Tests for Class hierarchy membership.
String * description(const Object *self)
_Bool isEqual(const Object *self, const Object *other)
Tests equality of the other Object.
int hash(const Object *self)
void dealloc(Object *self)
Frees all resources held by this Object.
OBJECTIVELY_EXPORT MutableString * mstr(const char *fmt,...)
A convenience function for instantiating MutableStrings.