Class: BidirectionalHash
- Inherits:
-
Object
- Object
- BidirectionalHash
- Defined in:
- lib/cpp_dependency_graph/bidirectional_hash.rb
Instance Method Summary collapse
- #fetch(k) ⇒ Object
-
#initialize ⇒ BidirectionalHash
constructor
A new instance of BidirectionalHash.
- #insert(k, v) ⇒ Object
- #rfetch(v) ⇒ Object
Constructor Details
#initialize ⇒ BidirectionalHash
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 |