graphos 0.3.5 → 0.3.6

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: 954f1ab14ea2478a159df3d397088aade9bad337
4
- data.tar.gz: 05b945a9d9aa5de90260897a2cf7aac2d3949a67
3
+ metadata.gz: f21187c2df4b584bf41035d87bc53213ae09b03e
4
+ data.tar.gz: d2799e3540346b13dd14f27d482e02e451a680dc
5
5
  SHA512:
6
- metadata.gz: a11b436bc5e501b84cfaeca18ff38f3accabfc37779006f749d94bd22c1f5c9d94d2cc803eddbbb51ca938d6fcc16f968ebd2b47e9799f6399cd87c94ddde0b9
7
- data.tar.gz: 539c8289d370dace0d336948e227cd26cd345361ca4987d189882c9c2a291964082bde2cdc98f09d47615a4371a45b88c27d4cc864877412076e76f904f314ff
6
+ metadata.gz: 9d5c13999ce03fd28a13e15cb1713bf82ee9e4d3a4a244731ac4155baff19df7495939dbdc1879b25520ddceca0aba116744172285d8177813ee953023cdae57
7
+ data.tar.gz: 1d5e2398bc67196b87fbe8e115e28077171ddb891a9858290a67d1cce37a534968e50f8fa2aa2844adb601bb0879e7be94351e0d1e70c9f6bed87c73a0a11a07
@@ -1,3 +1,3 @@
1
1
  module Graphos
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -5,32 +5,43 @@ module Graphos
5
5
  # This class represents a node in a weighted graph
6
6
 
7
7
  class Node
8
- attr_reader :index, :edges
8
+ attr_reader :index
9
9
  def initialize index
10
10
  @index = index
11
11
  @edges = []
12
+ @edge_count = 0
13
+ end
14
+
15
+ def edges
16
+ return [] if @edge_count == 0
17
+ @edges[0..@edge_count-1]
12
18
  end
13
19
 
14
20
  def add_edge to, weight
15
21
  # Does a O(n) check deleting existing edges
16
- @edges.delete_if{|n| n.to == to}
17
- @edges << Edge.new(self, to, weight)
22
+ current_idx = @edges.index{|n| n.to == to}
23
+ if current_idx
24
+ @edges[current_idx] = Edge.new(self,to,weight)
25
+ else
26
+ @edges << Edge.new(self, to, weight)
27
+ @edge_count += 1
28
+ end
18
29
  end
19
30
 
20
31
  def degree
21
- @edges.inject(0){|sum,e| sum+e.weight }
32
+ edges.inject(0){|sum,e| sum+e.weight }
22
33
  end
23
34
 
24
35
  def neighbor_of? index
25
- @edges.any? {|node| node.to.index == index }
36
+ edges.any? {|node| node.to.index == index }
26
37
  end
27
38
 
28
39
  def neighbors
29
- @edges.map{|edge| edge.to}
40
+ edges.map{|edge| edge.to}
30
41
  end
31
42
 
32
43
  def edge to
33
- @edges.lazy.select{|e| e.to.index == to}.first
44
+ edges.lazy.select{|e| e.to.index == to}.first
34
45
  end
35
46
  end
36
47
 
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.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernardo Amorim
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-12 00:00:00.000000000 Z
12
+ date: 2014-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler