research/brotlidump.py
def setDecode(self, decodeTable):
        """Store decodeTable,
        and compute lengthTable, minLength, maxLength from encodings.
        """
        self.decodeTable = decodeTable
        #set of symbols with unknown length
        todo = set(decodeTable)
        #bit size under investigation
        maskLength = 0
        lengthTable = {}
        while todo:
            mask = (1<<maskLength)-1
            #split the encodings that we didn't find yet using b bits
            splitSymbols = defaultdict(list)
            for s in todo: splitSymbols[s&mask].append(s)
            #unique encodings have a length of maskLength bits
            #set length, and remove from todo list
            for s,subset in splitSymbols.items():
                if len(subset)==1:
                    lengthTable[self.decodeTable[s]] = maskLength
                    todo.remove(s)
            #now investigate with longer mask
            maskLength +=1
        #save result
        self.lengthTable = lengthTable
        self.minLength = min(lengthTable.values())
        self.maxLength = max(lengthTable.values())
        self.switchToPrefix()
def setDecode(self, decodeTable):
        self.decodeTable = decodeTable
        #set of symbols with unknown length
        todo = set(decodeTable)
        #bit size under investigation
        maskLength = 0
        lengthTable = {}
        while todo:
            mask = (1<<maskLength)-1
            #split the encodings that we didn't find yet using b bits
            splitSymbols = defaultdict(list)
            for s in todo: splitSymbols[s&mask].append(s)
            #unique encodings have a length of maskLength bits
            #set length, and remove from todo list
            for s,subset in splitSymbols.items():
                if len(subset)==1:
                    lengthTable[self.decodeTable[s]] = maskLength
                    todo.remove(s)
            #now investigate with longer mask
            maskLength +=1
        #save result
        self.lengthTable = lengthTable
        self.minLength = min(lengthTable.values())
        self.maxLength = max(lengthTable.values())
        self.switchToPrefix()
def setDecode ( self , decodeTable ) : self . decodeTable = decodeTable #set of symbols with unknown length todo = set ( decodeTable ) #bit size under investigation maskLength = 0 lengthTable = { } while todo : mask = ( 1 << maskLength ) - 1 #split the encodings that we didn't find yet using b bits splitSymbols = defaultdict ( list ) for s in todo : splitSymbols [ s & mask ] . append ( s ) #unique encodings have a length of maskLength bits #set length, and remove from todo list for s , subset in splitSymbols . items ( ) : if len ( subset ) == 1 : lengthTable [ self . decodeTable [ s ] ] = maskLength todo . remove ( s ) #now investigate with longer mask maskLength += 1 #save result self . lengthTable = lengthTable self . minLength = min ( lengthTable . values ( ) ) self . maxLength = max ( lengthTable . values ( ) ) self . switchToPrefix ( )
Store decodeTable,
        and compute lengthTable, minLength, maxLength from encodings.
Store decodeTable and compute lengthTable minLength maxLength from encodings .