simple_dag 0.0.0 → 0.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa2d29444d0ba1fc5d58a978b2155b6ae935bbab
4
- data.tar.gz: 169ecd6b74d0dbcb692be5d7d31451a962acefbf
3
+ metadata.gz: 24f74f8db152d6814b0b323b1e419a4b307f91b2
4
+ data.tar.gz: 2f06fe90b5b5638319d774ca9b3e047dc8ceb482
5
5
  SHA512:
6
- metadata.gz: bfec6a34670faf8dfc41cb179e8a77c2aa5185f7810d380072bce9fd2295b457a4dd7c56e9cb8577b5e8fc03a56992d03f6ea842b5e6f163e7db70932e5eddd8
7
- data.tar.gz: e4efddca431809b0e28e04cfa80b7eb30e170242e33f12c4fc3653e329c727d6fddb615d1f4a88deaa1771839929c2efb2c0431a023373519d0820fac90f1a39
6
+ metadata.gz: 1754b090487a7c066b0dfba06d46c80c04a03c5c155799c209d0a0eefb0aff305b21dcf3f29241514b09ad9cf6dc3118379a2d7ef4518a95e9b33ab69e1e04aa
7
+ data.tar.gz: 1660662e9bdfa43018dc3ff6974cc12d19218330c75c762a7017a09b46d2c9c7f2499c8072fb90508341620788bf01e8e2437783afac26a98fb10a4bbc19f86f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_dag (0.0.0)
4
+ simple_dag (0.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/simple_dag.rb CHANGED
@@ -68,33 +68,27 @@ class DAG
68
68
  predecessors_set = Set.new(predecessors_of)
69
69
  predecessors_of.each { |v| v.ancestors(predecessors_set) }
70
70
 
71
- predecessors_set.each do |v|
72
- vertex_mapping[v] = result.add_vertex(v.payload)
73
- end
74
-
75
71
  # Get the set of successor vertices and add a copy to the result
76
72
  successors_set = Set.new(successors_of)
77
73
  successors_of.each { |v| v.descendants(successors_set) }
78
74
 
79
- successors_set.each do |v|
80
- vertex_mapping[v] = result.add_vertex(v.payload) unless
81
- vertex_mapping.include? v
75
+ (predecessors_set + successors_set).each do |v|
76
+ vertex_mapping[v] = result.add_vertex(v.payload)
82
77
  end
83
78
 
84
- # get the unique edges
85
- edge_set = (
86
- predecessors_set.flat_map(&:incoming_edges) +
87
- successors_set.flat_map(&:outgoing_edges)
88
- ).uniq
89
-
90
- # Add them to the result via the vertex mapping
91
- edge_set.each do |e|
92
- result.add_edge(
93
- from: vertex_mapping[e.origin],
94
- to: vertex_mapping[e.destination],
95
- properties: e.properties
96
- )
79
+ predecessor_edges =
80
+ predecessors_set.flat_map(&:outgoing_edges).select do |e|
81
+ predecessors_set.include? e.destination
82
+ end
83
+
84
+ # Add the edges to the result via the vertex mapping
85
+ n_of_result_edges = 0
86
+ (predecessor_edges | successors_set.flat_map(&:outgoing_edges)).each do |e|
87
+ n_of_result_edges += 1
88
+ vertex_mapping[e.origin].send :add_edge, vertex_mapping[e.destination],
89
+ e.properties
97
90
  end
91
+ result.instance_variable_set :@n_of_edges, n_of_result_edges
98
92
 
99
93
  result
100
94
  end
@@ -75,20 +75,14 @@ class DAG
75
75
 
76
76
  def ancestors(result_set = Set.new)
77
77
  predecessors.each do |v|
78
- unless result_set.include? v
79
- result_set.add(v)
80
- v.ancestors(result_set)
81
- end
78
+ v.ancestors(result_set) unless result_set.add?(v).nil?
82
79
  end
83
80
  result_set
84
81
  end
85
82
 
86
83
  def descendants(result_set = Set.new)
87
84
  successors.each do |v|
88
- unless result_set.include? v
89
- result_set.add(v)
90
- v.descendants(result_set)
91
- end
85
+ v.descendants(result_set) unless result_set.add?(v).nil?
92
86
  end
93
87
  result_set
94
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_dag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rutherford
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-19 00:00:00.000000000 Z
12
+ date: 2018-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake