︙ | | | ︙ | |
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
|
- (void)_resizeForCount: (size_t)newCount
{
size_t fullness = newCount * 4 / size;
struct of_dictionary_hashtable_bucket **newData;
uint32_t i, newSize;
if (newCount > UINT32_MAX)
@throw [OFOutOfRangeException exceptionWithClass: isa];
if (fullness >= 3)
newSize = size << 1;
else if (fullness <= 1)
newSize = size >> 1;
else
return;
if (newSize == 0)
@throw [OFOutOfRangeException exceptionWithClass: isa];
newData = [self allocMemoryWithSize: sizeof(*newData)
count: newSize];
for (i = 0; i < newSize; i++)
newData[i] = NULL;
|
|
|
|
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
|
- (void)_resizeForCount: (size_t)newCount
{
size_t fullness = newCount * 4 / size;
struct of_dictionary_hashtable_bucket **newData;
uint32_t i, newSize;
if (newCount > UINT32_MAX)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
if (fullness >= 3)
newSize = size << 1;
else if (fullness <= 1)
newSize = size >> 1;
else
return;
if (newSize == 0)
@throw [OFOutOfRangeException exceptionWithClass: [self class]];
newData = [self allocMemoryWithSize: sizeof(*newData)
count: newSize];
for (i = 0; i < newSize; i++)
newData[i] = NULL;
|
︙ | | | ︙ | |
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
|
for (j = 0; j < last &&
newData[j] != NULL; j++);
}
if (j >= last) {
[self freeMemory: newData];
@throw [OFOutOfRangeException
exceptionWithClass: isa];
}
newData[j] = data[i];
}
}
[self freeMemory: data];
data = newData;
size = newSize;
}
- (void)_setObject: (id)object
forKey: (id)key
copyKey: (BOOL)copyKey
{
uint32_t i, hash, last;
id old;
if (key == nil || object == nil)
@throw [OFInvalidArgumentException exceptionWithClass: isa
selector: _cmd];
hash = [key hash];
last = size;
for (i = hash & (size - 1); i < last && data[i] != NULL; i++) {
if (data[i] == DELETED)
continue;
|
|
|
>
|
|
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
|
for (j = 0; j < last &&
newData[j] != NULL; j++);
}
if (j >= last) {
[self freeMemory: newData];
@throw [OFOutOfRangeException
exceptionWithClass: [self class]];
}
newData[j] = data[i];
}
}
[self freeMemory: data];
data = newData;
size = newSize;
}
- (void)_setObject: (id)object
forKey: (id)key
copyKey: (BOOL)copyKey
{
uint32_t i, hash, last;
id old;
if (key == nil || object == nil)
@throw [OFInvalidArgumentException
exceptionWithClass: [self class]
selector: _cmd];
hash = [key hash];
last = size;
for (i = hash & (size - 1); i < last && data[i] != NULL; i++) {
if (data[i] == DELETED)
continue;
|
︙ | | | ︙ | |
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
last = hash & (size - 1);
for (i = 0; i < last && data[i] != NULL &&
data[i] != DELETED; i++);
}
if (i >= last)
@throw [OFOutOfRangeException exceptionWithClass: isa];
bucket = [self allocMemoryWithSize: sizeof(*bucket)];
if (copyKey) {
@try {
bucket->key = [key copy];
} @catch (id e) {
|
|
>
|
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
last = hash & (size - 1);
for (i = 0; i < last && data[i] != NULL &&
data[i] != DELETED; i++);
}
if (i >= last)
@throw [OFOutOfRangeException
exceptionWithClass: [self class]];
bucket = [self allocMemoryWithSize: sizeof(*bucket)];
if (copyKey) {
@try {
bucket->key = [key copy];
} @catch (id e) {
|
︙ | | | ︙ | |
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
}
- (void)removeObjectForKey: (id)key
{
uint32_t i, hash, last;
if (key == nil)
@throw [OFInvalidArgumentException exceptionWithClass: isa
selector: _cmd];
hash = [key hash];
last = size;
for (i = hash & (size - 1); i < last && data[i] != NULL; i++) {
if (data[i] == DELETED)
continue;
|
|
>
|
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
}
- (void)removeObjectForKey: (id)key
{
uint32_t i, hash, last;
if (key == nil)
@throw [OFInvalidArgumentException
exceptionWithClass: [self class]
selector: _cmd];
hash = [key hash];
last = size;
for (i = hash & (size - 1); i < last && data[i] != NULL; i++) {
if (data[i] == DELETED)
continue;
|
︙ | | | ︙ | |
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
|
size_t i;
BOOL stop = NO;
unsigned long mutations2 = mutations;
for (i = 0; i < size && !stop; i++) {
if (mutations != mutations2)
@throw [OFEnumerationMutationException
exceptionWithClass: isa
object: self];
if (data[i] != NULL && data[i] != DELETED)
block(data[i]->key, data[i]->object, &stop);
}
}
- (void)replaceObjectsUsingBlock: (of_dictionary_replace_block_t)block
{
size_t i;
BOOL stop = NO;
unsigned long mutations2 = mutations;
for (i = 0; i < size && !stop; i++) {
if (mutations != mutations2)
@throw [OFEnumerationMutationException
exceptionWithClass: isa
object: self];
if (data[i] != NULL && data[i] != DELETED) {
id new = block(data[i]->key, data[i]->object, &stop);
if (new == nil)
@throw [OFInvalidArgumentException
exceptionWithClass: isa
selector: _cmd];
[new retain];
[data[i]->object release];
data[i]->object = new;
}
}
}
#endif
- (void)makeImmutable
{
isa = [OFDictionary_hashtable class];
}
@end
|
|
|
|
|
|
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
|
size_t i;
BOOL stop = NO;
unsigned long mutations2 = mutations;
for (i = 0; i < size && !stop; i++) {
if (mutations != mutations2)
@throw [OFEnumerationMutationException
exceptionWithClass: [self class]
object: self];
if (data[i] != NULL && data[i] != DELETED)
block(data[i]->key, data[i]->object, &stop);
}
}
- (void)replaceObjectsUsingBlock: (of_dictionary_replace_block_t)block
{
size_t i;
BOOL stop = NO;
unsigned long mutations2 = mutations;
for (i = 0; i < size && !stop; i++) {
if (mutations != mutations2)
@throw [OFEnumerationMutationException
exceptionWithClass: [self class]
object: self];
if (data[i] != NULL && data[i] != DELETED) {
id new = block(data[i]->key, data[i]->object, &stop);
if (new == nil)
@throw [OFInvalidArgumentException
exceptionWithClass: [self class]
selector: _cmd];
[new retain];
[data[i]->object release];
data[i]->object = new;
}
}
}
#endif
- (void)makeImmutable
{
object_setClass(self, [OFDictionary_hashtable class]);
}
@end
|