graphos 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphos/version.rb +1 -1
- data/lib/graphos/weighted/graph.rb +2 -2
- data/lib/graphos/weighted/node.rb +9 -4
- data/lib/graphos/weighted/text_factory.rb +11 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42c42cf29ae018c9494886c5304e5d5bb841838f
|
4
|
+
data.tar.gz: 7e832db797e4a5933b5e20252716d2a5d74ca94f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c76a0bb92d6238ee73d171014bdc23c5efbceef1ef7ca4d7a0acdde1cb7cf454c2d07e0f1365958ac1bc4d2612f09bbbf8fadc16e1e129dec01ed4ba5ee99b3
|
7
|
+
data.tar.gz: d4fa8c0310ccb909b0dfe5c70c7a9b64e90e0d30c1504300f38f9cd2975971ffb1ae8f02de21da50ef4999f2c3f0e16ef7c2f02ef97d9928e30d912efd10cca7
|
data/lib/graphos/version.rb
CHANGED
@@ -6,9 +6,9 @@ module Graphos
|
|
6
6
|
|
7
7
|
class Node
|
8
8
|
attr_reader :index
|
9
|
-
def initialize index
|
9
|
+
def initialize index, size=0
|
10
10
|
@index = index
|
11
|
-
@edges =
|
11
|
+
@edges = Array.new(size||0)
|
12
12
|
@edge_count = 0
|
13
13
|
end
|
14
14
|
|
@@ -19,11 +19,16 @@ module Graphos
|
|
19
19
|
|
20
20
|
def add_edge to, weight
|
21
21
|
# Does a O(n) check deleting existing edges
|
22
|
-
current_idx =
|
22
|
+
current_idx = edges.index{|n| n.to == to}
|
23
23
|
if current_idx
|
24
24
|
@edges[current_idx] = Edge.new(self,to,weight)
|
25
25
|
else
|
26
|
-
|
26
|
+
edge = Edge.new(self, to, weight)
|
27
|
+
if(@edges.size > @edge_count)
|
28
|
+
@edges[@edge_count] = edge
|
29
|
+
else
|
30
|
+
@edges << edge
|
31
|
+
end
|
27
32
|
@edge_count += 1
|
28
33
|
end
|
29
34
|
end
|
@@ -3,7 +3,17 @@ module Graphos
|
|
3
3
|
module TextFactory
|
4
4
|
def self.read path
|
5
5
|
lines = IO.readlines(path)
|
6
|
-
|
6
|
+
size = lines[0].to_i
|
7
|
+
|
8
|
+
edges = Array.new(size,0)
|
9
|
+
|
10
|
+
lines[1..-1].each do |line|
|
11
|
+
args = line.split(/[ \n]+/)
|
12
|
+
edges[args[0].to_i-1] += 1
|
13
|
+
edges[args[1].to_i-1] += 1
|
14
|
+
end
|
15
|
+
|
16
|
+
graph = Graph.new(lines[0].to_i,edges)
|
7
17
|
lines[1..-1].each do |line|
|
8
18
|
args = line.split(/[ \n]+/)
|
9
19
|
graph.add_edge args[0].to_i-1, args[1].to_i-1, args[2].to_f
|