summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhang zhihao <[email protected]>2022-11-13 11:00:25 +0000
committerzhang zhihao <[email protected]>2022-11-13 11:00:25 +0000
commit48e5db5deb162884e803a97a95cda261e937e79a (patch)
tree44132b63b3fa37f034d8ea8360366036c8e2841d
parent9747f39c56da8e8b5d887fc35bcf28cd4d9e78cb (diff)
Upload New File
-rw-r--r--HeavyKeeper/LossyCounting.cpp66
1 files changed, 66 insertions, 0 deletions
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 <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <iostream>
+#include <algorithm>
+#include <string>
+#include <cstring>
+#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()<c)
+ {
+ int t=ss->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<string ,int> LossyCounting::Query(int k)
+ {
+ return make_pair(q[k].x,q[k].y);
+ }
+
+
+ // LossyCounting::~LossyCounting()
+ //{
+
+ // } \ No newline at end of file