ObjFW
OFMapTable.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2021 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 
19 OF_ASSUME_NONNULL_BEGIN
20 
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);
38 };
40 
41 #ifdef OF_HAVE_BLOCKS
50 typedef void (^of_map_table_enumeration_block_t)(void *_Nullable key,
51  void *_Nullable object, bool *stop);
52 
61  void *_Nullable object);
62 #endif
63 
65 
72 OF_SUBCLASSING_RESTRICTED
74 {
75  of_map_table_functions_t _keyFunctions, _objectFunctions;
76  struct of_map_table_bucket *_Nonnull *_Nullable _buckets;
77  unsigned long _count, _capacity;
78  unsigned char _rotate;
79  unsigned long _mutations;
80 }
81 
85 @property (readonly, nonatomic) of_map_table_functions_t keyFunctions;
86 
90 @property (readonly, nonatomic) of_map_table_functions_t objectFunctions;
91 
95 @property (readonly, nonatomic) size_t count;
96 
104 + (instancetype)mapTableWithKeyFunctions: (of_map_table_functions_t)keyFunctions
105  objectFunctions: (of_map_table_functions_t)
106  objectFunctions;
107 
118 + (instancetype)mapTableWithKeyFunctions: (of_map_table_functions_t)keyFunctions
119  objectFunctions: (of_map_table_functions_t)
120  objectFunctions
121  capacity: (size_t)capacity;
122 
123 - (instancetype)init OF_UNAVAILABLE;
124 
133 - (instancetype)initWithKeyFunctions: (of_map_table_functions_t)keyFunctions
134  objectFunctions: (of_map_table_functions_t)objectFunctions;
135 
146 - (instancetype)initWithKeyFunctions: (of_map_table_functions_t)keyFunctions
147  objectFunctions: (of_map_table_functions_t)objectFunctions
148  capacity: (size_t)capacity
149  OF_DESIGNATED_INITIALIZER;
150 
157 - (nullable void *)objectForKey: (void *)key;
158 
165 - (void)setObject: (nullable void *)object forKey: (nullable void *)key;
166 
172 - (void)removeObjectForKey: (nullable void *)key;
173 
177 - (void)removeAllObjects;
178 
186 - (bool)containsObject: (nullable void *)object;
187 
196 - (bool)containsObjectIdenticalTo: (nullable void *)object;
197 
204 - (OFMapTableEnumerator *)keyEnumerator;
205 
212 - (OFMapTableEnumerator *)objectEnumerator;
213 
214 #ifdef OF_HAVE_BLOCKS
220 - (void)enumerateKeysAndObjectsUsingBlock:
222 
228 - (void)replaceObjectsUsingBlock: (of_map_table_replace_block_t)block;
229 #endif
230 @end
231 
238 @interface OFMapTableEnumerator: OFObject
239 {
240  OFMapTable *_mapTable;
241  struct of_map_table_bucket *_Nonnull *_Nullable _buckets;
242  unsigned long _capacity, _mutations, *_Nullable _mutationsPtr;
243  unsigned long _position;
244 }
245 
246 - (instancetype)init OF_UNAVAILABLE;
247 
254 - (void *_Nullable *_Nullable)nextObject;
255 @end
256 
257 OF_ASSUME_NONNULL_END
void *_Nullable(^ of_map_table_replace_block_t)(void *_Nullable key, void *_Nullable object)
A block for replacing objects in an OFMapTable.
Definition: OFMapTable.h:60
void(^ of_map_table_enumeration_block_t)(void *_Nullable key, void *_Nullable object, bool *stop)
A block for enumerating an OFMapTable.
Definition: OFMapTable.h:50
A class which provides methods to enumerate through an OFMapTable's keys or objects.
Definition: OFMapTable.h:240
A class similar to OFDictionary, but providing more options how keys and objects should be retained,...
Definition: OFMapTable.h:75
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A protocol for the creation of copies.
Definition: OFObject.h:1187
A protocol for fast enumeration.
Definition: OFEnumerator.h:71
A struct describing the functions to be used by the map table.
Definition: OFMapTable.h:28
void *_Nullable(* _Nullable)(void *_Nullable object)
Definition: OFMapTable.h:30