-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertex.erl
46 lines (37 loc) · 1023 Bytes
/
vertex.erl
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
-module(vertex).
%% add player
%% player log
%% vertex log
%% time machine: go back in log
%% should player see older self?
%% should universe be forked?
%% wormhole: a vertex with 0 distance between two vertices
%% higher dimension: a vertex with 0 distance to all vertices
%% quantum entaglement
add_vertex() ->
spawn_link(fun() -> vertex_loop([]) end).
add_vertex(Vertex) ->
NewVertex = add_vertex(),
add_edge(Vertex, NewVertex).
add_vertex_two_way(Vertex) ->
NewVertex = add_vertex(),
two_way_edge(Vertex, NewVertex).
add_edge(Vertex1, Vertex2) ->
Vertex1 ! {add_edge, Vertex2}.
list_vertics(Vertex) ->
Vertex ! {list_vertics, self()},
receive
VertexList ->
VertexList
end.
two_way_edge(Vertex1, Vertex2) ->
add_edge(Vertex1, Vertex2),
add_edge(Vertex2, Vertex1).
vertex_loop(VertexList) ->
receive
{add_edge, Vertex} ->
VertexList2 = [Vertex | VertexList],
vertex_loop(VertexList2);
{list_vertics, From} ->
From ! VertexList
end.