X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fgscphftaaux%2FManku_HH.cc;fp=src%2Flib%2Fgscphftaaux%2FManku_HH.cc;h=24c3393d4716acd73a186f48f07c06ee7aabb849;hb=c9783d8ea8b85d810483559e50dbf2297109e349;hp=0000000000000000000000000000000000000000;hpb=2f2369dfc58997659b3007b1cea68ad6bfc49a90;p=com%2Fgs-lite.git diff --git a/src/lib/gscphftaaux/Manku_HH.cc b/src/lib/gscphftaaux/Manku_HH.cc new file mode 100644 index 0000000..24c3393 --- /dev/null +++ b/src/lib/gscphftaaux/Manku_HH.cc @@ -0,0 +1,73 @@ +/* ------------------------------------------------ + Copyright 2014 AT&T Intellectual Property + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ------------------------------------------- */ +//######################################### +// Stateful functions for Manku and Motwani +// heavy hitters algorithm +//######################################## + +#include +#define max(x,y) ((x)>(y)?(x):(y)) + +struct MankuHHstate { + unsigned int count; + unsigned int count_bucket; + unsigned int need_to_clean; +}; + +void _sfun_state_clean_init_manku_hh_state(void *s){ + struct MankuHHstate *state = (struct MankuHHstate *)s; + + state->count = 0; + state->count_bucket = 1; + state->need_to_clean = 0; + +} + +void _sfun_state_dirty_init_manku_hh_state(void *s_new, void *s_old, int curr_num_samples){ + struct MankuHHstate *state_new = (struct MankuHHstate *)s_new; + struct MankuHHstate *state_old = (struct MankuHHstate *)s_old; + + state_new->count = 0; + state_new->count_bucket = 1; +} + +void _sfun_state_final_init_manku_hh_state(void *s, int curr_num_samples){ + struct MankuHHstate *state = (struct MankuHHstate *)s; +} + +int local_count(void *s,int curr_num_samples, unsigned int bucket_size){ + struct MankuHHstate *state = (struct MankuHHstate *)s; + + state->count++; + if(state->count >= bucket_size){ + //cout << "bucket_size: " << bucket_size << "\n"; + state->count_bucket++; + state->need_to_clean = 1; + //cout << "bucket_count: " << state->count_bucket << "\n"; + //cout << "packet count: " << state->count << "\n"; + state->count = 0; + return 1; + } + return 0; +} + +unsigned int current_bucket(void *s, int curr_num_samples){ + struct MankuHHstate *state = (struct MankuHHstate *)s; + if(state->need_to_clean == 1){ + state->need_to_clean = 0; + return (state->count_bucket)-1; + } + return state->count_bucket; +}