Overview
Comment: | Add -[removeItemAtIndex:] and -[removeNItems:atIndex:] to OFDataArray. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
24928c1da17bb8fe24b77d66a4157a0d |
User & Date: | js on 2009-11-19 15:41:27 |
Other Links: | manifest | tags |
Context
2009-11-22
| ||
15:44 | Add -[removeObjectAtIndex] and -[removeNObjects:atIndex:] to OFArray. check-in: 0b6fc2523a user: js tags: trunk | |
2009-11-19
| ||
15:41 | Add -[removeItemAtIndex:] and -[removeNItems:atIndex:] to OFDataArray. check-in: 24928c1da1 user: js tags: trunk | |
2009-11-18
| ||
23:11 | Remove now unnecessary CFLAGS from Makefile. check-in: 7b1079712b user: js tags: trunk | |
Changes
Modified src/OFDataArray.h from [ba261f3f5c] to [302afd5292].
︙ | ︙ | |||
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | * * \param nitems The number of items to add * \param carray A C array containing the items to add */ - addNItems: (size_t)nitems fromCArray: (void*)carray; /** * Removes the specified amount of items from the end of the OFDataArray. * * \param nitems The number of items to remove */ - removeNItems: (size_t)nitems; @end /** * The OFBigDataArray class provides a class for storing arbitrary data in an * array and is designed to store large hunks of data. Therefore, it allocates * memory in pages rather than a chunk of memory for each item. */ | > > > > > > > > > > > > > > > > | 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 | * * \param nitems The number of items to add * \param carray A C array containing the items to add */ - addNItems: (size_t)nitems fromCArray: (void*)carray; /** * Removes the item at the specified index. * * \param index The index of the item to remove */ - removeItemAtIndex: (size_t)index; /** * Removes the specified amount of items from the end of the OFDataArray. * * \param nitems The number of items to remove */ - removeNItems: (size_t)nitems; /** * Removes the specified amount of items at the specified index. * * \param nitems The number of items to remove * \param index The index at which the items are removed */ - removeNItems: (size_t)nitems atIndex: (size_t)index; @end /** * The OFBigDataArray class provides a class for storing arbitrary data in an * array and is designed to store large hunks of data. Therefore, it allocates * memory in pages rather than a chunk of memory for each item. */ |
︙ | ︙ |
Modified src/OFDataArray.m from [f5681d0dfa] to [019e3d878c].
︙ | ︙ | |||
113 114 115 116 117 118 119 120 121 122 123 124 125 126 | withSize: itemsize]; memcpy(data + count * itemsize, carray, nitems * itemsize); count += nitems; return self; } - removeNItems: (size_t)nitems { if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMemory: data | > > > > > > > > > > > > > > > > > > > > > > > > > | < < | 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 | withSize: itemsize]; memcpy(data + count * itemsize, carray, nitems * itemsize); count += nitems; return self; } - removeItemAtIndex: (size_t)index { return [self removeNItems: 1 atIndex: index]; } - removeNItems: (size_t)nitems { if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; count -= nitems; data = [self resizeMemory: data toNItems: count withSize: itemsize]; return self; } - removeNItems: (size_t)nitems atIndex: (size_t)index { if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; memmove(data + index * itemsize, data + (index + nitems) * itemsize, nitems * itemsize); count -= nitems; data = [self resizeMemory: data toNItems: count withSize: itemsize]; return self; } - (id)copy { OFDataArray *new = [[OFDataArray alloc] initWithItemSize: itemsize]; |
︙ | ︙ | |||
259 260 261 262 263 264 265 | - removeNItems: (size_t)nitems { size_t nsize; if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; | > | > > > > > > > > > > > > > > > > > > > > | 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 311 312 313 314 315 316 317 318 319 320 321 322 323 | - removeNItems: (size_t)nitems { size_t nsize; if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; count -= nitems; nsize = (count * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; size = nsize; return self; } - removeNItems: (size_t)nitems atIndex: (size_t)index { size_t nsize; if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; memmove(data + index * itemsize, data + (index + nitems) * itemsize, nitems * itemsize); count -= nitems; nsize = (count * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMemory: data toSize: nsize]; size = nsize; return self; } - (id)copy { |
︙ | ︙ |
Modified tests/OFDataArray.m from [9aaf176836] to [adb8e9f54e].
︙ | ︙ | |||
70 71 72 73 74 75 76 | [array[1] removeNItems: 1] && [array[0] compare: array[1]] == OF_ORDERED_DESCENDING && [array[1] compare: array[0]] == OF_ORDERED_ASCENDING && [array[2] compare: array[3]] == OF_ORDERED_ASCENDING) TEST(@"-[hash]", [array[0] hash] == 0xC54621B6) | > > > > | > > > > > > > > | 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 | [array[1] removeNItems: 1] && [array[0] compare: array[1]] == OF_ORDERED_DESCENDING && [array[1] compare: array[0]] == OF_ORDERED_ASCENDING && [array[2] compare: array[3]] == OF_ORDERED_ASCENDING) TEST(@"-[hash]", [array[0] hash] == 0xC54621B6) array[0] = [class dataArrayWithItemSize: 1]; [array[0] addNItems: 6 fromCArray: "abcdef"]; TEST(@"-[removeNItems:]", [array[0] removeNItems: 1] && [array[0] count] == 5 && !memcmp([array[0] cArray], "abcde", 5)) TEST(@"-[removeNItems:atIndex:]", [array[0] removeNItems: 2 atIndex: 1] && [array[0] count] == 3 && !memcmp([array[0] cArray], "ade", 3)) [array[0] addItem: ""]; TEST(@"Building strings", (array[0] = [class dataArrayWithItemSize: 1]) && [array[0] addNItems: 6 fromCArray: (void*)str] && [array[0] addItem: ""] && !strcmp([array[0] cArray], str)) |
︙ | ︙ |