class SymbolMap(object): def __init__(self, min_v): self._list = SortedCollection((), lambda x : x[0]) self._min_vaddr = min_v def add_symbol(self, start, length, name): tuple = (start, length, name) self._list.insert(tuple) def find(self, addr): try: tuple = self._list.find_le(addr) if addr < tuple[0] + tuple[1]: return tuple[2] return None except ValueError: return None def copy(self): ret = SymbolMap() ret._list = self._list.copy() return ret def __str__(self): return "SymbolMap: " + self._list.__str__() def __repr__(self): return self.__str__()
class MmapState(object): def __init__(self): self._list = SortedCollection((), lambda x : x[0]) def add_map(self, start, length, pgoff, name): tuple = (start, length, pgoff, name) self._list.insert(tuple) def find(self, addr): try: tuple = self._list.find_le(addr) if addr < tuple[0] + tuple[1]: return tuple return None except ValueError: return None def copy(self): ret = MmapState() ret._list = self._list.copy() return ret def __str__(self): return "MmapState: " + self._list.__str__() def __repr__(self): return self.__str__()
class MmapState(object): def __init__(self): self._list = SortedCollection((), lambda x: x[0]) def add_map(self, start, length, pgoff, name): map_tuple = (start, length, pgoff, name) self._list.insert(map_tuple) def find(self, addr): try: map_tuple = self._list.find_le(addr) if addr < map_tuple[0] + map_tuple[1]: return map_tuple return None except ValueError: return None def copy(self): ret = MmapState() ret._list = self._list.copy() return ret def __str__(self): return 'MmapState: ' + self._list.__str__() def __repr__(self): return self.__str__()
class SymbolMap(object): def __init__(self, min_v): self._list = SortedCollection((), lambda x: x[0]) self._min_vaddr = min_v def add_symbol(self, start, length, name): tuple = (start, length, name) self._list.insert(tuple) def find(self, addr): try: tuple = self._list.find_le(addr) if addr < tuple[0] + tuple[1]: return tuple[2] return None except ValueError: return None def copy(self): ret = SymbolMap() ret._list = self._list.copy() return ret def __str__(self): return "SymbolMap: " + self._list.__str__() def __repr__(self): return self.__str__()
def find_overlapping_bins(arr1, arr2): ''' Function to calculate overlaps for every bin in array 1 against every bin in array 2. Accepts two arrays of tuples as inputs. Where each tuple is the start and end site of a bin within that array. Returns a list of Overlap objects for each bin in arr1. Each overlap object contains the indices of all the bins in arr2 that a given arr1 bin overlaps with along with the amount of overlap represented as tuples. ''' arr2_sc = SortedCollection(arr2, key=(lambda x: x[0])) overlapping_bins = [] for bin in arr1: overlaps = Overlap(bin) bin_beg, bin_end = bin # Find the closest bin in array2 try: closest_bin = arr2_sc.find_le(bin_beg) indx = arr2.index(closest_bin) except ValueError: closest_bin = arr2[0] indx = 0 overlap_amt = get_overlap_amount(bin, closest_bin) if overlap_amt > 0: overlaps.add_bin(indx, overlap_amt) # Check bins after the closest for overlaps flag = True while flag: indx += 1 try: next_bin = arr2[indx] overlap_amt = get_overlap_amount(bin, next_bin) if overlap_amt > 0: overlaps.add_bin(indx, overlap_amt) else: flag = False except IndexError: flag = False overlapping_bins.append(overlaps) return overlapping_bins