Debian Codegraph @

plugins/tokenizers/h3_index.c

raw symbols SCIP
1 /*
2 Copyright (C) 2024 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 #ifdef GRN_EMBEDDED
20 # define GRN_PLUGIN_FUNCTION_TAG tokenizers_h3_index
21 #endif
22
23 #include <groonga.h>cxx . . $ `<file>/include/groonga.h`/
24 #include <groonga/tokenizer.h>cxx . . $ `<file>/include/groonga/tokenizer.h`/
25
26 static const char *grn_h3_index_tagcxx . . $ grn_h3_index_tag. = "[tokenizer][h3-index]";
27
28 typedef structcxx . . $ $anonymous_type_f2eab5844426decb_0# {
29 uint8_tcxx . . $ uint8_t# resolutioncxx . . $ $anonymous_type_f2eab5844426decb_0#resolution.;
30 } grn_h3_index_optionscxx . . $ grn_h3_index_options#;
31
32 static void
33 grn_h3_index_options_initcxx . . $ grn_h3_index_options_init(3c1b5980eb15d3f2).(grn_ctxcxx . . $ grn_ctx# *ctx,
34 grn_h3_index_optionscxx . . $ grn_h3_index_options# *options,
35 int32_tcxx . . $ int32_t# resolution)
36 {
37 options->resolutioncxx . . $ $anonymous_type_f2eab5844426decb_0#resolution. = resolution;
38 }
39
40 static void
41 grn_h3_index_options_fincxx . . $ grn_h3_index_options_fin(5dcc86d1978a6240).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_h3_index_optionscxx . . $ grn_h3_index_options# *options)
42 {
43 }
44
45 typedef structcxx . . $ $anonymous_type_f2eab5844426decb_1# {
46 grn_h3_index_optionscxx . . $ grn_h3_index_options# optionscxx . . $ $anonymous_type_f2eab5844426decb_1#options.;
47 grn_geo_pointcxx . . $ grn_geo_point# geo_pointcxx . . $ $anonymous_type_f2eab5844426decb_1#geo_point.;
48 uint64_tcxx . . $ uint64_t# indexcxx . . $ $anonymous_type_f2eab5844426decb_1#index.;
49 } grn_h3_index_tokenizercxx . . $ grn_h3_index_tokenizer#;
50
51 static void
52 grn_h3_index_close_optionscxx . . $ grn_h3_index_close_options(b6b6153f622d9caa).(grn_ctxcxx . . $ grn_ctx# *ctx, void *data)
53 {
54 grn_h3_index_optionscxx . . $ grn_h3_index_options# *options = data;
55 grn_h3_index_options_fincxx . . $ grn_h3_index_options_fin(5dcc86d1978a6240).(ctx, options);
56 GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, options);
57 }
58
59 static void *
60 grn_h3_index_open_optionscxx . . $ grn_h3_index_open_options(935e2583f8354665).(grn_ctxcxx . . $ grn_ctx# *ctx,
61 grn_objcxx . . $ grn_obj# *tokenizer,
62 grn_objcxx . . $ grn_obj# *raw_options,
63 void *user_data)
64 {
65 grn_h3_index_optionscxx . . $ grn_h3_index_options# *options =
66 GRN_PLUGIN_CALLOCcxx . . $ `include/groonga/plugin.h:96:9`!(ctx, sizeof(grn_h3_index_options));
67 if (!options) {
68 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
69 GRN_NO_MEMORY_AVAILABLE,
70 "%s failed to allocate memory for options",
71 grn_h3_index_tag);
72 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
73 }
74
75 grn_h3_index_options_initcxx . . $ grn_h3_index_options_init(3c1b5980eb15d3f2).(ctx, options, 15);
76 GRN_OPTION_VALUES_EACH_BEGINcxx . . $ `include/groonga/option.h:29:9`!(ctx, raw_options, i, name, name_length)
77 {
78 grn_raw_stringcxx . . $ grn_raw_string# name_raw;
79 name_raw.valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. = name;
80 name_raw.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. = name_length;
81
82 if (GRN_RAW_STRING_EQUAL_CSTRINGcxx . . $ `include/groonga/raw_string.h:57:9`!(name_raw, "resolution")) {
83 options->resolutioncxx . . $ $anonymous_type_f2eab5844426decb_0#resolution. =
84 grn_vector_get_element_uint8cxx . . $ grn_vector_get_element_uint8(5ed32569363705e5).(ctx, raw_options, i, options->resolutioncxx . . $ $anonymous_type_f2eab5844426decb_0#resolution.);
85 }
86 }
87 GRN_OPTION_VALUES_EACH_ENDcxx . . $ `include/groonga/option.h:55:9`!();
88
89 return options;
90 }
91
92 static void
93 grn_h3_index_fincxx . . $ grn_h3_index_fin(b6b6153f622d9caa).(grn_ctxcxx . . $ grn_ctx# *ctx, void *user_data)
94 {
95 grn_h3_index_tokenizercxx . . $ grn_h3_index_tokenizer# *tokenizer = user_data;
96
97 if (!tokenizer) {
98 return;
99 }
100
101 GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, tokenizer);
102 }
103
104 static void *
105 grn_h3_index_initcxx . . $ grn_h3_index_init(78928ddd02ab5cc6).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_tokenizer_querycxx . . $ grn_tokenizer_query# *query)
106 {
107 grn_geo_pointcxx . . $ grn_geo_point# geo_point;
108 size_t query_size;
109 grn_idcxx . . $ grn_id# query_domain;
110 const char *raw_query =
111 grn_tokenizer_query_get_datacxx . . $ grn_tokenizer_query_get_data(a6aa476078bce42a).(ctx, query, &query_size, &query_domain);
112 if (query_domain == GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
113 if (query_size != sizeof(grn_geo_pointcxx . . $ grn_geo_point#)) {
114 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
115 GRN_INVALID_ARGUMENT,
116 "%s query must be a WGS84GeoPoint: %zu != %zu",
117 grn_h3_index_tag,
118 query_size,
119 sizeof(grn_geo_point));
120 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
121 }
122 geo_point = *((const grn_geo_pointcxx . . $ grn_geo_point# *)raw_query);
123 } else {
124 if (grn_type_id_is_text_familycxx . . $ grn_type_id_is_text_family(a2a496425acc5b40).(ctx, query_domain)) {
125 grn_objcxx . . $ grn_obj# text_geo_point;
126 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&text_geo_point, GRN_OBJ_DO_SHALLOW_COPYcxx . . $ `include/groonga/groonga.h:2732:9`!);
127 GRN_TEXT_SETcxx . . $ `include/groonga/groonga.h:2761:9`!(ctx, &text_geo_point, raw_query, query_size);
128 grn_objcxx . . $ grn_obj# geo_point_buffer;
129 GRN_WGS84_GEO_POINT_INITcxx . . $ `include/groonga/groonga.h:2876:9`!(&geo_point_buffer, 0);
130 grn_rccxx . . $ grn_rc# rc = grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, &text_geo_point, &geo_point_buffer, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
131 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
132 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &geo_point_buffer);
133 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(
134 ctx,
135 rc,
136 "%s query must be valid WGS84GeoPoint text representation: <%.*s>",
137 grn_h3_index_tag,
138 (int)query_size,
139 raw_query);
140 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
141 }
142 GRN_GEO_POINT_VALUEcxx . . $ `include/groonga/groonga.h:3113:9`!(&geo_point_buffer,
143 geo_point.latitude,
144 geo_point.longitude);
145 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &geo_point_buffer);
146 } else {
147 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
148 GRN_INVALID_ARGUMENT,
149 "%s query must be WGS84GeoPoint: %s(%u)",
150 grn_h3_index_tag,
151 grn_type_id_to_string_builtin(ctx, query_domain),
152 query_domain);
153 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
154 }
155 }
156
157 grn_objcxx . . $ grn_obj# *lexicon = grn_tokenizer_query_get_lexiconcxx . . $ grn_tokenizer_query_get_lexicon(94bd48ba32a54cd8).(ctx, query);
158 grn_h3_index_optionscxx . . $ grn_h3_index_options# *options =
159 grn_table_cache_default_tokenizer_optionscxx . . $ grn_table_cache_default_tokenizer_options(d2cf5c417953e151).(ctx,
160 lexicon,
161 grn_h3_index_open_optionscxx . . $ grn_h3_index_open_options(935e2583f8354665).,
162 grn_h3_index_close_optionscxx . . $ grn_h3_index_close_options(b6b6153f622d9caa).,
163 query);
164 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
165 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
166 }
167
168 grn_h3_index_tokenizercxx . . $ grn_h3_index_tokenizer# *tokenizer =
169 GRN_PLUGIN_CALLOCcxx . . $ `include/groonga/plugin.h:96:9`!(ctx, sizeof(grn_h3_index_tokenizer));
170 if (!tokenizer) {
171 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
172 GRN_NO_MEMORY_AVAILABLE,
173 "%s failed to allocate tokenizer",
174 grn_h3_index_tag);
175 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
176 }
177
178 tokenizer->optionscxx . . $ $anonymous_type_f2eab5844426decb_1#options. = *options;
179 tokenizer->geo_pointcxx . . $ $anonymous_type_f2eab5844426decb_1#geo_point. = geo_point;
180
181 return tokenizer;
182 }
183
184 static void
185 grn_h3_index_nextcxx . . $ grn_h3_index_next(71a9f2a3a5ca0984).(grn_ctxcxx . . $ grn_ctx# *ctx,
186 grn_tokenizer_querycxx . . $ grn_tokenizer_query# *query,
187 grn_tokencxx . . $ grn_token# *token,
188 void *user_data)
189 {
190 grn_h3_index_tokenizercxx . . $ grn_h3_index_tokenizer# *tokenizer = user_data;
191
192 tokenizer->indexcxx . . $ $anonymous_type_f2eab5844426decb_1#index. = grn_h3_compute_cellcxx . . $ grn_h3_compute_cell(20c0e0a6e42575f).(ctx,
193 &(tokenizer->geo_pointcxx . . $ $anonymous_type_f2eab5844426decb_1#geo_point.),
194 tokenizer->optionscxx . . $ $anonymous_type_f2eab5844426decb_1#options..resolutioncxx . . $ $anonymous_type_f2eab5844426decb_0#resolution.,
195 grn_h3_index_tagcxx . . $ grn_h3_index_tag.);
196 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
197 return;
198 }
199 grn_token_set_datacxx . . $ grn_token_set_data(6ab8cb5e36c467ee).(ctx,
200 token,
201 (const char *)&(tokenizer->indexcxx . . $ $anonymous_type_f2eab5844426decb_1#index.),
202 sizeof(uint64_tcxx . . $ uint64_t#));
203 grn_token_set_domaincxx . . $ grn_token_set_domain(ab0ad35a1c0de1a).(ctx, token, GRN_DB_UINT64cxx . . $ GRN_DB_UINT64.);
204 grn_token_set_statuscxx . . $ grn_token_set_status(ab0ad35a1c0de1a).(ctx, token, GRN_TOKEN_LASTcxx . . $ `include/groonga/token.h:82:9`!);
205 }
206
207 grn_rccxx . . $ grn_rc#
208 GRN_PLUGIN_INITcxx . . $ `include/groonga/plugin.h:43:9`!(grn_ctxcxx . . $ grn_ctx# *ctx)
209 {
210 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
211 }
212
213 grn_rccxx . . $ grn_rc#
214 GRN_PLUGIN_REGISTERcxx . . $ `include/groonga/plugin.h:44:9`!(grn_ctxcxx . . $ grn_ctx# *ctx)
215 {
216 grn_objcxx . . $ grn_obj# *tokenizer = grn_tokenizer_createcxx . . $ grn_tokenizer_create(70fde0087014f9ea).(ctx, "TokenH3Index", -1);
217 if (tokenizer) {
218 grn_tokenizer_set_init_funccxx . . $ grn_tokenizer_set_init_func(9b546f012584c62c).(ctx, tokenizer, grn_h3_index_initcxx . . $ grn_h3_index_init(78928ddd02ab5cc6).);
219 grn_tokenizer_set_next_funccxx . . $ grn_tokenizer_set_next_func(274c55b60b47101c).(ctx, tokenizer, grn_h3_index_nextcxx . . $ grn_h3_index_next(71a9f2a3a5ca0984).);
220 grn_tokenizer_set_fin_funccxx . . $ grn_tokenizer_set_fin_func(638e0fa4e92f09de).(ctx, tokenizer, grn_h3_index_fincxx . . $ grn_h3_index_fin(b6b6153f622d9caa).);
221 }
222 return ctx->rccxx . . $ _grn_ctx#rc.;
223 }
224
225 grn_rccxx . . $ grn_rc#
226 GRN_PLUGIN_FINcxx . . $ `include/groonga/plugin.h:45:9`!(grn_ctxcxx . . $ grn_ctx# *ctx)
227 {
228 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
229 }