-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountSketch.cs
More file actions
59 lines (49 loc) · 1.98 KB
/
CountSketch.cs
File metadata and controls
59 lines (49 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Numerics;
using System.Collections.Generic;
using System.Diagnostics;
namespace Hash {
public static class CountSketchFunctions{
public static Stopwatch stoperh = new Stopwatch();
public static Stopwatch stopers = new Stopwatch();
public static Stopwatch stoperC = new Stopwatch();
public static BigInteger[] CountSketch(Func<ulong,ulong> h,Func<ulong,sbyte> s,
IEnumerable <Tuple<ulong, int>> stream,
ulong m){
BigInteger[] sketchC = new BigInteger[m];
// proccesing val in stream
foreach (Tuple<ulong,int> tuple in stream) {
var x = tuple.Item1;
var d = tuple.Item2;
stoperh.Start();
var hofx = h(x);
stoperh.Stop();
stopers.Start();
var sofx = s(x);
stopers.Stop();
stoperC.Start();
sketchC[hofx] +=(d*sofx);
stoperC.Stop();
}
return sketchC;
}
// public static BigInteger[] CountSketch(Func<ulong,ulong> h,Func<ulong,sbyte> s,
// IEnumerable <Tuple<ulong, int>> stream,
// ulong m){
// BigInteger[] sketchC = new BigInteger[m];
// // proccesing val in stream
// foreach (Tuple<ulong,int> tuple in stream) {
// sketchC[h(tuple.Item1)] +=(tuple.Item2*s(tuple.Item1));
// }
// return sketchC;
// }
public static BigInteger QuadSumOfSketch(BigInteger[] C){
BigInteger quadSum = new BigInteger(0);
int table_size = C.Length;
for (int i=0; i<table_size; i++) {
quadSum = quadSum + (C[i]*C[i]);
}
return quadSum;
}
}
}