node/lib/metasm/samples/dbg-plugins/heapscan/heapscan.rb
# dichotomic search of the chunk containing ptr
# len = hash ptr => length
# list = list of hash keys sorted
dichotomic search of the chunk containing ptr
len = hash ptr => length
list = list of hash keys sorted
dichotomic search of the chunk containing ptr len = hash ptr = > length list = list of hash keys sorted
def find_elem(ptr, len, list=nil)
		return ptr if len[ptr]
		list ||= len.keys.sort
		if list.length < 16
			return list.find { |p| p <= ptr and p + len[p] > ptr }
		end 
		window = list
		while window and not window.empty?
			i = window.length/2
			wi = window[i]
			if ptr < wi
				window = window[0, i]
			elsif ptr < wi + len[wi]
				return wi
			else
				window = window[i+1, i]
			end
		end
	end
def find_elem ( ptr , len , list = nil ) return ptr if len [ ptr ] list ||= len . keys . sort if list . length < 16 return list . find { | p | p <= ptr and p + len [ p ] > ptr } end window = list while window and not window . empty? i = window . length / 2 wi = window [ i ] if ptr < wi window = window [ 0 , i ] elsif ptr < wi + len [ wi ] return wi else window = window [ i + 1 , i ] end end end
dichotomic search of the chunk containing ptr
len = hash ptr => length
list = list of hash keys sorted
dichotomic search of the chunk containing ptr len = hash ptr = > length list = list of hash keys sorted
ptr
len
list