Sha256: 8e7b81ab9355cc2330a644780ab235c2a8f092ab1ca93256e995cc77f609baf5

Contents?: true

Size: 595 Bytes

Versions: 1

Compression:

Stored size: 595 Bytes

Contents

require 'tsort'

module Ykytils
  class TreeManager
    include TSort
    
    def initialize
      @table = { }
    end

    def add( parent_name , name )
      if parent_name
        parent = @table[parent_name]
        if parent
          @table[parent_name] << name
        else 
          @table[parent_name] = [name]
        end
      else
        @table[name] = []
      end
    end

    def tsort_each_child(node, &block)
      ary = @table[node]
      if ary
        ary.each(&block)
      end
    end

    def tsort_each_node( &block)
      @table.keys.each(&block)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ykutils-0.1.0 lib/ykutils/treemanager.rb