research/brotlidump.py
def contextMap(self, kind):
        """Read context maps
        Returns the number of differnt values on the context map
        (In other words, the number of prefix trees)
        """
        NTREES = self.verboseRead(TypeCountAlphabet(
            kind[0].upper()+'T#',
            description='{} prefix trees'.format(kind)))
        mapSize = {L:64, D:4}[kind]
        if NTREES<2:
            self.cmaps[kind] = [0]*mapSize
        else:
            #read CMAPkind
            RLEMAX = self.verboseRead(RLEmaxAlphabet(
                'RLE#'+kind[0].upper(),
                description=kind+' context map'))
            alphabet = TreeAlphabet('CM'+kind[0].upper(), NTREES=NTREES, RLEMAX=RLEMAX)
            cmapCode = self.readPrefixCode(alphabet)
            tableSize = mapSize*self.numberOfBlockTypes[kind]
            cmap = []
            while len(cmap)<tableSize:
                cmapCode.description = 'map {}, entry {}'.format(
                    *divmod(len(cmap), mapSize))
                count, value = self.verboseRead(cmapCode)
                cmap.extend([value]*count)
            assert len(cmap)==tableSize
            IMTF = self.verboseRead(BoolCode('IMTF', description='Apply inverse MTF'))
            if IMTF:
                self.IMTF(cmap)
            if kind==L:
                print('Context maps for literal data:')
                for i in range(0, len(cmap), 64):
                    print(*(
                        ''.join(map(str, cmap[j:j+8]))
                        for j in range(i, i+64, 8)
                        ))
            else:
                print('Context map for distances:')
                print(*(
                    ''.join(map('{:x}'.format, cmap[i:i+4]))
                    for i in range(0, len(cmap), 4)
                    ))
            self.cmaps[kind] = cmap
        return NTREES
def contextMap(self, kind):
        """Read context maps
        Returns the number of differnt values on the context map
        (In other words, the number of prefix trees)
        """
        NTREES = self.verboseRead(TypeCountAlphabet(
            kind[0].upper()+'T#',
            description='{} prefix trees'.format(kind)))
        mapSize = {L:64, D:4}[kind]
        if NTREES<2:
            self.cmaps[kind] = [0]*mapSize
        else:
            #read CMAPkind
            RLEMAX = self.verboseRead(RLEmaxAlphabet(
                'RLE#'+kind[0].upper(),
                description=kind+' context map'))
            alphabet = TreeAlphabet('CM'+kind[0].upper(), NTREES=NTREES, RLEMAX=RLEMAX)
            cmapCode = self.readPrefixCode(alphabet)
            tableSize = mapSize*self.numberOfBlockTypes[kind]
            cmap = []
            while len(cmap)<tableSize:
                cmapCode.description = 'map {}, entry {}'.format(
                    *divmod(len(cmap), mapSize))
                count, value = self.verboseRead(cmapCode)
                cmap.extend([value]*count)
            assert len(cmap)==tableSize
            IMTF = self.verboseRead(BoolCode('IMTF', description='Apply inverse MTF'))
            if IMTF:
                self.IMTF(cmap)
            if kind==L:
                print('Context maps for literal data:')
                for i in range(0, len(cmap), 64):
                    print(*(
                        ''.join(map(str, cmap[j:j+8]))
                        for j in range(i, i+64, 8)
                        ))
            else:
                print('Context map for distances:')
                print(*(
                    ''.join(map('{:x}'.format, cmap[i:i+4]))
                    for i in range(0, len(cmap), 4)
                    ))
            self.cmaps[kind] = cmap
        return NTREES
def contextMap ( self , kind ) : NTREES = self . verboseRead ( TypeCountAlphabet ( kind [ 0 ] . upper ( ) + 'T#' , description = '{} prefix trees' . format ( kind ) ) ) mapSize = { L : 64 , D : 4 } [ kind ] if NTREES < 2 : self . cmaps [ kind ] = [ 0 ] * mapSize else : #read CMAPkind RLEMAX = self . verboseRead ( RLEmaxAlphabet ( 'RLE#' + kind [ 0 ] . upper ( ) , description = kind + ' context map' ) ) alphabet = TreeAlphabet ( 'CM' + kind [ 0 ] . upper ( ) , NTREES = NTREES , RLEMAX = RLEMAX ) cmapCode = self . readPrefixCode ( alphabet ) tableSize = mapSize * self . numberOfBlockTypes [ kind ] cmap = [ ] while len ( cmap ) < tableSize : cmapCode . description = 'map {}, entry {}' . format ( * divmod ( len ( cmap ) , mapSize ) ) count , value = self . verboseRead ( cmapCode ) cmap . extend ( [ value ] * count ) assert len ( cmap ) == tableSize IMTF = self . verboseRead ( BoolCode ( 'IMTF' , description = 'Apply inverse MTF' ) ) if IMTF : self . IMTF ( cmap ) if kind == L : print ( 'Context maps for literal data:' ) for i in range ( 0 , len ( cmap ) , 64 ) : print ( * ( '' . join ( map ( str , cmap [ j : j + 8 ] ) ) for j in range ( i , i + 64 , 8 ) ) ) else : print ( 'Context map for distances:' ) print ( * ( '' . join ( map ( '{:x}' . format , cmap [ i : i + 4 ] ) ) for i in range ( 0 , len ( cmap ) , 4 ) ) ) self . cmaps [ kind ] = cmap return NTREES
Read context maps
        Returns the number of differnt values on the context map
        (In other words, the number of prefix trees)
Read context maps Returns the number of differnt values on the context map ( In other words the number of prefix trees )