| 1 | /* |
| 2 | Copyright (C) 2011 Brazil |
| 3 | Copyright (C) 2022 Sutou Kouhei <[email protected]> |
| 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 as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "key-cursor.hpp"cxx . . $ `<file>/lib/dat/key-cursor.hpp`/ |
| 21 | |
| 22 | #include <algorithm> |
| 23 | #include <cstring> |
| 24 | |
| 25 | #include "trie.hpp"cxx . . $ `<file>/lib/dat/trie.hpp`/ |
| 26 | |
| 27 | #include <groonga/portability.h>cxx . . $ `<file>/include/groonga/portability.h`/ |
| 28 | |
| 29 | namespace grncxx . . $ grn/ { |
| 30 | namespace datcxx . . $ grn/dat/ { |
| 31 | |
| 32 | KeyCursorcxx . . $ grn/dat/KeyCursor#::KeyCursorcxx . . $ grn/dat/KeyCursor#KeyCursor(49f6e7a06ebc5aa8).() |
| 33 | : trie_cxx . . $ grn/dat/KeyCursor#trie_.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!), |
| 34 | offset_cxx . . $ grn/dat/KeyCursor#offset_.(0), |
| 35 | limit_cxx . . $ grn/dat/KeyCursor#limit_.(MAX_UINT32cxx . . $ grn/dat/MAX_UINT32.), |
| 36 | flags_cxx . . $ grn/dat/KeyCursor#flags_.(KEY_RANGE_CURSORcxx . . $ grn/dat/KEY_RANGE_CURSOR.), |
| 37 | buf_cxx . . $ grn/dat/KeyCursor#buf_.(), |
| 38 | count_cxx . . $ grn/dat/KeyCursor#count_.(0), |
| 39 | max_count_cxx . . $ grn/dat/KeyCursor#max_count_.(0), |
| 40 | finished_cxx . . $ grn/dat/KeyCursor#finished_.(false), |
| 41 | end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!), |
| 42 | end_str_cxx . . $ grn/dat/KeyCursor#end_str_.() {} |
| 43 | |
| 44 | KeyCursorcxx . . $ grn/dat/KeyCursor#::~cxx . . $ grn/dat/KeyCursor#`~KeyCursor`(ced63f7c635d850d).KeyCursorcxx . . $ grn/dat/KeyCursor#() { |
| 45 | if (end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) { |
| 46 | delete [] end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_.; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void KeyCursorcxx . . $ grn/dat/KeyCursor#::opencxx . . $ grn/dat/KeyCursor#open(ff67b50667d7ad53).(const Triecxx . . $ grn/dat/Trie# &trie, |
| 51 | const Stringcxx . . $ grn/dat/String# &min_str, |
| 52 | const Stringcxx . . $ grn/dat/String# &max_str, |
| 53 | UInt32cxx . . $ grn/dat/UInt32# offset, |
| 54 | UInt32cxx . . $ grn/dat/UInt32# limit, |
| 55 | UInt32cxx . . $ grn/dat/UInt32# flags) { |
| 56 | GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, |
| 57 | (min_str.ptr() == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) && (min_str.length() != 0)); |
| 58 | GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, |
| 59 | (max_str.ptr() == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) && (max_str.length() != 0)); |
| 60 | |
| 61 | flags = fix_flagscxx . . $ grn/dat/KeyCursor#fix_flags(560347b7e9428769).(flags); |
| 62 | KeyCursorcxx . . $ grn/dat/KeyCursor# new_cursorcxx . . $ grn/dat/KeyCursor#KeyCursor(86ae9facf0bf692d).(trie, offset, limit, flags); |
| 63 | new_cursor.initcxx . . $ grn/dat/KeyCursor#init(c46cb21227c95581).(min_str, max_str); |
| 64 | new_cursor.swapcxx . . $ grn/dat/KeyCursor#swap(6b7003c3030ac84a).(this); |
| 65 | } |
| 66 | |
| 67 | void KeyCursorcxx . . $ grn/dat/KeyCursor#::closecxx . . $ grn/dat/KeyCursor#close(49f6e7a06ebc5aa8).() { |
| 68 | KeyCursorcxx . . $ grn/dat/KeyCursor# new_cursorcxx . . $ grn/dat/KeyCursor#KeyCursor(49f6e7a06ebc5aa8).; |
| 69 | new_cursor.swapcxx . . $ grn/dat/KeyCursor#swap(6b7003c3030ac84a).(this); |
| 70 | } |
| 71 | |
| 72 | const Keycxx . . $ grn/dat/Key# &KeyCursorcxx . . $ grn/dat/KeyCursor#::nextcxx . . $ grn/dat/KeyCursor#next(741ea5814372790).() { |
| 73 | if (finished_cxx . . $ grn/dat/KeyCursor#finished_. || (count_cxx . . $ grn/dat/KeyCursor#count_. >= max_count_cxx . . $ grn/dat/KeyCursor#max_count_.)) { |
| 74 | return Keycxx . . $ grn/dat/Key#::invalid_keycxx . . $ grn/dat/Key#invalid_key(741ea5814372790).(); |
| 75 | } |
| 76 | |
| 77 | if ((flags_cxx . . $ grn/dat/KeyCursor#flags_. & ASCENDING_CURSORcxx . . $ grn/dat/ASCENDING_CURSOR.) == ASCENDING_CURSORcxx . . $ grn/dat/ASCENDING_CURSOR.) { |
| 78 | return ascending_nextcxx . . $ grn/dat/KeyCursor#ascending_next(741ea5814372790).(); |
| 79 | } else { |
| 80 | return descending_nextcxx . . $ grn/dat/KeyCursor#descending_next(741ea5814372790).(); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | KeyCursorcxx . . $ grn/dat/KeyCursor#::KeyCursorcxx . . $ grn/dat/KeyCursor#KeyCursor(86ae9facf0bf692d).(const Triecxx . . $ grn/dat/Trie# &trie, |
| 85 | UInt32cxx . . $ grn/dat/UInt32# offset, UInt32cxx . . $ grn/dat/UInt32# limit, UInt32cxx . . $ grn/dat/UInt32# flags) |
| 86 | : trie_cxx . . $ grn/dat/KeyCursor#trie_.(&trie), |
| 87 | offset_cxx . . $ grn/dat/KeyCursor#offset_.(offset), |
| 88 | limit_cxx . . $ grn/dat/KeyCursor#limit_.(limit), |
| 89 | flags_cxx . . $ grn/dat/KeyCursor#flags_.(flags), |
| 90 | buf_cxx . . $ grn/dat/KeyCursor#buf_.(), |
| 91 | count_cxx . . $ grn/dat/KeyCursor#count_.(0), |
| 92 | max_count_cxx . . $ grn/dat/KeyCursor#max_count_.(0), |
| 93 | finished_cxx . . $ grn/dat/KeyCursor#finished_.(false), |
| 94 | end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!), |
| 95 | end_str_cxx . . $ grn/dat/KeyCursor#end_str_.() {} |
| 96 | |
| 97 | UInt32cxx . . $ grn/dat/UInt32# KeyCursorcxx . . $ grn/dat/KeyCursor#::fix_flagscxx . . $ grn/dat/KeyCursor#fix_flags(560347b7e9428769).(UInt32cxx . . $ grn/dat/UInt32# flags) const { |
| 98 | const UInt32cxx . . $ grn/dat/UInt32# cursor_type = flags & CURSOR_TYPE_MASKcxx . . $ grn/dat/CURSOR_TYPE_MASK.; |
| 99 | GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, (cursor_type != 0) && |
| 100 | (cursor_type != KEY_RANGE_CURSOR)); |
| 101 | flags |= KEY_RANGE_CURSORcxx . . $ grn/dat/KEY_RANGE_CURSOR.; |
| 102 | |
| 103 | const UInt32cxx . . $ grn/dat/UInt32# cursor_order = flags & CURSOR_ORDER_MASKcxx . . $ grn/dat/CURSOR_ORDER_MASK.; |
| 104 | GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, (cursor_order != 0) && |
| 105 | (cursor_order != ASCENDING_CURSOR) && |
| 106 | (cursor_order != DESCENDING_CURSOR)); |
| 107 | if (cursor_order == 0) { |
| 108 | flags |= ASCENDING_CURSORcxx . . $ grn/dat/ASCENDING_CURSOR.; |
| 109 | } |
| 110 | |
| 111 | const UInt32cxx . . $ grn/dat/UInt32# cursor_options = flags & CURSOR_OPTIONS_MASKcxx . . $ grn/dat/CURSOR_OPTIONS_MASK.; |
| 112 | GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, |
| 113 | cursor_options & ~(EXCEPT_LOWER_BOUND | EXCEPT_UPPER_BOUND)); |
| 114 | |
| 115 | return flags; |
| 116 | } |
| 117 | |
| 118 | void KeyCursorcxx . . $ grn/dat/KeyCursor#::initcxx . . $ grn/dat/KeyCursor#init(c46cb21227c95581).(const Stringcxx . . $ grn/dat/String# &min_str, const Stringcxx . . $ grn/dat/String# &max_str) { |
| 119 | if (offset_cxx . . $ grn/dat/KeyCursor#offset_. > (MAX_UINT32cxx . . $ grn/dat/MAX_UINT32. - limit_cxx . . $ grn/dat/KeyCursor#limit_.)) { |
| 120 | max_count_cxx . . $ grn/dat/KeyCursor#max_count_. = MAX_UINT32cxx . . $ grn/dat/MAX_UINT32.; |
| 121 | } else { |
| 122 | max_count_cxx . . $ grn/dat/KeyCursor#max_count_. = offset_cxx . . $ grn/dat/KeyCursor#offset_. + limit_cxx . . $ grn/dat/KeyCursor#limit_.; |
| 123 | } |
| 124 | |
| 125 | if (limit_cxx . . $ grn/dat/KeyCursor#limit_. == 0) { |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | if ((flags_cxx . . $ grn/dat/KeyCursor#flags_. & ASCENDING_CURSORcxx . . $ grn/dat/ASCENDING_CURSOR.) == ASCENDING_CURSORcxx . . $ grn/dat/ASCENDING_CURSOR.) { |
| 130 | ascending_initcxx . . $ grn/dat/KeyCursor#ascending_init(c46cb21227c95581).(min_str, max_str); |
| 131 | } else { |
| 132 | descending_initcxx . . $ grn/dat/KeyCursor#descending_init(c46cb21227c95581).(min_str, max_str); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | void KeyCursorcxx . . $ grn/dat/KeyCursor#::ascending_initcxx . . $ grn/dat/KeyCursor#ascending_init(c46cb21227c95581).(const Stringcxx . . $ grn/dat/String# &min_str, const Stringcxx . . $ grn/dat/String# &max_str) { |
| 137 | if (max_str.ptrcxx . . $ grn/dat/String#ptr(3a8ef3fdc6e817ef).() != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) { |
| 138 | if (max_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).() != 0) { |
| 139 | end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_. = new UInt8cxx . . $ grn/dat/UInt8#[max_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()]; |
| 140 | grn_memcpycxx . . $ `include/groonga/portability.h:30:13`!(end_buf_, max_str.ptr(), max_str.length()); |
| 141 | end_str_cxx . . $ grn/dat/KeyCursor#end_str_..assigncxx . . $ grn/dat/String#assign(d249e89a313417f2).(end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_., max_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if ((min_str.ptrcxx . . $ grn/dat/String#ptr(3a8ef3fdc6e817ef).() == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) || (min_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).() == 0)) { |
| 146 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.); |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | UInt32cxx . . $ grn/dat/UInt32# node_id = ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.; |
| 151 | Nodecxx . . $ grn/dat/Node# nodecxx . . $ grn/dat/Node#Node(49f6e7a06ebc5aa8).; |
| 152 | for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i < min_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).(); ++i) { |
| 153 | node =cxx . . $ grn/dat/Node#`operator=`(9d493a0bcaaa24d4). trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id); |
| 154 | if (node.is_linkercxx . . $ grn/dat/Node#is_linker(50ce9a9e25b4a850).()) { |
| 155 | const Keycxx . . $ grn/dat/Key# &key = trie_cxx . . $ grn/dat/KeyCursor#trie_.->get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(node.key_poscxx . . $ grn/dat/Node#key_pos(ddd8539a2fcdd4ce).()); |
| 156 | const int result = key.strcxx . . $ grn/dat/Key#str(3f4ba625c018c01d).().comparecxx . . $ grn/dat/String#compare(6575af31c4a8b936).(min_str, i); |
| 157 | if ((result > 0) || ((result == 0) && |
| 158 | ((flags_cxx . . $ grn/dat/KeyCursor#flags_. & EXCEPT_LOWER_BOUNDcxx . . $ grn/dat/EXCEPT_LOWER_BOUND.) != EXCEPT_LOWER_BOUNDcxx . . $ grn/dat/EXCEPT_LOWER_BOUND.))) { |
| 159 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id); |
| 160 | } else if (node.siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).() != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 161 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id ^ node.labelcxx . . $ grn/dat/Node#label(ddd8539a2fcdd4ce).() ^ node.siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).()); |
| 162 | } |
| 163 | return; |
| 164 | } else if (node.siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).() != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 165 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id ^ node.labelcxx . . $ grn/dat/Node#label(ddd8539a2fcdd4ce).() ^ node.siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).()); |
| 166 | } |
| 167 | |
| 168 | node_id = node.offsetcxx . . $ grn/dat/Node#offset(ddd8539a2fcdd4ce).() ^ min_str[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i]; |
| 169 | if (trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).labelcxx . . $ grn/dat/Node#label(ddd8539a2fcdd4ce).() != min_str[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i]) { |
| 170 | UInt32cxx . . $ grn/dat/UInt32# label = node.childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).(); |
| 171 | if (label == TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) { |
| 172 | label = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node.offsetcxx . . $ grn/dat/Node#offset(ddd8539a2fcdd4ce).() ^ label).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).(); |
| 173 | } |
| 174 | while (label != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 175 | if (label > min_str[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i]) { |
| 176 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node.offsetcxx . . $ grn/dat/Node#offset(ddd8539a2fcdd4ce).() ^ label); |
| 177 | break; |
| 178 | } |
| 179 | label = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node.offsetcxx . . $ grn/dat/Node#offset(ddd8539a2fcdd4ce).() ^ label).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).(); |
| 180 | } |
| 181 | return; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | node =cxx . . $ grn/dat/Node#`operator=`(9d493a0bcaaa24d4). trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id); |
| 186 | if (node.is_linkercxx . . $ grn/dat/Node#is_linker(50ce9a9e25b4a850).()) { |
| 187 | const Keycxx . . $ grn/dat/Key# &key = trie_cxx . . $ grn/dat/KeyCursor#trie_.->get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(node.key_poscxx . . $ grn/dat/Node#key_pos(ddd8539a2fcdd4ce).()); |
| 188 | if ((key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).() != min_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()) || |
| 189 | ((flags_cxx . . $ grn/dat/KeyCursor#flags_. & EXCEPT_LOWER_BOUNDcxx . . $ grn/dat/EXCEPT_LOWER_BOUND.) != EXCEPT_LOWER_BOUNDcxx . . $ grn/dat/EXCEPT_LOWER_BOUND.)) { |
| 190 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id); |
| 191 | } else if (node.siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).() != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 192 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id ^ node.labelcxx . . $ grn/dat/Node#label(ddd8539a2fcdd4ce).() ^ node.siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).()); |
| 193 | } |
| 194 | return; |
| 195 | } else if (node.siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).() != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 196 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id ^ node.labelcxx . . $ grn/dat/Node#label(ddd8539a2fcdd4ce).() ^ node.siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).()); |
| 197 | } |
| 198 | |
| 199 | UInt32cxx . . $ grn/dat/UInt32# label = node.childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).(); |
| 200 | if ((label == TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) && |
| 201 | ((flags_cxx . . $ grn/dat/KeyCursor#flags_. & EXCEPT_LOWER_BOUNDcxx . . $ grn/dat/EXCEPT_LOWER_BOUND.) == EXCEPT_LOWER_BOUNDcxx . . $ grn/dat/EXCEPT_LOWER_BOUND.)) { |
| 202 | label = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node.offsetcxx . . $ grn/dat/Node#offset(ddd8539a2fcdd4ce).() ^ label).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).(); |
| 203 | } |
| 204 | if (label != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 205 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node.offsetcxx . . $ grn/dat/Node#offset(ddd8539a2fcdd4ce).() ^ label); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | void KeyCursorcxx . . $ grn/dat/KeyCursor#::descending_initcxx . . $ grn/dat/KeyCursor#descending_init(c46cb21227c95581).(const Stringcxx . . $ grn/dat/String# &min_str, const Stringcxx . . $ grn/dat/String# &max_str) { |
| 210 | if (min_str.ptrcxx . . $ grn/dat/String#ptr(3a8ef3fdc6e817ef).() != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) { |
| 211 | if (min_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).() != 0) { |
| 212 | end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_. = new UInt8cxx . . $ grn/dat/UInt8#[min_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()]; |
| 213 | grn_memcpycxx . . $ `include/groonga/portability.h:30:13`!(end_buf_, min_str.ptr(), min_str.length()); |
| 214 | end_str_cxx . . $ grn/dat/KeyCursor#end_str_..assigncxx . . $ grn/dat/String#assign(d249e89a313417f2).(end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_., min_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if ((max_str.ptrcxx . . $ grn/dat/String#ptr(3a8ef3fdc6e817ef).() == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) || (max_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).() == 0)) { |
| 219 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.); |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | UInt32cxx . . $ grn/dat/UInt32# node_id = ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.; |
| 224 | for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i < max_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).(); ++i) { |
| 225 | const Basecxx . . $ grn/dat/Base# base = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).(); |
| 226 | if (base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) { |
| 227 | const Keycxx . . $ grn/dat/Key# &key = trie_cxx . . $ grn/dat/KeyCursor#trie_.->get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).()); |
| 228 | const int result = key.strcxx . . $ grn/dat/Key#str(3f4ba625c018c01d).().comparecxx . . $ grn/dat/String#compare(6575af31c4a8b936).(max_str, i); |
| 229 | if ((result < 0) || ((result == 0) && |
| 230 | ((flags_cxx . . $ grn/dat/KeyCursor#flags_. & EXCEPT_UPPER_BOUNDcxx . . $ grn/dat/EXCEPT_UPPER_BOUND.) != EXCEPT_UPPER_BOUNDcxx . . $ grn/dat/EXCEPT_UPPER_BOUND.))) { |
| 231 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id | POST_ORDER_FLAGcxx . . $ grn/dat/KeyCursor#POST_ORDER_FLAG.); |
| 232 | } |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | UInt32cxx . . $ grn/dat/UInt32# label = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).(); |
| 237 | if (label == TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) { |
| 238 | node_id = base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ label; |
| 239 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id | POST_ORDER_FLAGcxx . . $ grn/dat/KeyCursor#POST_ORDER_FLAG.); |
| 240 | label = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).(); |
| 241 | } |
| 242 | while (label != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 243 | node_id = base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ label; |
| 244 | if (label < max_str[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i]) { |
| 245 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id); |
| 246 | } else if (label > max_str[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i]) { |
| 247 | return; |
| 248 | } else { |
| 249 | break; |
| 250 | } |
| 251 | label = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).(); |
| 252 | } |
| 253 | if (label == INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 254 | return; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | const Basecxx . . $ grn/dat/Base# base = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).(); |
| 259 | if (base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) { |
| 260 | const Keycxx . . $ grn/dat/Key# &key = trie_cxx . . $ grn/dat/KeyCursor#trie_.->get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).()); |
| 261 | if ((key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).() == max_str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()) && |
| 262 | ((flags_cxx . . $ grn/dat/KeyCursor#flags_. & EXCEPT_UPPER_BOUNDcxx . . $ grn/dat/EXCEPT_UPPER_BOUND.) != EXCEPT_UPPER_BOUNDcxx . . $ grn/dat/EXCEPT_UPPER_BOUND.)) { |
| 263 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id | POST_ORDER_FLAGcxx . . $ grn/dat/KeyCursor#POST_ORDER_FLAG.); |
| 264 | } |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | UInt32cxx . . $ grn/dat/UInt32# label = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).(); |
| 269 | if ((label == TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) && |
| 270 | ((flags_cxx . . $ grn/dat/KeyCursor#flags_. & EXCEPT_UPPER_BOUNDcxx . . $ grn/dat/EXCEPT_UPPER_BOUND.) != EXCEPT_UPPER_BOUNDcxx . . $ grn/dat/EXCEPT_UPPER_BOUND.)) { |
| 271 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).((base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ label) | POST_ORDER_FLAGcxx . . $ grn/dat/KeyCursor#POST_ORDER_FLAG.); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | void KeyCursorcxx . . $ grn/dat/KeyCursor#::swapcxx . . $ grn/dat/KeyCursor#swap(6b7003c3030ac84a).(KeyCursorcxx . . $ grn/dat/KeyCursor# *cursor) { |
| 276 | std::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(trie_cxx . . $ grn/dat/KeyCursor#trie_., cursor->trie_cxx . . $ grn/dat/KeyCursor#trie_.); |
| 277 | std::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(offset_cxx . . $ grn/dat/KeyCursor#offset_., cursor->offset_cxx . . $ grn/dat/KeyCursor#offset_.); |
| 278 | std::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(limit_cxx . . $ grn/dat/KeyCursor#limit_., cursor->limit_cxx . . $ grn/dat/KeyCursor#limit_.); |
| 279 | std::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(flags_cxx . . $ grn/dat/KeyCursor#flags_., cursor->flags_cxx . . $ grn/dat/KeyCursor#flags_.); |
| 280 | buf_cxx . . $ grn/dat/KeyCursor#buf_..swapcxx . . $ grn/dat/Vector#swap(31b4a4301f47d369).(&cursor->buf_cxx . . $ grn/dat/KeyCursor#buf_.); |
| 281 | std::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(count_cxx . . $ grn/dat/KeyCursor#count_., cursor->count_cxx . . $ grn/dat/KeyCursor#count_.); |
| 282 | std::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(max_count_cxx . . $ grn/dat/KeyCursor#max_count_., cursor->max_count_cxx . . $ grn/dat/KeyCursor#max_count_.); |
| 283 | std::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(finished_cxx . . $ grn/dat/KeyCursor#finished_., cursor->finished_cxx . . $ grn/dat/KeyCursor#finished_.); |
| 284 | std::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_., cursor->end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_.); |
| 285 | end_str_cxx . . $ grn/dat/KeyCursor#end_str_..swapcxx . . $ grn/dat/String#swap(4b87ba8cc331336f).(&cursor->end_str_cxx . . $ grn/dat/KeyCursor#end_str_.); |
| 286 | } |
| 287 | |
| 288 | const Keycxx . . $ grn/dat/Key# &KeyCursorcxx . . $ grn/dat/KeyCursor#::ascending_nextcxx . . $ grn/dat/KeyCursor#ascending_next(741ea5814372790).() { |
| 289 | while (!buf_cxx . . $ grn/dat/KeyCursor#buf_..emptycxx . . $ grn/dat/Vector#empty(50ce9a9e25b4a850).()) { |
| 290 | const UInt32cxx . . $ grn/dat/UInt32# node_id = buf_cxx . . $ grn/dat/KeyCursor#buf_..backcxx . . $ grn/dat/Vector#back(19b2b6f17af048b).(); |
| 291 | buf_cxx . . $ grn/dat/KeyCursor#buf_..pop_backcxx . . $ grn/dat/Vector#pop_back(49f6e7a06ebc5aa8).(); |
| 292 | |
| 293 | const Nodecxx . . $ grn/dat/Node# node = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id); |
| 294 | if (node.siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).() != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 295 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node_id ^ node.labelcxx . . $ grn/dat/Node#label(ddd8539a2fcdd4ce).() ^ node.siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).()); |
| 296 | } |
| 297 | |
| 298 | if (node.is_linkercxx . . $ grn/dat/Node#is_linker(50ce9a9e25b4a850).()) { |
| 299 | const Keycxx . . $ grn/dat/Key# &key = trie_cxx . . $ grn/dat/KeyCursor#trie_.->get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(node.key_poscxx . . $ grn/dat/Node#key_pos(ddd8539a2fcdd4ce).()); |
| 300 | if (end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) { |
| 301 | const int result = key.strcxx . . $ grn/dat/Key#str(3f4ba625c018c01d).().comparecxx . . $ grn/dat/String#compare(6575af31c4a8b936).(end_str_cxx . . $ grn/dat/KeyCursor#end_str_.); |
| 302 | if ((result > 0) || ((result == 0) && |
| 303 | ((flags_cxx . . $ grn/dat/KeyCursor#flags_. & EXCEPT_UPPER_BOUNDcxx . . $ grn/dat/EXCEPT_UPPER_BOUND.) == EXCEPT_UPPER_BOUNDcxx . . $ grn/dat/EXCEPT_UPPER_BOUND.))) { |
| 304 | finished_cxx . . $ grn/dat/KeyCursor#finished_. = true; |
| 305 | return Keycxx . . $ grn/dat/Key#::invalid_keycxx . . $ grn/dat/Key#invalid_key(741ea5814372790).(); |
| 306 | } |
| 307 | } |
| 308 | if (count_cxx . . $ grn/dat/KeyCursor#count_.++ >= offset_cxx . . $ grn/dat/KeyCursor#offset_.) { |
| 309 | return key; |
| 310 | } |
| 311 | } else if (node.childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).() != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 312 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(node.offsetcxx . . $ grn/dat/Node#offset(ddd8539a2fcdd4ce).() ^ node.childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).()); |
| 313 | } |
| 314 | } |
| 315 | return Keycxx . . $ grn/dat/Key#::invalid_keycxx . . $ grn/dat/Key#invalid_key(741ea5814372790).(); |
| 316 | } |
| 317 | |
| 318 | const Keycxx . . $ grn/dat/Key# &KeyCursorcxx . . $ grn/dat/KeyCursor#::descending_nextcxx . . $ grn/dat/KeyCursor#descending_next(741ea5814372790).() { |
| 319 | while (!buf_cxx . . $ grn/dat/KeyCursor#buf_..emptycxx . . $ grn/dat/Vector#empty(50ce9a9e25b4a850).()) { |
| 320 | const bool post_order = (buf_cxx . . $ grn/dat/KeyCursor#buf_..backcxx . . $ grn/dat/Vector#back(19b2b6f17af048b).() & POST_ORDER_FLAGcxx . . $ grn/dat/KeyCursor#POST_ORDER_FLAG.) == POST_ORDER_FLAGcxx . . $ grn/dat/KeyCursor#POST_ORDER_FLAG.; |
| 321 | const UInt32cxx . . $ grn/dat/UInt32# node_id = buf_cxx . . $ grn/dat/KeyCursor#buf_..backcxx . . $ grn/dat/Vector#back(19b2b6f17af048b).() & ~POST_ORDER_FLAGcxx . . $ grn/dat/KeyCursor#POST_ORDER_FLAG.; |
| 322 | |
| 323 | const Basecxx . . $ grn/dat/Base# base = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).(); |
| 324 | if (post_order) { |
| 325 | buf_cxx . . $ grn/dat/KeyCursor#buf_..pop_backcxx . . $ grn/dat/Vector#pop_back(49f6e7a06ebc5aa8).(); |
| 326 | if (base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) { |
| 327 | const Keycxx . . $ grn/dat/Key# &key = trie_cxx . . $ grn/dat/KeyCursor#trie_.->get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).()); |
| 328 | if (end_buf_cxx . . $ grn/dat/KeyCursor#end_buf_. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) { |
| 329 | const int result = key.strcxx . . $ grn/dat/Key#str(3f4ba625c018c01d).().comparecxx . . $ grn/dat/String#compare(6575af31c4a8b936).(end_str_cxx . . $ grn/dat/KeyCursor#end_str_.); |
| 330 | if ((result < 0) || ((result == 0) && |
| 331 | ((flags_cxx . . $ grn/dat/KeyCursor#flags_. & EXCEPT_LOWER_BOUNDcxx . . $ grn/dat/EXCEPT_LOWER_BOUND.) == EXCEPT_LOWER_BOUNDcxx . . $ grn/dat/EXCEPT_LOWER_BOUND.))) { |
| 332 | finished_cxx . . $ grn/dat/KeyCursor#finished_. = true; |
| 333 | return Keycxx . . $ grn/dat/Key#::invalid_keycxx . . $ grn/dat/Key#invalid_key(741ea5814372790).(); |
| 334 | } |
| 335 | } |
| 336 | if (count_cxx . . $ grn/dat/KeyCursor#count_.++ >= offset_cxx . . $ grn/dat/KeyCursor#offset_.) { |
| 337 | return key; |
| 338 | } |
| 339 | } |
| 340 | } else { |
| 341 | buf_cxx . . $ grn/dat/KeyCursor#buf_..backcxx . . $ grn/dat/Vector#back(19b2b6f17af048b).() |= POST_ORDER_FLAGcxx . . $ grn/dat/KeyCursor#POST_ORDER_FLAG.; |
| 342 | UInt32cxx . . $ grn/dat/UInt32# label = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).(); |
| 343 | while (label != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) { |
| 344 | buf_cxx . . $ grn/dat/KeyCursor#buf_..push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ label); |
| 345 | label = trie_cxx . . $ grn/dat/KeyCursor#trie_.->ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ label).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).(); |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | return Keycxx . . $ grn/dat/Key#::invalid_keycxx . . $ grn/dat/Key#invalid_key(741ea5814372790).(); |
| 350 | } |
| 351 | |
| 352 | } // namespace dat |
| 353 | } // namespace grn |