1 /* -*- c-basic-offset: 2 -*- */
2 /*
3   Copyright(C) 2009-2016 Brazil
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 version 2.1 as published by the Free Software Foundation.
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-1335  USA
17 */
18 
19 #pragma once
20 
21 #include "grn.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef struct {
28   double score;
29   int n_subrecs;
30   int subrecs[1];
31 } grn_rset_recinfo;
32 
33 typedef struct {
34   grn_id rid;
35   uint32_t sid;
36   uint32_t pos;
37 } grn_rset_posinfo;
38 
39 #define GRN_RSET_UTIL_BIT (0x80000000)
40 
41 #define GRN_RSET_N_SUBRECS_SIZE (sizeof(int))
42 #define GRN_RSET_MAX_SIZE       (sizeof(int64_t))
43 #define GRN_RSET_MIN_SIZE       (sizeof(int64_t))
44 #define GRN_RSET_SUM_SIZE       (sizeof(int64_t))
45 #define GRN_RSET_AVG_SIZE       (sizeof(double))
46 
47 #define GRN_RSET_SCORE_SIZE (sizeof(double))
48 
49 #define GRN_RSET_N_SUBRECS(ri) ((ri)->n_subrecs & ~GRN_RSET_UTIL_BIT)
50 
51 #define GRN_RSET_SUBREC_SIZE(subrec_size) \
52   (GRN_RSET_SCORE_SIZE + subrec_size)
53 #define GRN_RSET_SUBRECS_CMP(a,b,dir) (((a) - (b))*(dir))
54 #define GRN_RSET_SUBRECS_NTH(subrecs,size,n) \
55   ((double *)((byte *)subrecs + n * GRN_RSET_SUBREC_SIZE(size)))
56 #define GRN_RSET_SUBRECS_COPY(subrecs,size,n,src) \
57   (grn_memcpy(GRN_RSET_SUBRECS_NTH(subrecs, size, n), src, GRN_RSET_SUBREC_SIZE(size)))
58 #define GRN_RSET_SUBRECS_SIZE(subrec_size,n) \
59   (GRN_RSET_SUBREC_SIZE(subrec_size) * n)
60 
61 uint32_t grn_rset_recinfo_calc_values_size(grn_ctx *ctx,
62                                            grn_table_group_flags flags);
63 void grn_rset_recinfo_update_calc_values(grn_ctx *ctx,
64                                          grn_rset_recinfo *ri,
65                                          grn_obj *table,
66                                          grn_obj *value);
67 
68 int64_t *grn_rset_recinfo_get_max_(grn_ctx *ctx,
69                                    grn_rset_recinfo *ri,
70                                    grn_obj *table);
71 int64_t grn_rset_recinfo_get_max(grn_ctx *ctx,
72                                  grn_rset_recinfo *ri,
73                                  grn_obj *table);
74 void grn_rset_recinfo_set_max(grn_ctx *ctx,
75                               grn_rset_recinfo *ri,
76                               grn_obj *table,
77                               int64_t max);
78 
79 int64_t *grn_rset_recinfo_get_min_(grn_ctx *ctx,
80                                    grn_rset_recinfo *ri,
81                                    grn_obj *table);
82 int64_t grn_rset_recinfo_get_min(grn_ctx *ctx,
83                                  grn_rset_recinfo *ri,
84                                  grn_obj *table);
85 void grn_rset_recinfo_set_min(grn_ctx *ctx,
86                               grn_rset_recinfo *ri,
87                               grn_obj *table,
88                               int64_t min);
89 
90 int64_t *grn_rset_recinfo_get_sum_(grn_ctx *ctx,
91                                    grn_rset_recinfo *ri,
92                                    grn_obj *table);
93 int64_t grn_rset_recinfo_get_sum(grn_ctx *ctx,
94                                  grn_rset_recinfo *ri,
95                                  grn_obj *table);
96 void grn_rset_recinfo_set_sum(grn_ctx *ctx,
97                               grn_rset_recinfo *ri,
98                               grn_obj *table,
99                               int64_t sum);
100 
101 double *grn_rset_recinfo_get_avg_(grn_ctx *ctx,
102                                   grn_rset_recinfo *ri,
103                                   grn_obj *table);
104 double grn_rset_recinfo_get_avg(grn_ctx *ctx,
105                                 grn_rset_recinfo *ri,
106                                 grn_obj *table);
107 void grn_rset_recinfo_set_avg(grn_ctx *ctx,
108                               grn_rset_recinfo *ri,
109                               grn_obj *table,
110                               double avg);
111 
112 #ifdef __cplusplus
113 }
114 #endif
115