Class: BidirectionalHash

Inherits:
Object
  • Object
show all
Defined in:
lib/cpp_dependency_graph/bidirectional_hash.rb

Instance Method Summary collapse

Constructor Details

#initializeBidirectionalHash

Returns a new instance of BidirectionalHash.



4
5
6
7
# File 'lib/cpp_dependency_graph/bidirectional_hash.rb', line 4

def initialize
  @forward = Hash.new { |h, k| h[k] = [ ] }
  @reverse = Hash.new { |h, k| h[k] = [ ] }
end

Instance Method Details

#fetch(k) ⇒ Object



15
16
17
# File 'lib/cpp_dependency_graph/bidirectional_hash.rb', line 15

def fetch(k)
  fetch_from(@forward, k)
end

#insert(k, v) ⇒ Object



9
10
11
12
13
# File 'lib/cpp_dependency_graph/bidirectional_hash.rb', line 9

def insert(k, v)
  @forward[k].push(v)
  @reverse[v].push(k)
  v
end

#rfetch(v) ⇒ Object



19
20
21
# File 'lib/cpp_dependency_graph/bidirectional_hash.rb', line 19

def rfetch(v)
  fetch_from(@reverse, v)
end