| 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 | #include "dat.hpp"cxx . . $ `<file>/lib/dat/dat.hpp`/ |
| 22 | |
| 23 | namespace grncxx . . $ grn/ { |
| 24 | namespace datcxx . . $ grn/dat/ { |
| 25 | |
| 26 | class GRN_DAT_APIcxx . . $ `lib/dat/dat.hpp:44:12`! Blockcxx . . $ grn/dat/Block# { |
| 27 | public: |
| 28 | Blockcxx . . $ grn/dat/Block#Block(49f6e7a06ebc5aa8).() : next_cxx . . $ grn/dat/Block#next_.(0), prev_cxx . . $ grn/dat/Block#prev_.(0), first_phantom_cxx . . $ grn/dat/Block#first_phantom_.(0), num_phantoms_cxx . . $ grn/dat/Block#num_phantoms_.(0) {} |
| 29 | |
| 30 | // Blocks in the same level are stored in a doubly-linked list which is |
| 31 | // represented by the following next() and prev(). |
| 32 | UInt32cxx . . $ grn/dat/UInt32# nextcxx . . $ grn/dat/Block#next(ddd8539a2fcdd4ce).() const { |
| 33 | return next_cxx . . $ grn/dat/Block#next_. / BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.; |
| 34 | } |
| 35 | UInt32cxx . . $ grn/dat/UInt32# prevcxx . . $ grn/dat/Block#prev(ddd8539a2fcdd4ce).() const { |
| 36 | return prev_cxx . . $ grn/dat/Block#prev_. / BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.; |
| 37 | } |
| 38 | |
| 39 | // A level indicates how easily find_offset() can find a good offset in that |
| 40 | // block. It is easier in lower level blocks. |
| 41 | UInt32cxx . . $ grn/dat/UInt32# levelcxx . . $ grn/dat/Block#level(ddd8539a2fcdd4ce).() const { |
| 42 | return next_cxx . . $ grn/dat/Block#next_. & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.; |
| 43 | } |
| 44 | // A block level rises when find_offset() fails to find a good offset |
| 45 | // MAX_FAILURE_COUNT times in that block. |
| 46 | UInt32cxx . . $ grn/dat/UInt32# failure_countcxx . . $ grn/dat/Block#failure_count(ddd8539a2fcdd4ce).() const { |
| 47 | return prev_cxx . . $ grn/dat/Block#prev_. & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.; |
| 48 | } |
| 49 | |
| 50 | UInt32cxx . . $ grn/dat/UInt32# first_phantomcxx . . $ grn/dat/Block#first_phantom(ddd8539a2fcdd4ce).() const { |
| 51 | return first_phantom_cxx . . $ grn/dat/Block#first_phantom_.; |
| 52 | } |
| 53 | UInt32cxx . . $ grn/dat/UInt32# num_phantomscxx . . $ grn/dat/Block#num_phantoms(ddd8539a2fcdd4ce).() const { |
| 54 | return num_phantoms_cxx . . $ grn/dat/Block#num_phantoms_.; |
| 55 | } |
| 56 | |
| 57 | void set_nextcxx . . $ grn/dat/Block#set_next(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) { |
| 58 | GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > MAX_BLOCK_ID); |
| 59 | next_cxx . . $ grn/dat/Block#next_. = (next_cxx . . $ grn/dat/Block#next_. & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.) | (x * BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.); |
| 60 | } |
| 61 | void set_prevcxx . . $ grn/dat/Block#set_prev(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) { |
| 62 | GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > MAX_BLOCK_ID); |
| 63 | prev_cxx . . $ grn/dat/Block#prev_. = (prev_cxx . . $ grn/dat/Block#prev_. & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.) | (x * BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.); |
| 64 | } |
| 65 | |
| 66 | void set_levelcxx . . $ grn/dat/Block#set_level(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) { |
| 67 | GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > MAX_BLOCK_LEVEL); |
| 68 | GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > BLOCK_MASK); |
| 69 | next_cxx . . $ grn/dat/Block#next_. = (next_cxx . . $ grn/dat/Block#next_. & ~BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.) | x; |
| 70 | } |
| 71 | void set_failure_countcxx . . $ grn/dat/Block#set_failure_count(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) { |
| 72 | GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > MAX_FAILURE_COUNT); |
| 73 | GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > BLOCK_MASK); |
| 74 | prev_cxx . . $ grn/dat/Block#prev_. = (prev_cxx . . $ grn/dat/Block#prev_. & ~BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.) | x; |
| 75 | } |
| 76 | |
| 77 | void set_first_phantomcxx . . $ grn/dat/Block#set_first_phantom(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) { |
| 78 | GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x >= BLOCK_SIZE); |
| 79 | first_phantom_cxx . . $ grn/dat/Block#first_phantom_. = (UInt16cxx . . $ grn/dat/UInt16#)x; |
| 80 | } |
| 81 | void set_num_phantomscxx . . $ grn/dat/Block#set_num_phantoms(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) { |
| 82 | GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > BLOCK_SIZE); |
| 83 | num_phantoms_cxx . . $ grn/dat/Block#num_phantoms_. = (UInt16cxx . . $ grn/dat/UInt16#)x; |
| 84 | } |
| 85 | |
| 86 | private: |
| 87 | UInt32cxx . . $ grn/dat/UInt32# next_cxx . . $ grn/dat/Block#next_.; |
| 88 | UInt32cxx . . $ grn/dat/UInt32# prev_cxx . . $ grn/dat/Block#prev_.; |
| 89 | UInt16cxx . . $ grn/dat/UInt16# first_phantom_cxx . . $ grn/dat/Block#first_phantom_.; |
| 90 | UInt16cxx . . $ grn/dat/UInt16# num_phantoms_cxx . . $ grn/dat/Block#num_phantoms_.; |
| 91 | }; |
| 92 | |
| 93 | } // namespace dat |
| 94 | } // namespace grn |