Skip to content

Commit

Permalink
Merge c35e341 into e6a24a0
Browse files Browse the repository at this point in the history
  • Loading branch information
PBrrtrn committed Oct 28, 2020
2 parents e6a24a0 + c35e341 commit 775407b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/hierarchical_graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def roots

def add_node(id, attributes={})
clear_cache
parent_to_children[id] = Set.new
child_to_parents[id] = Set.new
parent_to_children[id] ||= Set.new
child_to_parents[id] ||= Set.new
nodes[id] = Node.new self, id, attributes
end

Expand Down Expand Up @@ -73,11 +73,11 @@ def remove_relation(parent_id:, child_id:)
end

def parents_of(id)
child_to_parents[id].map { |node_id| nodes[node_id] }
child_to_parents.fetch(id, Set.new).map { |node_id| nodes[node_id] }
end

def children_of(id)
parent_to_children[id].map { |node_id| nodes[node_id] }
parent_to_children.fetch(id, Set.new).map { |node_id| nodes[node_id] }
end

def ancestors_of(id)
Expand Down

0 comments on commit 775407b

Please sign in to comment.