Comment: | New OFDictionary implementation and removal of a hack in OFList.
The new implementation is easier to use as it does automatic resizing, I decided to change the implementation as only very few need a As the new implementation no longer uses OFList, this also made it |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
bbf1f79b8fc25a5f7213dd14b73c649d |
User & Date: | js on 2009-09-08 16:06:10 |
Other Links: | manifest | tags |
2009-09-11
| ||
11:41 | Fix a warning with old GCC versions. check-in: 3468abde19 user: js tags: trunk | |
2009-09-08
| ||
16:06 | New OFDictionary implementation and removal of a hack in OFList. check-in: bbf1f79b8f user: js tags: trunk | |
2009-09-01
| ||
11:39 | Use OFMutableString in OFPlugin instead of doing it manually. check-in: cdfdea289e user: js tags: trunk | |
Modified src/OFDictionary.h from [a1a71dda9a] to [27b0d8980d].
︙ | |||
8 9 10 11 12 13 14 | 8 9 10 11 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 | - - + - + - - - + - - - + - + - - + + + - + - - - - - - - - | * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #include <stdarg.h> #import "OFObject.h" |
︙ | |||
77 78 79 80 81 82 83 | 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 | - + - + - + - - - - - - - - | */ + dictionaryWithObjects: (OFArray*)objs forKeys: (OFArray*)keys; /** * Creates a new OFDictionary with the specified keys objects. * |
︙ | |||
147 148 149 150 151 152 153 | 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 | - - - - - - - - + + + + + + - | * * \param first The first key * \return A new initialized OFDictionary */ - initWithKey: (OFObject <OFCopying>*)first argList: (va_list)args; |
Modified src/OFDictionary.m from [c824cfaef7] to [3ddd956ea4].
︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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 | + + - - - - - | #include <string.h> #import "OFDictionary.h" #import "OFIterator.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #define BUCKET_SIZE sizeof(struct of_dictionary_bucket) /* References for static linking */ void _references_to_categories_of_OFDictionary() { _OFIterator_reference = 1; } @implementation OFDictionary + dictionary; { return [[[self alloc] init] autorelease]; } + dictionaryWithDictionary: (OFDictionary*)dict { return [[[self alloc] initWithDictionary: dict] autorelease]; } |
︙ | |||
67 68 69 70 71 72 73 | 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 | - + - + - - + - - - + - - - - - + + - - - - - - - + + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + - - - + - - - - + - - - - - - - + - - + - - - - - - - - - + - - - - - + + - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - + + + + - - - - - - - - + - + - - - - - - - - - - - - - - + - - + - - - - + + + + - + - - + - - - - - + - - - - - + - - - + + - - + - - + + - - - - - - - - - - - - - + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - + + + - + + + + + + + + - - + + + - - - - + + + | return ret; } - init { self = [super init]; |
︙ | |||
460 461 462 463 464 465 466 | 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 | - + - - - - - + - - + - - - - - - | */ - (void)dealloc { size_t i; for (i = 0; i < size; i++) { |
Modified src/OFIterator.h from [0fb8f20721] to [86392c7533].
︙ | |||
17 18 19 20 21 22 23 | 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 | - - - - + + - - + + + + + + + + + + + + | * An iterator pair combines a key and its object in a single struct. */ typedef struct __of_iterator_pair { /// The key id key; /// The object for the key id object; |
Modified src/OFIterator.m from [6e8102a07c] to [d7091488bd].
︙ | |||
21 22 23 24 25 26 27 | 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 | - + + + - + + + + + + + - + + - + - + - + - - - - - + + + - - - - - - + + + + + + - - + - - - + + + + - - - - - - - + + + + + + + + + + - | @implementation OFIterator - init { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } |
Modified src/OFList.h from [03977d0bbb] to [d42967ddf0].
︙ | |||
28 29 30 31 32 33 34 | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | - + - - - - - - - - - - - - - - | /** * The OFList class provides easy to use double-linked lists. */ @interface OFList: OFObject <OFCopying> { of_list_object_t *first; of_list_object_t *last; |
︙ |
Modified src/OFList.m from [6526cc451e] to [18ec5ebfcc].
︙ | |||
18 19 20 21 22 23 24 | 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 | - - - - - - - - - - - - - - - - - - - - | @implementation OFList + list { return [[[self alloc] init] autorelease]; } |
︙ | |||
83 84 85 86 87 88 89 | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | - + | return last; } - (of_list_object_t*)append: (id)obj { of_list_object_t *o; |
︙ | |||
107 108 109 110 111 112 113 | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | - + | return o; } - (of_list_object_t*)prepend: (id)obj { of_list_object_t *o; |
︙ | |||
132 133 134 135 136 137 138 | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | - + | } - (of_list_object_t*)insert: (id)obj before: (of_list_object_t*)listobj { of_list_object_t *o; |
︙ | |||
158 159 160 161 162 163 164 | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | - + | } - (of_list_object_t*)insert: (id)obj after: (of_list_object_t*)listobj { of_list_object_t *o; |
︙ | |||
242 243 244 245 246 247 248 | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | - + | new = [[OFList alloc] initWithoutRetainAndRelease]; o = NULL; prev = NULL; @try { for (iter = first; iter != NULL; iter = iter->next) { |
︙ |
Modified src/OFMutableDictionary.h from [2cfd9e5d81] to [21cc3f3819].
︙ | |||
26 27 28 29 30 31 32 | 26 27 28 29 30 31 32 33 | - - - - - - - | /** * Remove the object with the given key from the dictionary. * * \param key The key whose object should be removed */ - removeObjectForKey: (OFObject*)key; |
Modified src/OFMutableDictionary.m from [48a81d9fea] to [436bcef63e].
︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 | 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 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + - - - + + - + + - + - - + - - - - - - + + + + + + + + + + + + - + + + + - + - - + - - - - - - - + + + + - + - - + - - - + - - - + - - - - - - - + - - - - + - - - + - - - - - - + - - - - - - - - + - - + - - + - - - - - + - - - - + - - - + - - - + + - - - + - - - | #include "config.h" #include <string.h> #import "OFMutableDictionary.h" #import "OFExceptions.h" #import "OFMacros.h" #define BUCKET_SIZE sizeof(struct of_dictionary_bucket) static OF_INLINE void resize(id self, size_t count, struct of_dictionary_bucket **data, size_t *size) { float fill = (float)count / *size; size_t newsize; struct of_dictionary_bucket *newdata; uint32_t i; /* * FIXME: * * Throw an OFOutOfRangeException if it would overflow (unlikely to * happen). */ if (fill > 0.75) newsize = *size * 2; else if (fill < 0.25) newsize = *size / 2; else return; newdata = [self allocMemoryForNItems: newsize withSize: BUCKET_SIZE]; memset(newdata, 0, newsize * BUCKET_SIZE); for (i = 0; i < *size; i++) { if ((*data)[i].key != nil) { uint32_t j = (*data)[i].hash & (newsize - 1); for (; j < newsize && newdata[j].key != nil; j++); /* In case the last bucket is already used */ if (j >= newsize) for (j = 0; j < newsize && newdata[j].key != nil; i++); if (j >= newsize) @throw [OFOutOfRangeException newWithClass: [self class]]; newdata[j].key = (*data)[i].key; newdata[j].object = (*data)[i].object; newdata[j].hash = (*data)[i].hash; } } [self freeMemory: *data]; *data = newdata; *size = newsize; } @implementation OFMutableDictionary - setObject: (OFObject*)obj forKey: (OFObject <OFCopying>*)key { |
Modified tests/OFDictionary/OFDictionary.m from [3fa2e6f5e3] to [cdca107008].
︙ | |||
15 16 17 18 19 20 21 | 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 | - + - + - + - - - - + + + + - - - - - - - - - - - - - + - - + + | #include <string.h> #import "OFAutoreleasePool.h" #import "OFDictionary.h" #import "OFString.h" #import "OFExceptions.h" |
︙ |