1 | /* -*- c-basic-offset: 2 -*- */ |
2 | /* |
3 | Copyright(C) 2011-2016 Brazil |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License version 2.1 as published by the Free Software Foundation. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with this library; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | #pragma once |
20 | |
21 | #include "dat.hpp" |
22 | |
23 | namespace grn { |
24 | namespace dat { |
25 | |
26 | class GRN_DAT_API { |
27 | public: |
28 | () |
29 | : file_size_(0), |
30 | total_key_length_(0), |
31 | next_key_id_(grn::dat::MIN_KEY_ID), |
32 | max_key_id_(0), |
33 | num_keys_(0), |
34 | max_num_keys_(0), |
35 | num_phantoms_(0), |
36 | num_zombies_(0), |
37 | num_blocks_(0), |
38 | max_num_blocks_(0), |
39 | next_key_pos_(0), |
40 | key_buf_size_(0), |
41 | status_flags_(0) { |
42 | for (UInt32 i = 0; i <= MAX_BLOCK_LEVEL; ++i) { |
43 | leaders_[i] = INVALID_LEADER; |
44 | } |
45 | for (UInt32 i = 0; i < (sizeof(reserved_) / sizeof(*reserved_)); ++i) { |
46 | reserved_[i] = 0; |
47 | } |
48 | } |
49 | |
50 | UInt64 () const { |
51 | return file_size_; |
52 | } |
53 | UInt32 () const { |
54 | return total_key_length_; |
55 | } |
56 | UInt32 () const { |
57 | return MIN_KEY_ID; |
58 | } |
59 | UInt32 () const { |
60 | return next_key_id_; |
61 | } |
62 | UInt32 () const { |
63 | return max_key_id_; |
64 | } |
65 | UInt32 () const { |
66 | return num_keys_; |
67 | } |
68 | UInt32 () const { |
69 | return max_num_keys_; |
70 | } |
71 | UInt32 () const { |
72 | return num_blocks() * BLOCK_SIZE; |
73 | } |
74 | UInt32 () const { |
75 | return num_phantoms_; |
76 | } |
77 | UInt32 () const { |
78 | return num_zombies_; |
79 | } |
80 | UInt32 () const { |
81 | return max_num_blocks() * BLOCK_SIZE; |
82 | } |
83 | UInt32 () const { |
84 | return num_blocks_; |
85 | } |
86 | UInt32 () const { |
87 | return max_num_blocks_; |
88 | } |
89 | UInt32 () const { |
90 | return next_key_pos_; |
91 | } |
92 | UInt32 () const { |
93 | return key_buf_size_; |
94 | } |
95 | UInt32 () const { |
96 | return status_flags_; |
97 | } |
98 | UInt32 (UInt32 i) const { |
99 | GRN_DAT_DEBUG_THROW_IF(i > MAX_BLOCK_LEVEL); |
100 | return leaders_[i]; |
101 | } |
102 | |
103 | void (UInt64 x) { |
104 | GRN_DAT_DEBUG_THROW_IF(x > MAX_FILE_SIZE); |
105 | file_size_ = x; |
106 | } |
107 | void (UInt32 x) { |
108 | GRN_DAT_DEBUG_THROW_IF(x > MAX_TOTAL_KEY_LENGTH); |
109 | total_key_length_ = x; |
110 | } |
111 | void (UInt32 x) { |
112 | GRN_DAT_DEBUG_THROW_IF((x - 1) > MAX_KEY_ID); |
113 | next_key_id_ = x; |
114 | } |
115 | void (UInt32 x) { |
116 | GRN_DAT_DEBUG_THROW_IF(x > MAX_KEY_ID); |
117 | max_key_id_ = x; |
118 | } |
119 | void (UInt32 x) { |
120 | GRN_DAT_DEBUG_THROW_IF(x > MAX_NUM_KEYS); |
121 | num_keys_ = x; |
122 | } |
123 | void (UInt32 x) { |
124 | GRN_DAT_DEBUG_THROW_IF(x > MAX_NUM_KEYS); |
125 | max_num_keys_ = x; |
126 | } |
127 | void (UInt32 x) { |
128 | GRN_DAT_DEBUG_THROW_IF(x > max_num_nodes()); |
129 | num_phantoms_ = x; |
130 | } |
131 | void (UInt32 x) { |
132 | GRN_DAT_DEBUG_THROW_IF(x > max_num_nodes()); |
133 | num_zombies_ = x; |
134 | } |
135 | void (UInt32 x) { |
136 | GRN_DAT_DEBUG_THROW_IF(x > max_num_blocks()); |
137 | num_blocks_ = x; |
138 | } |
139 | void (UInt32 x) { |
140 | GRN_DAT_DEBUG_THROW_IF(x > MAX_NUM_BLOCKS); |
141 | max_num_blocks_ = x; |
142 | } |
143 | void (UInt32 x) { |
144 | GRN_DAT_DEBUG_THROW_IF(x > key_buf_size()); |
145 | next_key_pos_ = x; |
146 | } |
147 | void (UInt32 x) { |
148 | GRN_DAT_DEBUG_THROW_IF(x > MAX_KEY_BUF_SIZE); |
149 | key_buf_size_ = x; |
150 | } |
151 | void (UInt32 x) { |
152 | status_flags_ = x; |
153 | } |
154 | void (UInt32 i, UInt32 x) { |
155 | GRN_DAT_DEBUG_THROW_IF(i > MAX_BLOCK_LEVEL); |
156 | GRN_DAT_DEBUG_THROW_IF((x != INVALID_LEADER) && (x >= num_blocks())); |
157 | leaders_[i] = x; |
158 | } |
159 | |
160 | private: |
161 | UInt64 ; |
162 | UInt32 ; |
163 | UInt32 ; |
164 | UInt32 ; |
165 | UInt32 ; |
166 | UInt32 ; |
167 | UInt32 ; |
168 | UInt32 ; |
169 | UInt32 ; |
170 | UInt32 ; |
171 | UInt32 ; |
172 | UInt32 ; |
173 | UInt32 [MAX_BLOCK_LEVEL + 1]; |
174 | UInt32 ; |
175 | UInt32 [12]; |
176 | }; |
177 | |
178 | } // namespace dat |
179 | } // namespace grn |
180 | |