directed_graph 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/directed_graph/edge.rb +4 -4
- data/lib/directed_graph/graph.rb +2 -8
- data/lib/directed_graph/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0adbde84d2c5293373788a5ce73f444fa41d3129
|
4
|
+
data.tar.gz: 691938d500c03589376637969b320ade01699fee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 843edf49bae2d53557d2c749b1caaae3a523502f505d4306905dc43285b8f8a10047a39424617bb9edf9d97fe1e58456f9ebf1a11f6efa03ee62cebf9a68963f
|
7
|
+
data.tar.gz: df3e337f5f782951bab9974b6ade178ce10692fab50c2a0641a6efa1a38ee7a2f5f5859d116e88793a6c993a9ba9891a72cc78a709b6b3b48d1c9bcdf59dad65
|
data/README.md
CHANGED
@@ -11,12 +11,12 @@ The `Graph` class should be instantiated with an array of edges:
|
|
11
11
|
```ruby
|
12
12
|
# The first argument is the origin_vertex
|
13
13
|
# and the second is the destination_vertex
|
14
|
-
@ra = Edge.new("root", "a")
|
15
|
-
@ab = Edge.new("a", "b")
|
16
|
-
@bc = Edge.new("b", "c")
|
17
|
-
@bd = Edge.new("b", "d")
|
18
|
-
@ae = Edge.new("a", "e")
|
19
|
-
@de = Edge.new("d", "e")
|
14
|
+
@ra = Edge.new(origin_vertex: "root", destination_vertex: "a")
|
15
|
+
@ab = Edge.new(origin_vertex: "a", destination_vertex: "b")
|
16
|
+
@bc = Edge.new(origin_vertex: "b", destination_vertex: "c")
|
17
|
+
@bd = Edge.new(origin_vertex: "b", destination_vertex: "d")
|
18
|
+
@ae = Edge.new(origin_vertex: "a", destination_vertex: "e")
|
19
|
+
@de = Edge.new(origin_vertex: "d", destination_vertex: "e")
|
20
20
|
@edges = [@ra, @ab, @bc, @bd, @ae, @de]
|
21
21
|
@graph = Graph.new(@edges)
|
22
22
|
```
|
data/lib/directed_graph/edge.rb
CHANGED
@@ -4,10 +4,10 @@ module DirectedGraph
|
|
4
4
|
|
5
5
|
attr_reader :origin_vertex, :destination_vertex, :value
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@origin_vertex = origin_vertex
|
9
|
-
@destination_vertex = destination_vertex
|
10
|
-
@value = value
|
7
|
+
def initialize(args)
|
8
|
+
@origin_vertex = args.fetch(:origin_vertex)
|
9
|
+
@destination_vertex = args.fetch(:destination_vertex)
|
10
|
+
@value = args.fetch(:value, nil)
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
data/lib/directed_graph/graph.rb
CHANGED
@@ -8,12 +8,6 @@ module DirectedGraph
|
|
8
8
|
@edges = edges
|
9
9
|
end
|
10
10
|
|
11
|
-
def vertices_longest_path_to_root(root_vertex)
|
12
|
-
vertices.map do |v|
|
13
|
-
[v, longest_path(root_vertex, v)]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
11
|
def vertices
|
18
12
|
r = []
|
19
13
|
edges.each {|e| r.push(e.origin_vertex, e.destination_vertex)}
|
@@ -43,8 +37,6 @@ module DirectedGraph
|
|
43
37
|
end.inject([]) {|m, arr| m = arr if arr.length > m.length; m}
|
44
38
|
end
|
45
39
|
|
46
|
-
private
|
47
|
-
|
48
40
|
def children(vertex)
|
49
41
|
edges.select {|e| e.origin_vertex == vertex}.map{|e| e.destination_vertex}
|
50
42
|
end
|
@@ -53,6 +45,8 @@ module DirectedGraph
|
|
53
45
|
edges.select {|e| e.destination_vertex == vertex}.map{|e| e.origin_vertex}
|
54
46
|
end
|
55
47
|
|
48
|
+
private
|
49
|
+
|
56
50
|
def vertices_and_children
|
57
51
|
vertices.map {|v| [v, children(v)]}
|
58
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: directed_graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MrPowers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|