Sha256: 8d03c0e4a861bd55b9bad29b1bbc06c2c459ca34e36bee4e1d2137a3e17f1524

Contents?: true

Size: 508 Bytes

Versions: 1

Compression:

Stored size: 508 Bytes

Contents

module Fathom
  class AdjacencyMatrix
    
    include Enumerable
    
    def initialize(default=0)
      @default = default
      @store = Hash.new(default)
    end
  
    def [](parent, child)
      @store[[parent, child]]
    end
  
    def []=(parent, child, value)
      if value == @default
        @store.delete([parent, child]) # preserves a little memory
      else
        @store[[parent, child]] = value
      end
    end
    
    def each
      @store.each {|k, v| yield(k,v)}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fathom-0.5.0 lib/fathom/data/adjacency_matrix.rb