Skip to content

Instantly share code, notes, and snippets.

@AquaGeek
Created September 11, 2015 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AquaGeek/99d72e427b4059658f9a to your computer and use it in GitHub Desktop.
Save AquaGeek/99d72e427b4059658f9a to your computer and use it in GitHub Desktop.
Graphs
@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