Created
September 11, 2015 22:42
-
-
Save AquaGeek/99d72e427b4059658f9a to your computer and use it in GitHub Desktop.
Graphs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface TSGraph : NSObject | |
- (void)addEdgeFrom:(id)vertexA to:(id)vertexB; | |
@end | |
@implementation TSGraph | |
{ | |
NSMutableDictionary *_vertices; | |
} | |
- (instancetype)init | |
{ | |
if ((self = [super init])) { | |
_vertices = [NSMutableDictionary dictionary]; | |
} | |
return self; | |
} | |
- (void)addEdgeFrom:(id)vertexA to:(id)vertexB | |
{ | |
NSMutableArray *edges = _vertices[vertexA]; | |
if (!edges) { | |
edges = [NSMutableArray array]; | |
_vertices[vertexA] = edges; | |
} | |
[edges addObject:vertexB]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment