Debian Codegraph @

lib/dat/check.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 #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`! Checkcxx . . $ grn/dat/Check# {
27 public:
28 Checkcxx . . $ grn/dat/Check#Check(49f6e7a06ebc5aa8).() : value_cxx . . $ grn/dat/Check#value_.(0) {}
29
30 bool operatorcxx . . $ grn/dat/Check#`operator==`(bcce3e99213ecef1).==(const Checkcxx . . $ grn/dat/Check# &rhs) const {
31 return value_cxx . . $ grn/dat/Check#value_. == rhs.value_cxx . . $ grn/dat/Check#value_.;
32 }
33
34 // The most significant bit represents whether or not the node ID is used as
35 // an offset. Note that the MSB is independent of the other bits.
36 bool is_offsetcxx . . $ grn/dat/Check#is_offset(50ce9a9e25b4a850).() const {
37 return (value_cxx . . $ grn/dat/Check#value_. & IS_OFFSET_FLAGcxx . . $ grn/dat/Check#IS_OFFSET_FLAG.) == IS_OFFSET_FLAGcxx . . $ grn/dat/Check#IS_OFFSET_FLAG.;
38 }
39
40 UInt32cxx . . $ grn/dat/UInt32# except_is_offsetcxx . . $ grn/dat/Check#except_is_offset(ddd8539a2fcdd4ce).() const {
41 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(is_phantom());
42 return value_cxx . . $ grn/dat/Check#value_. & ~IS_OFFSET_FLAGcxx . . $ grn/dat/Check#IS_OFFSET_FLAG.;
43 }
44
45 // A phantom node is a node that has never been used, and such a node is also
46 // called an empty element. Phantom nodes form a doubly linked list in each
47 // block, and the linked list is represented by next() and prev().
48 bool is_phantomcxx . . $ grn/dat/Check#is_phantom(50ce9a9e25b4a850).() const {
49 return (value_cxx . . $ grn/dat/Check#value_. & IS_PHANTOM_FLAGcxx . . $ grn/dat/Check#IS_PHANTOM_FLAG.) == IS_PHANTOM_FLAGcxx . . $ grn/dat/Check#IS_PHANTOM_FLAG.;
50 }
51
52 UInt32cxx . . $ grn/dat/UInt32# nextcxx . . $ grn/dat/Check#next(ddd8539a2fcdd4ce).() const {
53 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!is_phantom());
54 return (value_cxx . . $ grn/dat/Check#value_. >> NEXT_SHIFTcxx . . $ grn/dat/Check#NEXT_SHIFT.) & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.;
55 }
56 UInt32cxx . . $ grn/dat/UInt32# prevcxx . . $ grn/dat/Check#prev(ddd8539a2fcdd4ce).() const {
57 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!is_phantom());
58 return (value_cxx . . $ grn/dat/Check#value_. >> PREV_SHIFTcxx . . $ grn/dat/Check#PREV_SHIFT.) & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.;
59 }
60
61 // A label is attached to each non-phantom node. A label is represented by
62 // a byte except for a terminal label '\256'. Note that a phantom node always
63 // returns an invalid label with its phantom bit flag so as to reject invalid
64 // transitions.
65 UInt32cxx . . $ grn/dat/UInt32# labelcxx . . $ grn/dat/Check#label(ddd8539a2fcdd4ce).() const {
66 return value_cxx . . $ grn/dat/Check#value_. & (IS_PHANTOM_FLAGcxx . . $ grn/dat/Check#IS_PHANTOM_FLAG. | LABEL_MASKcxx . . $ grn/dat/LABEL_MASK.);
67 }
68
69 // A non-phantom node has the labels of the first child and the next sibling.
70 // Note that INVALID_LABEL is stored if the node has no child nodes or has
71 // no more siblings.
72 UInt32cxx . . $ grn/dat/UInt32# childcxx . . $ grn/dat/Check#child(ddd8539a2fcdd4ce).() const {
73 return (value_cxx . . $ grn/dat/Check#value_. >> CHILD_SHIFTcxx . . $ grn/dat/Check#CHILD_SHIFT.) & LABEL_MASKcxx . . $ grn/dat/LABEL_MASK.;
74 }
75 UInt32cxx . . $ grn/dat/UInt32# siblingcxx . . $ grn/dat/Check#sibling(ddd8539a2fcdd4ce).() const {
76 return (value_cxx . . $ grn/dat/Check#value_. >> SIBLING_SHIFTcxx . . $ grn/dat/Check#SIBLING_SHIFT.) & LABEL_MASKcxx . . $ grn/dat/LABEL_MASK.;
77 }
78
79 void set_is_offsetcxx . . $ grn/dat/Check#set_is_offset(b45ddcbc8423892c).(bool x) {
80 if (x) {
81 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(is_offset());
82 value_cxx . . $ grn/dat/Check#value_. |= IS_OFFSET_FLAGcxx . . $ grn/dat/Check#IS_OFFSET_FLAG.;
83 } else {
84 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!is_offset());
85 value_cxx . . $ grn/dat/Check#value_. &= ~IS_OFFSET_FLAGcxx . . $ grn/dat/Check#IS_OFFSET_FLAG.;
86 }
87 }
88
89 void set_except_is_offsetcxx . . $ grn/dat/Check#set_except_is_offset(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) {
90 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(is_phantom());
91 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!((x & IS_OFFSET_FLAG) == IS_OFFSET_FLAG);
92 value_cxx . . $ grn/dat/Check#value_. = (value_cxx . . $ grn/dat/Check#value_. & IS_OFFSET_FLAGcxx . . $ grn/dat/Check#IS_OFFSET_FLAG.) | x;
93 }
94
95 // To reject a transition to an incomplete node, set_is_phantom() invalidates
96 // its label and links when it becomes non-phantom.
97 void set_is_phantomcxx . . $ grn/dat/Check#set_is_phantom(b45ddcbc8423892c).(bool x) {
98 if (x) {
99 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(is_phantom());
100 value_cxx . . $ grn/dat/Check#value_. |= IS_PHANTOM_FLAGcxx . . $ grn/dat/Check#IS_PHANTOM_FLAG.;
101 } else {
102 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!is_phantom());
103 value_cxx . . $ grn/dat/Check#value_. = (value_cxx . . $ grn/dat/Check#value_. & IS_OFFSET_FLAGcxx . . $ grn/dat/Check#IS_OFFSET_FLAG.) | (INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL. << CHILD_SHIFTcxx . . $ grn/dat/Check#CHILD_SHIFT.) |
104 (INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL. << SIBLING_SHIFTcxx . . $ grn/dat/Check#SIBLING_SHIFT.) | INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.;
105 }
106 }
107
108 void set_nextcxx . . $ grn/dat/Check#set_next(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) {
109 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!is_phantom());
110 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > BLOCK_MASK);
111 value_cxx . . $ grn/dat/Check#value_. = (value_cxx . . $ grn/dat/Check#value_. & ~(BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK. << NEXT_SHIFTcxx . . $ grn/dat/Check#NEXT_SHIFT.)) | (x << NEXT_SHIFTcxx . . $ grn/dat/Check#NEXT_SHIFT.);
112 }
113 void set_prevcxx . . $ grn/dat/Check#set_prev(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) {
114 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!is_phantom());
115 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > BLOCK_MASK);
116 value_cxx . . $ grn/dat/Check#value_. = (value_cxx . . $ grn/dat/Check#value_. & ~(BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK. << PREV_SHIFTcxx . . $ grn/dat/Check#PREV_SHIFT.)) | (x << PREV_SHIFTcxx . . $ grn/dat/Check#PREV_SHIFT.);
117 }
118
119 void set_labelcxx . . $ grn/dat/Check#set_label(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) {
120 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(is_phantom());
121 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > MAX_LABEL);
122 value_cxx . . $ grn/dat/Check#value_. = (value_cxx . . $ grn/dat/Check#value_. & ~LABEL_MASKcxx . . $ grn/dat/LABEL_MASK.) | x;
123 }
124
125 void set_childcxx . . $ grn/dat/Check#set_child(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) {
126 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(is_phantom());
127 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(x > MAX_LABEL);
128 value_cxx . . $ grn/dat/Check#value_. = (value_cxx . . $ grn/dat/Check#value_. & ~(LABEL_MASKcxx . . $ grn/dat/LABEL_MASK. << CHILD_SHIFTcxx . . $ grn/dat/Check#CHILD_SHIFT.)) | (x << CHILD_SHIFTcxx . . $ grn/dat/Check#CHILD_SHIFT.);
129 }
130 void set_siblingcxx . . $ grn/dat/Check#set_sibling(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) {
131 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(is_phantom());
132 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(label() > MAX_LABEL);
133 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!((sibling() != INVALID_LABEL) && (x == INVALID_LABEL));
134 value_cxx . . $ grn/dat/Check#value_. = (value_cxx . . $ grn/dat/Check#value_. & ~(LABEL_MASKcxx . . $ grn/dat/LABEL_MASK. << SIBLING_SHIFTcxx . . $ grn/dat/Check#SIBLING_SHIFT.)) | (x << SIBLING_SHIFTcxx . . $ grn/dat/Check#SIBLING_SHIFT.);
135 }
136
137 private:
138 UInt32cxx . . $ grn/dat/UInt32# value_cxx . . $ grn/dat/Check#value_.;
139
140 static const UInt32cxx . . $ grn/dat/UInt32# IS_OFFSET_FLAGcxx . . $ grn/dat/Check#IS_OFFSET_FLAG. = 1U << 31;
141 static const UInt32cxx . . $ grn/dat/UInt32# IS_PHANTOM_FLAGcxx . . $ grn/dat/Check#IS_PHANTOM_FLAG. = 1U << 30;
142 static const UInt32cxx . . $ grn/dat/UInt32# NEXT_SHIFTcxx . . $ grn/dat/Check#NEXT_SHIFT. = 9;
143 static const UInt32cxx . . $ grn/dat/UInt32# PREV_SHIFTcxx . . $ grn/dat/Check#PREV_SHIFT. = 18;
144 static const UInt32cxx . . $ grn/dat/UInt32# CHILD_SHIFTcxx . . $ grn/dat/Check#CHILD_SHIFT. = 9;
145 static const UInt32cxx . . $ grn/dat/UInt32# SIBLING_SHIFTcxx . . $ grn/dat/Check#SIBLING_SHIFT. = 18;
146 };
147
148 } // namespace dat
149 } // namespace grn