Overview
Comment: | OFSet_hashtable: Store in OFMapTable. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ed438b979d6ffe49e375685678c6c140 |
User & Date: | js on 2012-12-01 17:50:44 |
Other Links: | manifest | tags |
Context
2012-12-01
| ||
18:08 | OFDictionary_hashtable: Store in OFMapTable. check-in: 1abbb97747 user: js tags: trunk | |
17:50 | OFSet_hashtable: Store in OFMapTable. check-in: ed438b979d user: js tags: trunk | |
17:26 | Add OFMapTable. check-in: 6f081c14f9 user: js tags: trunk | |
Changes
Modified src/OFCountedSet_hashtable.h from [764c37fc25] to [9613e59d54].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFCountedSet.h" | | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFCountedSet.h" @class OFMapTable; @interface OFCountedSet_hashtable: OFCountedSet { OFMapTable *mapTable; } @end |
Modified src/OFCountedSet_hashtable.m from [2d16b912f5] to [f0855688b6].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < | < > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFMutableSet_hashtable.h" #import "OFCountedSet_hashtable.h" #import "OFMapTable.h" #import "OFString.h" #import "OFArray.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFEnumerationMutationException.h" #import "OFOutOfRangeException.h" #import "autorelease.h" @implementation OFCountedSet_hashtable + (void)initialize { if (self == [OFCountedSet_hashtable class]) |
︙ | ︙ | |||
152 153 154 155 156 157 158 | objects = [element elementsForName: @"object" namespace: OF_SERIALIZATION_NS]; enumerator = [objects objectEnumerator]; while ((objectElement = [enumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *object; | | | | | < | < > | < | > | | | > > > > > < < | < | < > | | < < < | < | < | | | | < | < < | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | objects = [element elementsForName: @"object" namespace: OF_SERIALIZATION_NS]; enumerator = [objects objectEnumerator]; while ((objectElement = [enumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *object; OFXMLAttribute *count_; size_t count; object = [[objectElement elementsForNamespace: OF_SERIALIZATION_NS] firstObject]; count_ = [objectElement attributeForName: @"count"]; if (object == nil || count_ == nil) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; count = (size_t)[[count_ stringValue] decimalValue]; [mapTable setValue: (void*)(uintptr_t)count forKey: [object objectByDeserializing]]; objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (size_t)countForObject: (id)object { return (size_t)(uintptr_t)[mapTable valueForKey: object]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsAndCountUsingBlock: (of_counted_set_enumeration_block_t)block { @try { [mapTable enumerateKeysAndValuesUsingBlock: ^ (void *key, void *value, BOOL *stop) { block(key, (size_t)(uintptr_t)value, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithClass: [self class] object: self]; } } #endif - (void)addObject: (id)object { size_t count = (size_t)(uintptr_t)[mapTable valueForKey: object]; if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; [mapTable setValue: (void*)(uintptr_t)(count + 1) forKey: object]; } - (void)removeObject: (id)object { size_t count = (size_t)(uintptr_t)[mapTable valueForKey: object]; if (count == 0) return; count--; if (count > 0) [mapTable setValue: (void*)(uintptr_t)count forKey: object]; else [mapTable removeValueForKey: object]; } - (void)makeImmutable { } @end |
Modified src/OFMapTable.h from [b9cf6cd576] to [dcccbffbc5].
︙ | ︙ | |||
233 234 235 236 237 238 239 | /*! * @brief Resets the enumerator, so the next call to nextKey returns the first * key again. */ - (void)reset; @end | > > > > > > > > > > | 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | /*! * @brief Resets the enumerator, so the next call to nextKey returns the first * key again. */ - (void)reset; @end @interface OFMapTableEnumeratorWrapper: OFEnumerator { OFMapTableEnumerator *enumerator; id object; } - initWithEnumerator: (OFMapTableEnumerator*)enumerator object: (id)object; @end |
Modified src/OFMapTable.m from [e82f78e00b] to [c18a26ad1f].
︙ | ︙ | |||
701 702 703 704 705 706 707 708 709 | for (; position < capacity && (buckets[position] == NULL || buckets[position] == &deleted); position++); if (position < capacity) return buckets[position++]->value; else return NULL; } @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | for (; position < capacity && (buckets[position] == NULL || buckets[position] == &deleted); position++); if (position < capacity) return buckets[position++]->value; else return NULL; } @end @implementation OFMapTableEnumeratorWrapper - initWithEnumerator: (OFMapTableEnumerator*)enumerator_ object: (id)object_ { self = [super init]; enumerator = [enumerator_ retain]; object = [object_ retain]; return self; } - (void)dealloc { [enumerator release]; [object release]; [super dealloc]; } - (id)nextObject { id ret; @try { ret = [enumerator nextValue]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithClass: [object class] object: object]; } return ret; } - (void)reset { @try { [enumerator reset]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithClass: [object class] object: object]; } } @end |
Modified src/OFMutableSet_hashtable.h from [ee1ba34d52] to [bcdeaaadac].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFMutableSet.h" | | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFMutableSet.h" @class OFMapTable; @interface OFMutableSet_hashtable: OFMutableSet { OFMapTable *mapTable; } @end |
Modified src/OFMutableSet_hashtable.m from [f1c4d45a2c] to [2312031144].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < < | | | < | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFSet_hashtable.h" #import "OFMutableSet_hashtable.h" #import "OFMapTable.h" @implementation OFMutableSet_hashtable + (void)initialize { if (self == [OFMutableSet_hashtable class]) [self inheritMethodsFromClass: [OFSet_hashtable class]]; } - (void)addObject: (id)object { [mapTable setValue: (void*)1 forKey: object]; } - (void)removeObject: (id)object { [mapTable removeValueForKey: object]; } - (void)makeImmutable { object_setClass(self, [OFSet_hashtable class]); } @end |
Modified src/OFSet_hashtable.h from [673218c8e7] to [b2ed28094e].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFSet.h" | | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFSet.h" @class OFMapTable; @interface OFSet_hashtable: OFSet { OFMapTable *mapTable; } @end |
Modified src/OFSet_hashtable.m from [b5f65d1f93] to [e6fb2fdb69].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < | < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > | | > > > > > > > > > < < < < < < < | | < | > > > > > > > > > < | | < | < < | | < < < | < < > > > | > > > > > > > > | < | | < < < < < < | | < | | | | > | > | > | | > > > > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFSet_hashtable.h" #import "OFMutableSet_hashtable.h" #import "OFCountedSet_hashtable.h" #import "OFMapTable.h" #import "OFArray.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFEnumerationMutationException.h" #import "autorelease.h" static void* retain(void *value) { return [(id)value retain]; } static void release(void *value) { [(id)value release]; } static uint32_t hash(void *value) { return [(id)value hash]; } static BOOL equal(void *value1, void *value2) { return [(id)value1 isEqual: (id)value2]; } static of_map_table_functions_t keyFunctions = { .retain = retain, .release = release, .hash = hash, .equal = equal }; static of_map_table_functions_t valueFunctions = {}; @implementation OFSet_hashtable - init { return [self initWithCapacity: 0]; } - initWithCapacity: (size_t)capacity { self = [super init]; @try { mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions valueFunctions: valueFunctions capacity: capacity]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithSet: (OFSet*)set { size_t count; if (set == nil) return [self init]; @try { count = [set count]; } @catch (id e) { [self release]; @throw e; } self = [self initWithCapacity: count]; @try { void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator; id object; enumerator = [set objectEnumerator]; while ((object = [enumerator nextObject]) != nil) [mapTable setValue: (void*)1 forKey: object]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - initWithArray: (OFArray*)array { size_t count; if (array == nil) return self; @try { count = [array count]; } @catch (id e) { [self release]; @throw e; } self = [self initWithCapacity: count]; @try { void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator; id object; enumerator = [array objectEnumerator]; while ((object = [enumerator nextObject]) != nil) [mapTable setValue: (void*)1 forKey: object]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - initWithObjects: (id const*)objects count: (size_t)count { self = [self initWithCapacity: count]; @try { size_t i; for (i = 0; i < count; i++) [mapTable setValue: (void*)1 forKey: objects[i]]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithObject: (id)firstObject arguments: (va_list)arguments { self = [super init]; @try { id object; va_list argumentsCopy; size_t count; va_copy(argumentsCopy, arguments); for (count = 1; va_arg(argumentsCopy, id) != nil; count++); mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions valueFunctions: valueFunctions capacity: count]; [mapTable setValue: (void*)1 forKey: firstObject]; while ((object = va_arg(arguments, id)) != nil) [mapTable setValue: (void*)1 forKey: object]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator; OFXMLElement *child; if ((![[element name] isEqual: @"OFSet"] && ![[element name] isEqual: @"OFMutableSet"]) || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; enumerator = [[element elementsForNamespace: OF_SERIALIZATION_NS] objectEnumerator]; while ((child = [enumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); [mapTable setValue: (void*)1 forKey: [child objectByDeserializing]]; objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [mapTable release]; [super dealloc]; } - (size_t)count { return [mapTable count]; } - (BOOL)containsObject: (id)object { if (object == nil) return NO; return ([mapTable valueForKey: object] != nil); } - (BOOL)isEqual: (id)object { OFSet_hashtable *otherSet; if (![object isKindOfClass: [OFSet_hashtable class]] && ![object isKindOfClass: [OFMutableSet_hashtable class]] && ![object isKindOfClass: [OFCountedSet_hashtable class]]) return [super isEqual: object]; otherSet = object; return [otherSet->mapTable isEqual: mapTable]; } - (OFEnumerator*)objectEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] initWithEnumerator: [mapTable keyEnumerator] object: self] autorelease]; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count { return [mapTable countByEnumeratingWithState: state objects: objects count: count]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block { @try { [mapTable enumerateKeysAndValuesUsingBlock: ^ (void *key, void *value, BOOL *stop) { block(key, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithClass: [self class] object: self]; } } #endif @end |
Modified tests/OFSet.m from [aefbf99a85] to [d636bb81c7].
︙ | ︙ | |||
47 48 49 50 51 52 53 | TEST(@"-[isEqual:]", [set1 isEqual: set2]) TEST(@"-[hash]", [set1 hash] == [set2 hash]) TEST(@"-[description]", [[set1 description] | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | TEST(@"-[isEqual:]", [set1 isEqual: set2]) TEST(@"-[hash]", [set1 hash] == [set2 hash]) TEST(@"-[description]", [[set1 description] isEqual: @"{(\n\tx,\n\tbar,\n\tfoo,\n\tbaz\n)}"] && [[set1 description] isEqual: [set2 description]]) TEST(@"-[copy]", [set1 isEqual: [[set1 copy] autorelease]]) TEST(@"-[mutableCopy]", (mutableSet = [[set1 mutableCopy] autorelease])); |
︙ | ︙ | |||
94 95 96 97 98 99 100 | #ifdef OF_HAVE_FAST_ENUMERATION ok = YES; i = 0; for (OFString *s in set1) { switch (i) { case 0: | | | | | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | #ifdef OF_HAVE_FAST_ENUMERATION ok = YES; i = 0; for (OFString *s in set1) { switch (i) { case 0: if (![s isEqual: @"x"]) ok = NO; break; case 1: if (![s isEqual: @"bar"]) ok = NO; break; case 2: if (![s isEqual: @"foo"]) ok = NO; break; case 3: if (![s isEqual: @"baz"]) ok = NO; break; } i++; } |
︙ | ︙ |
Modified tests/serialization.xml from [4afe0bff59] to [0489605714].
︙ | ︙ | |||
37 38 39 40 41 42 43 | <OFMutableArray> <OFXMLElement name='y'/> <OFXMLCDATA><![CDATA[<]]></OFXMLCDATA> </OFMutableArray> </children> </OFXMLElement> <OFSet> | < > > > > < < < | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | <OFMutableArray> <OFXMLElement name='y'/> <OFXMLCDATA><![CDATA[<]]></OFXMLCDATA> </OFMutableArray> </children> </OFXMLElement> <OFSet> <OFString>bar</OFString> <OFString>foo</OFString> </OFSet> <OFCountedSet> <object count='1'> <OFString>bar</OFString> </object> <object count='2'> <OFString>foo</OFString> </object> </OFCountedSet> </OFList> </key> <object> <OFString>list</OFString> </object> </OFMutableDictionary> </serialization> |