Debian Codegraph @

lib/grn_rset.h

raw symbols SCIP
1 /*
2 Copyright (C) 2009-2016 Brazil
3 Copyright (C) 2020-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 #pragma once
21
22 #include "grn.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /* rset is result set */
29
30 typedef struct {
31 double score;
32 uint32_t n_subrecs;
33 int subrecs[1];
34 } grn_rset_recinfo;
35
36 typedef struct {
37 grn_id rid;
38 uint32_t sid;
39 uint32_t pos;
40 } grn_rset_posinfo;
41
42 #define GRN_RSET_UTIL_BIT (0x80000000)
43
44 typedef union {
45 int64_t value_int64;
46 double value_double;
47 } grn_rset_aggregated_value;
48
49 #define GRN_RSET_N_SUBRECS_SIZE (sizeof(int))
50 #define GRN_RSET_MAX_SIZE (sizeof(grn_rset_aggregated_value))
51 #define GRN_RSET_MIN_SIZE (sizeof(grn_rset_aggregated_value))
52 #define GRN_RSET_SUM_SIZE (sizeof(grn_rset_aggregated_value))
53 #define GRN_RSET_MEAN_SIZE (sizeof(double) + sizeof(uint64_t))
54
55 #define GRN_RSET_SCORE_SIZE (sizeof(double))
56
57 #define GRN_RSET_N_SUBRECS(ri) ((ri)->n_subrecs & ~GRN_RSET_UTIL_BIT)
58
59 #define GRN_RSET_SUBREC_SIZE(subrec_size) \
60 (GRN_RSET_SCORE_SIZE + (subrec_size))
61 #define GRN_RSET_SUBRECS_CMP(a,b,dir) (((a) - (b))*(dir))
62 #define GRN_RSET_SUBRECS_NTH(subrecs,size,n) \
63 ((double *)((byte *)subrecs + n * GRN_RSET_SUBREC_SIZE(size)))
64 #define GRN_RSET_SUBRECS_COPY(subrecs,size,n,src) \
65 (grn_memcpy(GRN_RSET_SUBRECS_NTH(subrecs, size, n), src, GRN_RSET_SUBREC_SIZE(size)))
66 #define GRN_RSET_SUBRECS_SIZE(subrec_size,n) \
67 (GRN_RSET_SUBREC_SIZE(subrec_size) * n)
68
69 void grn_rset_add_subrec(grn_ctx *ctx,
70 grn_rset_recinfo *ri,
71 grn_obj *table,
72 double score,
73 grn_rset_posinfo *pi,
74 int dir);
75
76 uint32_t grn_rset_recinfo_calc_values_size(grn_ctx *ctx,
77 grn_table_group_flags flags);
78
79 void grn_rset_recinfo_update_calc_values(grn_ctx *ctx,
80 grn_rset_recinfo *ri,
81 grn_obj *table,
82 grn_obj *value);
83
84 grn_rset_aggregated_value *
85 grn_rset_recinfo_get_max_(grn_ctx *ctx,
86 grn_rset_recinfo *ri,
87 grn_obj *table);
88 grn_rset_aggregated_value
89 grn_rset_recinfo_get_max(grn_ctx *ctx,
90 grn_rset_recinfo *ri,
91 grn_obj *table);
92 void
93 grn_rset_recinfo_set_max(grn_ctx *ctx,
94 grn_rset_recinfo *ri,
95 grn_obj *table,
96 grn_rset_aggregated_value max);
97
98 grn_rset_aggregated_value *
99 grn_rset_recinfo_get_min_(grn_ctx *ctx,
100 grn_rset_recinfo *ri,
101 grn_obj *table);
102 grn_rset_aggregated_value
103 grn_rset_recinfo_get_min(grn_ctx *ctx,
104 grn_rset_recinfo *ri,
105 grn_obj *table);
106 void
107 grn_rset_recinfo_set_min(grn_ctx *ctx,
108 grn_rset_recinfo *ri,
109 grn_obj *table,
110 grn_rset_aggregated_value min);
111
112 grn_rset_aggregated_value *
113 grn_rset_recinfo_get_sum_(grn_ctx *ctx,
114 grn_rset_recinfo *ri,
115 grn_obj *table);
116 grn_rset_aggregated_value
117 grn_rset_recinfo_get_sum(grn_ctx *ctx,
118 grn_rset_recinfo *ri,
119 grn_obj *table);
120 void
121 grn_rset_recinfo_set_sum(grn_ctx *ctx,
122 grn_rset_recinfo *ri,
123 grn_obj *table,
124 grn_rset_aggregated_value sum);
125
126 double *grn_rset_recinfo_get_mean_(grn_ctx *ctx,
127 grn_rset_recinfo *ri,
128 grn_obj *table);
129 double grn_rset_recinfo_get_mean(grn_ctx *ctx,
130 grn_rset_recinfo *ri,
131 grn_obj *table);
132 void grn_rset_recinfo_set_mean(grn_ctx *ctx,
133 grn_rset_recinfo *ri,
134 grn_obj *table,
135 double avg);
136
137 #ifdef __cplusplus
138 }
139 #endif