Sha256: be02acac4fa5779e3f507a61c66ad31e0704d236c53f0a97604042db7516bfe8

Contents?: true

Size: 808 Bytes

Versions: 2

Compression:

Stored size: 808 Bytes

Contents

module MemDump
    def self.subgraph_of(dump, root_address, max_depth: Float::INFINITY)
        remaining_records = Hash.new
        dump.each_record do |r|
            address = (r['address'] || r['root'])
            remaining_records[address] = r
        end

        selected_records = Hash.new
        queue = [[root_address, 0]]
        while !queue.empty?
            address, depth = queue.shift
            if record = remaining_records.delete(address)
                selected_records[address] = record
                if (depth < max_depth) && (refs = record['references'])
                    refs.each do |ref_address|
                        queue << [ref_address, depth + 1]
                    end
                end
            end
        end

        selected_records.values
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
memdump-0.2.0 lib/memdump/subgraph_of.rb
memdump-0.1.0 lib/memdump/subgraph_of.rb