Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
Dictionary.c
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#include <assert.h>
25#include <stdarg.h>
26#include <stdlib.h>
27
28#include "Dictionary.h"
29#include "Hash.h"
30#include "String.h"
31#include "Null.h"
32
33#define _Class _Dictionary
34
35#define DICTIONARY_DEFAULT_CAPACITY 64
36#define DICTIONARY_GROW_FACTOR 2.0
37#define DICTIONARY_MAX_LOAD 0.75f
38
39#pragma mark - Object
40
44static Object *copy(const Object *self) {
45
46 const Dictionary *this = (const Dictionary *) self;
47
48 Dictionary *that = $(alloc(Dictionary), initWithCapacity, this->capacity);
49 if (that) {
50 $(that, addEntriesFromDictionary, this);
51 }
52
53 return (Object *) that;
54}
55
59static void dealloc(Object *self) {
60
61 Dictionary *this = (Dictionary *) self;
62
63 for (size_t i = 0; i < this->capacity; i++) {
64 release(this->elements[i]);
65 }
66
67 free(this->elements);
68
69 super(Object, self, dealloc);
70}
71
75static void description_enumerator(const Dictionary *dict, ident obj, ident key, ident data) {
76
77 String *desc = (String *) data;
78
79 String *objDesc = $((Object *) obj, description);
80 String *keyDesc = $((Object *) key, description);
81
82 $(desc, appendFormat, "%s: %s, ", keyDesc->chars, objDesc->chars);
83
84 release(objDesc);
85 release(keyDesc);
86}
87
91static String *description(const Object *self) {
92
93 const Dictionary *this = (Dictionary *) self;
94
95 String *desc = $(alloc(String), init);
96
97 $(desc, appendCharacters, "{");
98
100
101 $(desc, appendCharacters, "}");
102
103 return (String *) desc;
104}
105
109static int hash(const Object *self) {
110
111 const Dictionary *this = (Dictionary *) self;
112
113 int hash = HashForInteger(HASH_SEED, this->count);
114
115 for (size_t i = 0; i < this->capacity; i++) {
116 if (this->elements[i]) {
117 hash = HashForObject(hash, this->elements[i]);
118 }
119 }
120
121 return hash;
122}
123
127static bool isEqual(const Object *self, const Object *other) {
128
129 if (super(Object, self, isEqual, other)) {
130 return true;
131 }
132
133 if (other && $(other, isKindOfClass, _Dictionary())) {
134
135 const Dictionary *this = (Dictionary *) self;
136 const Dictionary *that = (Dictionary *) other;
137
138 if (this->count == that->count) {
139
140 Array *keys = $(this, allKeys);
141
142 for (size_t i = 0; i < keys->count; i++) {
143 const ident key = $(keys, objectAtIndex, i);
144
145 const Object *thisObject = $(this, objectForKey, key);
146 const Object *thatObject = $(that, objectForKey, key);
147
148 if ($(thisObject, isEqual, thatObject) == false) {
149 release(keys);
150 return false;
151 }
152 }
153
154 release(keys);
155 return true;
156 }
157 }
158
159 return false;
160}
161
162#pragma mark - Dictionary
163
168 $((Dictionary *) data, setObjectForKey, obj, key);
169}
170
181
185static void allKeys_enumerator(const Dictionary *dict, ident obj, ident key, ident data) {
186 $((Array *) data, addObject, key);
187}
188
193static Array *allKeys(const Dictionary *self) {
194
195 Array *keys = $(alloc(Array), initWithCapacity, self->count);
196
198
199 return (Array *) keys;
200}
201
205static void allObjects_enumerator(const Dictionary *dict, ident obj, ident key, ident data) {
206 $((Array *) data, addObject, obj);
207}
208
213static Array *allObjects(const Dictionary *self) {
214
215 Array *objects = $(alloc(Array), initWithCapacity, self->count);
216
218
219 return (Array *) objects;
220}
221
226static bool containsKey(const Dictionary *self, const ident key) {
227 return $(self, objectForKey, key) != NULL;
228}
229
234static bool containsKeyPath(const Dictionary *self, const char *path) {
235 return $(self, objectForKeyPath, path) != NULL;
236}
237
242static Dictionary *dictionary(void) {
243
244 return $(alloc(Dictionary), init);
245}
246
251static Dictionary *dictionaryWithCapacity(size_t capacity) {
252
253 return $(alloc(Dictionary), initWithCapacity, capacity);
254}
255
264
270
271 Dictionary *dict = (Dictionary *) $((Object *) alloc(Dictionary), init);
272 if (dict) {
273
274 va_list args;
275 va_start(args, obj);
276
277 while (obj) {
278 ident key = va_arg(args, ident);
279
280 $(dict, setObjectForKey, obj, key);
281
282 obj = va_arg(args, ident);
283 }
284
285 va_end(args);
286 }
287
288 return dict;
289}
290
295static void enumerateObjectsAndKeys(const Dictionary *self, DictionaryEnumerator enumerator,
296 ident data) {
297
298 assert(enumerator);
299
300 for (size_t i = 0; i < self->capacity; i++) {
301
302 Array *array = self->elements[i];
303 if (array) {
304
305 for (size_t j = 0; j < array->count; j += 2) {
306
307 ident key = $(array, objectAtIndex, j);
308 ident obj = $(array, objectAtIndex, j + 1);
309
310 enumerator(self, obj, key, data);
311 }
312 }
313 }
314}
315
321
322 assert(predicate);
323
325
326 for (size_t i = 0; i < self->capacity; i++) {
327
328 Array *array = self->elements[i];
329 if (array) {
330
331 for (size_t j = 0; j < array->count; j += 2) {
332
333 ident key = $(array, objectAtIndex, j);
334 ident obj = $(array, objectAtIndex, j + 1);
335
336 if (predicate(obj, key, data)) {
338 }
339 }
340 }
341 }
342
343 return dictionary;
344}
345
350static Dictionary *init(Dictionary *self) {
351
353}
354
359static Dictionary *initWithCapacity(Dictionary *self, size_t capacity) {
360
361 self = (Dictionary *) super(Object, self, init);
362 if (self) {
363
364 self->capacity = capacity;
365 if (self->capacity) {
366
367 self->elements = calloc(self->capacity, sizeof(ident));
368 assert(self->elements);
369 }
370 }
371
372 return self;
373}
374
380
381 self = (Dictionary *) super(Object, self, init);
382 if (self) {
383 if (dictionary) {
384
385 self->capacity = dictionary->capacity;
386
387 self->elements = calloc(self->capacity, sizeof(ident));
388 assert(self->elements);
389
390 for (size_t i = 0; i < dictionary->capacity; i++) {
391
392 Array *array = dictionary->elements[i];
393 if (array) {
394 self->elements[i] = $((Object *) array, copy);
395 }
396 }
397
398 self->count = dictionary->count;
399 }
400 }
401
402 return self;
403}
404
410
411 self = (Dictionary *) super(Object, self, init);
412 if (self) {
413
414 va_list args;
415 va_start(args, self);
416
417 while (true) {
418
419 ident obj = va_arg(args, ident);
420 if (obj) {
421
422 ident key = va_arg(args, ident);
423 $(self, setObjectForKey, obj, key);
424 } else {
425 break;
426 }
427 }
428
429 va_end(args);
430 }
431
432 return self;
433}
434
439static ident objectForKey(const Dictionary *self, const ident key) {
440
441 if (self->capacity == 0) {
442 return NULL;
443 }
444
445 const size_t bin = HashForObject(HASH_SEED, key) % self->capacity;
446
447 Array *array = self->elements[bin];
448 if (array) {
449
450 const ssize_t index = $(array, indexOfObject, key);
451 if (index > -1 && (index & 1) == 0) {
452 return $(array, objectAtIndex, index + 1);
453 }
454 }
455
456 return NULL;
457}
458
463static ident objectForKeyPath(const Dictionary *self, const char *path) {
464
465 assert(path);
466
467 String *key = str(path);
468
469 ident obj = $(self, objectForKey, key);
470
471 release(key);
472
473 return obj;
474}
475
480static ident objectForKeyPathWithClass(const Dictionary *self, const char *path, const Class *clazz) {
481
482 assert(path);
483
484 const ident value = $(self, objectForKeyPath, path);
485 if (value) {
486 if (instanceof(Null, value)) {
487 return NULL;
488 } else {
489 return _cast(clazz, value);
490 }
491 }
492
493 return NULL;
494}
495
500static void removeAllObjects(Dictionary *self) {
501
502 for (size_t i = 0; i < self->capacity; i++) {
503
504 Array *array = self->elements[i];
505 if (array) {
506 self->elements[i] = release(array);
507 }
508 }
509
510 self->count = 0;
511}
512
518
519 assert(enumerator);
520
521 for (size_t i = 0; i < self->capacity; i++) {
522
523 Array *array = self->elements[i];
524 if (array) {
525 for (size_t j = array->count; j > 0; j -= 2) {
526
527 ident obj = array->elements[j - 1];
528 ident key = array->elements[j - 2];
529
530 enumerator(self, obj, key, data);
531
532 $((Array *) array, removeObjectAtIndex, j - 1);
533 $((Array *) array, removeObjectAtIndex, j - 2);
534 }
535
536 self->elements[i] = release(array);
537 }
538 }
539
540 self->count = 0;
541}
542
547static void removeObjectForKey(Dictionary *self, const ident key) {
548
549 if (self->capacity == 0) {
550 return;
551 }
552
553 const size_t bin = HashForObject(HASH_SEED, key) % self->capacity;
554
555 Array *array = self->elements[bin];
556 if (array) {
557
558 const ssize_t index = $((Array *) array, indexOfObject, key);
559 if (index > -1) {
560
561 $(array, removeObjectAtIndex, index);
562 $(array, removeObjectAtIndex, index);
563
564 if (((Array *) array)->count == 0) {
565 self->elements[bin] = release(array);
566 }
567
568 self->count--;
569 }
570 }
571}
572
577static void removeObjectForKeyPath(Dictionary *self, const char *path) {
578
579 String *key = $$(String, stringWithCharacters, path);
580
581 $(self, removeObjectForKey, key);
582
583 release(key);
584}
585
591
592 if (dict->capacity) {
593
594 const float load = dict->count / (float) dict->capacity;
595 if (load >= DICTIONARY_MAX_LOAD) {
596
597 size_t capacity = dict->capacity;
598 ident *elements = dict->elements;
599
600 dict->capacity = dict->capacity * DICTIONARY_GROW_FACTOR;
601 dict->count = 0;
602
603 dict->elements = calloc(dict->capacity, sizeof(ident));
604 assert(dict->elements);
605
606 for (size_t i = 0; i < capacity; i++) {
607
608 Array *array = elements[i];
609 if (array) {
610
611 for (size_t j = 0; j < array->count; j += 2) {
612
613 ident key = $(array, objectAtIndex, j);
614 ident obj = $(array, objectAtIndex, j + 1);
615
616 $$(Dictionary, setObjectForKey, dict, obj, key);
617 }
618
619 release(array);
620 }
621 }
622
623 free(elements);
624 }
625 } else {
627 }
628}
629
634static void setObjectForKey(Dictionary *self, const ident obj, const ident key) {
635
636 Dictionary *dict = self;
637
639
640 const size_t bin = HashForObject(HASH_SEED, key) % dict->capacity;
641
642 Array *array = dict->elements[bin];
643 if (array == NULL) {
644 array = dict->elements[bin] = $$(Array, arrayWithCapacity, (dict->capacity >> 2) + 1);
645 }
646
647 const ssize_t index = $((Array *) array, indexOfObject, key);
648 if (index > -1 && (index & 1) == 0) {
649 $(array, setObjectAtIndex, obj, index + 1);
650 } else {
651 $(array, addObject, key);
652 $(array, addObject, obj);
653
654 dict->count++;
655 }
656}
657
662static void setObjectForKeyPath(Dictionary *self, const ident obj, const char *path) {
663
664 String *key = $$(String, stringWithCharacters, path);
665
666 $(self, setObjectForKey, obj, key);
667
668 release(key);
669}
670
675static void setObjectsForKeyPaths(Dictionary *self, ...) {
676
677 va_list args;
678 va_start(args, self);
679
680 while (true) {
681
682 ident obj = va_arg(args, ident);
683 if (obj) {
684 const char *path = va_arg(args, const char *);
685 $(self, setObjectForKeyPath, obj, path);
686 } else {
687 break;
688 }
689 }
690
691 va_end(args);
692}
693
698static void setObjectsForKeys(Dictionary *self, ...) {
699
700 va_list args;
701 va_start(args, self);
702
703 while (true) {
704
705 ident obj = va_arg(args, ident);
706 if (obj) {
707 ident key = va_arg(args, ident);
708 $(self, setObjectForKey, obj, key);
709 } else {
710 break;
711 }
712 }
713
714 va_end(args);
715}
716
717#pragma mark - Class lifecycle
718
722static void initialize(Class *clazz) {
723
724 ((ObjectInterface *) clazz->interface)->copy = copy;
725 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
726 ((ObjectInterface *) clazz->interface)->description = description;
727 ((ObjectInterface *) clazz->interface)->hash = hash;
728 ((ObjectInterface *) clazz->interface)->isEqual = isEqual;
729
730 ((DictionaryInterface *) clazz->interface)->addEntriesFromDictionary = addEntriesFromDictionary;
731 ((DictionaryInterface *) clazz->interface)->allKeys = allKeys;
732 ((DictionaryInterface *) clazz->interface)->allObjects = allObjects;
733 ((DictionaryInterface *) clazz->interface)->containsKey = containsKey;
734 ((DictionaryInterface *) clazz->interface)->containsKeyPath = containsKeyPath;
735 ((DictionaryInterface *) clazz->interface)->dictionary = dictionary;
736 ((DictionaryInterface *) clazz->interface)->dictionaryWithCapacity = dictionaryWithCapacity;
737 ((DictionaryInterface *) clazz->interface)->dictionaryWithDictionary = dictionaryWithDictionary;
738 ((DictionaryInterface *) clazz->interface)->dictionaryWithObjectsAndKeys = dictionaryWithObjectsAndKeys;
739 ((DictionaryInterface *) clazz->interface)->enumerateObjectsAndKeys = enumerateObjectsAndKeys;
740 ((DictionaryInterface *) clazz->interface)->filterObjectsAndKeys = filterObjectsAndKeys;
741 ((DictionaryInterface *) clazz->interface)->init = init;
742 ((DictionaryInterface *) clazz->interface)->initWithCapacity = initWithCapacity;
743 ((DictionaryInterface *) clazz->interface)->initWithDictionary = initWithDictionary;
744 ((DictionaryInterface *) clazz->interface)->initWithObjectsAndKeys = initWithObjectsAndKeys;
745 ((DictionaryInterface *) clazz->interface)->objectForKey = objectForKey;
746 ((DictionaryInterface *) clazz->interface)->objectForKeyPath = objectForKeyPath;
747 ((DictionaryInterface *) clazz->interface)->objectForKeyPathWithClass = objectForKeyPathWithClass;
748 ((DictionaryInterface *) clazz->interface)->removeAllObjects = removeAllObjects;
749 ((DictionaryInterface *) clazz->interface)->removeAllObjectsWithEnumerator = removeAllObjectsWithEnumerator;
750 ((DictionaryInterface *) clazz->interface)->removeObjectForKey = removeObjectForKey;
751 ((DictionaryInterface *) clazz->interface)->removeObjectForKeyPath = removeObjectForKeyPath;
752 ((DictionaryInterface *) clazz->interface)->setObjectForKey = setObjectForKey;
753 ((DictionaryInterface *) clazz->interface)->setObjectForKeyPath = setObjectForKeyPath;
754 ((DictionaryInterface *) clazz->interface)->setObjectsForKeyPaths = setObjectsForKeyPaths;
755 ((DictionaryInterface *) clazz->interface)->setObjectsForKeys = setObjectsForKeys;
756}
757
763 static Class *clazz;
764 static Once once;
765
766 do_once(&once, {
767 clazz = _initialize(&(const ClassDef) {
768 .name = "Dictionary",
769 .superclass = _Object(),
770 .instanceSize = sizeof(Dictionary),
771 .interfaceOffset = offsetof(Dictionary, interface),
772 .interfaceSize = sizeof(DictionaryInterface),
774 });
775 });
776
777 return clazz;
778}
779
780#undef _Class
static void removeObjectAtIndex(Array *self, size_t index)
Definition Array.c:654
static void setObjectAtIndex(Array *self, const ident obj, size_t index)
Definition Array.c:671
static ident objectAtIndex(const Array *self, size_t index)
Definition Array.c:578
static Array * arrayWithCapacity(size_t capacity)
Definition Array.c:252
static void addObject(Array *self, const ident obj)
Definition Array.c:181
static Array * array(void)
Definition Array.c:234
static ssize_t indexOfObject(const Array *self, const ident obj)
Definition Array.c:403
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Definition Class.c:195
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition Class.c:86
ident _cast(const Class *clazz, const ident obj)
Perform a type-checking cast.
Definition Class.c:142
#define obj
#define alloc(type)
Allocate and initialize and instance of type.
Definition Class.h:176
#define super(type, obj, method,...)
#define instanceof(type, obj)
Test if the given pointer is an instance of the specified type.
Definition Class.h:170
static Data * data(void)
Definition Data.c:286
static void setObjectForKey(Dictionary *self, const ident obj, const ident key)
Definition Dictionary.c:634
Class * _Dictionary(void)
Definition Dictionary.c:762
static void removeAllObjects(Dictionary *self)
Definition Dictionary.c:500
static void setObjectsForKeys(Dictionary *self,...)
Definition Dictionary.c:698
static Dictionary * dictionaryWithDictionary(const Dictionary *dictionary)
Definition Dictionary.c:260
static Dictionary * init(Dictionary *self)
Definition Dictionary.c:350
#define DICTIONARY_DEFAULT_CAPACITY
Definition Dictionary.c:35
static void addEntriesFromDictionary_enumerator(const Dictionary *dict, ident obj, ident key, ident data)
DictionaryEnumerator for addEntriesFromDictionary.
Definition Dictionary.c:167
static void description_enumerator(const Dictionary *dict, ident obj, ident key, ident data)
A DictionaryEnumerator for description.
Definition Dictionary.c:75
static void setObjectsForKeyPaths(Dictionary *self,...)
Definition Dictionary.c:675
static bool containsKeyPath(const Dictionary *self, const char *path)
Definition Dictionary.c:234
static Dictionary * dictionaryWithCapacity(size_t capacity)
Definition Dictionary.c:251
static bool isEqual(const Object *self, const Object *other)
Definition Dictionary.c:127
static void removeObjectForKey(Dictionary *self, const ident key)
Definition Dictionary.c:547
static Array * allObjects(const Dictionary *self)
Definition Dictionary.c:213
static Dictionary * initWithObjectsAndKeys(Dictionary *self,...)
Definition Dictionary.c:409
static void enumerateObjectsAndKeys(const Dictionary *self, DictionaryEnumerator enumerator, ident data)
Definition Dictionary.c:295
static String * description(const Object *self)
Definition Dictionary.c:91
static Dictionary * dictionary(void)
Definition Dictionary.c:242
static Array * allKeys(const Dictionary *self)
Definition Dictionary.c:193
static Dictionary * dictionaryWithObjectsAndKeys(ident obj,...)
Definition Dictionary.c:269
static ident objectForKeyPathWithClass(const Dictionary *self, const char *path, const Class *clazz)
Definition Dictionary.c:480
static ident objectForKey(const Dictionary *self, const ident key)
Definition Dictionary.c:439
static void removeObjectForKeyPath(Dictionary *self, const char *path)
Definition Dictionary.c:577
static void addEntriesFromDictionary(Dictionary *self, const Dictionary *dictionary)
Definition Dictionary.c:175
static void dealloc(Object *self)
Definition Dictionary.c:59
static void setObjectForKeyPath(Dictionary *self, const ident obj, const char *path)
Definition Dictionary.c:662
static Dictionary * initWithCapacity(Dictionary *self, size_t capacity)
Definition Dictionary.c:359
static void setObjectForKey_resize(Dictionary *dict)
A helper for resizing Dictionaries as pairs are added to them.
Definition Dictionary.c:590
static Dictionary * initWithDictionary(Dictionary *self, const Dictionary *dictionary)
Definition Dictionary.c:379
static void allKeys_enumerator(const Dictionary *dict, ident obj, ident key, ident data)
DictionaryEnumerator for allKeys.
Definition Dictionary.c:185
static void allObjects_enumerator(const Dictionary *dict, ident obj, ident key, ident data)
DictionaryEnumerator for allObjects.
Definition Dictionary.c:205
static Dictionary * filterObjectsAndKeys(const Dictionary *self, DictionaryPredicate predicate, ident data)
Definition Dictionary.c:320
static Object * copy(const Object *self)
Definition Dictionary.c:44
static void initialize(Class *clazz)
Definition Dictionary.c:722
static void removeAllObjectsWithEnumerator(Dictionary *self, DictionaryEnumerator enumerator, ident data)
Definition Dictionary.c:517
static bool containsKey(const Dictionary *self, const ident key)
Definition Dictionary.c:226
#define DICTIONARY_GROW_FACTOR
Definition Dictionary.c:36
static ident objectForKeyPath(const Dictionary *self, const char *path)
Definition Dictionary.c:463
#define DICTIONARY_MAX_LOAD
Definition Dictionary.c:37
static int hash(const Object *self)
Definition Dictionary.c:109
Key-value stores.
void(* DictionaryEnumerator)(const Dictionary *dictionary, ident obj, ident key, ident data)
A function type for Dictionary enumeration (iteration).
Definition Dictionary.h:44
bool(* DictionaryPredicate)(ident obj, ident key, ident data)
A function pointer for Dictionary filtering.
Definition Dictionary.h:53
int HashForInteger(int hash, const long integer)
Accumulates the hash value of integer into hash.
Definition Hash.c:66
int HashForObject(int hash, const ident obj)
Accumulates the hash value of object into hash.
Definition Hash.c:72
Utilities for calculating hash values.
#define HASH_SEED
The hash seed value.
Definition Hash.h:37
The Null sentinel.
static bool isKindOfClass(const Object *self, const Class *clazz)
Definition Object.c:101
Class * _Object(void)
Definition Object.c:136
String * str(const char *fmt,...)
Definition String.c:1084
static void appendCharacters(String *self, const char *chars)
Definition String.c:506
static void appendFormat(String *self, const char *fmt,...)
Definition String.c:541
static String * stringWithCharacters(const char *chars)
Definition String.c:349
UTF-8 strings.
void * ident
The identity type, similar to Objective-C id.
Definition Types.h:49
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
Arrays.
Definition Array.h:56
size_t count
The count of elements.
Definition Array.h:72
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
ident interface
The interface of the Class.
Definition Class.h:105
Key-value stores.
Definition Dictionary.h:60
Dictionary * initWithCapacity(Dictionary *self, size_t capacity)
Initializes this Dictionary with the specified capacity.
Definition Dictionary.c:359
Dictionary * dictionaryWithObjectsAndKeys(ident obj,...)
Returns a new Dictionary containing pairs from the given arguments.
Definition Dictionary.c:269
Dictionary * init(Dictionary *self)
Initializes this Dictionary.
Definition Dictionary.c:350
Dictionary * initWithDictionary(Dictionary *self, const Dictionary *dictionary)
Initializes this Dictionary to contain elements of dictionary.
Definition Dictionary.c:379
Dictionary * dictionaryWithCapacity(size_t capacity)
Returns a new Dictionary with the given capacity.
Definition Dictionary.c:251
size_t count
The count of elements.
Definition Dictionary.h:82
Dictionary * dictionaryWithDictionary(const Dictionary *dictionary)
Returns a new Dictionary containing all pairs from dictionary.
Definition Dictionary.c:260
ident objectForKey(const Dictionary *self, const ident key)
Definition Dictionary.c:439
Dictionary * initWithObjectsAndKeys(Dictionary *self,...)
Initializes this Dictionary with the NULL-terminated list of Objects and keys.
Definition Dictionary.c:409
void enumerateObjectsAndKeys(const Dictionary *self, DictionaryEnumerator enumerator, ident data)
Enumerate the pairs of this Dictionary with the given function.
Definition Dictionary.c:295
The Null sentinel.
Definition Null.h:42
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46
int hash(const Object *self)
Definition Array.c:129
void dealloc(Object *self)
Frees all resources held by this Object.
Definition Array.c:99
UTF-8 strings.
Definition String.h:69
char * chars
The backing null-terminated UTF-8 encoded character array.
Definition String.h:85