diff --git a/HeavyKeeper/LossyCounting.cpp b/HeavyKeeper/LossyCounting.cpp new file mode 100644 index 0000000..24143f3 --- /dev/null +++ b/HeavyKeeper/LossyCounting.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +#include +#include "../init/BOBHash32.h" +#include "../init/BOBHash64.h" +#include "../init/params.h" +#include "../init/ssummary.h" +#include "../include/LossyCounting.h" +using namespace std; + LossyCounting::LossyCounting(int K):K(K) {ss=new ssummary(0); ss->clear();} + + + void LossyCounting::Insert(string x,int c) + { + bool mon=false; + int p=ss->find(x); + if (p) mon=true; + if (!mon) + { + int q=c+1; + int i=ss->getid(); + ss->add2(ss->location(x),i); + ss->str[i]=x; + ss->sum[i]=q; + ss->link(i,0); + } else + { + int tmp=ss->Left[ss->sum[p]]; + ss->cut(p); + if(ss->head[ss->sum[p]])tmp=ss->sum[p]; + ss->sum[p]++; + ss->link(p,tmp); + } + } + void LossyCounting::clear(int c) + { + while (ss->getmin()Right[0]; + int tmp=ss->head[t]; + ss->cut(ss->head[t]); + ss->recycling(tmp); + } + } + + void LossyCounting::work() + { + int CNT=0; + for(int i=N;i;i=ss->Left[i]) + for(int j=ss->head[i];j;j=ss->Next[j]) {q[CNT].x=ss->str[j]; q[CNT].y=ss->sum[j]; CNT++; } + sort(q,q+CNT,cmp); + } + pair LossyCounting::Query(int k) + { + return make_pair(q[k].x,q[k].y); + } + + + // LossyCounting::~LossyCounting() + //{ + + // } \ No newline at end of file