ObjFW
OFMapTable.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
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 *OF_NONNULL (*OF_NULLABLE retain)(void *value);
33  void (*OF_NULLABLE release)(void *value);
35  uint32_t (*OF_NULLABLE hash)(void *value);
37  bool (*OF_NULLABLE equal)(void *value1, void *value2);
39 
40 #ifdef OF_HAVE_BLOCKS
41 
49 typedef void (^of_map_table_enumeration_block_t)(void *key, void *value,
50  bool *stop);
51 
59 typedef void *OF_NONNULL (^of_map_table_replace_block_t)(
60  void *key, void *value);
61 #endif
62 
64 
72 {
73  of_map_table_functions_t _keyFunctions, _valueFunctions;
74  struct of_map_table_bucket **_buckets;
75  uint32_t _count, _capacity;
76  uint8_t _rotate;
77  unsigned long _mutations;
78 }
79 
87 + (instancetype)mapTableWithKeyFunctions: (of_map_table_functions_t)keyFunctions
88  valueFunctions: (of_map_table_functions_t)
89  valueFunctions;
90 
101 + (instancetype)mapTableWithKeyFunctions: (of_map_table_functions_t)keyFunctions
102  valueFunctions: (of_map_table_functions_t)
103  valueFunctions
104  capacity: (size_t)capacity;
105 
114 - initWithKeyFunctions: (of_map_table_functions_t)keyFunctions
115  valueFunctions: (of_map_table_functions_t)valueFunctions;
116 
127 - initWithKeyFunctions: (of_map_table_functions_t)keyFunctions
128  valueFunctions: (of_map_table_functions_t)valueFunctions
129  capacity: (size_t)capacity;
130 
136 - (size_t)count;
137 
144 - (nullable void*)valueForKey: (void*)key;
145 
152 - (void)setValue: (void*)value
153  forKey: (void*)key;
154 
160 - (void)removeValueForKey: (void*)key;
161 
165 - (void)removeAllValues;
166 
174 - (bool)containsValue: (nullable void*)value;
175 
184 - (bool)containsValueIdenticalTo: (nullable void*)value;
185 
192 - (OFMapTableEnumerator*)keyEnumerator;
193 
200 - (OFMapTableEnumerator*)valueEnumerator;
201 
202 #ifdef OF_HAVE_BLOCKS
203 
208 - (void)enumerateKeysAndValuesUsingBlock:
210 
216 - (void)replaceValuesUsingBlock: (of_map_table_replace_block_t)block;
217 #endif
218 
224 - (of_map_table_functions_t)keyFunctions;
225 
231 - (of_map_table_functions_t)valueFunctions;
232 @end
233 
240 @interface OFMapTableEnumerator: OFObject
241 {
242  OFMapTable *_mapTable;
243  struct of_map_table_bucket **_buckets;
244  uint32_t _capacity;
245  unsigned long _mutations;
246  unsigned long *_mutationsPtr;
247  uint32_t _position;
248 }
249 
255 - (void*)nextValue;
256 
261 - (void)reset;
262 @end
263 
264 OF_ASSUME_NONNULL_END
A struct describing the functions to be used by the map table.
Definition: OFMapTable.h:29
A protocol for fast enumeration.
Definition: OFEnumerator.h:111
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
A class which provides methods to enumerate through an OFMapTable's keys or values.
Definition: OFMapTable.h:241
A class similar to OFDictionary, but providing more options how keys and values should be retained...
Definition: OFMapTable.h:71
A protocol for the creation of copies.
Definition: OFObject.h:896
void(^ of_map_table_enumeration_block_t)(void *key, void *value, bool *stop)
A block for enumerating an OFMapTable.
Definition: OFMapTable.h:49
void *OF_NONNULL(^ of_map_table_replace_block_t)(void *key, void *value)
A block for replacing values in an OFMapTable.
Definition: OFMapTable.h:59