Beispiel #1
0
        public bool Equals(ScalableBloomFilter other)
        {
            if (this.R != other.R)
            {
                return(false);
            }
            if (this.Fp != other.Fp)
            {
                return(false);
            }
            if (this.P != other.P)
            {
                return(false);
            }
            if (this.Hint != other.Hint)
            {
                return(false);
            }
            if (!this.Filters.SequenceEqual(other.Filters))
            {
                return(false);
            }

            return(true);
        }
        public ScalableBloomFilter Deserialize(Stream stream)
        {
            using (var br = new BinaryReader(stream))
            {
                int dataFormatMajorVersion = br.ReadUInt16();
                int dataFormatMinorVersion = br.ReadUInt16();

                AssertDataVersionCanBeRead(dataFormatMajorVersion, dataFormatMinorVersion);

                double r    = br.ReadDouble();
                double fp   = br.ReadDouble();
                double p    = br.ReadDouble();
                uint   hint = br.ReadUInt32();

                int count  = br.ReadInt32();
                var stored = new List <PartitionedBloomState>();
                for (var i = 0; i < count; i++)
                {
                    stored.Add(ParitionedBloomSerializer.Deserialize(br));
                }


                var data = new ScalableBloomState
                {
                    Partitions = stored.ToArray(),
                    R          = r,
                    Fp         = fp,
                    P          = p,
                    Hint       = hint
                };

                var result = new ScalableBloomFilter(data);

                return(result);
            }
        }
        public void Serialize(Stream stream, ScalableBloomFilter filter)
        {
            using (var bw = new BinaryWriter(stream))
            {
                bw.Write(DataFormatMajorVersion);
                bw.Write(DataFormatMinorVersion);

                ScalableBloomState data = filter.GetState();

                bw.Write(data.R);
                bw.Write(data.Fp);
                bw.Write(data.P);
                bw.Write(data.Hint);

                bw.Write(data.Partitions.Length);

                foreach (var partition in data.Partitions)
                {
                    ParitionedBloomSerializer.Serialize(bw, partition);
                }

                bw.Flush();
            }
        }