ObjFW
Loading...
Searching...
No Matches
OFMapTable.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This file is part of ObjFW. It may be distributed under the terms of the
7 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8 * the packaging of this file.
9 *
10 * Alternatively, it may be distributed under the terms of the GNU General
11 * Public License, either version 2 or 3, which can be found in the file
12 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13 * file.
14 */
15
16#import "OFObject.h"
17#import "OFEnumerator.h"
18
19OF_ASSUME_NONNULL_BEGIN
20
28typedef struct {
30 void *_Nullable (*_Nullable retain)(void *_Nullable object);
32 void (*_Nullable release)(void *_Nullable object);
34 unsigned long (*_Nullable hash)(void *_Nullable object);
36 bool (*_Nullable equal)(void *_Nullable object1,
37 void *_Nullable object2);
39
40#ifdef OF_HAVE_BLOCKS
49typedef void (^OFMapTableEnumerationBlock)(void *_Nullable key,
50 void *_Nullable object, bool *stop);
51
59typedef void *_Nullable (^OFMapTableReplaceBlock)(void *_Nullable key,
60 void *_Nullable object);
61#endif
62
64
71OF_SUBCLASSING_RESTRICTED
73{
74 OFMapTableFunctions _keyFunctions, _objectFunctions;
75 struct OFMapTableBucket *_Nonnull *_Nullable _buckets;
76 uint32_t _count, _capacity;
77 unsigned char _rotation;
78 unsigned long _mutations;
79}
80
84@property (readonly, nonatomic) OFMapTableFunctions keyFunctions;
89@property (readonly, nonatomic) OFMapTableFunctions objectFunctions;
94@property (readonly, nonatomic) size_t count;
103+ (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions
104 objectFunctions: (OFMapTableFunctions)objectFunctions;
105
116+ (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions
117 objectFunctions: (OFMapTableFunctions)objectFunctions
118 capacity: (size_t)capacity;
119
120- (instancetype)init OF_UNAVAILABLE;
121
130- (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions
131 objectFunctions: (OFMapTableFunctions)objectFunctions;
132
143- (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions
144 objectFunctions: (OFMapTableFunctions)objectFunctions
145 capacity: (size_t)capacity
146 OF_DESIGNATED_INITIALIZER;
147
154- (nullable void *)objectForKey: (void *)key;
155
162- (void)setObject: (nullable void *)object forKey: (nullable void *)key;
163
169- (void)removeObjectForKey: (nullable void *)key;
170
174- (void)removeAllObjects;
175
183- (bool)containsObject: (nullable void *)object;
184
193- (bool)containsObjectIdenticalTo: (nullable void *)object;
194
201- (OFMapTableEnumerator *)keyEnumerator;
202
209- (OFMapTableEnumerator *)objectEnumerator;
210
211#ifdef OF_HAVE_BLOCKS
217- (void)enumerateKeysAndObjectsUsingBlock: (OFMapTableEnumerationBlock)block;
218
224- (void)replaceObjectsUsingBlock: (OFMapTableReplaceBlock)block;
225#endif
226@end
227
234#ifndef OF_MAP_TABLE_M
235OF_SUBCLASSING_RESTRICTED
236#endif
239 OFMapTable *_mapTable;
240 struct OFMapTableBucket *_Nonnull *_Nullable _buckets;
241 uint32_t _capacity;
242 unsigned long _mutations, *_Nullable _mutationsPtr, _position;
243}
244
245- (instancetype)init OF_UNAVAILABLE;
246
253- (void *_Nullable *_Nullable)nextObject;
254@end
255
256OF_ASSUME_NONNULL_END
void *(^ OFMapTableReplaceBlock)(void *key, void *object)
A block for replacing objects in an OFMapTable.
Definition OFMapTable.h:59
void(^ OFMapTableEnumerationBlock)(void *key, void *object, bool *stop)
A block for enumerating an OFMapTable.
Definition OFMapTable.h:49
A class which provides methods to enumerate through an OFMapTable's keys or objects.
Definition OFMapTable.h:239
A class similar to OFDictionary, but providing more options how keys and objects should be retained,...
Definition OFMapTable.h:74
The root class for all other classes inside ObjFW.
Definition OFObject.h:688
A protocol for the creation of copies.
Definition OFObject.h:1346
A protocol for fast enumeration.
Definition OFEnumerator.h:75
A struct describing the functions to be used by the map table.
Definition OFMapTable.h:28