00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef XAPIAN_INCLUDED_BITSTREAM_H
00023 #define XAPIAN_INCLUDED_BITSTREAM_H
00024
00025 #include <xapian/types.h>
00026 #include <xapian/visibility.h>
00027
00028 #include <string>
00029 #include <vector>
00030
00031 namespace Xapian {
00032
00033 class XAPIAN_VISIBILITY_DEFAULT BitWriter {
00034 std::string buf;
00035 int n_bits;
00036 unsigned int acc;
00037
00038 public:
00039 BitWriter() : n_bits(0), acc(0) { }
00040
00041 BitWriter(const std::string & seed) : buf(seed), n_bits(0), acc(0) { }
00042
00043 void encode(size_t value, size_t outof);
00044
00045 std::string & freeze() {
00046 if (n_bits) {
00047 buf += char(acc);
00048 n_bits = 0;
00049 acc = 0;
00050 }
00051 return buf;
00052 }
00053
00054 void encode_interpolative(const std::vector<Xapian::termpos> &pos, int j, int k);
00055 };
00056
00057 class XAPIAN_VISIBILITY_DEFAULT BitReader {
00058 std::string buf;
00059 size_t idx;
00060 int n_bits;
00061 unsigned int acc;
00062
00063 unsigned int read_bits(int count);
00064
00065 public:
00066 BitReader(const std::string &buf_)
00067 : buf(buf_), idx(0), n_bits(0), acc(0) { }
00068
00069 BitReader(const std::string &buf_, size_t skip)
00070 : buf(buf_, skip), idx(0), n_bits(0), acc(0) { }
00071
00072 Xapian::termpos decode(Xapian::termpos outof);
00073
00074
00075
00076
00077
00078 bool check_all_gone() const {
00079 return (idx == buf.size() && n_bits < 7 && acc == 0);
00080 }
00081
00082 void decode_interpolative(std::vector<Xapian::termpos> & pos, int j, int k);
00083 };
00084
00085 }
00086
00087 using Xapian::BitWriter;
00088 using Xapian::BitReader;
00089
00090 #endif // XAPIAN_INCLUDED_BITSTREAM_H