Occupancy() public method

public Occupancy ( ) : float
return float
Exemplo n.º 1
0
    public static int Main()
    {
        var hashes = new IStringHash[] { new StandardHash (),
                     new MurmurHash2Simple (),
                     new SuperFastHashSimple (),
                     /*
                     new CryptographicHash (MD5.Create ()),
                     new CryptographicHash (SHA1.Create ()),
                     new CryptographicHash (RIPEMD160Managed.Create ()),
                     new CryptographicHash (MACTripleDES.Create ())
                     */ };
        var bloom = new BloomFilter (1000003, hashes);
        var positive = new List<string> ();
        var negative = new List<string> ();
        var toggle = true;
        foreach (var line in File.ReadAllLines ("/usr/share/dict/words"))
        {
        var l = line.Trim ();
        if (toggle)
        {
        positive.Add (l);
        bloom.Add (l);
        }
        else
        {
        negative.Add (l);
        }
        toggle = !toggle;
        }

        Console.WriteLine ("occupancy for " + positive.Count + " words: " + bloom.Occupancy ());

        foreach (var line in positive)
        {
        if (!bloom.Lookup (line))
        {
        Console.WriteLine ("error!");
        return 1;
        }
        }

        int false_positives = 0;
        foreach (var line in negative)
        {
        if (bloom.Lookup (line))
        ++false_positives;
        }

        Console.WriteLine ("false positives: " + ((float)false_positives / negative.Count));

        return 0;
    }