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
|
{
if (data == NULL || count == 0)
return NULL;
return data + (count - 1) * itemsize;
}
- addItem: (void*)item
{
if (SIZE_MAX - count < 1)
@throw [OFOutOfRangeException newWithClass: isa];
data = [self resizeMemory: data
toNItems: count + 1
withSize: itemsize];
memcpy(data + count * itemsize, item, itemsize);
count++;
return self;
}
- addItem: (void*)item
atIndex: (size_t)index
{
return [self addNItems: 1
fromCArray: item
atIndex: index];
}
- addNItems: (size_t)nitems
fromCArray: (void*)carray
{
if (nitems > SIZE_MAX - count)
@throw [OFOutOfRangeException newWithClass: isa];
data = [self resizeMemory: data
toNItems: count + nitems
withSize: itemsize];
memcpy(data + count * itemsize, carray, nitems * itemsize);
count += nitems;
return self;
}
- addNItems: (size_t)nitems
fromCArray: (void*)carray
atIndex: (size_t)index
{
if (nitems > SIZE_MAX - count)
@throw [OFOutOfRangeException newWithClass: isa];
data = [self resizeMemory: data
toNItems: count + nitems
withSize: itemsize];
memmove(data + (index + nitems) * itemsize, data + index * itemsize,
(count - index) * itemsize);
memcpy(data + index * 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;
@try {
data = [self resizeMemory: data
toNItems: count
withSize: itemsize];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
[e dealloc];
}
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,
(count - index - nitems) * itemsize);
count -= nitems;
@try {
data = [self resizeMemory: data
toNItems: count
withSize: itemsize];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
[e dealloc];
}
return self;
}
- (id)copy
{
OFDataArray *new = [[OFDataArray alloc] initWithItemSize: itemsize];
[new addNItems: count
fromCArray: data];
|
|
|
<
|
<
|
|
|
|
|
|
|
|
<
|
<
|
|
|
|
<
|
<
|
|
|
|
|
<
|
<
|
|
<
<
|
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
|
{
if (data == NULL || count == 0)
return NULL;
return data + (count - 1) * itemsize;
}
- (void)addItem: (void*)item
{
if (SIZE_MAX - count < 1)
@throw [OFOutOfRangeException newWithClass: isa];
data = [self resizeMemory: data
toNItems: count + 1
withSize: itemsize];
memcpy(data + count * itemsize, item, itemsize);
count++;
}
- (void)addItem: (void*)item
atIndex: (size_t)index
{
[self addNItems: 1
fromCArray: item
atIndex: index];
}
- (void)addNItems: (size_t)nitems
fromCArray: (void*)carray
{
if (nitems > SIZE_MAX - count)
@throw [OFOutOfRangeException newWithClass: isa];
data = [self resizeMemory: data
toNItems: count + nitems
withSize: itemsize];
memcpy(data + count * itemsize, carray, nitems * itemsize);
count += nitems;
}
- (void)addNItems: (size_t)nitems
fromCArray: (void*)carray
atIndex: (size_t)index
{
if (nitems > SIZE_MAX - count)
@throw [OFOutOfRangeException newWithClass: isa];
data = [self resizeMemory: data
toNItems: count + nitems
withSize: itemsize];
memmove(data + (index + nitems) * itemsize, data + index * itemsize,
(count - index) * itemsize);
memcpy(data + index * itemsize, carray, nitems * itemsize);
count += nitems;
}
- (void)removeItemAtIndex: (size_t)index
{
[self removeNItems: 1
atIndex: index];
}
- (void)removeNItems: (size_t)nitems
{
if (nitems > count)
@throw [OFOutOfRangeException newWithClass: isa];
count -= nitems;
@try {
data = [self resizeMemory: data
toNItems: count
withSize: itemsize];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
[e dealloc];
}
}
- (void)removeNItems: (size_t)nitems
atIndex: (size_t)index
{
if (nitems > count)
@throw [OFOutOfRangeException newWithClass: isa];
memmove(data + index * itemsize, data + (index + nitems) * itemsize,
(count - index - nitems) * itemsize);
count -= nitems;
@try {
data = [self resizeMemory: data
toNItems: count
withSize: itemsize];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
[e dealloc];
}
}
- (id)copy
{
OFDataArray *new = [[OFDataArray alloc] initWithItemSize: itemsize];
[new addNItems: count
fromCArray: data];
|
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
OF_HASH_FINALIZE(hash);
return hash;
}
@end
@implementation OFBigDataArray
- addItem: (void*)item
{
size_t nsize, lastpagebyte;
if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemsize)
@throw [OFOutOfRangeException newWithClass: isa];
lastpagebyte = of_pagesize - 1;
nsize = ((count + 1) * itemsize + lastpagebyte) & ~lastpagebyte;
if (size != nsize)
data = [self resizeMemory: data
toSize: nsize];
memcpy(data + count * itemsize, item, itemsize);
count++;
size = nsize;
return self;
}
- addNItems: (size_t)nitems
fromCArray: (void*)carray
{
size_t nsize, lastpagebyte;
if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize)
@throw [OFOutOfRangeException newWithClass: isa];
lastpagebyte = of_pagesize - 1;
nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte;
if (size != nsize)
data = [self resizeMemory: data
toSize: nsize];
memcpy(data + count * itemsize, carray, nitems * itemsize);
count += nitems;
size = nsize;
return self;
}
- addNItems: (size_t)nitems
fromCArray: (void*)carray
atIndex: (size_t)index
{
size_t nsize, lastpagebyte;
if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize)
@throw [OFOutOfRangeException newWithClass: isa];
lastpagebyte = of_pagesize - 1;
nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte;
if (size != nsize)
data = [self resizeMemory: data
toNItems: nsize
withSize: itemsize];
memmove(data + (index + nitems) * itemsize, data + index * itemsize,
(count - index) * itemsize);
memcpy(data + index * itemsize, carray, nitems * itemsize);
count += nitems;
size = nsize;
return self;
}
- removeNItems: (size_t)nitems
{
size_t nsize, lastpagebyte;
if (nitems > count)
@throw [OFOutOfRangeException newWithClass: isa];
count -= nitems;
lastpagebyte = of_pagesize - 1;
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, lastpagebyte;
if (nitems > count)
@throw [OFOutOfRangeException newWithClass: isa];
memmove(data + index * itemsize, data + (index + nitems) * itemsize,
(count - index - nitems) * itemsize);
count -= nitems;
lastpagebyte = of_pagesize - 1;
nsize = (count * itemsize + lastpagebyte) & ~lastpagebyte;
if (size != nsize)
data = [self resizeMemory: data
toSize: nsize];
size = nsize;
return self;
}
- (id)copy
{
OFDataArray *new = [[OFBigDataArray alloc] initWithItemSize: itemsize];
[new addNItems: count
fromCArray: data];
return new;
}
@end
|
|
|
<
|
<
|
|
|
<
|
<
|
|
|
|
<
|
<
|
|
<
|
<
|
|
<
<
|
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
OF_HASH_FINALIZE(hash);
return hash;
}
@end
@implementation OFBigDataArray
- (void)addItem: (void*)item
{
size_t nsize, lastpagebyte;
if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemsize)
@throw [OFOutOfRangeException newWithClass: isa];
lastpagebyte = of_pagesize - 1;
nsize = ((count + 1) * itemsize + lastpagebyte) & ~lastpagebyte;
if (size != nsize)
data = [self resizeMemory: data
toSize: nsize];
memcpy(data + count * itemsize, item, itemsize);
count++;
size = nsize;
}
- (void)addNItems: (size_t)nitems
fromCArray: (void*)carray
{
size_t nsize, lastpagebyte;
if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize)
@throw [OFOutOfRangeException newWithClass: isa];
lastpagebyte = of_pagesize - 1;
nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte;
if (size != nsize)
data = [self resizeMemory: data
toSize: nsize];
memcpy(data + count * itemsize, carray, nitems * itemsize);
count += nitems;
size = nsize;
}
- (void)addNItems: (size_t)nitems
fromCArray: (void*)carray
atIndex: (size_t)index
{
size_t nsize, lastpagebyte;
if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize)
@throw [OFOutOfRangeException newWithClass: isa];
lastpagebyte = of_pagesize - 1;
nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte;
if (size != nsize)
data = [self resizeMemory: data
toNItems: nsize
withSize: itemsize];
memmove(data + (index + nitems) * itemsize, data + index * itemsize,
(count - index) * itemsize);
memcpy(data + index * itemsize, carray, nitems * itemsize);
count += nitems;
size = nsize;
}
- (void)removeNItems: (size_t)nitems
{
size_t nsize, lastpagebyte;
if (nitems > count)
@throw [OFOutOfRangeException newWithClass: isa];
count -= nitems;
lastpagebyte = of_pagesize - 1;
nsize = (count * itemsize + lastpagebyte) & ~lastpagebyte;
if (size != nsize)
data = [self resizeMemory: data
toSize: nsize];
size = nsize;
}
- (void)removeNItems: (size_t)nitems
atIndex: (size_t)index
{
size_t nsize, lastpagebyte;
if (nitems > count)
@throw [OFOutOfRangeException newWithClass: isa];
memmove(data + index * itemsize, data + (index + nitems) * itemsize,
(count - index - nitems) * itemsize);
count -= nitems;
lastpagebyte = of_pagesize - 1;
nsize = (count * itemsize + lastpagebyte) & ~lastpagebyte;
if (size != nsize)
data = [self resizeMemory: data
toSize: nsize];
size = nsize;
}
- (id)copy
{
OFDataArray *new = [[OFBigDataArray alloc] initWithItemSize: itemsize];
[new addNItems: count
fromCArray: data];
return new;
}
@end
|