1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ------------------------------------------- */
24 #define max(a,b) ((a) > (b) ? (a) : (b))
25 #define MAX_BUFSIZE 128
28 /****************************************************************/
30 /****************************************************************/
33 ////////////////////////////////////////////////////////////////////////
36 typedef struct avg_udaf_lfta_struct_t{
39 } avg_udaf_lfta_struct_t;
41 void avg_udaf_lfta_LFTA_AGGR_INIT_(gs_sp_t b){
42 avg_udaf_lfta_struct_t *s = (avg_udaf_lfta_struct_t *)b;
47 void avg_udaf_lfta_LFTA_AGGR_UPDATE_(gs_sp_t b,gs_uint32_t v){
48 avg_udaf_lfta_struct_t *s = (avg_udaf_lfta_struct_t *)b;
53 gs_retval_t avg_udaf_lfta_LFTA_AGGR_FLUSHME_(gs_sp_t b){
57 void avg_udaf_lfta_LFTA_AGGR_OUTPUT_(struct gs_string *r,gs_sp_t b){
62 void avg_udaf_lfta_LFTA_AGGR_DESTROY_(gs_sp_t b){
66 /////////////////////////////////////////////////////////
69 typedef struct moving_sum_lfta_struct{
72 } moving_sum_lfta_struct;
74 void moving_sum_lfta_LFTA_AGGR_INIT_(gs_sp_t b){
75 moving_sum_lfta_struct *s = (moving_sum_lfta_struct *)b;
80 void moving_sum_lfta_LFTA_AGGR_UPDATE_(gs_sp_t b, gs_uint32_t v, gs_uint32_t N){
81 moving_sum_lfta_struct *s = (moving_sum_lfta_struct *)b;
86 gs_retval_t moving_sum_lfta_LFTA_AGGR_FLUSHME_(gs_sp_t b){
90 void moving_sum_lfta_LFTA_AGGR_OUTPUT_(gs_uint64_t *r, gs_sp_t b){
91 moving_sum_lfta_struct *s = (moving_sum_lfta_struct *)b;
92 *r = ((gs_uint64_t)(s->N) << 32) | (gs_uint64_t)(s->sum);
95 gs_retval_t moving_sum_lfta_LFTA_AGGR_DESTROY_(gs_sp_t b){
99 /////////////////////////////////////////////////////////
100 // FIRST and LAST aggregates
102 void FIRST_lfta_LFTA_AGGR_INIT_(gs_uint32_t* scratch) {
103 *scratch = UINT_MAX; // we will encode uninitialized value of UINT_MAX
107 void FIRST_lfta_LFTA_AGGR_UPDATE_(gs_uint32_t* scratch, gs_uint32_t val) {
108 if (*scratch == UINT_MAX)
113 gs_retval_t FIRST_lfta_LFTA_AGGR_FLUSHME_( gs_uint32_t* scratch) { return 0; }
115 void FIRST_lfta_LFTA_AGGR_OUTPUT_(gs_uint32_t* res, gs_uint32_t* scratch) {
119 void FIRST_lfta_LFTA_AGGR_DESTROY_(gs_uint32_t* scratch) { return; }
121 void FIRST_ULL_lfta_LFTA_AGGR_INIT_(gs_uint64_t* scratch) {
122 *scratch = ULLONG_MAX; // we will encode uninitialized value of ULLONG_MAX
126 void FIRST_ULL_lfta_LFTA_AGGR_UPDATE_(gs_uint64_t* scratch, gs_uint64_t val) {
127 if (*scratch == ULLONG_MAX)
132 gs_retval_t FIRST_ULL_lfta_LFTA_AGGR_FLUSHME_( gs_uint64_t* scratch) { return 0; }
134 void FIRST_ULL_lfta_LFTA_AGGR_OUTPUT_(gs_uint64_t* res, gs_uint64_t* scratch) {
138 void FIRST_ULL_lfta_LFTA_AGGR_DESTROY_(gs_uint64_t* scratch) { return; }
142 void FIRST_STR_lfta_LFTA_AGGR_INIT_(struct gs_string* scratch) {
143 scratch->data = NULL;
147 void FIRST_STR_lfta_LFTA_AGGR_UPDATE_(struct gs_string* scratch, struct gs_string* val) {
148 if (!scratch->data) {
149 str_assign_with_copy(NULL, scratch, val);
154 gs_retval_t FIRST_STR_lfta_LFTA_AGGR_FLUSHME_(struct gs_string* scratch) { return 0; }
156 void FIRST_STR_lfta_LFTA_AGGR_OUTPUT_(struct gs_string* res, struct gs_string* scratch) {
160 void FIRST_STR_lfta_LFTA_AGGR_DESTROY_(struct gs_string* scratch) {
162 fta_free(NULL, scratch->data);
165 void LAST_lfta_LFTA_AGGR_INIT_(gs_uint32_t* scratch) { }
167 void LAST_lfta_LFTA_AGGR_UPDATE_(gs_uint32_t* scratch, gs_uint32_t val) {
172 gs_retval_t LAST_lfta_LFTA_AGGR_FLUSHME_( gs_uint32_t* scratch) { return 0; }
174 void LAST_lfta_LFTA_AGGR_OUTPUT_(gs_uint32_t* res, gs_uint32_t* scratch) {
178 void LAST_lfta_LFTA_AGGR_DESTROY_(gs_uint32_t* scratch) { return; }
180 void LAST_ULL_lfta_LFTA_AGGR_INIT_(gs_uint64_t* scratch) { }
182 void LAST_ULL_lfta_LFTA_AGGR_UPDATE_(gs_uint64_t* scratch, gs_uint64_t val) {
187 gs_retval_t LAST_ULL_lfta_LFTA_AGGR_FLUSHME_( gs_uint64_t* scratch) { return 0; }
189 void LAST_ULL_lfta_LFTA_AGGR_OUTPUT_(gs_uint64_t* res, gs_uint64_t* scratch) {
193 void LAST_ULL_lfta_LFTA_AGGR_DESTROY_(gs_uint64_t* scratch) { return; }
197 void LAST_STR_lfta_LFTA_AGGR_INIT_(struct gs_string* scratch) {
198 scratch->data = NULL;
202 void LAST_STR_lfta_LFTA_AGGR_UPDATE_(struct gs_string* scratch, struct gs_string* val) {
203 if (!scratch->data) {
204 str_assign_with_copy(NULL, scratch, val);
206 if (!str_compare(scratch, val)) {
207 fta_free(NULL, scratch->data);
208 str_assign_with_copy(NULL, scratch, val);
214 gs_retval_t LAST_STR_lfta_LFTA_AGGR_FLUSHME_(struct gs_string* scratch) { return 0; }
216 void LAST_STR_lfta_LFTA_AGGR_OUTPUT_(struct gs_string* res, struct gs_string* scratch) {
220 void LAST_STR_lfta_LFTA_AGGR_DESTROY_(struct gs_string* scratch) {
222 fta_free(NULL, scratch->data);
226 /////////////////////////////////////////////////////////
227 // running_array_aggr aggregate
229 struct running_array_aggr_str{
230 gs_uint32_t num_list[4];
234 void running_array_aggr_lfta_LFTA_AGGR_INIT_(char* scratch) {
235 struct running_array_aggr_str* aggr = (struct running_array_aggr_str*)scratch;
239 void running_array_aggr_lfta_LFTA_AGGR_UPDATE_(char* scratch, gs_uint32_t val) {
240 struct running_array_aggr_str* aggr = (struct running_array_aggr_str*)scratch;
241 aggr->num_list[aggr->n_num++] = val;
244 gs_retval_t running_array_aggr_lfta_LFTA_AGGR_FLUSHME_(char* scratch) {
245 struct running_array_aggr_str* aggr = (struct running_array_aggr_str*)scratch;
246 return (aggr->n_num == 4);
248 void running_array_aggr_lfta_LFTA_AGGR_OUTPUT_(struct gs_string* res, char* scratch) {
249 struct running_array_aggr_str* aggr = (struct running_array_aggr_str*)scratch;
251 res->length = aggr->n_num * sizeof(gs_uint32_t);
255 void running_array_aggr_lfta_LFTA_AGGR_DESTROY_(char* scratch) { }