Esempio n. 1
0
        public void Load(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException();
            }

            using (Stream stream = new FileStream(filename, FileMode.Open))
                using (BinaryReader br = new BinaryReader(stream))
                {
                    Capacity     = br.ReadInt64();
                    ErrorRate    = br.ReadSingle();
                    BitCount     = (ulong)br.ReadInt64();
                    NumHashFuncs = (uint)br.ReadInt32();
                    Algorithm    = br.ReadInt32();

                    hashBits = new BitStorage(BitCount, false);

                    hashBits.Load(br);
                }
        }
Esempio n. 2
0
        public BloomFilter(long capacity, float errorRate, ulong bitCount, uint numHashFuncs)
        {
            if (capacity <= 0)
            {
                throw new ArgumentOutOfRangeException("capacity", capacity, "capacity must be positive");
            }
            if (errorRate >= 1 || errorRate <= 0)
            {
                throw new ArgumentOutOfRangeException("errorRate", errorRate, "errorRate must be between 0 and 1");
            }

            Capacity     = capacity;
            ErrorRate    = errorRate;
            BitCount     = bitCount;
            NumHashFuncs = numHashFuncs;

            // different algorithms could be added in the future
            Algorithm = 0;

            hashBits = new BitStorage(bitCount);
        }