Class: KVDAG

Inherits:
Object
  • Object
show all
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.3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hash_proxy_classObject (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

#edgesObject

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

#inspectObject



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