Class: Ronin::Recon::Graph
- Inherits:
-
Object
- Object
- Ronin::Recon::Graph
- Defined in:
- lib/ronin/recon/graph.rb
Overview
Represents a directed graph of discovered values and their parent values.
Instance Attribute Summary collapse
-
#edges ⇒ Hash{Value => Set<Value>}
readonly
The edges between nodes in the graph.
-
#nodes ⇒ Set<Value>
readonly
The nodes in the graph.
Instance Method Summary collapse
-
#[](value) ⇒ Set<Value>?
Fetches the parent value nodes for the value.
-
#add_edge(new_value, parent_value) ⇒ Boolean
private
Adds a value to the graph, if it already hasn't been added.
-
#add_node(new_value) ⇒ Boolean
private
Adds a value to the graph, if it already hasn't been added.
-
#empty? ⇒ Boolean
Determines if the graph is empty.
-
#include?(value) ⇒ Boolean
Determines if the value is in the graph.
-
#initialize ⇒ Graph
constructor
private
Initializes the graph.
Constructor Details
#initialize ⇒ Graph
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the graph.
45 46 47 48 |
# File 'lib/ronin/recon/graph.rb', line 45 def initialize @nodes = Set.new @edges = {} end |
Instance Attribute Details
#edges ⇒ Hash{Value => Set<Value>} (readonly)
The edges between nodes in the graph.
38 39 40 |
# File 'lib/ronin/recon/graph.rb', line 38 def edges @edges end |
#nodes ⇒ Set<Value> (readonly)
The nodes in the graph.
33 34 35 |
# File 'lib/ronin/recon/graph.rb', line 33 def nodes @nodes end |
Instance Method Details
#[](value) ⇒ Set<Value>?
Fetches the parent value nodes for the value.
112 113 114 |
# File 'lib/ronin/recon/graph.rb', line 112 def [](value) @edges[value] end |
#add_edge(new_value, parent_value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds a value to the graph, if it already hasn't been added.
81 82 83 84 85 86 87 |
# File 'lib/ronin/recon/graph.rb', line 81 def add_edge(new_value,parent_value) if parent_value node_parents = (@edges[new_value] ||= Set.new) return !node_parents.add?(parent_value).nil? end end |
#add_node(new_value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds a value to the graph, if it already hasn't been added.
62 63 64 |
# File 'lib/ronin/recon/graph.rb', line 62 def add_node(new_value) !@nodes.add?(new_value).nil? end |
#empty? ⇒ Boolean
Determines if the graph is empty.
121 122 123 |
# File 'lib/ronin/recon/graph.rb', line 121 def empty? @nodes.empty? end |
#include?(value) ⇒ Boolean
Determines if the value is in the graph.
98 99 100 |
# File 'lib/ronin/recon/graph.rb', line 98 def include?(value) @nodes.include?(value) end |