lib/memdump/memory_dump.rb
# Remove all components that are smaller than the given number of nodes
#
# It really looks only at the number of nodes reachable from a root
# (i.e. won't notice if two smaller-than-threshold roots have nodes in
# common)
Remove all components that are smaller than the given number of nodes
It really looks only at the number of nodes reachable from a root
Remove all components that are smaller than the given number of nodes It really looks only at the number of nodes reachable from a root
def remove_small_components(max_size: 1)
            roots = self.addresses.to_set.dup
            leaves  = Set.new
            each_record do |r|
                refs = r['references']
                if refs.empty?
                    leaves << r['address']
                else
                    roots.subtract(r['references'])
                end
            end
            to_remove = Set.new
            roots.each do |root_address|
                component = Set[]
                queue = Set[root_address]
                while !queue.empty? && (component.size <= max_size)
                    address = queue.first
                    queue.delete(address)
                    next if component.include?(address)
                    component << address
                    queue.merge(address_to_record[address]['references'])
                end
                if component.size <= max_size
                    to_remove.merge(component)
                end
            end
            without(find_all { |r| to_remove.include?(r['address']) })
        end
def remove_small_components ( max_size : 1 ) roots = self . addresses . to_set . dup leaves = Set . new each_record do | r | refs = r [ 'references' ] if refs . empty? leaves << r [ 'address' ] else roots . subtract ( r [ 'references' ] ) end end to_remove = Set . new roots . each do | root_address | component = Set [ ] queue = Set [ root_address ] while ! queue . empty? && ( component . size <= max_size ) address = queue . first queue . delete ( address ) next if component . include? ( address ) component << address queue . merge ( address_to_record [ address ] [ 'references' ] ) end if component . size <= max_size to_remove . merge ( component ) end end without ( find_all { | r | to_remove . include? ( r [ 'address' ] ) } ) end
Remove all components that are smaller than the given number of nodes
It really looks only at the number of nodes reachable from a root
(i.e.
Remove all components that are smaller than the given number of nodes It really looks only at the number of nodes reachable from a root ( i . e .
max_size