def write_8bitfloat(self, f, mantissabits=5, zeroexp=2): """Writes a byte-sized representation of floating point value f to the wrapped file. :param mantissabits: the number of bits to use for the mantissa (with the rest used for the exponent). :param zeroexp: the zero point for the exponent. """ self.write_byte(float_to_byte(f, mantissabits, zeroexp))
def encode(self, posns_boosts): # posns_boosts = [(pos, boost), ...] codes = [] base = 0 summedboost = 0 for pos, boost in posns_boosts: summedboost += boost codes.extend((varint(pos - base), float_to_byte(boost))) base = pos return pack("!If", len(posns_boosts), summedboost) + "".join(codes)
def encode(self, posns_chars_boosts): # posns_chars_boosts = [(pos, startchar, endchar, boost), ...] codes = [] posbase = 0 charbase = 0 summedboost = 0 for pos, startchar, endchar, boost in posns_chars_boosts: summedboost += boost codes.append(varint(pos - posbase)) posbase = pos codes.extend((varint(startchar - charbase), varint(endchar - startchar), float_to_byte(boost))) charbase = endchar b = pack("!If", len(posns_chars_boosts), summedboost) return b + "".join(codes)
def encode(self, freq_docboost): freq, docboost = freq_docboost return pack("!I", freq) + float_to_byte(docboost)