BitsetsNET.RoaringArray.Deserialize C# (CSharp) Method

Deserialize() public static method

Deserialize a roaring array from a binary format, as written by the Serialize method.
public static Deserialize ( BinaryReader reader ) : RoaringArray
reader BinaryReader The reader from which to deserialize the roaring array.
return RoaringArray
        public static RoaringArray Deserialize(BinaryReader reader)
        {
            int size = reader.ReadInt32();
            RoaringArray array = new RoaringArray(size);
            array.Size = size;

            for(int i = 0; i < size; i++)
            {
                array.keys[i] = (ushort) reader.ReadInt16();
                array.values[i] = Container.Deserialize(reader);
            }

            return array;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Read a binary serialization of a roaring bitset, as written by the Serialize method.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        /// <returns>The bitset deserialized from the stream.</returns>
        public static RoaringBitset Deserialize(Stream stream)
        {
            RoaringBitset bitset = new RoaringBitset();

            //We don't care about the encoding, but we have to specify something to be able to set the stream as leave open.
            using (BinaryReader reader = new BinaryReader(stream, Encoding.Default, true))
            {
                bitset.containers = RoaringArray.Deserialize(reader);
            }

            return(bitset);
        }