-
Notifications
You must be signed in to change notification settings - Fork 0
/
EPTwittererMapHintStore.m
94 lines (71 loc) · 2.78 KB
/
EPTwittererMapHintStore.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// EPTwittererMapHintStore.m
// Degrees of Tweetdom
//
// Created by Simone Manganelli on 2008-04-24.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "EPTwittererMapHintStore.h"
#import "EPTwittererChain.h"
@implementation EPTwittererMapHintStore
- (id)init;
{
if (self = [super init]) {
twitterMapHintsDict = [[NSMutableDictionary alloc] init];
}
return self;
}
- (void)dealloc;
{
[twitterMapHintsDict release];
[super dealloc];
}
- (NSString *)description;
{
return [twitterMapHintsDict description];
}
// this method will return a partial twitter chain if there's already a known path between
// the start twitterer and the end twitterer, and nil if there isn't a known partial chain
- (EPTwittererChain *)knownPathExistsFromTwitterer:(NSString *)startTwitterer toTwitterer:(NSString *)endTwitterer;
{
NSDictionary *specificTwitterHintsDict = [twitterMapHintsDict objectForKey:endTwitterer];
EPTwittererChain *knownPartialChain = nil;
if (specificTwitterHintsDict) {
// knownPartialChain will be nil if there is no known
// partial path, which is perfect
knownPartialChain = [specificTwitterHintsDict objectForKey:startTwitterer];
}
return knownPartialChain;
}
- (void)addKnownPathBetweenTwitterers:(EPTwittererChain *)partialTwitterChain;
{
NSMutableDictionary *specificTwittererHintsDict = [twitterMapHintsDict objectForKey:[partialTwitterChain lastTwittererInChain]];
if (specificTwittererHintsDict) {
EPTwittererChain *existingPartialChain = [specificTwittererHintsDict objectForKey:[partialTwitterChain firstTwittererInChain]];
if (existingPartialChain) {
// there's already a known partial path between these two twitterers;
// so we do nothing
// something to think about: if there already exists a known partial
// path, is it guaranteed to be the shortest?
} else {
[specificTwittererHintsDict setObject:partialTwitterChain forKey:[partialTwitterChain firstTwittererInChain]];
}
} else {
NSMutableDictionary *newSpecificTwittererHintsDict = [[NSMutableDictionary alloc] init];
[newSpecificTwittererHintsDict setObject:partialTwitterChain forKey:[partialTwitterChain firstTwittererInChain]];
[twitterMapHintsDict setObject:newSpecificTwittererHintsDict forKey:[partialTwitterChain lastTwittererInChain]];
[newSpecificTwittererHintsDict release];
}
}
- (void)addAllPartialPathsToEndTwittererOfChain:(EPTwittererChain *)twitterChain;
{
int i;
NSArray *chainStepsArray = [twitterChain chainStepsArray];
for (i = 0; i < [chainStepsArray count] - 1; i++) {
EPTwittererChain *newChain = [[EPTwittererChain alloc] initWithInitialChainStepsArray:
[chainStepsArray subarrayWithRange:NSMakeRange(i,[chainStepsArray count] - i)]];
[self addKnownPathBetweenTwitterers:newChain];
[newChain release];
}
}
@end