1#import "Entry.h"
2#import <Foundation/Foundation.h>
3#import "RuntimeException.h"
4
5@implementation HTEntry
6
7@synthesize next;
8@synthesize hash;
9@synthesize key;
10@synthesize value;
11
12+ (id) newEntry:(int)aHash key:(NSString *)aKey value:(id)aValue next:(HTEntry *)aNext
13{
14    return [[HTEntry alloc] init:aHash key:aKey value:aValue next:aNext];
15}
16
17- (id) init:(int)aHash key:(NSString *)aKey value:(id)aValue next:(HTEntry *)aNext
18{
19    if ( (self = [super init]) != nil) {
20        next  = aNext;
21        hash  = aHash;
22        key   = aKey;
23        value = aValue;
24    }
25    return self;
26}
27
28- (void) dealloc
29{
30    [next release];
31    [key release];
32    [value release];
33    [super dealloc];
34}
35
36
37- (id) copyWithZone:(NSZone *)zone
38{
39    HTEntry *copy = [[HTEntry allocWithZone:zone] init:hash key:key value:value next:next];
40    copy.next  = next;
41    copy.hash  = hash;
42    copy.key   = key;
43    copy.value = value;
44    //    return [[[HTEntry allocWithZone:zone] init:hash key:key value:value next:(next == nil ? nil : (HTEntry *)[next copyWithZone])] autorelease];
45    return copy;
46}
47
48- (void) setValue:(id)aValue
49{
50    if (aValue == nil)
51        @throw [[[NullPointerException alloc] init] autorelease];
52    //    id oldValue = value;
53    value = aValue;
54    //    return oldValue;
55}
56
57- (BOOL) isEqualTo:(id)o
58{
59/*
60    if (!([o conformsToProtocol:@protocol(HTEntry)]))
61        return NO;
62 */
63    HTEntry *e = (HTEntry *)o;
64    return (key == nil ? e.key == nil : [key isEqualTo:e.key]) && (value == nil ? e.value == nil : [value isEqualTo:e.value]);
65}
66
67- (int) hash
68{
69    return hash ^ (value == nil ? 0 : [value hash]);
70}
71
72- (NSString *) description
73{
74    return [NSString stringWithFormat:@"%@ = %@",[key description], [value description]];
75}
76
77@end
78
79@implementation LMNode
80
81@synthesize next;
82@synthesize prev;
83@synthesize item;
84
85+ (LMNode *) newNode:(LMNode *)aPrev element:(id)anElement next:(LMNode *)aNext
86{
87    return [[LMNode alloc] init:aPrev element:anElement next:aNext];
88}
89
90- (id) init:(LMNode *)aPrev element:(id)anElement next:(LMNode *)aNext
91{
92    self = [super init];
93    if (self) {
94        item = anElement;
95        next = aNext;
96        prev = aPrev;
97    }
98    return self;
99}
100
101- (void) dealloc
102{
103    [item release];
104    [next release];
105    [prev release];
106    [super dealloc];
107}
108
109@end
110
111