Fix out-of-order errors in join operator
[com/gs-lite.git] / include / hfta / hfta_runtime_library.h
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
6
7      http://www.apache.org/licenses/LICENSE-2.0
8
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  ------------------------------------------- */
15
16 #ifndef __HFTA_RUNTIME_LIBRARY__
17 #define __HFTA_RUNTIME_LIBRARY__
18 #include "host_tuple.h"
19 #include "gsconfig.h"
20 #include "gstypes.h"
21
22
23 #define string_hash(s) hfta_vstr_hashfunc(s)
24 #define string_hash_long(s) hfta_vstr_long_hashfunc(s) 
25
26
27 #define DNS_SAMPLE_HASH_SZ 50000000
28 #define DNS_HITLIST_HASH_SZ 50000000
29 #define DNS_HITLIST_ENTRY_SZ 500000
30
31
32 //              Internal functions
33 gs_retval_t Vstring_Constructor(vstring *, gs_csp_t);
34 gs_retval_t hfta_vstr_length(vstring *);
35 void hfta_vstr_assign_with_copy_in_tuple(vstring32 *, vstring *, gs_sp_t, int);
36 void hfta_vstr_assign_with_copy(vstring *, vstring *);
37 void hfta_vstr_destroy(vstring *);
38 void hfta_vstr_replace(vstring *, vstring *);
39
40 gs_uint32_t hfta_vstr_hashfunc(const vstring *);
41 gs_uint64_t hfta_vstr_long_hashfunc(const vstring *);
42 gs_retval_t hfta_vstr_compare(const vstring *, const vstring *);
43
44 gs_retval_t hfta_ipv6_compare(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
45 hfta_ipv6_str And_Ipv6(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
46 hfta_ipv6_str Or_Ipv6(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
47 gs_uint32_t hfta_ipv6_hashfunc(const hfta_ipv6_str *s) ;
48 hfta_ipv6_str hton_ipv6(hfta_ipv6_str s);
49 hfta_ipv6_str ntoh_ipv6(hfta_ipv6_str s);
50 gs_retval_t HFTA_Ipv6_Constructor(hfta_ipv6_str *s, gs_csp_t l) ;
51
52
53
54
55 //              External functions
56
57 inline static gs_retval_t str_truncate(vstring * result, vstring *str, gs_uint32_t length) {
58         result->offset=str->offset;
59         result->length=(str->length<length)?str->length:length;
60         result->reserved=SHALLOW_COPY;
61         return 0;
62 }
63
64 gs_retval_t str_exists_substr(vstring * s1, vstring * s2);
65 gs_retval_t str_compare(vstring * s1, vstring * s2);
66
67 gs_uint32_t str_match_offset(gs_uint32_t offset,vstring *s1,vstring *s2);
68 gs_uint32_t byte_match_offset( gs_uint32_t offset, gs_uint32_t val,vstring *s2);
69
70
71 // REGEX functions
72
73 gs_retval_t str_regex_match(vstring* str, gs_param_handle_t pattern_handle);
74 gs_param_handle_t register_handle_for_str_regex_match_slot_1(vstring* pattern);
75 gs_retval_t deregister_handle_for_str_regex_match_slot_1(gs_param_handle_t handle);
76
77 gs_retval_t str_partial_regex_match(vstring* str, gs_param_handle_t pattern_handle);
78 gs_param_handle_t register_handle_for_str_partial_regex_match_slot_1(vstring* pattern);
79 gs_retval_t deregister_handle_for_str_partial_regex_match_slot_1(gs_param_handle_t handle);
80
81 gs_param_handle_t register_handle_for_str_extract_regex_slot_1(vstring* pattern);
82 gs_retval_t str_extract_regex( vstring * result, vstring * str, gs_param_handle_t handle);
83 gs_retval_t deregister_handle_for_str_extract_regex_slot_1(gs_param_handle_t handle);
84
85
86
87
88 // type conversion
89 //              Avoid redefinition from rts_udaf.h
90 #ifndef INT
91         #define INT(c) ((int)(c))
92         #define UINT(c) ((gs_uint32_t)(c))
93         #define FLOAT(c) ((gs_float_t)(c))
94         #define LLONG(c) ((long long int)(c))
95         #define ULLONG(c) ((gs_uint64_t)(c))
96 #endif
97
98 // string conversions
99
100 gs_uint32_t strtoi(gs_uint32_t * r, struct vstring *data);
101 gs_uint32_t strtoip(gs_uint32_t * r, struct vstring *data);
102
103 //      constant string conversions
104 //              Avoid redefinition from rts_udaf.h
105 #ifndef strtoi_c
106         #define strtoi_c(h) ((gs_uint32_t)(h))
107         #define strtoip_c(h) ((gs_uint32_t)(h))
108 #endif
109 gs_param_handle_t register_handle_for_strtoi_c_slot_0(vstring* istr) ;
110 gs_retval_t deregister_handle_for_strtoi_c_slot_0(gs_param_handle_t h) ;
111
112 gs_param_handle_t register_handle_for_strtoip_c_slot_0(vstring* istr) ;
113 gs_retval_t deregister_handle_for_strtoip_c_slot_0(gs_param_handle_t h) ;
114
115
116 inline gs_uint32_t str_match_offset( gs_uint32_t offset, struct vstring * s1, struct vstring * s2) {
117         register gs_uint8_t *st1 = (gs_uint8_t *) s1->offset;
118         register gs_uint8_t *st2 = (gs_uint8_t *) (s2->offset+offset);
119         register gs_int32_t x;
120         register gs_int32_t len2 = s2->length-offset;
121         register gs_int32_t len1 = s1->length;
122         if (len2<len1) return 0;
123         for(x=0; x<len1; x++) {
124                 if (st1[x]!=st2[x]) return 0;
125         }
126         return 1;
127 }
128
129 // -------------------------------------------------------
130 //              map_int_to_string and its support functions, structs
131
132 gs_param_handle_t register_handle_for_int_to_string_map_slot_1(vstring *filename);
133 gs_retval_t int_to_string_map(vstring *result, gs_int64_t val, gs_param_handle_t handle);
134 gs_param_handle_t deregister_handle_for_int_to_string_map_slot_1(gs_param_handle_t handle);
135
136
137 #endif