Created
May 20, 2017 21:20
-
-
Save musoftware/642334853c7a244c95ac56e75794d822 to your computer and use it in GitHub Desktop.
BigHashSet for x86
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BigHashSet<T> | |
{ | |
int count = 0; | |
private List<HashSet<T>> hashes = new List<HashSet<T>>(); | |
public void Add(T item) | |
{ | |
int pos = count / 10000000; | |
if (pos >= hashes.Count) | |
{ | |
hashes.Add(new HashSet<T>()); | |
} | |
for (int i = 0; i < pos; i++) | |
{ | |
if (hashes[i].Contains(item)) | |
{ | |
return; | |
} | |
} | |
if (hashes[pos].Add(item)) | |
{ | |
count++; | |
} | |
} | |
public long Count() | |
{ | |
long res = 0; | |
foreach (var item in hashes) | |
{ | |
res += item.Count; | |
} | |
return res; | |
} | |
public void ToFile(string filename, Encoding encoding) | |
{ | |
File.WriteAllText(filename, "", encoding); | |
foreach (var item in hashes) | |
{ | |
File.AppendAllLines(filename, item.Cast<string>(), encoding); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment