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 program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFObject.h"
21#import "OFEnumerator.h"
22
23OF_ASSUME_NONNULL_BEGIN
24
32typedef struct {
34 void *_Nullable (*_Nullable retain)(void *_Nullable object);
36 void (*_Nullable release)(void *_Nullable object);
38 unsigned long (*_Nullable hash)(void *_Nullable object);
40 bool (*_Nullable equal)(void *_Nullable object1,
41 void *_Nullable object2);
43
44#ifdef OF_HAVE_BLOCKS
53typedef void (^OFMapTableEnumerationBlock)(void *_Nullable key,
54 void *_Nullable object, bool *stop);
55
63typedef void *_Nullable (^OFMapTableReplaceBlock)(void *_Nullable key,
64 void *_Nullable object);
65#endif
66
68
75OF_SUBCLASSING_RESTRICTED
77{
78 OFMapTableFunctions _keyFunctions, _objectFunctions;
79 struct OFMapTableBucket *_Nonnull *_Nullable _buckets;
80 uint32_t _count, _capacity;
81 unsigned char _rotation;
82 unsigned long _mutations;
83}
84
88@property (readonly, nonatomic) OFMapTableFunctions keyFunctions;
93@property (readonly, nonatomic) OFMapTableFunctions objectFunctions;
98@property (readonly, nonatomic) size_t count;
107+ (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions
108 objectFunctions: (OFMapTableFunctions)objectFunctions;
109
120+ (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions
121 objectFunctions: (OFMapTableFunctions)objectFunctions
122 capacity: (size_t)capacity;
123
124- (instancetype)init OF_UNAVAILABLE;
125
134- (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions
135 objectFunctions: (OFMapTableFunctions)objectFunctions;
136
147- (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions
148 objectFunctions: (OFMapTableFunctions)objectFunctions
149 capacity: (size_t)capacity
150 OF_DESIGNATED_INITIALIZER;
151
158- (nullable void *)objectForKey: (void *)key;
159
166- (void)setObject: (nullable void *)object forKey: (nullable void *)key;
167
173- (void)removeObjectForKey: (nullable void *)key;
174
178- (void)removeAllObjects;
179
187- (bool)containsObject: (nullable void *)object;
188
197- (bool)containsObjectIdenticalTo: (nullable void *)object;
198
205- (OFMapTableEnumerator *)keyEnumerator;
206
213- (OFMapTableEnumerator *)objectEnumerator;
214
215#ifdef OF_HAVE_BLOCKS
221- (void)enumerateKeysAndObjectsUsingBlock: (OFMapTableEnumerationBlock)block;
222
228- (void)replaceObjectsUsingBlock: (OFMapTableReplaceBlock)block;
229#endif
230@end
231
238#ifndef OF_MAP_TABLE_M
239OF_SUBCLASSING_RESTRICTED
240#endif
243 OFMapTable *_mapTable;
244 struct OFMapTableBucket *_Nonnull *_Nullable _buckets;
245 uint32_t _capacity;
246 unsigned long _mutations, *_Nullable _mutationsPtr, _position;
247}
248
249- (instancetype)init OF_UNAVAILABLE;
250
257- (void *_Nullable *_Nullable)nextObject;
258@end
259
260OF_ASSUME_NONNULL_END
void *(^ OFMapTableReplaceBlock)(void *key, void *object)
A block for replacing objects in an OFMapTable.
Definition OFMapTable.h:63
void(^ OFMapTableEnumerationBlock)(void *key, void *object, bool *stop)
A block for enumerating an OFMapTable.
Definition OFMapTable.h:53
A class which provides methods to enumerate through an OFMapTable's keys or objects.
Definition OFMapTable.h:243
A class similar to OFDictionary, but providing more options how keys and objects should be retained,...
Definition OFMapTable.h:78
The root class for all other classes inside ObjFW.
Definition OFObject.h:692
A protocol for the creation of copies.
Definition OFObject.h:1350
A protocol for fast enumeration.
Definition OFEnumerator.h:79
A struct describing the functions to be used by the map table.
Definition OFMapTable.h:32