Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constructors to the main objects that can accept a HashAlgorithm #1

Open
mattlorimor opened this issue Dec 14, 2015 · 1 comment

Comments

@mattlorimor
Copy link
Owner

It would be nice if the all the main objects that have a HashAlgorithm set could have that algorithm set at instantiation-time rather than an extra call to SetHash()

@dferreyra
Copy link
Contributor

Hi @mattlorimor, are you still interested in this change? If so, I could give it a shot, but I would have some questions.

Would you be okay with leaving the existing constructors, and adding new constructors that include the hash as the last argument? For BloomFilter, that would look something like this:

public BloomFilter(uint n, double fpRate) :
    this(n, fpRate, Defaults.GetDefaultHashAlgorithm())
{
}

public BloomFilter(uint n, double fpRate, HashAlgorithm hash)
{
    var m = Utils.OptimalM(n, fpRate);
    var k = Utils.OptimalK(fpRate);
    Buckets = new Buckets(m, 1);
    this.Hash = hash;
    this.m = m;
    this.k = k;
}

Another option would be to have one constructor, but make the hash default to null and have null mean "default"; e.g.,

public BloomFilter(uint n, double fpRate, HashAlgorithm hash = null)
{
    var m = Utils.OptimalM(n, fpRate);
    var k = Utils.OptimalK(fpRate);
    Buckets = new Buckets(m, 1);
    this.Hash = hash ?? Defaults.GetDefaultHashAlgorithm();
    this.m = m;
    this.k = k;
}

My personal preference would be for the two constructor approach, but either way is fine.

Would you be okay with actually removing the SetHash() functions entirely? That would be my vote. If you wanted to keep the SetHash() methods, I would suggest that we change them to throw an exception if any data has already been added to the collection, since changing the hash function at that time must be a mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants