def mkmasks(self, slices, base=None): # print "mkmasks(%r, %r)"%(slices, base) my_bl = packer.slices_to_bitlist(self.__packer.slices()) de_bl = packer.slices_to_bitlist(slices) assert set(de_bl) <= set(my_bl), ValueError(de_bl, my_bl) poss = [""] mask = "" if base == None: base = "X" * len(my_bl) for n, b in enumerate(my_bl): if b in de_bl: poss = map(lambda x:x+"0", poss) \ + map(lambda x:x+"1", poss) mask = "%s" + mask else: mask = base[-1 - n] + mask if len(poss) > 1: masks = [] for x in poss: m = mask % tuple(list(x)) masks.append(m) # print " ", m else: masks = [mask] return sorted(masks)
def mkmasks(self, slices, base = None): # print "mkmasks(%r, %r)"%(slices, base) my_bl = packer.slices_to_bitlist(self.__packer.slices()) de_bl = packer.slices_to_bitlist(slices) assert set(de_bl) <= set(my_bl), ValueError(de_bl, my_bl) poss = [""] mask = "" if base == None: base = "X"*len(my_bl) for n, b in enumerate(my_bl): if b in de_bl: poss = map(lambda x:x+"0", poss) \ + map(lambda x:x+"1", poss) mask = "%s"+mask else: mask = base[-1-n]+mask if len(poss) > 1: masks = [] for x in poss: m = mask%tuple(list(x)) masks.append(m) # print " ", m else: masks = [mask] return sorted(masks)
def get_useless_bits(slices, values): useful_bits = list(sorted(packer.slices_to_bitlist(slices))) useless_bits = [] for n, bit in enumerate(useful_bits): idem = True for i in range(1 << len(useful_bits)): idem &= (values[i | (1 << n)] == values[i & ~(1 << n)]) if idem: useless_bits.append((n, bit)) return useless_bits
def get_useless_bits(slices, values): useful_bits = list(sorted(packer.slices_to_bitlist(slices))) useless_bits = [] for n, bit in enumerate(useful_bits): idem = True for i in range(1<<len(useful_bits)): idem &= ( values[i | (1<<n)] == values[i & ~(1<<n)] ) if idem: useless_bits.append((n,bit)) return useless_bits