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 +4 -4
- data/lib/graphos/version.rb +1 -1
- data/lib/graphos/weighted/node.rb +18 -7
- 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: f21187c2df4b584bf41035d87bc53213ae09b03e
|
4
|
+
data.tar.gz: d2799e3540346b13dd14f27d482e02e451a680dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d5c13999ce03fd28a13e15cb1713bf82ee9e4d3a4a244731ac4155baff19df7495939dbdc1879b25520ddceca0aba116744172285d8177813ee953023cdae57
|
7
|
+
data.tar.gz: 1d5e2398bc67196b87fbe8e115e28077171ddb891a9858290a67d1cce37a534968e50f8fa2aa2844adb601bb0879e7be94351e0d1e70c9f6bed87c73a0a11a07
|
data/lib/graphos/version.rb
CHANGED
@@ -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
|
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.
|
17
|
-
|
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
|
-
|
32
|
+
edges.inject(0){|sum,e| sum+e.weight }
|
22
33
|
end
|
23
34
|
|
24
35
|
def neighbor_of? index
|
25
|
-
|
36
|
+
edges.any? {|node| node.to.index == index }
|
26
37
|
end
|
27
38
|
|
28
39
|
def neighbors
|
29
|
-
|
40
|
+
edges.map{|edge| edge.to}
|
30
41
|
end
|
31
42
|
|
32
43
|
def edge to
|
33
|
-
|
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.
|
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
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|