Debian Codegraph @

lib/dat/dat.hpp

raw symbols SCIP
1 /*
2 Copyright(C) 2011-2016 Brazil
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
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 #ifndef _MSC_VER
22 # include <stddef.h>
23 # include <stdint.h>
24 #endif // _MSC_VER
25
26 #include <cstddef>
27 #include <exception>
28
29 #ifdef _DEBUG
30 # include <iostream>
31 #endif // _DEBUG
32
33 #ifdef GRN_STATIC
34 # define GRN_DAT_API
35 #else
36 # ifndef GRN_DAT_API
37 # ifdef WIN32
38 # ifdef GRN_DAT_EXPORT
39 # define GRN_DAT_API __declspec(dllexport)
40 # else // GRN_DAT_EXPORT
41 # define GRN_DAT_API __declspec(dllimport)
42 # endif // GRN_DAT_EXPORT
43 # else // WIN32
44 # define GRN_DAT_APIcxx . . $ `lib/dat/dat.hpp:44:12`!
45 # endif // WIN32
46 # endif // GRN_DAT_API
47 #endif
48
49 namespace grncxx . . $ grn/ {
50 namespace datcxx . . $ grn/dat/ {
51
52 #ifdef _MSC_VER
53 typedef unsigned __int8 UInt8;
54 typedef unsigned __int16 UInt16;
55 typedef unsigned __int32 UInt32;
56 typedef unsigned __int64 UInt64;
57 #else // _MSC_VER
58 typedef ::uint8_tcxx . . $ uint8_t# UInt8cxx . . $ grn/dat/UInt8#;
59 typedef ::uint16_tcxx . . $ uint16_t# UInt16cxx . . $ grn/dat/UInt16#;
60 typedef ::uint32_tcxx . . $ uint32_t# UInt32cxx . . $ grn/dat/UInt32#;
61 typedef ::uint64_tcxx . . $ uint64_t# UInt64cxx . . $ grn/dat/UInt64#;
62 #endif // _MSC_VER
63
64 const UInt8cxx . . $ grn/dat/UInt8# MAX_UINT8cxx . . $ grn/dat/MAX_UINT8. = static_cast<UInt8cxx . . $ grn/dat/UInt8#>(0xFFU);
65 const UInt16cxx . . $ grn/dat/UInt16# MAX_UINT16cxx . . $ grn/dat/MAX_UINT16. = static_cast<UInt16cxx . . $ grn/dat/UInt16#>(0xFFFFU);
66 const UInt32cxx . . $ grn/dat/UInt32# MAX_UINT32cxx . . $ grn/dat/MAX_UINT32. = static_cast<UInt32cxx . . $ grn/dat/UInt32#>(0xFFFFFFFFU);
67 const UInt64cxx . . $ grn/dat/UInt64# MAX_UINT64cxx . . $ grn/dat/MAX_UINT64. = static_cast<UInt64cxx . . $ grn/dat/UInt64#>(0xFFFFFFFFFFFFFFFFULL);
68
69 // If a key is a prefix of another key, such a key is associated with a special
70 // terminal node which has TERMINAL_LABEL.
71 const UInt16cxx . . $ grn/dat/UInt16# TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL. = 0x100;
72 const UInt16cxx . . $ grn/dat/UInt16# MIN_LABELcxx . . $ grn/dat/MIN_LABEL. = '\0';
73 const UInt16cxx . . $ grn/dat/UInt16# MAX_LABELcxx . . $ grn/dat/MAX_LABEL. = TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.;
74 const UInt32cxx . . $ grn/dat/UInt32# INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL. = 0x1FF;
75 const UInt32cxx . . $ grn/dat/UInt32# LABEL_MASKcxx . . $ grn/dat/LABEL_MASK. = 0x1FF;
76
77 // The MSB of BASE is used to represent whether the node is a linker node or
78 // not and the other 31 bits represent the offset to its child nodes. So, the
79 // number of nodes is limited to 2^31.
80 const UInt32cxx . . $ grn/dat/UInt32# ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID. = 0;
81 const UInt32cxx . . $ grn/dat/UInt32# MAX_NODE_IDcxx . . $ grn/dat/MAX_NODE_ID. = 0x7FFFFFFF;
82 const UInt32cxx . . $ grn/dat/UInt32# MAX_NUM_NODEScxx . . $ grn/dat/MAX_NUM_NODES. = MAX_NODE_IDcxx . . $ grn/dat/MAX_NODE_ID. + 1;
83 const UInt32cxx . . $ grn/dat/UInt32# INVALID_NODE_IDcxx . . $ grn/dat/INVALID_NODE_ID. = MAX_NODE_IDcxx . . $ grn/dat/MAX_NODE_ID. + 1;
84
85 // 0 is reserved for non-linker leaf nodes. For example, the root node of an
86 // initial double-array is a non-linker leaf node.
87 const UInt32cxx . . $ grn/dat/UInt32# MAX_OFFSETcxx . . $ grn/dat/MAX_OFFSET. = MAX_NODE_IDcxx . . $ grn/dat/MAX_NODE_ID.;
88 const UInt32cxx . . $ grn/dat/UInt32# INVALID_OFFSETcxx . . $ grn/dat/INVALID_OFFSET. = 0;
89
90 // Phantom nodes are managed in each block because siblings are always put in
91 // the same block.
92 const UInt32cxx . . $ grn/dat/UInt32# BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE. = 0x200;
93 const UInt32cxx . . $ grn/dat/UInt32# BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK. = 0x1FF;
94 const UInt32cxx . . $ grn/dat/UInt32# MAX_BLOCK_IDcxx . . $ grn/dat/MAX_BLOCK_ID. = MAX_NODE_IDcxx . . $ grn/dat/MAX_NODE_ID. / BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.;
95 const UInt32cxx . . $ grn/dat/UInt32# MAX_NUM_BLOCKScxx . . $ grn/dat/MAX_NUM_BLOCKS. = MAX_BLOCK_IDcxx . . $ grn/dat/MAX_BLOCK_ID. + 1;
96
97 // Blocks are divided by their levels, which indicate how easily update
98 // operations can find a good offset in them. The level of a block rises when
99 // find_offset() fails in that block many times. MAX_FAILURE_COUNT is the
100 // threshold. Also, in order to limit the time cost, find_offset() scans at
101 // most MAX_BLOCK_COUNT blocks.
102 // Larger parameters bring more chances of finding good offsets but it leads to
103 // more node renumberings, which are costly operations, and thus results in
104 // a degradation of space/time efficiencies.
105 const UInt32cxx . . $ grn/dat/UInt32# MAX_FAILURE_COUNTcxx . . $ grn/dat/MAX_FAILURE_COUNT. = 4;
106 const UInt32cxx . . $ grn/dat/UInt32# MAX_BLOCK_COUNTcxx . . $ grn/dat/MAX_BLOCK_COUNT. = 16;
107 const UInt32cxx . . $ grn/dat/UInt32# MAX_BLOCK_LEVELcxx . . $ grn/dat/MAX_BLOCK_LEVEL. = 5;
108
109 // Blocks in the same level compose a doubly linked list. The entry block of
110 // a linked list is called a leader. INVALID_LEADER means that a linked list is
111 // empty and there exists no leader.
112 const UInt32cxx . . $ grn/dat/UInt32# INVALID_LEADERcxx . . $ grn/dat/INVALID_LEADER. = 0x7FFFFFFF;
113
114 const UInt32cxx . . $ grn/dat/UInt32# MIN_KEY_IDcxx . . $ grn/dat/MIN_KEY_ID. = 1;
115 const UInt32cxx . . $ grn/dat/UInt32# MAX_KEY_IDcxx . . $ grn/dat/MAX_KEY_ID. = MAX_NODE_IDcxx . . $ grn/dat/MAX_NODE_ID.;
116 const UInt32cxx . . $ grn/dat/UInt32# INVALID_KEY_IDcxx . . $ grn/dat/INVALID_KEY_ID. = 0;
117
118 // A key length is represented as a 12-bit unsigned integer in Key.
119 // 4096 bytes key overflows to 0, so 0 is treated as 4096.
120 // A key ID is represented as a 28-bit unsigned integer in Key.
121 const UInt32cxx . . $ grn/dat/UInt32# MAX_KEY_LENGTHcxx . . $ grn/dat/MAX_KEY_LENGTH. = (1U << 12);
122 const UInt32cxx . . $ grn/dat/UInt32# MAX_NUM_KEYScxx . . $ grn/dat/MAX_NUM_KEYS. = (1U << 28) - 1;
123
124 const UInt64cxx . . $ grn/dat/UInt64# MIN_FILE_SIZEcxx . . $ grn/dat/MIN_FILE_SIZE. = 1 << 16;
125 const UInt64cxx . . $ grn/dat/UInt64# DEFAULT_FILE_SIZEcxx . . $ grn/dat/DEFAULT_FILE_SIZE. = 1 << 20;
126 const UInt64cxx . . $ grn/dat/UInt64# MAX_FILE_SIZEcxx . . $ grn/dat/MAX_FILE_SIZE. = (UInt64cxx . . $ grn/dat/UInt64#)1 << 40;
127 const double DEFAULT_NUM_NODES_PER_KEYcxx . . $ grn/dat/DEFAULT_NUM_NODES_PER_KEY. = 4.0;
128 const double MAX_NUM_NODES_PER_KEYcxx . . $ grn/dat/MAX_NUM_NODES_PER_KEY. = 16.0;
129 const double DEFAULT_AVERAGE_KEY_LENGTHcxx . . $ grn/dat/DEFAULT_AVERAGE_KEY_LENGTH. = 16.0;
130 const UInt32cxx . . $ grn/dat/UInt32# MAX_KEY_BUF_SIZEcxx . . $ grn/dat/MAX_KEY_BUF_SIZE. = 0x80000000U;
131 const UInt32cxx . . $ grn/dat/UInt32# MAX_TOTAL_KEY_LENGTHcxx . . $ grn/dat/MAX_TOTAL_KEY_LENGTH. = 0xFFFFFFFFU;
132
133 const UInt32cxx . . $ grn/dat/UInt32# ID_RANGE_CURSORcxx . . $ grn/dat/ID_RANGE_CURSOR. = 0x00001;
134 const UInt32cxx . . $ grn/dat/UInt32# KEY_RANGE_CURSORcxx . . $ grn/dat/KEY_RANGE_CURSOR. = 0x00002;
135 const UInt32cxx . . $ grn/dat/UInt32# PREFIX_CURSORcxx . . $ grn/dat/PREFIX_CURSOR. = 0x00004;
136 const UInt32cxx . . $ grn/dat/UInt32# PREDICTIVE_CURSORcxx . . $ grn/dat/PREDICTIVE_CURSOR. = 0x00008;
137 const UInt32cxx . . $ grn/dat/UInt32# CURSOR_TYPE_MASKcxx . . $ grn/dat/CURSOR_TYPE_MASK. = 0x000FF;
138
139 const UInt32cxx . . $ grn/dat/UInt32# ASCENDING_CURSORcxx . . $ grn/dat/ASCENDING_CURSOR. = 0x00100;
140 const UInt32cxx . . $ grn/dat/UInt32# DESCENDING_CURSORcxx . . $ grn/dat/DESCENDING_CURSOR. = 0x00200;
141 const UInt32cxx . . $ grn/dat/UInt32# CURSOR_ORDER_MASKcxx . . $ grn/dat/CURSOR_ORDER_MASK. = 0x00F00;
142
143 const UInt32cxx . . $ grn/dat/UInt32# EXCEPT_LOWER_BOUNDcxx . . $ grn/dat/EXCEPT_LOWER_BOUND. = 0x01000;
144 const UInt32cxx . . $ grn/dat/UInt32# EXCEPT_UPPER_BOUNDcxx . . $ grn/dat/EXCEPT_UPPER_BOUND. = 0x02000;
145 const UInt32cxx . . $ grn/dat/UInt32# EXCEPT_EXACT_MATCHcxx . . $ grn/dat/EXCEPT_EXACT_MATCH. = 0x04000;
146 const UInt32cxx . . $ grn/dat/UInt32# CURSOR_OPTIONS_MASKcxx . . $ grn/dat/CURSOR_OPTIONS_MASK. = 0xFF000;
147
148 const UInt32cxx . . $ grn/dat/UInt32# REMOVING_FLAGcxx . . $ grn/dat/REMOVING_FLAG. = 1U << 0;
149 const UInt32cxx . . $ grn/dat/UInt32# INSERTING_FLAGcxx . . $ grn/dat/INSERTING_FLAG. = 1U << 1;
150 const UInt32cxx . . $ grn/dat/UInt32# UPDATING_FLAGcxx . . $ grn/dat/UPDATING_FLAG. = 1U << 2;
151 const UInt32cxx . . $ grn/dat/UInt32# CHANGING_MASKcxx . . $ grn/dat/CHANGING_MASK. = REMOVING_FLAGcxx . . $ grn/dat/REMOVING_FLAG. | INSERTING_FLAGcxx . . $ grn/dat/INSERTING_FLAG. | UPDATING_FLAGcxx . . $ grn/dat/UPDATING_FLAG.;
152
153 const UInt32cxx . . $ grn/dat/UInt32# MKQ_SORT_THRESHOLDcxx . . $ grn/dat/MKQ_SORT_THRESHOLD. = 10;
154
155 enum ErrorCodecxx . . $ grn/dat/ErrorCode# {
156 PARAM_ERRORcxx . . $ grn/dat/PARAM_ERROR. = -1,
157 IO_ERRORcxx . . $ grn/dat/IO_ERROR. = -2,
158 FORMAT_ERRORcxx . . $ grn/dat/FORMAT_ERROR. = -3,
159 MEMORY_ERRORcxx . . $ grn/dat/MEMORY_ERROR. = -4,
160 SIZE_ERRORcxx . . $ grn/dat/SIZE_ERROR. = -5,
161 UNEXPECTED_ERRORcxx . . $ grn/dat/UNEXPECTED_ERROR. = -6,
162 STATUS_ERRORcxx . . $ grn/dat/STATUS_ERROR. = -7
163 };
164
165 class Exceptioncxx . . $ grn/dat/Exception# : public stdcxx . . $ std/::exception {
166 public:
167 Exceptioncxx . . $ grn/dat/Exception#Exception(ced63f7c635d850d).() throw()
168 : stdcxx . . $ std/::exception(),
169 file_cxx . . $ grn/dat/Exception#file_.(""),
170 line_cxx . . $ grn/dat/Exception#line_.(-1),
171 what_cxx . . $ grn/dat/Exception#what_.("") {}
172 Exceptioncxx . . $ grn/dat/Exception#Exception(33e249814c878b19).(const char *file, int line, const char *what) throw()
173 : stdcxx . . $ std/::exception(),
174 file_cxx . . $ grn/dat/Exception#file_.(file),
175 line_cxx . . $ grn/dat/Exception#line_.(line),
176 what_cxx . . $ grn/dat/Exception#what_.((what != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) ? what : "") {}
177 Exceptioncxx . . $ grn/dat/Exception#Exception(b0f36b7d99ced815).(const Exceptioncxx . . $ grn/dat/Exception# &ex) throw()
178 : stdcxx . . $ std/::exception(ex),
179 file_cxx . . $ grn/dat/Exception#file_.(ex.file_cxx . . $ grn/dat/Exception#file_.),
180 line_cxx . . $ grn/dat/Exception#line_.(ex.line_cxx . . $ grn/dat/Exception#line_.),
181 what_cxx . . $ grn/dat/Exception#what_.(ex.what_cxx . . $ grn/dat/Exception#what_.) {}
182 virtual ~cxx . . $ grn/dat/Exception#`~Exception`(ced63f7c635d850d).Exceptioncxx . . $ grn/dat/Exception#() throw() {}
183
184 virtual ErrorCodecxx . . $ grn/dat/ErrorCode# codecxx . . $ grn/dat/Exception#code(c161794fcc47bf61).() const throw() = 0;
185 virtual const char *filecxx . . $ grn/dat/Exception#file(ba32b354807b2b81).() const throw() {
186 return file_cxx . . $ grn/dat/Exception#file_.;
187 }
188 virtual int linecxx . . $ grn/dat/Exception#line(ea6fe5115c70a13f).() const throw() {
189 return line_cxx . . $ grn/dat/Exception#line_.;
190 }
191 virtual const char *whatcxx . . $ grn/dat/Exception#what(ba32b354807b2b81).() const throw() override {
192 return what_cxx . . $ grn/dat/Exception#what_.;
193 }
194
195 private:
196 const char *file_cxx . . $ grn/dat/Exception#file_.;
197 int line_cxx . . $ grn/dat/Exception#line_.;
198 const char *what_cxx . . $ grn/dat/Exception#what_.;
199 };
200
201 template <ErrorCodecxx . . $ grn/dat/ErrorCode# T>
202 class Errorcxx . . $ grn/dat/Error# : public Exceptioncxx . . $ grn/dat/Exception# {
203 public:
204 Errorcxx . . $ grn/dat/Error#`Error<T>`(ced63f7c635d850d).() throw()
205 : Exceptioncxx . . $ grn/dat/Exception#() {}
206 Errorcxx . . $ grn/dat/Error#`Error<T>`(33e249814c878b19).(const char *file, int line, const char *what) throw()
207 : Exceptioncxx . . $ grn/dat/Exception#(file, line, what) {}
208 Errorcxx . . $ grn/dat/Error#`Error<T>`(41532c5700835e21).(const Error &ex) throw()
209 : Exceptioncxx . . $ grn/dat/Exception#(ex) {}
210 virtual ~cxx . . $ grn/dat/Error#`~Error<T>`(ced63f7c635d850d).Error() throw() {}
211
212 virtual ErrorCodecxx . . $ grn/dat/ErrorCode# codecxx . . $ grn/dat/Error#code(c161794fcc47bf61).() const throw() override {
213 return T;
214 }
215 };
216
217 typedef Errorcxx . . $ grn/dat/Error#<PARAM_ERRORcxx . . $ grn/dat/PARAM_ERROR.> ParamErrorcxx . . $ grn/dat/ParamError#;
218 typedef Errorcxx . . $ grn/dat/Error#<IO_ERRORcxx . . $ grn/dat/IO_ERROR.> IOErrorcxx . . $ grn/dat/IOError#;
219 typedef Errorcxx . . $ grn/dat/Error#<FORMAT_ERRORcxx . . $ grn/dat/FORMAT_ERROR.> FormatErrorcxx . . $ grn/dat/FormatError#;
220 typedef Errorcxx . . $ grn/dat/Error#<MEMORY_ERRORcxx . . $ grn/dat/MEMORY_ERROR.> MemoryErrorcxx . . $ grn/dat/MemoryError#;
221 typedef Errorcxx . . $ grn/dat/Error#<SIZE_ERRORcxx . . $ grn/dat/SIZE_ERROR.> SizeErrorcxx . . $ grn/dat/SizeError#;
222 typedef Errorcxx . . $ grn/dat/Error#<UNEXPECTED_ERRORcxx . . $ grn/dat/UNEXPECTED_ERROR.> UnexpectedErrorcxx . . $ grn/dat/UnexpectedError#;
223 typedef Errorcxx . . $ grn/dat/Error#<STATUS_ERRORcxx . . $ grn/dat/STATUS_ERROR.> StatusErrorcxx . . $ grn/dat/StatusError#;
224
225 #define GRN_DAT_INT_TO_STRcxx . . $ `lib/dat/dat.hpp:225:9`!(value) #value
226 #define GRN_DAT_LINE_TO_STRcxx . . $ `lib/dat/dat.hpp:226:9`!(line) GRN_DAT_INT_TO_STRcxx . . $ `lib/dat/dat.hpp:225:9`!(line)
227 #define GRN_DAT_LINE_STRcxx . . $ `lib/dat/dat.hpp:227:9`! GRN_DAT_LINE_TO_STRcxx . . $ `lib/dat/dat.hpp:226:9`!(__LINE__)
228
229 #define GRN_DAT_THROWcxx . . $ `lib/dat/dat.hpp:229:9`!(code, msg)\
230 (throw grn::dat::Error<code>(__FILE__, __LINE__,\
231 __FILE__ ":" GRN_DAT_LINE_STRcxx . . $ `lib/dat/dat.hpp:227:9`! ": " #code ": " msg))
232 #define GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(code, cond)\
233 (void)((!(cond)) || (GRN_DAT_THROWcxx . . $ `lib/dat/dat.hpp:229:9`!(code, #cond), 0))
234
235 #ifdef _DEBUG
236 #define GRN_DAT_DEBUG_THROW_IF(cond)\
237 GRN_DAT_THROW_IF(grn::dat::UNEXPECTED_ERROR, cond)
238 #define GRN_DAT_DEBUG_LOG(var)\
239 (std::clog << __FILE__ ":" GRN_DAT_LINE_STR ": " #var ": "\
240 << (var) << std::endl)
241 #else // _DEBUG
242 #define GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(cond)
243 #define GRN_DAT_DEBUG_LOGcxx . . $ `lib/dat/dat.hpp:243:10`!(var)
244 #endif // _DEBUG
245
246 } // namespace dat
247 } // namespace grn