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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f21187c2df4b584bf41035d87bc53213ae09b03e
4
- data.tar.gz: d2799e3540346b13dd14f27d482e02e451a680dc
3
+ metadata.gz: 42c42cf29ae018c9494886c5304e5d5bb841838f
4
+ data.tar.gz: 7e832db797e4a5933b5e20252716d2a5d74ca94f
5
5
  SHA512:
6
- metadata.gz: 9d5c13999ce03fd28a13e15cb1713bf82ee9e4d3a4a244731ac4155baff19df7495939dbdc1879b25520ddceca0aba116744172285d8177813ee953023cdae57
7
- data.tar.gz: 1d5e2398bc67196b87fbe8e115e28077171ddb891a9858290a67d1cce37a534968e50f8fa2aa2844adb601bb0879e7be94351e0d1e70c9f6bed87c73a0a11a07
6
+ metadata.gz: 6c76a0bb92d6238ee73d171014bdc23c5efbceef1ef7ca4d7a0acdde1cb7cf454c2d07e0f1365958ac1bc4d2612f09bbbf8fadc16e1e129dec01ed4ba5ee99b3
7
+ data.tar.gz: d4fa8c0310ccb909b0dfe5c70c7a9b64e90e0d30c1504300f38f9cd2975971ffb1ae8f02de21da50ef4999f2c3f0e16ef7c2f02ef97d9928e30d912efd10cca7
@@ -1,3 +1,3 @@
1
1
  module Graphos
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
@@ -9,8 +9,8 @@ module Graphos
9
9
 
10
10
  attr_reader :nodes
11
11
 
12
- def initialize size
13
- @nodes = (0..size-1).map{|i| Node.new i }
12
+ def initialize size, edges=[]
13
+ @nodes = (0..size-1).map{|i| Node.new i, edges[i] }
14
14
  end
15
15
 
16
16
  def size
@@ -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 = @edges.index{|n| n.to == to}
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
- @edges << Edge.new(self, to, weight)
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
- graph = Graph.new(lines[0].to_i)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernardo Amorim