diff --git a/HeavyKeeper/heavykeeper.cpp b/HeavyKeeper/heavykeeper.cpp new file mode 100644 index 0000000..2e4622b --- /dev/null +++ b/HeavyKeeper/heavykeeper.cpp @@ -0,0 +1,98 @@ +#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/heavykeeper.h" +using namespace std; + heavykeeper::heavykeeper(int M2,int K):M2(M2),K(K) {ss=new ssummary(K); ss->clear(); bobhash=new BOBHash64(1005);} + void heavykeeper::clear() + { + for (int i=0; irun(ST.c_str(),ST.size())); + } + void heavykeeper::Insert(string x) + { + bool mon=false; + int p=ss->find(x); + if (p) mon=true; + int maxv=0; + unsigned long long H=Hash(x); int FP=(H>>48); + for (int j=0; jgetmin()) + HK[j][Hsh].C++; + maxv=max(maxv,HK[j][Hsh].C); + } else + { + if (!(rand()%int(pow(HK_b,HK[j][Hsh].C)))) + { + HK[j][Hsh].C--; + if (HK[j][Hsh].C<=0) + { + HK[j][Hsh].FP=FP; + HK[j][Hsh].C=1; + maxv=max(maxv,1); + } + } + } + } + if (!mon) + { + if (maxv-(ss->getmin())==1 || ss->totgetid(); + ss->add2(ss->location(x),i); + ss->str[i]=x; + ss->sum[i]=maxv; + ss->link(i,0); + while(ss->tot>K) + { + int t=ss->Right[0]; + int tmp=ss->head[t]; + ss->cut(ss->head[t]); + ss->recycling(tmp); + } + } + } else + if (maxv>ss->sum[p]) + { + int tmp=ss->Left[ss->sum[p]]; + ss->cut(p); + if(ss->head[ss->sum[p]]) tmp=ss->sum[p]; + ss->sum[p]=maxv; + ss->link(p,tmp); + } + } + + void heavykeeper::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 heavykeeper::Query(int k) + { + return make_pair(q[k].x,q[k].y); + } + + + // heavykeeper::~heavykeeper() + // { + + // } \ No newline at end of file