| 1 | /* |
| 2 | Copyright (C) 2025 Sutou Kouhei <[email protected]> |
| 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 | #include "grn_sorter.h"cxx . . $ `<file>/lib/grn_sorter.h`/ |
| 20 | #include "grn_expr.h"cxx . . $ `<file>/lib/grn_expr.h`/ |
| 21 | |
| 22 | grn_objcxx . . $ grn_obj# * |
| 23 | grn_sorter_data_get_tablecxx . . $ grn_sorter_data_get_table(7614de0143e67c9c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data) |
| 24 | { |
| 25 | return data->tablecxx . . $ _grn_sorter_data#table.; |
| 26 | } |
| 27 | |
| 28 | size_t |
| 29 | grn_sorter_data_get_offsetcxx . . $ grn_sorter_data_get_offset(e2e7e6d68a2b0473).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data) |
| 30 | { |
| 31 | return data->offsetcxx . . $ _grn_sorter_data#offset.; |
| 32 | } |
| 33 | |
| 34 | size_t |
| 35 | grn_sorter_data_get_limitcxx . . $ grn_sorter_data_get_limit(e2e7e6d68a2b0473).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data) |
| 36 | { |
| 37 | return data->limitcxx . . $ _grn_sorter_data#limit.; |
| 38 | } |
| 39 | |
| 40 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 41 | grn_sorter_data_is_ascendingcxx . . $ grn_sorter_data_is_ascending(36ffe662e3dbf6f6).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data) |
| 42 | { |
| 43 | return !(data->keyscxx . . $ _grn_sorter_data#keys.[0].flagscxx . . $ _grn_table_sort_key#flags. & GRN_TABLE_SORT_DESCcxx . . $ `include/groonga/table.h:683:9`!); |
| 44 | } |
| 45 | |
| 46 | grn_table_sort_keycxx . . $ grn_table_sort_key# * |
| 47 | grn_sorter_data_get_keyscxx . . $ grn_sorter_data_get_keys(ce50f505f262643c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data, size_t *n_keys) |
| 48 | { |
| 49 | *n_keys = data->n_keyscxx . . $ _grn_sorter_data#n_keys.; |
| 50 | return data->keyscxx . . $ _grn_sorter_data#keys.; |
| 51 | } |
| 52 | |
| 53 | grn_objcxx . . $ grn_obj# * |
| 54 | grn_sorter_data_get_resultcxx . . $ grn_sorter_data_get_result(7614de0143e67c9c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data) |
| 55 | { |
| 56 | return data->resultcxx . . $ _grn_sorter_data#result.; |
| 57 | } |
| 58 | |
| 59 | grn_objcxx . . $ grn_obj# * |
| 60 | grn_sorter_data_get_sortercxx . . $ grn_sorter_data_get_sorter(7614de0143e67c9c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data) |
| 61 | { |
| 62 | return data->sortercxx . . $ _grn_sorter_data#sorter.; |
| 63 | } |
| 64 | |
| 65 | grn_objcxx . . $ grn_obj# ** |
| 66 | grn_sorter_data_get_argscxx . . $ grn_sorter_data_get_args(6e0ec7429a6da1fd).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data, size_t *n_args) |
| 67 | { |
| 68 | *n_args = GRN_PTR_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3265:9`!(&(data->args)); |
| 69 | return (grn_objcxx . . $ grn_obj# **)GRN_BULK_HEADcxx . . $ `include/groonga/groonga.h:2648:9`!(&(data->args)); |
| 70 | } |
| 71 | |
| 72 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 73 | grn_sorter_data_extractcxx . . $ grn_sorter_data_extract(36ffe662e3dbf6f6).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data) |
| 74 | { |
| 75 | grn_objcxx . . $ grn_obj# *first_key = data->keyscxx . . $ _grn_sorter_data#keys.[0].keycxx . . $ _grn_table_sort_key#key.; |
| 76 | if (!grn_obj_is_exprcxx . . $ grn_obj_is_expr(a5760e5c319a06ee).(ctx, first_key)) { |
| 77 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 78 | } |
| 79 | |
| 80 | grn_exprcxx . . $ grn_expr# *expr = (grn_exprcxx . . $ grn_expr# *)first_key; |
| 81 | grn_expr_codecxx . . $ grn_expr_code# *codes = expr->codescxx . . $ _grn_expr#codes.; |
| 82 | uint32_tcxx . . $ uint32_t# codes_curr = expr->codes_currcxx . . $ _grn_expr#codes_curr.; |
| 83 | if (codes_curr < 3) { |
| 84 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 85 | } |
| 86 | if (codes[0].opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op. != GRN_OP_PUSHcxx . . $ GRN_OP_PUSH.) { |
| 87 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 88 | } |
| 89 | if (!grn_obj_is_sorter_proccxx . . $ grn_obj_is_sorter_proc(a5760e5c319a06ee).(ctx, codes[0].valuecxx . . $ $anonymous_type_640a68f6a3c9e981_0#value.)) { |
| 90 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 91 | } |
| 92 | |
| 93 | data->sortercxx . . $ _grn_sorter_data#sorter. = codes[0].valuecxx . . $ $anonymous_type_640a68f6a3c9e981_0#value.; |
| 94 | if (codes[0].modifycxx . . $ $anonymous_type_640a68f6a3c9e981_0#modify. == 0) { |
| 95 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 96 | } |
| 97 | uint32_tcxx . . $ uint32_t# call_i = codes[0].modifycxx . . $ $anonymous_type_640a68f6a3c9e981_0#modify.; |
| 98 | if (codes[call_i].opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op. != GRN_OP_CALLcxx . . $ GRN_OP_CALL.) { |
| 99 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 100 | } |
| 101 | if (call_i != codes_curr - 1) { |
| 102 | if (call_i + 1 == codes_curr - 1 && codes[call_i + 1].opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op. == GRN_OP_MINUScxx . . $ GRN_OP_MINUS.) { |
| 103 | /* -sorter(...): OK */ |
| 104 | data->keyscxx . . $ _grn_sorter_data#keys.[0].flagscxx . . $ _grn_table_sort_key#flags. = GRN_TABLE_SORT_DESCcxx . . $ `include/groonga/table.h:683:9`!; |
| 105 | } else { |
| 106 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | for (uint32_tcxx . . $ uint32_t# i = 1; i < call_i; i++) { |
| 111 | switch (codes[i].opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op.) { |
| 112 | case GRN_OP_GET_VALUEcxx . . $ GRN_OP_GET_VALUE.: |
| 113 | case GRN_OP_PUSHcxx . . $ GRN_OP_PUSH.: |
| 114 | if (codes[i].modifycxx . . $ $anonymous_type_640a68f6a3c9e981_0#modify. == 0) { |
| 115 | GRN_PTR_PUTcxx . . $ `include/groonga/groonga.h:3218:9`!(ctx, &(data->args), codes[i].value); |
| 116 | } else { |
| 117 | uint32_tcxx . . $ uint32_t# sub_call_i = i + codes[i].modifycxx . . $ $anonymous_type_640a68f6a3c9e981_0#modify.; |
| 118 | if (codes[sub_call_i].opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op. != GRN_OP_CALLcxx . . $ GRN_OP_CALL.) { |
| 119 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 120 | } |
| 121 | /* Literal argument expressions are only supported for |
| 122 | * now. Nested function call and so on aren't supported |
| 123 | * yet. */ |
| 124 | if (!grn_obj_is_function_proccxx . . $ grn_obj_is_function_proc(a5760e5c319a06ee).(ctx, codes[i].valuecxx . . $ $anonymous_type_640a68f6a3c9e981_0#value.)) { |
| 125 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 126 | } |
| 127 | for (uint32_tcxx . . $ uint32_t# j = i + 1; j < sub_call_i; j++) { |
| 128 | if (codes[j].opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op. != GRN_OP_PUSHcxx . . $ GRN_OP_PUSH.) { |
| 129 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 130 | } |
| 131 | grn_objcxx . . $ grn_obj# *sub_arg = codes[j].valuecxx . . $ $anonymous_type_640a68f6a3c9e981_0#value.; |
| 132 | if (!sub_arg) { |
| 133 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 134 | } |
| 135 | switch (sub_arg->headercxx . . $ _grn_obj#header..typecxx . . $ _grn_obj_header#type.) { |
| 136 | case GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!: |
| 137 | case GRN_VECTORcxx . . $ `include/groonga/groonga.h:877:9`!: |
| 138 | case GRN_UVECTORcxx . . $ `include/groonga/groonga.h:875:9`!: |
| 139 | case GRN_PVECTORcxx . . $ `include/groonga/groonga.h:876:9`!: |
| 140 | /* supported */ |
| 141 | break; |
| 142 | default: |
| 143 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 144 | } |
| 145 | } |
| 146 | expr->codescxx . . $ _grn_expr#codes. += i; |
| 147 | expr->codes_currcxx . . $ _grn_expr#codes_curr. = call_i - i + 1; |
| 148 | grn_expr_executorcxx . . $ grn_expr_executor# executor; |
| 149 | grn_expr_executor_initcxx . . $ grn_expr_executor_init(16b7e5d9c819f729).(ctx, &executor, (grn_objcxx . . $ grn_obj# *)expr); |
| 150 | grn_objcxx . . $ grn_obj# *arg = grn_expr_executor_execcxx . . $ grn_expr_executor_exec(16f9569af33219a9).(ctx, &executor, GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!); |
| 151 | GRN_PTR_PUTcxx . . $ `include/groonga/groonga.h:3218:9`!(ctx, &(data->args), arg); |
| 152 | grn_expr_executor_fincxx . . $ grn_expr_executor_fin(55b9315442a275ec).(ctx, &executor); |
| 153 | expr->codescxx . . $ _grn_expr#codes. = codes; |
| 154 | expr->codes_currcxx . . $ _grn_expr#codes_curr. = codes_curr; |
| 155 | i += codes[i].modifycxx . . $ $anonymous_type_640a68f6a3c9e981_0#modify.; |
| 156 | } |
| 157 | break; |
| 158 | default: |
| 159 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 164 | } |
| 165 | |
| 166 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 167 | grn_sorter_data_initcxx . . $ grn_sorter_data_init(28d2fa25f9a02d7b).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 168 | grn_sorter_datacxx . . $ grn_sorter_data# *data, |
| 169 | grn_objcxx . . $ grn_obj# *table, |
| 170 | size_t offset, |
| 171 | size_t limit, |
| 172 | grn_table_sort_keycxx . . $ grn_table_sort_key# *keys, |
| 173 | size_t n_keys, |
| 174 | grn_objcxx . . $ grn_obj# *result) |
| 175 | { |
| 176 | data->tablecxx . . $ _grn_sorter_data#table. = table; |
| 177 | data->offsetcxx . . $ _grn_sorter_data#offset. = offset; |
| 178 | data->limitcxx . . $ _grn_sorter_data#limit. = limit; |
| 179 | data->keyscxx . . $ _grn_sorter_data#keys. = keys; |
| 180 | data->n_keyscxx . . $ _grn_sorter_data#n_keys. = n_keys; |
| 181 | data->resultcxx . . $ _grn_sorter_data#result. = result; |
| 182 | data->sortercxx . . $ _grn_sorter_data#sorter. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 183 | GRN_PTR_INITcxx . . $ `include/groonga/groonga.h:2869:9`!(&(data->args), GRN_OBJ_VECTORcxx . . $ `include/groonga/groonga.h:2734:9`!, GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!); |
| 184 | |
| 185 | return grn_sorter_data_extractcxx . . $ grn_sorter_data_extract(36ffe662e3dbf6f6).(ctx, data); |
| 186 | } |
| 187 | |
| 188 | void |
| 189 | grn_sorter_data_fincxx . . $ grn_sorter_data_fin(902828a8c64802b4).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data) |
| 190 | { |
| 191 | GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(data->args)); |
| 192 | } |
| 193 | |
| 194 | grn_rccxx . . $ grn_rc# |
| 195 | grn_sorter_data_runcxx . . $ grn_sorter_data_run(7034fb15f72963af).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data) |
| 196 | { |
| 197 | grn_proccxx . . $ grn_proc# *proc = (grn_proccxx . . $ grn_proc# *)(data->sortercxx . . $ _grn_sorter_data#sorter.); |
| 198 | return proc->callbackscxx . . $ _grn_proc#callbacks..functioncxx . . $ _grn_proc#$anonymous_type_5#function..sortercxx . . $ _grn_proc#$anonymous_type_5#$anonymous_type_6#sorter.(ctx, data); |
| 199 | } |