18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
-
-
-
-
-
-
|
#import "OFArray.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "OFMacros.h"
#define BUCKET_SIZE sizeof(struct of_dictionary_bucket)
/* References for static linking */
void _references_to_categories_of_OFDictionary()
{
_OFEnumerator_reference = 1;
}
@implementation OFDictionary
+ dictionary;
{
return [[[self alloc] init] autorelease];
}
+ dictionaryWithDictionary: (OFDictionary*)dict
|
527
528
529
530
531
532
533
534
535
536
537
538
539
540
|
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
}
state->itemsPtr = objects;
state->mutationsPtr = (unsigned long*)self;
return i;
}
- (OFEnumerator*)objectEnumerator
{
return [[[OFDictionaryObjectEnumerator alloc]
initWithData: data
size: size
mutationsPointer: NULL] autorelease];
}
- (OFEnumerator*)keyEnumerator
{
return [[[OFDictionaryKeyEnumerator alloc]
initWithData: data
size: size
mutationsPointer: NULL] autorelease];
}
- (void)dealloc
{
size_t i;
for (i = 0; i < size; i++) {
if (data[i].key != nil) {
|
570
571
572
573
574
575
576
|
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
}
OF_HASH_FINALIZE(hash);
return hash;
}
@end
@implementation OFDictionaryEnumerator
- initWithData: (struct of_dictionary_bucket*)data_
size: (size_t)size_
mutationsPointer: (unsigned long*)mutations_ptr_
{
self = [super init];
data = data_;
size = size_;
mutations = *mutations_ptr_;
mutations_ptr = mutations_ptr_;
return self;
}
- reset
{
if (mutations_ptr != NULL && *mutations_ptr != mutations)
@throw [OFEnumerationMutationException newWithClass: isa];
pos = 0;
return self;
}
@end
@implementation OFDictionaryObjectEnumerator
- (id)nextObject
{
if (mutations_ptr != NULL && *mutations_ptr != mutations)
@throw [OFEnumerationMutationException newWithClass: isa];
for (; pos < size && data[pos].key == nil; pos++);
if (pos < size)
return data[pos++].object;
else
return nil;
}
@end
@implementation OFDictionaryKeyEnumerator
- (id)nextObject
{
if (mutations_ptr != NULL && *mutations_ptr != mutations)
@throw [OFEnumerationMutationException newWithClass: isa];
for (; pos < size && data[pos].key == nil; pos++);
if (pos < size)
return data[pos++].key;
else
return nil;
}
@end
|