Example #1
0
 internal ScalableBloomFilter(ScalableBloomState state)
 {
     this.Filters = state.Partitions.Select(x => new PartitionedBloomFilter(x)).ToList();
     this.R       = state.R;
     this.Fp      = state.Fp;
     this.P       = state.P;
     this.Hint    = state.Hint;
 }
        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 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();
            }
        }