Skip to content

Instantly share code, notes, and snippets.

@musoftware
Created May 20, 2017 21:20
Show Gist options
  • Save musoftware/642334853c7a244c95ac56e75794d822 to your computer and use it in GitHub Desktop.
Save musoftware/642334853c7a244c95ac56e75794d822 to your computer and use it in GitHub Desktop.
BigHashSet for x86
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