• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#import "ANTLRDoubleKeyMap.h"
2
3@implementation ANTLRDoubleKeyMap
4
5- (id) init
6{
7    self = [super init];
8    if ( self  != nil ) {
9        data = [[AMutableDictionary dictionaryWithCapacity:30] retain];
10    }
11    return self;
12}
13
14- (id) setObject:(id)v forKey1:(id)k1 forKey2:(id)k2
15{
16    AMutableDictionary *data2 = [data objectForKey:k1];
17    id prev = nil;
18    if ( data2 == nil ) {
19        data2 = [AMutableDictionary dictionaryWithCapacity:30];
20        [data setObject:data2 forKey:k1];
21    }
22    else {
23        prev = [data2 objectForKey:k2];
24    }
25    [data2 setObject:v forKey:k2];
26    return prev;
27}
28
29- (id) objectForKey1:(id)k1 forKey2:(id)k2
30{
31    AMutableDictionary *data2 = [data objectForKey:k1];
32    if ( data2 == nil )
33        return nil;
34    return [data2 objectForKey:k2];
35}
36
37- (AMutableDictionary *) objectForKey:(id)k1
38{
39    return [data objectForKey:k1];
40}
41
42
43/**
44 * Get all values associated with primary key
45 */
46- (NSArray *) valuesForKey:(id)k1
47{
48    AMutableDictionary *data2 = [data objectForKey:k1];
49    if ( data2 == nil )
50        return nil;
51    return [data2 allValues];
52}
53
54
55/**
56 * get all primary keys
57 */
58- (NSArray *) allKeys1
59{
60    return [data allKeys];
61}
62
63
64/**
65 * get all secondary keys associated with a primary key
66 */
67- (NSArray *) allKeys2:(id)k1
68{
69    AMutableDictionary * data2 = [data objectForKey:k1];
70    if ( data2 == nil )
71        return nil;
72    return [data2 allKeys];
73}
74
75- (AMutableArray *) values
76{
77//    ANTLRHashMap *s = [[ANTLRHashMap newANTLRHashMapWithLen:30];
78    AMutableArray *s = [AMutableArray arrayWithCapacity:30];
79
80    for (AMutableDictionary *k2 in [data allValues]) {
81
82        for ( NSString *v in [k2 allValues]) {
83            [s addObject:v];
84        }
85
86    }
87
88    return s;
89}
90
91- (void) dealloc
92{
93#ifdef DEBUG_DEALLOC
94    NSLog( @"called dealloc in ANTLRCommonToken" );
95#endif
96    [data release];
97    [super dealloc];
98}
99
100@synthesize data;
101@end
102