コード例 #1
0
ファイル: decoder.py プロジェクト: walafc0/soclib
    def create_table_slices(self, slices, base=None, pf=0):
        print(' ' * pf + 'Table slice').ljust(50), base, slices
        if base:
            t = self.__registry.reduced_table(base)
            matching_ops = set(t.uid_list())
            print t.uid_list(), t.slices(), matching_ops
            if len(matching_ops) == 1:
                return matching_ops.pop()

        masks = self.__registry.mkmasks(slices, base)
        #       print pf, 'Creating masks', slices, base, masks
        t = []
        for m in masks:
            n = self.put_table(m, slices, t)
            #           print (' '*pf+'Asking  table').ljust(50), m
            val = self.create_table(m, exact=False, pf=pf)
            t.append(val)
        if len(set(t)) == 1:
            return t[0]
        useless_bits = get_useless_bits(slices, t)
        if useless_bits:
            print "ohoh"
            nslices = packer.slices_diff(
                slices,
                packer.bitlist_to_slices(map(lambda x: x[1], useless_bits)))
            masks = self.__registry.mkmasks(nslices, base)
            t = []
            for m in masks:
                n = self.put_table(m, nslices, t)
                val = self.create_table(m, exact=False, pf=pf)
                t.append(val)
        return n
コード例 #2
0
ファイル: decoder.py プロジェクト: walafc0/soclib
    def create_table_slices(self, slices, base = None, pf = 0):
        print (' '*pf+'Table slice').ljust(50), base, slices
        if base:
            t = self.__registry.reduced_table(base)
            matching_ops = set(t.uid_list())
            print t.uid_list(), t.slices(), matching_ops
            if len(matching_ops) == 1:
                return matching_ops.pop()
            
        masks = self.__registry.mkmasks(slices, base)
#       print pf, 'Creating masks', slices, base, masks
        t = []
        for m in masks:
            n = self.put_table(m, slices, t)
#           print (' '*pf+'Asking  table').ljust(50), m
            val = self.create_table(m, exact = False, pf = pf)
            t.append(val)
        if len(set(t)) == 1:
            return t[0]
        useless_bits = get_useless_bits(slices, t)
        if useless_bits:
            print "ohoh"
            nslices = packer.slices_diff(slices, packer.bitlist_to_slices(map(lambda x:x[1], useless_bits)))
            masks = self.__registry.mkmasks(nslices, base)
            t = []
            for m in masks:
                n = self.put_table(m, nslices, t)
                val = self.create_table(m, exact = False, pf = pf)
                t.append(val)
        return n
コード例 #3
0
ファイル: decoder.py プロジェクト: walafc0/soclib
    def create_table(self, mask, exact=False, pf=0):
        sys.stdout.write((' ' * pf + 'Creating table ').ljust(50) + mask +
                         '\r')
        sys.stdout.flush()
        complete = self.__registry.table(mask, True)
        hollow = self.__registry.table(mask, False)
        #       print complete.uid_list(), hollow.uid_list()
        #       if mask == "0001XXX01XX0":
        #           raise
        while complete.size() != hollow.size():
            #bla
            #           print "complete", mask, "hollow", mask
            #           complete.printall()
            #           print "hollow", mask
            #           hollow.printall()
            d = packer.slices_diff(complete.slices(), hollow.slices())
            indirect_table_id = self.create_table_slices(d, mask, pf=pf + 1)
            if indirect_table_id > 0:
                break
            indirect_table = self.__tables[-indirect_table_id]
            if indirect_table_id >= 0:
                return indirect_table_id
            print "***", indirect_table, hollow.uid_list(), complete.uid_list()
            if indirect_table == hollow.uid_list():
                print "replaced"
                return indirect_table_id
            if pf < self.__max_depth:
                return indirect_table_id
            break
#       table = self.__registry.reduced_table(mask)
        table = complete
        t = table.uid_list()
        slices = table.slices()
        if len(set(t)) == 1:
            n = t[0]
        else:
            if t not in self.__tables:
                n = self.put_table(mask, slices, t)
            else:
                n = -self.__tables.index(t)
#       print mask, n
        return n
コード例 #4
0
ファイル: decoder.py プロジェクト: walafc0/soclib
    def create_table(self, mask, exact = False, pf=0):
        sys.stdout.write((' '*pf+'Creating table ').ljust(50)+mask+'\r')
        sys.stdout.flush()
        complete = self.__registry.table(mask, True)
        hollow = self.__registry.table(mask, False)
#       print complete.uid_list(), hollow.uid_list()
#       if mask == "0001XXX01XX0":
#           raise
        while complete.size() != hollow.size():
            #bla
#           print "complete", mask, "hollow", mask
#           complete.printall()
#           print "hollow", mask
#           hollow.printall()
            d = packer.slices_diff(complete.slices(), hollow.slices())
            indirect_table_id = self.create_table_slices(d, mask, pf = pf+1)
            if indirect_table_id > 0:
                break
            indirect_table = self.__tables[-indirect_table_id]
            if indirect_table_id >= 0:
                return indirect_table_id
            print "***", indirect_table, hollow.uid_list(), complete.uid_list()
            if indirect_table == hollow.uid_list():
                print "replaced"
                return indirect_table_id
            if pf < self.__max_depth:
                return indirect_table_id
            break
#       table = self.__registry.reduced_table(mask)
        table = complete
        t = table.uid_list()
        slices = table.slices()
        if len(set(t)) == 1:
            n = t[0]
        else:
            if t not in self.__tables:
                n = self.put_table(mask, slices, t)
            else:
                n = -self.__tables.index(t)
#       print mask, n
        return n