Class: KVDAG
- Inherits:
-
Object
- Object
- KVDAG
- Includes:
- Enumerable
- Defined in:
- lib/kvdag.rb,
lib/kvdag/edge.rb,
lib/kvdag/error.rb,
lib/kvdag/vertex.rb,
lib/kvdag/version.rb,
lib/kvdag/attrnode.rb,
lib/kvdag/keypathhash.rb
Overview
Directed Acyclic Graph for multiple inheritance key-value lookup
Defined Under Namespace
Modules: AttributeNode Classes: CyclicError, Edge, KeyPathHashProxy, Vertex, VertexError
Constant Summary collapse
- VERSION =
'0.1.5'
Instance Attribute Summary collapse
-
#hash_proxy_class ⇒ Object
readonly
Returns the value of attribute hash_proxy_class.
Instance Method Summary collapse
-
#each(filter = {}, &block) ⇒ Object
Enumerate all vertices in the DAG, possibly filtered by Vertex#match? expressions.
-
#edges ⇒ Object
Return the set of all edges.
- #inspect ⇒ Object
-
#vertex(attrs = {}) ⇒ Object
Create a new vertex in this DAG, optionally loaded with key-values.
-
#vertices(filter = {}) ⇒ Object
Return the set of all vertices, possibly filtered by Vertex#match? expressions.
Instance Attribute Details
#hash_proxy_class ⇒ Object (readonly)
Returns the value of attribute hash_proxy_class.
14 15 16 |
# File 'lib/kvdag.rb', line 14 def hash_proxy_class @hash_proxy_class end |
Instance Method Details
#each(filter = {}, &block) ⇒ Object
Enumerate all vertices in the DAG, possibly filtered by Vertex#match? expressions.
65 66 67 |
# File 'lib/kvdag.rb', line 65 def each(filter = {}, &block) vertices(filter).each(&block) end |
#edges ⇒ Object
Return the set of all edges
58 59 60 |
# File 'lib/kvdag.rb', line 58 def edges @vertices.reduce(Set.new) { |edges, vertex| edges + vertex.edges } end |
#inspect ⇒ Object
35 36 37 38 |
# File 'lib/kvdag.rb', line 35 def inspect '#<%s:%x(%d vertices, %d edges)>' % [self.class, self.object_id, vertices.length, edges.length] end |
#vertex(attrs = {}) ⇒ Object
Create a new vertex in this DAG, optionally loaded with key-values.
43 44 45 |
# File 'lib/kvdag.rb', line 43 def vertex(attrs = {}) KVDAG::Vertex.new(self, attrs) end |
#vertices(filter = {}) ⇒ Object
Return the set of all vertices, possibly filtered by Vertex#match? expressions.
50 51 52 53 54 |
# File 'lib/kvdag.rb', line 50 def vertices(filter = {}) return @vertices if filter.empty? Set.new(@vertices.select { |vertex| vertex.match?(filter) }) end |