ObjFW
OFMapTable.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 #import "OFEnumerator.h"
19 
20 OF_ASSUME_NONNULL_BEGIN
21 
29 typedef struct {
31  void *_Nonnull (*_Nullable retain)(void *object);
33  void (*_Nullable release)(void *object);
35  uint32_t (*_Nullable hash)(void *object);
37  bool (*_Nullable equal)(void *object1, void *object2);
39 
40 #ifdef OF_HAVE_BLOCKS
41 
49 typedef void (^of_map_table_enumeration_block_t)(void *key, void *object,
50  bool *stop);
51 
59 typedef void *_Nonnull (^of_map_table_replace_block_t)(void *key, void *object);
60 #endif
61 
63 
71 {
72  of_map_table_functions_t _keyFunctions, _objectFunctions;
73  struct of_map_table_bucket **_buckets;
74  uint32_t _count, _capacity;
75  uint8_t _rotate;
76  unsigned long _mutations;
77 }
78 
82 @property (readonly, nonatomic) of_map_table_functions_t keyFunctions;
83 
87 @property (readonly, nonatomic) of_map_table_functions_t objectFunctions;
88 
96 + (instancetype)mapTableWithKeyFunctions: (of_map_table_functions_t)keyFunctions
97  objectFunctions: (of_map_table_functions_t)
98  objectFunctions;
99 
110 + (instancetype)mapTableWithKeyFunctions: (of_map_table_functions_t)keyFunctions
111  objectFunctions: (of_map_table_functions_t)
112  objectFunctions
113  capacity: (size_t)capacity;
114 
115 - init OF_UNAVAILABLE;
116 
125 - initWithKeyFunctions: (of_map_table_functions_t)keyFunctions
126  objectFunctions: (of_map_table_functions_t)objectFunctions;
127 
138 - initWithKeyFunctions: (of_map_table_functions_t)keyFunctions
139  objectFunctions: (of_map_table_functions_t)objectFunctions
140  capacity: (size_t)capacity OF_DESIGNATED_INITIALIZER;
141 
147 - (size_t)count;
148 
155 - (nullable void *)objectForKey: (void *)key;
156 
163 - (void)setObject: (void *)object
164  forKey: (void *)key;
165 
171 - (void)removeObjectForKey: (void *)key;
172 
176 - (void)removeAllObjects;
177 
185 - (bool)containsObject: (nullable void *)object;
186 
195 - (bool)containsObjectIdenticalTo: (nullable void *)object;
196 
204 
212 
213 #ifdef OF_HAVE_BLOCKS
214 
219 - (void)enumerateKeysAndObjectsUsingBlock:
221 
227 - (void)replaceObjectsUsingBlock: (of_map_table_replace_block_t)block;
228 #endif
229 @end
230 
237 @interface OFMapTableEnumerator: OFObject
238 {
239  OFMapTable *_mapTable;
240  struct of_map_table_bucket **_buckets;
241  uint32_t _capacity;
242  unsigned long _mutations;
243  unsigned long *_mutationsPtr;
244  uint32_t _position;
245 }
246 
247 - init OF_UNAVAILABLE;
248 
254 - (void *)nextObject;
255 
260 - (void)reset;
261 @end
262 
263 OF_ASSUME_NONNULL_END
of_map_table_functions_t keyFunctions
Definition: OFMapTable.h:83
OFMapTableEnumerator * keyEnumerator()
Returns an OFMapTableEnumerator to enumerate through the map table&#39;s keys.
Definition: OFMapTable.m:576
A struct describing the functions to be used by the map table.
Definition: OFMapTable.h:29
OFMapTableEnumerator * objectEnumerator()
Returns an OFMapTableEnumerator to enumerate through the map table&#39;s objects.
Definition: OFMapTable.m:585
size_t count()
Returns the number of objects in the map table.
Definition: OFMapTable.m:260
A class which provides methods to enumerate through an OFMapTable&#39;s keys or objects.
Definition: OFMapTable.h:238
id init()
Initializes an already allocated object.
Definition: OFObject.m:488
A protocol for the creation of copies.
Definition: OFObject.h:912
A protocol for fast enumeration.
Definition: OFEnumerator.h:105
void(^ of_map_table_enumeration_block_t)(void *key, void *object, bool *stop)
A block for enumerating an OFMapTable.
Definition: OFMapTable.h:49
void *_Nonnull(^ of_map_table_replace_block_t)(void *key, void *object)
A block for replacing objects in an OFMapTable.
Definition: OFMapTable.h:59
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
void removeAllObjects()
Removes all objects.
Definition: OFMapTable.m:513
A class similar to OFDictionary, but providing more options how keys and objects should be retained...
Definition: OFMapTable.h:70
of_map_table_functions_t objectFunctions
Definition: OFMapTable.h:88