-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.cs
More file actions
51 lines (48 loc) · 1.79 KB
/
stream.cs
File metadata and controls
51 lines (48 loc) · 1.79 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
using System;
using System.Numerics;
using System.Collections.Generic;
using Hash;
namespace Hash {
public static class Stream{
//Wrap-function to make use of stream easier
public static List<Tuple<ulong, int>> CreateStreamWrap( int n , int l ) {
IEnumerable <Tuple<ulong, int>> stream = CreateStream(n,l);
List<Tuple<ulong,int>> retLst = new List<Tuple<ulong, int>>();
var e = stream.GetEnumerator();
while (e.MoveNext()) {
retLst.Add(e.Current);
}
return retLst;
}
// Copy-paste fun from project describtion
public static IEnumerable <Tuple<ulong, int>> CreateStream( int n , int l ) {
// We generate a random uint64 number .
Random rnd = new System.Random () ;
ulong a = 0UL ;
Byte [] b = new Byte [8];
rnd . NextBytes ( b ) ;
for( int i = 0; i < 8; ++ i ) {
a = ( a << 8) + ( ulong ) b [ i ];
}
// We demand that our random number has 30 zeros on the least
// significant bits and then a one.
a = ( a | ((1UL << 31) - 1UL ) ) ^ ((1UL << 30) - 1UL ) ;
ulong x = 0UL ;
for( int i = 0; i < n /3; ++ i ) {
x = x + a ;
yield return Tuple . Create ( x & (((1UL << l ) - 1UL ) <<
30) , 1) ;
}
for( int i = 0; i < ( n + 1) /3; ++ i ) {
x = x + a ;
yield return Tuple . Create ( x & (((1UL << l ) - 1UL ) <<
30) , -1) ;
}
for( int i = 0; i < ( n + 2) /3; ++ i ) {
x = x + a ;
yield return Tuple . Create ( x & (((1UL << l ) - 1UL ) <<
30) , 1) ;
}
}
}
}