︙ | | |
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
|
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
|
+
-
+
-
-
-
+
+
-
-
+
+
-
-
+
+
-
+
|
}
+ dictionaryWithHashSize: (int)hashsize
{
return [[[self alloc] initWithHashSize: hashsize] autorelease];
}
+ dictionaryWithObject: (OFObject*)obj
+ dictionaryWithKey: (OFObject <OFCopying>*)key
forKey: (OFObject <OFCopying>*)key
andObject: (OFObject*)obj
{
return [[[self alloc] initWithKey: key
andObject: obj] autorelease];
return [[[self alloc] initWithObject: obj
forKey: key] autorelease];
}
+ dictionaryWithKeys: (OFArray*)keys
andObjects: (OFArray*)objs
+ dictionaryWithObjects: (OFArray*)objs
forKeys: (OFArray*)keys
{
return [[[self alloc] initWithKeys: keys
andObjects: objs] autorelease];
return [[[self alloc] initWithObjects: objs
forKeys: keys] autorelease];
}
+ dictionaryWithKeysAndObjects: (OFObject <OFCopying>*)first, ...
{
id ret;
va_list args;
va_start(args, first);
ret = [[[self alloc] initWithKey: first
andArgList: args] autorelease];
argList: args] autorelease];
va_end(args);
return ret;
}
- init
{
|
︙ | | |
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
-
+
|
self = [super init];
if (dict == nil) {
Class c = isa;
size = 0;
[self dealloc];
@throw [OFInvalidArgumentException newWithClass: c
andSelector: _cmd];
selector: _cmd];
}
size = dict->size;
@try {
data = [self allocMemoryForNItems: size
withSize: sizeof(OFList*)];
|
︙ | | |
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
-
+
|
{
self = [super init];
if (hashsize < 8 || hashsize >= 28) {
Class c = isa;
[super dealloc];
@throw [OFInvalidArgumentException newWithClass: c
andSelector: _cmd];
selector: _cmd];
}
size = (size_t)1 << hashsize;
@try {
data = [self allocMemoryForNItems: size
withSize: sizeof(OFList*)];
|
︙ | | |
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
|
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
|
+
-
+
-
-
+
|
@throw e;
}
memset(data, 0, size * sizeof(OFList*));
return self;
}
- initWithObject: (OFObject*)obj
- initWithKey: (OFObject <OFCopying>*)key
forKey: (OFObject <OFCopying>*)key
andObject: (OFObject*)obj
{
Class c;
uint32_t fullhash, hash;
self = [self init];
if (key == nil || obj == nil) {
c = isa;
[self dealloc];
@throw [OFInvalidArgumentException newWithClass: isa
andSelector: _cmd];
selector: _cmd];
}
fullhash = [key hash];
hash = fullhash & (size - 1);
@try {
key = [key copy];
|
︙ | | |
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
|
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
|
-
-
+
+
-
+
-
+
|
[self dealloc];
@throw e;
}
return self;
}
- initWithKeys: (OFArray*)keys
andObjects: (OFArray*)objs
- initWithObjects: (OFArray*)objs
forKeys: (OFArray*)keys
{
Class c;
OFObject <OFCopying> **keys_data;
OFObject **objs_data;
size_t count, i;
self = [self init];
count = [keys count];
if (keys == nil || objs == nil || count != [objs count]) {
c = isa;
[self dealloc];
@throw [OFInvalidArgumentException newWithClass: isa
andSelector: _cmd];
selector: _cmd];
}
keys_data = [keys data];
objs_data = [objs data];
for (i = 0; i < count; i++) {
uint32_t fullhash, hash;
OFObject <OFCopying> *key;
if (keys_data[i] == nil || objs_data[i] == nil) {
c = isa;
[self dealloc];
@throw [OFInvalidArgumentException newWithClass: isa
andSelector: _cmd];
selector: _cmd];
}
fullhash = [keys_data[i] hash];
hash = fullhash & (size - 1);
@try {
key = [keys_data[i] copy];
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
|
- initWithKeysAndObjects: (OFObject <OFCopying>*)first, ...
{
id ret;
va_list args;
va_start(args, first);
ret = [self initWithKey: first
andArgList: args];
argList: args];
va_end(args);
return ret;
}
- initWithKey: (OFObject <OFCopying>*)first
andArgList: (va_list)args
argList: (va_list)args
{
OFObject <OFCopying> *key;
OFObject *obj;
Class c;
uint32_t fullhash, hash;
self = [self init];
obj = va_arg(args, OFObject*);
if (first == nil || obj == nil) {
c = isa;
[self dealloc];
@throw [OFInvalidArgumentException newWithClass: isa
andSelector: _cmd];
selector: _cmd];
}
fullhash = [first hash];
hash = fullhash & (size - 1);
@try {
key = [first copy];
|
︙ | | |
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
-
+
|
}
while ((key = va_arg(args, OFObject <OFCopying>*)) != nil) {
if ((obj = va_arg(args, OFObject*)) == nil) {
c = isa;
[self dealloc];
@throw [OFInvalidArgumentException newWithClass: isa
andSelector: _cmd];
selector: _cmd];
}
fullhash = [key hash];
hash = fullhash & (size - 1);
@try {
key = [key copy];
|
︙ | | |
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
-
+
|
- (id)objectForKey: (OFObject*)key
{
uint32_t hash;
of_dictionary_list_object_t *iter;
if (key == nil)
@throw [OFInvalidArgumentException newWithClass: isa
andSelector: _cmd];
selector: _cmd];
hash = [key hash] & (size - 1);
if (data[hash] == nil)
return nil;
for (iter = (of_dictionary_list_object_t*)[data[hash] first];
|
︙ | | |
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
-
+
-
+
-
+
|
[super dealloc];
}
- setObject: (OFObject*)obj
forKey: (OFObject <OFCopying>*)key
{
@throw [OFNotImplementedException newWithClass: isa
andSelector: _cmd];
selector: _cmd];
}
- removeObjectForKey: (OFObject*)key
{
@throw [OFNotImplementedException newWithClass: isa
andSelector: _cmd];
selector: _cmd];
}
- changeHashSize: (int)hashsize
{
@throw [OFNotImplementedException newWithClass: isa
andSelector: _cmd];
selector: _cmd];
}
@end
|