Welcome to mirror list, hosted at ThFree Co, Russian Federation.

varint_vector.hpp « coding - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e84460e32d851cd689cbfb0ffd43a8feaaf47b6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once

/*
#include "base/base.hpp"

#include "std/vector.hpp"


class Writer;
class Reader;

namespace varint
{

#pragma pack(push, 1)
struct TableEntry
{
  uint32_t pos;
  uint64_t sum;
};
#pragma pack(pop)


class VectorBuilder
{
protected:
  // Implicit expectation: total compressed size should be within 4GB.
  static uint64_t const DEF_NUM_ELEMENTS_PER_TABLE_ENTRY = 1024;

public:
  VectorBuilder(uint64_t numElemPerTableEntry = DEF_NUM_ELEMENTS_PER_TABLE_ENTRY);

  void AddNum(uint64_t num);
  void Finalize(Writer * writer);

protected:
  uint64_t m_numElemPerTableEntry;
  uint64_t m_numsCount;
  uint64_t m_sum;
  vector<TableEntry> m_selectTable;
  vector<uint8_t> m_serialNums;
};

class VectorBuilderDelayedLast : public VectorBuilder
{
  typedef VectorBuilder BaseT;
  uint64_t m_last;
  bool m_hasLast;

  void AddLast();
public:
  VectorBuilderDelayedLast(uint64_t numElemPerTableEntry = DEF_NUM_ELEMENTS_PER_TABLE_ENTRY)
    : BaseT(numElemPerTableEntry), m_hasLast(false)
  {
  }

  void AddNum(uint64_t num);
  void ReplaceLast(uint64_t num);
  void Finalize(Writer * writer);

  bool HasLast() const { return m_hasLast; }
  uint64_t GetLast() const { return m_last; }
  uint64_t GetNumsCount() const { return m_numsCount + (m_hasLast ? 1 : 0); }
};

class Vector
{
public:
  Vector(Reader * reader);

  void FindByIndex(uint64_t countBefore, uint32_t & serialPos, uint64_t & sumBefore);
  void FindBySum(uint64_t sum, uint32_t & serialPos, uint64_t & sumBefore, uint64_t & countBefore);
  void Read(uint32_t & serialPos, uint64_t & num);

private:
  Reader * m_reader;
  uint64_t m_numsCount;
  uint64_t m_numElemPerTableEntry;
  uint64_t m_numTableEntries;
  uint64_t m_serialNumsSize;
  uint64_t m_selectTableOffset;
  uint64_t m_serialNumsOffset;
};

}
*/