Debian Codegraph @

lib/window_function.c

raw symbols SCIP
1 /*
2 Copyright(C) 2016-2017 Brazil
3 Copyright(C) 2019-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 "grn_ctx.h"cxx . . $ `<file>/lib/grn_ctx.h`/
21 #include "grn_db.h"cxx . . $ `<file>/lib/grn_db.h`/
22 #include "grn_expr.h"cxx . . $ `<file>/lib/grn_expr.h`/
23 #include "grn_window_function.h"cxx . . $ `<file>/lib/grn_window_function.h`/
24
25 #include <string.h>
26
27 static void
28 grn_window_shard_initcxx . . $ grn_window_shard_init(1990a89438e83a51).(grn_ctxcxx . . $ grn_ctx# *ctx,
29 grn_window_shardcxx . . $ grn_window_shard# *shard,
30 grn_objcxx . . $ grn_obj# *table,
31 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_context_table,
32 grn_objcxx . . $ grn_obj# *window_function_call,
33 grn_objcxx . . $ grn_obj# *output_column,
34 grn_objcxx . . $ grn_obj# *key_columns)
35 {
36 shard->tablecxx . . $ $anonymous_type_8546c3b2810fbe7a_0#table. = table;
37 shard->is_context_tablecxx . . $ $anonymous_type_8546c3b2810fbe7a_0#is_context_table. = is_context_table;
38 shard->window_function_callcxx . . $ $anonymous_type_8546c3b2810fbe7a_0#window_function_call. = window_function_call;
39 grn_exprcxx . . $ grn_expr# *expr = (grn_exprcxx . . $ grn_expr# *)(window_function_call);
40 shard->window_functioncxx . . $ $anonymous_type_8546c3b2810fbe7a_0#window_function. = (grn_proccxx . . $ grn_proc# *)(expr->codescxx . . $ _grn_expr#codes.[0].valuecxx . . $ $anonymous_type_640a68f6a3c9e981_0#value.);
41 GRN_PTR_INITcxx . . $ `include/groonga/groonga.h:2869:9`!(&(shard->arguments), GRN_OBJ_VECTORcxx . . $ `include/groonga/groonga.h:2734:9`!, GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!);
42 uint32_tcxx . . $ uint32_t# n_arguments = expr->codes_currcxx . . $ _grn_expr#codes_curr. - 1;
43 for (uint32_tcxx . . $ uint32_t# i = 1; i < n_arguments; i++) {
44 /* TODO: Check op. */
45 GRN_PTR_PUTcxx . . $ `include/groonga/groonga.h:3218:9`!(ctx, &(shard->arguments), expr->codes[i].value);
46 }
47 shard->output_columncxx . . $ $anonymous_type_8546c3b2810fbe7a_0#output_column. = output_column;
48 GRN_PTR_INITcxx . . $ `include/groonga/groonga.h:2869:9`!(&(shard->key_columns), GRN_OBJ_VECTORcxx . . $ `include/groonga/groonga.h:2734:9`!, GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!);
49 size_t n_key_columns = GRN_PTR_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3265:9`!(key_columns);
50 for (size_t i = 0; i < n_key_columns; i++) {
51 grn_objcxx . . $ grn_obj# *key_column = GRN_PTR_VALUE_ATcxx . . $ `include/groonga/groonga.h:3150:9`!(key_columns, i);
52 GRN_PTR_PUTcxx . . $ `include/groonga/groonga.h:3218:9`!(ctx, &(shard->key_columns), key_column);
53 }
54 GRN_RECORD_INITcxx . . $ `include/groonga/groonga.h:2868:9`!(&(shard->ids), GRN_OBJ_VECTORcxx . . $ `include/groonga/groonga.h:2734:9`!, grn_obj_id(ctx, table));
55 shard->current_indexcxx . . $ $anonymous_type_8546c3b2810fbe7a_0#current_index. = -1;
56 }
57
58 static void
59 grn_window_shard_fincxx . . $ grn_window_shard_fin(e67c327a8a9c324f).(grn_ctxcxx . . $ grn_ctx# *ctx,
60 grn_window_shardcxx . . $ grn_window_shard# *shard)
61 {
62 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(shard->arguments));
63 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(shard->key_columns));
64 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(shard->ids));
65 }
66
67 grn_rccxx . . $ grn_rc#
68 grn_window_initcxx . . $ grn_window_init(e129d7a355eb2bb4).(grn_ctxcxx . . $ grn_ctx# *ctx,
69 grn_windowcxx . . $ grn_window# *window)
70 {
71 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
72
73 window->shardscxx . . $ _grn_window#shards. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
74 window->n_shardscxx . . $ _grn_window#n_shards. = 0;
75 window->current_shardcxx . . $ _grn_window#current_shard. = -1;
76 window->current_idcxx . . $ _grn_window#current_id. = GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!;
77 window->directioncxx . . $ _grn_window#direction. = GRN_WINDOW_DIRECTION_ASCENDINGcxx . . $ GRN_WINDOW_DIRECTION_ASCENDING.;
78 window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n. = 0;
79 window->valuescxx . . $ _grn_window#values..buffer1cxx . . $ _grn_window#$anonymous_type_1#buffer1. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
80 window->valuescxx . . $ _grn_window#values..buffer2cxx . . $ _grn_window#$anonymous_type_1#buffer2. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
81 window->valuescxx . . $ _grn_window#values..previouscxx . . $ _grn_window#$anonymous_type_1#previous. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
82 window->valuescxx . . $ _grn_window#values..currentcxx . . $ _grn_window#$anonymous_type_1#current. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
83 window->is_value_changed_computedcxx . . $ _grn_window#is_value_changed_computed. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
84 window->is_value_changedcxx . . $ _grn_window#is_value_changed. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
85
86 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_SUCCESS);
87 }
88
89 grn_rccxx . . $ grn_rc#
90 grn_window_fincxx . . $ grn_window_fin(e129d7a355eb2bb4).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
91 {
92 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
93
94 grn_window_resetcxx . . $ grn_window_reset(e129d7a355eb2bb4).(ctx, window);
95
96 if (window->valuescxx . . $ _grn_window#values..buffer1cxx . . $ _grn_window#$anonymous_type_1#buffer1.) {
97 for (size_t i = 0; i < window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n.; i++) {
98 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(window->values.buffer1[i]));
99 }
100 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(window->values.buffer1);
101 }
102 if (window->valuescxx . . $ _grn_window#values..buffer2cxx . . $ _grn_window#$anonymous_type_1#buffer2.) {
103 for (size_t i = 0; i < window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n.; i++) {
104 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(window->values.buffer2[i]));
105 }
106 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(window->values.buffer2);
107 }
108
109 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
110 }
111
112 grn_idcxx . . $ grn_id#
113 grn_window_nextcxx . . $ grn_window_next(f56381835d69aa75).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
114 {
115 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
116
117 if (!window) {
118 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!);
119 }
120
121 window->is_value_changed_computedcxx . . $ _grn_window#is_value_changed_computed. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
122
123 if (window->current_shardcxx . . $ _grn_window#current_shard. < 0) {
124 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!);
125 }
126
127 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[window->current_shardcxx . . $ _grn_window#current_shard.]);
128 if (window->directioncxx . . $ _grn_window#direction. == GRN_WINDOW_DIRECTION_ASCENDINGcxx . . $ GRN_WINDOW_DIRECTION_ASCENDING.) {
129 if ((size_t)(shard->current_indexcxx . . $ $anonymous_type_8546c3b2810fbe7a_0#current_index.) >=
130 GRN_RECORD_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3264:9`!(&(shard->ids))) {
131 if ((size_t)(window->current_shardcxx . . $ _grn_window#current_shard. + 1) < window->n_shardscxx . . $ _grn_window#n_shards.) {
132 window->current_shardcxx . . $ _grn_window#current_shard.++;
133 shard = &(window->shardscxx . . $ _grn_window#shards.[window->current_shardcxx . . $ _grn_window#current_shard.]);
134 } else {
135 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!);
136 }
137 }
138 } else {
139 if (shard->current_indexcxx . . $ $anonymous_type_8546c3b2810fbe7a_0#current_index. < 0) {
140 if (window->current_shardcxx . . $ _grn_window#current_shard. > 0) {
141 window->current_shardcxx . . $ _grn_window#current_shard.--;
142 shard = &(window->shardscxx . . $ _grn_window#shards.[window->current_shardcxx . . $ _grn_window#current_shard.]);
143 } else {
144 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!);
145 }
146 }
147 }
148
149 grn_idcxx . . $ grn_id# next_id = GRN_RECORD_VALUE_ATcxx . . $ `include/groonga/groonga.h:3148:9`!(&(shard->ids), shard->current_index);
150 if (window->directioncxx . . $ _grn_window#direction. == GRN_WINDOW_DIRECTION_ASCENDINGcxx . . $ GRN_WINDOW_DIRECTION_ASCENDING.) {
151 shard->current_indexcxx . . $ $anonymous_type_8546c3b2810fbe7a_0#current_index.++;
152 } else {
153 shard->current_indexcxx . . $ $anonymous_type_8546c3b2810fbe7a_0#current_index.--;
154 }
155
156 window->current_idcxx . . $ _grn_window#current_id. = next_id;
157 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(window->current_id);
158 }
159
160 grn_rccxx . . $ grn_rc#
161 grn_window_rewindcxx . . $ grn_window_rewind(e129d7a355eb2bb4).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
162 {
163 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
164
165 if (!window) {
166 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[window][rewind] window is NULL");
167 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
168 }
169
170 if (window->directioncxx . . $ _grn_window#direction. == GRN_WINDOW_DIRECTION_ASCENDINGcxx . . $ GRN_WINDOW_DIRECTION_ASCENDING.) {
171 window->current_shardcxx . . $ _grn_window#current_shard. = 0;
172 for (size_t i = 0; i < window->n_shardscxx . . $ _grn_window#n_shards.; i++) {
173 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[i]);
174 shard->current_indexcxx . . $ $anonymous_type_8546c3b2810fbe7a_0#current_index. = 0;
175 }
176 } else {
177 window->current_shardcxx . . $ _grn_window#current_shard. = (ssize_tcxx . . $ ssize_t#)(window->n_shardscxx . . $ _grn_window#n_shards. - 1);
178 for (size_t i = 0; i < window->n_shardscxx . . $ _grn_window#n_shards.; i++) {
179 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[i]);
180 shard->current_indexcxx . . $ $anonymous_type_8546c3b2810fbe7a_0#current_index. =
181 (ssize_tcxx . . $ ssize_t#)(GRN_RECORD_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3264:9`!(&(shard->ids)) - 1);
182 }
183 }
184
185 if (window->valuescxx . . $ _grn_window#values..buffer1cxx . . $ _grn_window#$anonymous_type_1#buffer1.) {
186 for (size_t i = 0; i < window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n.; i++) {
187 GRN_BULK_REWINDcxx . . $ `include/groonga/groonga.h:2599:9`!(&(window->values.buffer1[i]));
188 }
189 }
190 if (window->valuescxx . . $ _grn_window#values..buffer2cxx . . $ _grn_window#$anonymous_type_1#buffer2.) {
191 for (size_t i = 0; i < window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n.; i++) {
192 GRN_BULK_REWINDcxx . . $ `include/groonga/groonga.h:2599:9`!(&(window->values.buffer2[i]));
193 }
194 }
195
196 window->is_value_changed_computedcxx . . $ _grn_window#is_value_changed_computed. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
197
198 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_SUCCESS);
199 }
200
201 grn_objcxx . . $ grn_obj# *
202 grn_window_get_tablecxx . . $ grn_window_get_table(1720528b0f6a9957).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
203 {
204 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
205
206 if (!window) {
207 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[window][table][get] window is NULL");
208 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
209 }
210
211 if (window->current_shardcxx . . $ _grn_window#current_shard. < 0) {
212 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
213 }
214
215 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[window->current_shardcxx . . $ _grn_window#current_shard.]);
216 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(shard->table);
217 }
218
219 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
220 grn_window_is_context_tablecxx . . $ grn_window_is_context_table(455f6a6a90ff2430).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
221 {
222 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
223
224 if (!window) {
225 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[window][is-context-table] window is NULL");
226 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
227 }
228
229 if (window->current_shardcxx . . $ _grn_window#current_shard. < 0) {
230 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
231 }
232
233 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[window->current_shardcxx . . $ _grn_window#current_shard.]);
234 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(shard->is_context_table);
235 }
236
237 grn_objcxx . . $ grn_obj# *
238 grn_window_get_output_columncxx . . $ grn_window_get_output_column(1720528b0f6a9957).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
239 {
240 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
241
242 if (!window) {
243 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[window][output-column][get] window is NULL");
244 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
245 }
246
247 if (window->current_shardcxx . . $ _grn_window#current_shard. < 0) {
248 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
249 }
250
251 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[window->current_shardcxx . . $ _grn_window#current_shard.]);
252 if (shard->is_context_tablecxx . . $ $anonymous_type_8546c3b2810fbe7a_0#is_context_table.) {
253 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
254 } else {
255 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(shard->output_column);
256 }
257 }
258
259 size_t
260 grn_window_get_n_argumentscxx . . $ grn_window_get_n_arguments(3d016a5683171aef).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
261 {
262 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
263
264 if (!window) {
265 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[window][n-arguments][get] window is NULL");
266 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(0);
267 }
268
269 if (window->current_shardcxx . . $ _grn_window#current_shard. < 0) {
270 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(0);
271 }
272
273 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[window->current_shardcxx . . $ _grn_window#current_shard.]);
274 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_PTR_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3265:9`!(&(shard->arguments)));
275 }
276
277 grn_objcxx . . $ grn_obj# *
278 grn_window_get_argumentcxx . . $ grn_window_get_argument(97e99fc0170c9830).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window, size_t i)
279 {
280 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
281
282 if (!window) {
283 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[window][argument][get] window is NULL");
284 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
285 }
286
287 if (window->current_shardcxx . . $ _grn_window#current_shard. < 0) {
288 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
289 }
290
291 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[window->current_shardcxx . . $ _grn_window#current_shard.]);
292 if (i < GRN_PTR_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3265:9`!(&(shard->arguments))) {
293 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_PTR_VALUE_ATcxx . . $ `include/groonga/groonga.h:3150:9`!(&(shard->arguments), i));
294 } else {
295 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
296 }
297 }
298
299 grn_objcxx . . $ grn_obj# *
300 grn_window_get_key_columnscxx . . $ grn_window_get_key_columns(1720528b0f6a9957).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
301 {
302 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
303
304 if (!window) {
305 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[window][n-key-columns][get] window is NULL");
306 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
307 }
308
309 if (window->current_shardcxx . . $ _grn_window#current_shard. < 0) {
310 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
311 }
312
313 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[window->current_shardcxx . . $ _grn_window#current_shard.]);
314 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(&(shard->key_columns));
315 }
316
317 grn_rccxx . . $ grn_rc#
318 grn_window_set_directioncxx . . $ grn_window_set_direction(a002a76c98bde2cb).(grn_ctxcxx . . $ grn_ctx# *ctx,
319 grn_windowcxx . . $ grn_window# *window,
320 grn_window_directioncxx . . $ grn_window_direction# direction)
321 {
322 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
323
324 const char *tag = "[window][direction][set]";
325 if (!window) {
326 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "%s window is NULL", tag);
327 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
328 }
329
330 switch (direction) {
331 case GRN_WINDOW_DIRECTION_ASCENDINGcxx . . $ GRN_WINDOW_DIRECTION_ASCENDING. :
332 window->directioncxx . . $ _grn_window#direction. = direction;
333 break;
334 case GRN_WINDOW_DIRECTION_DESCENDINGcxx . . $ GRN_WINDOW_DIRECTION_DESCENDING. :
335 window->directioncxx . . $ _grn_window#direction. = direction;
336 break;
337 default :
338 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
339 "%s direction must be "
340 "GRN_WINDOW_DIRECTION_ASCENDING(%d) or "
341 "GRN_WINDOW_DIRECTION_DESCENDING(%d): %d",
342 tag,
343 GRN_WINDOW_DIRECTION_ASCENDING,
344 GRN_WINDOW_DIRECTION_DESCENDING,
345 direction);
346 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
347 break;
348 }
349 grn_window_rewindcxx . . $ grn_window_rewind(e129d7a355eb2bb4).(ctx, window);
350
351 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_SUCCESS);
352 }
353
354 grn_rccxx . . $ grn_rc#
355 grn_window_resetcxx . . $ grn_window_reset(e129d7a355eb2bb4).(grn_ctxcxx . . $ grn_ctx# *ctx,
356 grn_windowcxx . . $ grn_window# *window)
357 {
358 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
359
360 for (size_t i = 0; i < window->n_shardscxx . . $ _grn_window#n_shards.; i++) {
361 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[i]);
362 grn_window_shard_fincxx . . $ grn_window_shard_fin(e67c327a8a9c324f).(ctx, shard);
363 }
364 if (window->shardscxx . . $ _grn_window#shards.) {
365 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(window->shards);
366 window->shardscxx . . $ _grn_window#shards. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
367 window->n_shardscxx . . $ _grn_window#n_shards. = 0;
368 window->current_shardcxx . . $ _grn_window#current_shard. = -1;
369 }
370
371 window->current_idcxx . . $ _grn_window#current_id. = GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!;
372
373 if (window->valuescxx . . $ _grn_window#values..buffer1cxx . . $ _grn_window#$anonymous_type_1#buffer1.) {
374 for (size_t i = 0; i < window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n.; i++) {
375 GRN_BULK_REWINDcxx . . $ `include/groonga/groonga.h:2599:9`!(&(window->values.buffer1[i]));
376 }
377 }
378 if (window->valuescxx . . $ _grn_window#values..buffer2cxx . . $ _grn_window#$anonymous_type_1#buffer2.) {
379 for (size_t i = 0; i < window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n.; i++) {
380 GRN_BULK_REWINDcxx . . $ `include/groonga/groonga.h:2599:9`!(&(window->values.buffer2[i]));
381 }
382 }
383 window->is_value_changed_computedcxx . . $ _grn_window#is_value_changed_computed. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
384 window->is_value_changedcxx . . $ _grn_window#is_value_changed. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
385
386 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
387 }
388
389 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
390 grn_expr_is_window_function_callcxx . . $ grn_expr_is_window_function_call(a5760e5c319a06ee).(grn_ctxcxx . . $ grn_ctx# *ctx,
391 grn_objcxx . . $ grn_obj# *window_function_call)
392 {
393 grn_exprcxx . . $ grn_expr# *expr = (grn_exprcxx . . $ grn_expr# *)window_function_call;
394 grn_expr_codecxx . . $ grn_expr_code# *func;
395 grn_expr_codecxx . . $ grn_expr_code# *call;
396
397 func = &(expr->codescxx . . $ _grn_expr#codes.[0]);
398 call = &(expr->codescxx . . $ _grn_expr#codes.[expr->codes_currcxx . . $ _grn_expr#codes_curr. - 1]);
399
400 if (func->opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op. != GRN_OP_PUSHcxx . . $ GRN_OP_PUSH.) {
401 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
402 }
403 if (!grn_obj_is_window_function_proccxx . . $ grn_obj_is_window_function_proc(a5760e5c319a06ee).(ctx, func->valuecxx . . $ $anonymous_type_640a68f6a3c9e981_0#value.)) {
404 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
405 }
406
407 if (call->opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op. != GRN_OP_CALLcxx . . $ GRN_OP_CALL.) {
408 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
409 }
410 if (call->nargscxx . . $ $anonymous_type_640a68f6a3c9e981_0#nargs. != (int32_tcxx . . $ int32_t#)(expr->codes_currcxx . . $ _grn_expr#codes_curr. - 1)) {
411 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
412 }
413
414 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
415 }
416
417 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
418 grn_window_add_record_validatecxx . . $ grn_window_add_record_validate(679d37102d1c0883).(grn_ctxcxx . . $ grn_ctx# *ctx,
419 grn_windowcxx . . $ grn_window# *window,
420 grn_objcxx . . $ grn_obj# *table,
421 grn_objcxx . . $ grn_obj# *window_function_call,
422 grn_objcxx . . $ grn_obj# *output_column,
423 grn_objcxx . . $ grn_obj# *key_columns,
424 const char *tag)
425 {
426 if (!table) {
427 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "%s table is NULL", tag);
428 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
429 }
430
431 if (!grn_expr_is_window_function_callcxx . . $ grn_expr_is_window_function_call(a5760e5c319a06ee).(ctx, window_function_call)) {
432 grn_objcxx . . $ grn_obj# inspected;
433 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0);
434 grn_inspectcxx . . $ grn_inspect(88456f97fe0d41a).(ctx, &inspected, window_function_call);
435 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
436 "%s must be window function call: %.*s",
437 tag,
438 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected),
439 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected));
440 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected);
441 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
442 }
443
444 if (!output_column) {
445 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "%s output column is NULL", tag);
446 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
447 }
448
449 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
450 }
451
452 grn_rccxx . . $ grn_rc#
453 grn_window_add_recordcxx . . $ grn_window_add_record(dcfc7afbd5f143b6).(grn_ctxcxx . . $ grn_ctx# *ctx,
454 grn_windowcxx . . $ grn_window# *window,
455 grn_objcxx . . $ grn_obj# *table,
456 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_context_table,
457 grn_idcxx . . $ grn_id# record_id,
458 grn_objcxx . . $ grn_obj# *window_function_call,
459 grn_objcxx . . $ grn_obj# *output_column,
460 grn_objcxx . . $ grn_obj# *key_columns)
461 {
462 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
463 const char *tag = "[window][record][add]";
464 if (window->n_shardscxx . . $ _grn_window#n_shards. == 0) {
465 if (!grn_window_add_record_validatecxx . . $ grn_window_add_record_validate(679d37102d1c0883).(ctx,
466 window,
467 table,
468 window_function_call,
469 output_column,
470 key_columns,
471 tag)) {
472 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
473 }
474 window->shardscxx . . $ _grn_window#shards. = GRN_MALLOCNcxx . . $ `lib/grn_alloc.h:50:9`!(grn_window_shard, 1);
475 grn_window_shard_initcxx . . $ grn_window_shard_init(1990a89438e83a51).(ctx,
476 &(window->shardscxx . . $ _grn_window#shards.[0]),
477 table,
478 is_context_table,
479 window_function_call,
480 output_column,
481 key_columns);
482 window->current_shardcxx . . $ _grn_window#current_shard. = 0;
483 window->n_shardscxx . . $ _grn_window#n_shards. = 1;
484 } else if (window->shardscxx . . $ _grn_window#shards.[window->n_shardscxx . . $ _grn_window#n_shards. - 1].tablecxx . . $ $anonymous_type_8546c3b2810fbe7a_0#table. != table) {
485 if (!grn_window_add_record_validatecxx . . $ grn_window_add_record_validate(679d37102d1c0883).(ctx,
486 window,
487 table,
488 window_function_call,
489 output_column,
490 key_columns,
491 tag)) {
492 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
493 }
494 const size_t new_n_shards = window->n_shardscxx . . $ _grn_window#n_shards. + 1;
495 grn_window_shardcxx . . $ grn_window_shard# *shards =
496 GRN_REALLOCcxx . . $ `lib/grn_alloc.h:43:9`!(window->shards, sizeof(grn_window_shard) * new_n_shards);
497 if (!shards) {
498 grn_rccxx . . $ grn_rc# rc = ctx->rccxx . . $ _grn_ctx#rc.;
499 if (rc == GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
500 rc = GRN_NO_MEMORY_AVAILABLEcxx . . $ GRN_NO_MEMORY_AVAILABLE.;
501 }
502 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
503 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
504 ERRcxx . . $ `lib/grn_error.h:156:9`!(rc,
505 "%s failed to expand shards: %s",
506 tag,
507 message);
508 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
509 }
510 window->shardscxx . . $ _grn_window#shards. = shards;
511 window->n_shardscxx . . $ _grn_window#n_shards. = new_n_shards;
512 grn_window_shard_initcxx . . $ grn_window_shard_init(1990a89438e83a51).(ctx,
513 &(window->shardscxx . . $ _grn_window#shards.[window->n_shardscxx . . $ _grn_window#n_shards. - 1]),
514 table,
515 is_context_table,
516 window_function_call,
517 output_column,
518 key_columns);
519 }
520 GRN_RECORD_PUTcxx . . $ `include/groonga/groonga.h:3213:9`!(ctx,
521 &(window->shards[window->n_shards - 1].ids),
522 record_id);
523 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
524 }
525
526 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
527 grn_window_is_emptycxx . . $ grn_window_is_empty(455f6a6a90ff2430).(grn_ctxcxx . . $ grn_ctx# *ctx,
528 grn_windowcxx . . $ grn_window# *window)
529 {
530 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
531 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_empty = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
532 for (size_t i = 0; i < window->n_shardscxx . . $ _grn_window#n_shards.; i++) {
533 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[i]);
534 if (GRN_RECORD_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3264:9`!(&(shard->ids)) > 0) {
535 is_empty = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
536 break;
537 }
538 }
539 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(is_empty);
540 }
541
542 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
543 grn_window_is_sortedcxx . . $ grn_window_is_sorted(455f6a6a90ff2430).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
544 {
545 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
546
547 if (!window) {
548 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[window][is-sorted] window is NULL");
549 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
550 }
551
552 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(window->is_sorted);
553 }
554
555 grn_rccxx . . $ grn_rc#
556 grn_window_set_is_sortedcxx . . $ grn_window_set_is_sorted(316de395f9981a9a).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_sorted)
557 {
558 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
559
560 if (!window) {
561 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[window][is-sorted][set] window is NULL");
562 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
563 }
564
565 window->is_sortedcxx . . $ _grn_window#is_sorted. = is_sorted;
566
567 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
568 }
569
570 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
571 grn_window_is_value_changedcxx . . $ grn_window_is_value_changed(455f6a6a90ff2430).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
572 {
573 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
574
575 if (!window) {
576 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[window][is-value-changed] window is NULL");
577 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
578 }
579
580 if (window->is_value_changed_computedcxx . . $ _grn_window#is_value_changed_computed.) {
581 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(window->is_value_changed);
582 }
583
584 grn_objcxx . . $ grn_obj# *key_columns = grn_window_get_key_columnscxx . . $ grn_window_get_key_columns(1720528b0f6a9957).(ctx, window);
585 if (!key_columns) {
586 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
587 }
588
589 if (GRN_PTR_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3265:9`!(key_columns) == 0) {
590 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
591 }
592
593 window->is_value_changedcxx . . $ _grn_window#is_value_changed. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
594 if (window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n. == 0) {
595 window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n. = GRN_PTR_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3265:9`!(key_columns);
596 window->valuescxx . . $ _grn_window#values..buffer1cxx . . $ _grn_window#$anonymous_type_1#buffer1. = GRN_MALLOCNcxx . . $ `lib/grn_alloc.h:50:9`!(grn_obj, window->values.n);
597 window->valuescxx . . $ _grn_window#values..buffer2cxx . . $ _grn_window#$anonymous_type_1#buffer2. = GRN_MALLOCNcxx . . $ `lib/grn_alloc.h:50:9`!(grn_obj, window->values.n);
598 for (size_t i = 0; i < window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n.; i++) {
599 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&(window->values.buffer1[i]));
600 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&(window->values.buffer2[i]));
601 }
602 window->valuescxx . . $ _grn_window#values..previouscxx . . $ _grn_window#$anonymous_type_1#previous. = window->valuescxx . . $ _grn_window#values..buffer1cxx . . $ _grn_window#$anonymous_type_1#buffer1.;
603 window->valuescxx . . $ _grn_window#values..currentcxx . . $ _grn_window#$anonymous_type_1#current. = window->valuescxx . . $ _grn_window#values..buffer2cxx . . $ _grn_window#$anonymous_type_1#buffer2.;
604 }
605
606 for (size_t i = 0; i < window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n.; i++) {
607 grn_objcxx . . $ grn_obj# *key_column = GRN_PTR_VALUE_ATcxx . . $ `include/groonga/groonga.h:3150:9`!(key_columns, i);
608 grn_objcxx . . $ grn_obj# *value = &(window->valuescxx . . $ _grn_window#values..currentcxx . . $ _grn_window#$anonymous_type_1#current.[i]);
609 GRN_BULK_REWINDcxx . . $ `include/groonga/groonga.h:2599:9`!(value);
610 grn_obj_get_valuecxx . . $ grn_obj_get_value(6e06fec66698a6a).(ctx, key_column, window->current_idcxx . . $ _grn_window#current_id., value);
611 }
612 for (size_t i = 0; i < window->valuescxx . . $ _grn_window#values..ncxx . . $ _grn_window#$anonymous_type_1#n.; i++) {
613 grn_objcxx . . $ grn_obj# *previous = &(window->valuescxx . . $ _grn_window#values..previouscxx . . $ _grn_window#$anonymous_type_1#previous.[i]);
614 grn_objcxx . . $ grn_obj# *current = &(window->valuescxx . . $ _grn_window#values..currentcxx . . $ _grn_window#$anonymous_type_1#current.[i]);
615 if ((GRN_BULK_VSIZEcxx . . $ `include/groonga/groonga.h:2642:9`!(previous) != GRN_BULK_VSIZEcxx . . $ `include/groonga/groonga.h:2642:9`!(current)) ||
616 (memcmpcxx . . $ memcmp(36f949851efa3055).(GRN_BULK_HEADcxx . . $ `include/groonga/groonga.h:2648:9`!(previous),
617 GRN_BULK_HEADcxx . . $ `include/groonga/groonga.h:2648:9`!(current),
618 GRN_BULK_VSIZEcxx . . $ `include/groonga/groonga.h:2642:9`!(previous)) != 0)) {
619 window->is_value_changedcxx . . $ _grn_window#is_value_changed. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
620 break;
621 }
622 }
623 window->is_value_changed_computedcxx . . $ _grn_window#is_value_changed_computed. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
624 {
625 grn_objcxx . . $ grn_obj# *tmp = window->valuescxx . . $ _grn_window#values..currentcxx . . $ _grn_window#$anonymous_type_1#current.;
626 window->valuescxx . . $ _grn_window#values..currentcxx . . $ _grn_window#$anonymous_type_1#current. = window->valuescxx . . $ _grn_window#values..previouscxx . . $ _grn_window#$anonymous_type_1#previous.;
627 window->valuescxx . . $ _grn_window#values..previouscxx . . $ _grn_window#$anonymous_type_1#previous. = tmp;
628 }
629
630 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(window->is_value_changed);
631 }
632
633 size_t
634 grn_window_get_sizecxx . . $ grn_window_get_size(3d016a5683171aef).(grn_ctxcxx . . $ grn_ctx# *ctx,
635 grn_windowcxx . . $ grn_window# *window)
636 {
637 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
638 size_t n_ids = 0;
639 for (size_t i = 0; i < window->n_shardscxx . . $ _grn_window#n_shards.; i++) {
640 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[i]);
641 n_ids += GRN_RECORD_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3264:9`!(&(shard->ids));
642 }
643 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(n_ids);
644 }
645
646 grn_objcxx . . $ grn_obj# *
647 grn_window_function_createcxx . . $ grn_window_function_create(71af7e6e670dbda0).(grn_ctxcxx . . $ grn_ctx# *ctx,
648 const char *name,
649 int name_size,
650 grn_window_function_funccxx . . $ grn_window_function_func# *func)
651 {
652 grn_objcxx . . $ grn_obj# *window_function = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
653
654 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
655
656 if (name_size == -1) {
657 name_size = (int)strlencxx . . $ strlen(751346f8406fd082).(name);
658 }
659
660 window_function = grn_proc_createcxx . . $ grn_proc_create(195df001e5324f57).(ctx,
661 name,
662 name_size,
663 GRN_PROC_WINDOW_FUNCTIONcxx . . $ GRN_PROC_WINDOW_FUNCTION.,
664 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
665 if (!window_function) {
666 char errbuf[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
667 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(errbuf, GRN_CTX_MSGSIZE, ctx->errbuf);
668 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_WINDOW_FUNCTION_ERROR,
669 "[window-function][%.*s] failed to create proc: %s",
670 name_size, name,
671 errbuf);
672 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
673 }
674
675 {
676 grn_proccxx . . $ grn_proc# *proc = (grn_proccxx . . $ grn_proc# *)window_function;
677 proc->callbackscxx . . $ _grn_proc#callbacks..window_functioncxx . . $ _grn_proc#$anonymous_type_5#window_function. = func;
678 }
679
680 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(window_function);
681 }
682
683 grn_rccxx . . $ grn_rc#
684 grn_window_executecxx . . $ grn_window_execute(e129d7a355eb2bb4).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_windowcxx . . $ grn_window# *window)
685 {
686 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
687
688 if (window->n_shardscxx . . $ _grn_window#n_shards. == 0) {
689 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
690 }
691 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! have_non_context_table = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
692 size_t i;
693 for (i = 0; i < window->n_shardscxx . . $ _grn_window#n_shards.; i++) {
694 if (!window->shardscxx . . $ _grn_window#shards.[i].is_context_tablecxx . . $ $anonymous_type_8546c3b2810fbe7a_0#is_context_table.) {
695 have_non_context_table = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
696 break;
697 }
698 }
699 if (!have_non_context_table) {
700 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
701 }
702
703 grn_window_rewindcxx . . $ grn_window_rewind(e129d7a355eb2bb4).(ctx, window);
704 grn_window_shardcxx . . $ grn_window_shard# *shard = &(window->shardscxx . . $ _grn_window#shards.[window->current_shardcxx . . $ _grn_window#current_shard.]);
705 grn_window_function_funccxx . . $ grn_window_function_func# *window_function_func =
706 shard->window_functioncxx . . $ $anonymous_type_8546c3b2810fbe7a_0#window_function.->callbackscxx . . $ _grn_proc#callbacks..window_functioncxx . . $ _grn_proc#$anonymous_type_5#window_function.;
707 grn_rccxx . . $ grn_rc# rc = window_function_func(ctx,
708 shard->output_columncxx . . $ $anonymous_type_8546c3b2810fbe7a_0#output_column.,
709 window,
710 (grn_objcxx . . $ grn_obj# **)GRN_BULK_HEADcxx . . $ `include/groonga/groonga.h:2648:9`!(&(shard->arguments)),
711 (int)GRN_PTR_VECTOR_SIZEcxx . . $ `include/groonga/groonga.h:3265:9`!(&(shard->arguments)));
712
713 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(rc);
714 }
715
716 /* Deprecated since 9.0.2. */
717 grn_rccxx . . $ grn_rc#
718 grn_table_apply_window_functioncxx . . $ grn_table_apply_window_function(c462f12e2aeb56b8).(grn_ctxcxx . . $ grn_ctx# *ctx,
719 grn_objcxx . . $ grn_obj# *table,
720 grn_objcxx . . $ grn_obj# *output_column,
721 grn_window_definitioncxx . . $ grn_window_definition# *definition,
722 grn_objcxx . . $ grn_obj# *window_function_call)
723 {
724 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
725
726 if (!table) {
727 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
728 "[table][apply][window-function] table is NULL");
729 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
730 }
731
732 const size_t n_sort_keys = definition->n_group_keyscxx . . $ _grn_window_definition#n_group_keys. + definition->n_sort_keyscxx . . $ _grn_window_definition#n_sort_keys.;
733 grn_table_sort_keycxx . . $ grn_table_sort_key# *sort_keys = GRN_MALLOCNcxx . . $ `lib/grn_alloc.h:50:9`!(grn_table_sort_key, n_sort_keys);
734 if (!sort_keys) {
735 grn_rccxx . . $ grn_rc# rc = ctx->rccxx . . $ _grn_ctx#rc.;
736 char errbuf[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
737 if (rc == GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
738 rc = GRN_NO_MEMORY_AVAILABLEcxx . . $ GRN_NO_MEMORY_AVAILABLE.;
739 }
740 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(errbuf, GRN_CTX_MSGSIZE, ctx->errbuf);
741 ERRcxx . . $ `lib/grn_error.h:156:9`!(rc,
742 "[table][apply][window-function] "
743 "failed to allocate internal sort keys: %s",
744 errbuf);
745 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
746 }
747
748 grn_objcxx . . $ grn_obj# key_columns;
749 GRN_PTR_INITcxx . . $ `include/groonga/groonga.h:2869:9`!(&key_columns, GRN_OBJ_VECTORcxx . . $ `include/groonga/groonga.h:2734:9`!, GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!);
750 for (size_t i = 0; i < definition->n_group_keyscxx . . $ _grn_window_definition#n_group_keys.; i++) {
751 sort_keys[i] = definition->group_keyscxx . . $ _grn_window_definition#group_keys.[i];
752 GRN_PTR_PUTcxx . . $ `include/groonga/groonga.h:3218:9`!(ctx, &key_columns, sort_keys[i].key);
753 }
754 for (size_t i = 0; i < definition->n_sort_keyscxx . . $ _grn_window_definition#n_sort_keys.; i++) {
755 sort_keys[i + definition->n_group_keyscxx . . $ _grn_window_definition#n_group_keys.] = definition->sort_keyscxx . . $ _grn_window_definition#sort_keys.[i];
756 GRN_PTR_PUTcxx . . $ `include/groonga/groonga.h:3218:9`!(ctx, &key_columns, sort_keys[i + definition->n_group_keys].key);
757 }
758
759 grn_objcxx . . $ grn_obj# *sorted = grn_table_createcxx . . $ grn_table_create(51df5019e8d3bdc1).(ctx,
760 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
761 GRN_OBJ_TABLE_NO_KEYcxx . . $ `include/groonga/groonga.h:691:9`!,
762 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
763 table);
764 if (!sorted) {
765 grn_rccxx . . $ grn_rc# rc = ctx->rccxx . . $ _grn_ctx#rc.;
766 char errbuf[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
767 if (rc == GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
768 rc = GRN_NO_MEMORY_AVAILABLEcxx . . $ GRN_NO_MEMORY_AVAILABLE.;
769 }
770 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(errbuf, GRN_CTX_MSGSIZE, ctx->errbuf);
771 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &key_columns);
772 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(sort_keys);
773 ERRcxx . . $ `lib/grn_error.h:156:9`!(rc,
774 "[table][apply][window-function] "
775 "failed to allocate table to store sorted result: %s",
776 errbuf);
777 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
778 }
779 grn_table_sortcxx . . $ grn_table_sort(ae37406ac512253b).(ctx,
780 table,
781 0, -1,
782 sorted,
783 sort_keys, (int)n_sort_keys);
784
785 grn_windowcxx . . $ grn_window# window;
786 grn_window_initcxx . . $ grn_window_init(e129d7a355eb2bb4).(ctx, &window);
787 grn_window_set_is_sortedcxx . . $ grn_window_set_is_sorted(316de395f9981a9a).(ctx, &window, definition->n_sort_keyscxx . . $ _grn_window_definition#n_sort_keys. > 0);
788 if (definition->n_group_keyscxx . . $ _grn_window_definition#n_group_keys. > 0) {
789 grn_objcxx . . $ grn_obj# *previous_values = GRN_MALLOCNcxx . . $ `lib/grn_alloc.h:50:9`!(grn_obj, definition->n_group_keys);
790 grn_objcxx . . $ grn_obj# *current_values = GRN_MALLOCNcxx . . $ `lib/grn_alloc.h:50:9`!(grn_obj, definition->n_group_keys);
791
792 const size_t n = definition->n_group_keyscxx . . $ _grn_window_definition#n_group_keys.;
793 for (size_t i = 0; i < n; i++) {
794 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&(previous_values[i]));
795 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&(current_values[i]));
796 }
797
798 GRN_TABLE_EACH_BEGINcxx . . $ `include/groonga/table.h:614:9`!(ctx, sorted, cursor, id) {
799 void *value;
800 grn_table_cursor_get_valuecxx . . $ grn_table_cursor_get_value(7d620ebe94cee13a).(ctx, cursor, &value);
801 const grn_idcxx . . $ grn_id# record_id = *((grn_idcxx . . $ grn_id# *)value);
802
803 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_group_key_changed = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
804 for (size_t i = 0; i < n; i++) {
805 const size_t reverse_i = n - i - 1;
806 grn_objcxx . . $ grn_obj# *previous_value = &(previous_values[reverse_i]);
807 grn_objcxx . . $ grn_obj# *current_value = &(current_values[reverse_i]);
808 grn_objcxx . . $ grn_obj# *group_key = definition->group_keyscxx . . $ _grn_window_definition#group_keys.[reverse_i].keycxx . . $ _grn_table_sort_key#key.;
809
810 if (is_group_key_changed) {
811 GRN_BULK_REWINDcxx . . $ `include/groonga/groonga.h:2599:9`!(previous_value);
812 grn_obj_get_valuecxx . . $ grn_obj_get_value(6e06fec66698a6a).(ctx, group_key, record_id, previous_value);
813 } else {
814 GRN_BULK_REWINDcxx . . $ `include/groonga/groonga.h:2599:9`!(current_value);
815 grn_obj_get_valuecxx . . $ grn_obj_get_value(6e06fec66698a6a).(ctx, group_key, record_id, current_value);
816 if ((GRN_BULK_VSIZEcxx . . $ `include/groonga/groonga.h:2642:9`!(current_value) !=
817 GRN_BULK_VSIZEcxx . . $ `include/groonga/groonga.h:2642:9`!(previous_value)) ||
818 (memcmpcxx . . $ memcmp(36f949851efa3055).(GRN_BULK_HEADcxx . . $ `include/groonga/groonga.h:2648:9`!(current_value),
819 GRN_BULK_HEADcxx . . $ `include/groonga/groonga.h:2648:9`!(previous_value),
820 GRN_BULK_VSIZEcxx . . $ `include/groonga/groonga.h:2642:9`!(current_value)) != 0)) {
821 is_group_key_changed = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
822 grn_bulk_write_fromcxx . . $ grn_bulk_write_from(d8dd2947254981a1).(ctx,
823 previous_value,
824 GRN_BULK_HEADcxx . . $ `include/groonga/groonga.h:2648:9`!(current_value),
825 0,
826 GRN_BULK_VSIZEcxx . . $ `include/groonga/groonga.h:2642:9`!(current_value));
827 }
828 }
829 }
830
831 if (is_group_key_changed && !grn_window_is_emptycxx . . $ grn_window_is_empty(455f6a6a90ff2430).(ctx, &window)) {
832 grn_window_executecxx . . $ grn_window_execute(e129d7a355eb2bb4).(ctx, &window);
833 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
834 break;
835 }
836 grn_window_resetcxx . . $ grn_window_reset(e129d7a355eb2bb4).(ctx, &window);
837 }
838 grn_window_add_recordcxx . . $ grn_window_add_record(dcfc7afbd5f143b6).(ctx,
839 &window,
840 table,
841 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
842 record_id,
843 window_function_call,
844 output_column,
845 &key_columns);
846 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
847 break;
848 }
849 } GRN_TABLE_EACH_ENDcxx . . $ `include/groonga/table.h:665:9`!(ctx, cursor);
850 for (size_t i = 0; i < definition->n_group_keyscxx . . $ _grn_window_definition#n_group_keys.; i++) {
851 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(previous_values[i]));
852 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(current_values[i]));
853 }
854 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(previous_values);
855 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(current_values);
856 } else {
857 GRN_TABLE_EACH_BEGINcxx . . $ `include/groonga/table.h:614:9`!(ctx, sorted, cursor, id) {
858 void *value;
859 grn_table_cursor_get_valuecxx . . $ grn_table_cursor_get_value(7d620ebe94cee13a).(ctx, cursor, &value);
860 const grn_idcxx . . $ grn_id# record_id = *((grn_idcxx . . $ grn_id# *)value);
861 grn_window_add_recordcxx . . $ grn_window_add_record(dcfc7afbd5f143b6).(ctx,
862 &window,
863 table,
864 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
865 record_id,
866 window_function_call,
867 output_column,
868 &key_columns);
869 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
870 break;
871 }
872 } GRN_TABLE_EACH_ENDcxx . . $ `include/groonga/table.h:665:9`!(ctx, cursor);
873 }
874 if (ctx->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS. && !grn_window_is_emptycxx . . $ grn_window_is_empty(455f6a6a90ff2430).(ctx, &window)) {
875 grn_window_executecxx . . $ grn_window_execute(e129d7a355eb2bb4).(ctx, &window);
876 }
877
878 grn_window_fincxx . . $ grn_window_fin(e129d7a355eb2bb4).(ctx, &window);
879
880 grn_obj_closecxx . . $ grn_obj_close(4865d068a46d0f83).(ctx, sorted);
881
882 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &key_columns);
883
884 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(sort_keys);
885
886 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
887 }