summaryrefslogtreecommitdiffstats
path: root/storage/mroonga/vendor/groonga/lib/dat/header.hpp
blob: dbbb1efd97ebeb7a399d74f9b03b7eb347578f20 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* -*- c-basic-offset: 2 -*- */
/*
  Copyright(C) 2011-2016 Brazil

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License version 2.1 as published by the Free Software Foundation.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1335  USA
*/

#pragma once

#include "dat.hpp"

namespace grn {
namespace dat {

class GRN_DAT_API Header {
 public:
  Header()
      : file_size_(0),
        total_key_length_(0),
        next_key_id_(grn::dat::MIN_KEY_ID),
        max_key_id_(0),
        num_keys_(0),
        max_num_keys_(0),
        num_phantoms_(0),
        num_zombies_(0),
        num_blocks_(0),
        max_num_blocks_(0),
        next_key_pos_(0),
        key_buf_size_(0),
        status_flags_(0) {
    for (UInt32 i = 0; i <= MAX_BLOCK_LEVEL; ++i) {
      leaders_[i] = INVALID_LEADER;
    }
    for (UInt32 i = 0; i < (sizeof(reserved_) / sizeof(*reserved_)); ++i) {
      reserved_[i] = 0;
    }
  }

  UInt64 file_size() const {
    return file_size_;
  }
  UInt32 total_key_length() const {
    return total_key_length_;
  }
  UInt32 min_key_id() const {
    return MIN_KEY_ID;
  }
  UInt32 next_key_id() const {
    return next_key_id_;
  }
  UInt32 max_key_id() const {
    return max_key_id_;
  }
  UInt32 num_keys() const {
    return num_keys_;
  }
  UInt32 max_num_keys() const {
    return max_num_keys_;
  }
  UInt32 num_nodes() const {
    return num_blocks() * BLOCK_SIZE;
  }
  UInt32 num_phantoms() const {
    return num_phantoms_;
  }
  UInt32 num_zombies() const {
    return num_zombies_;
  }
  UInt32 max_num_nodes() const {
    return max_num_blocks() * BLOCK_SIZE;
  }
  UInt32 num_blocks() const {
    return num_blocks_;
  }
  UInt32 max_num_blocks() const {
    return max_num_blocks_;
  }
  UInt32 next_key_pos() const {
    return next_key_pos_;
  }
  UInt32 key_buf_size() const {
    return key_buf_size_;
  }
  UInt32 status_flags() const {
    return status_flags_;
  }
  UInt32 ith_leader(UInt32 i) const {
    GRN_DAT_DEBUG_THROW_IF(i > MAX_BLOCK_LEVEL);
    return leaders_[i];
  }

  void set_file_size(UInt64 x) {
    GRN_DAT_DEBUG_THROW_IF(x > MAX_FILE_SIZE);
    file_size_ = x;
  }
  void set_total_key_length(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(x > MAX_TOTAL_KEY_LENGTH);
    total_key_length_ = x;
  }
  void set_next_key_id(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF((x - 1) > MAX_KEY_ID);
    next_key_id_ = x;
  }
  void set_max_key_id(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(x > MAX_KEY_ID);
    max_key_id_ = x;
  }
  void set_num_keys(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(x > MAX_NUM_KEYS);
    num_keys_ = x;
  }
  void set_max_num_keys(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(x > MAX_NUM_KEYS);
    max_num_keys_ = x;
  }
  void set_num_phantoms(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(x > max_num_nodes());
    num_phantoms_ = x;
  }
  void set_num_zombies(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(x > max_num_nodes());
    num_zombies_ = x;
  }
  void set_num_blocks(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(x > max_num_blocks());
    num_blocks_ = x;
  }
  void set_max_num_blocks(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(x > MAX_NUM_BLOCKS);
    max_num_blocks_ = x;
  }
  void set_next_key_pos(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(x > key_buf_size());
    next_key_pos_ = x;
  }
  void set_key_buf_size(UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(x > MAX_KEY_BUF_SIZE);
    key_buf_size_ = x;
  }
  void set_status_flags(UInt32 x) {
    status_flags_ = x;
  }
  void set_ith_leader(UInt32 i, UInt32 x) {
    GRN_DAT_DEBUG_THROW_IF(i > MAX_BLOCK_LEVEL);
    GRN_DAT_DEBUG_THROW_IF((x != INVALID_LEADER) && (x >= num_blocks()));
    leaders_[i] = x;
  }

 private:
  UInt64 file_size_;
  UInt32 total_key_length_;
  UInt32 next_key_id_;
  UInt32 max_key_id_;
  UInt32 num_keys_;
  UInt32 max_num_keys_;
  UInt32 num_phantoms_;
  UInt32 num_zombies_;
  UInt32 num_blocks_;
  UInt32 max_num_blocks_;
  UInt32 next_key_pos_;
  UInt32 key_buf_size_;
  UInt32 leaders_[MAX_BLOCK_LEVEL + 1];
  UInt32 status_flags_;
  UInt32 reserved_[12];
};

}  // namespace dat
}  // namespace grn