public IDataContainer Read(BinaryReader reader)
        {
            int  count     = reader.ReadInt32();
            bool isOrdered = reader.ReadBoolean();

            var data = Locator.CreateDataContainer();
            var set  = (IOrderedSet <IData, IData>)data;

            if (!isOrdered)
            {
                for (int i = 0; i < count; i++)
                {
                    IData key    = keyPersist.Read(reader);
                    IData record = recordPersist.Read(reader);
                    set.Add(key, record);
                }
            }
            else
            {
                KeyValuePair <IData, IData>[] orderedArray = new KeyValuePair <IData, IData> [count];
                for (int i = 0; i < orderedArray.Length; i++)
                {
                    IData key    = keyPersist.Read(reader);
                    IData record = recordPersist.Read(reader);
                    orderedArray[i] = new KeyValuePair <IData, IData>(key, record);
                }

                set.AddOrdered(orderedArray, 0, orderedArray.Length);
            }

            return(data);
        }
Пример #2
0
        public IDataContainer Read(BinaryReader reader)
        {
            int  count     = (int)CountCompression.Deserialize(reader);
            bool isOrdered = reader.ReadBoolean();

            IData[] keys    = new IData[count];
            IData[] records = new IData[count];

            Action[] actions = new Action[2];
            byte[][] buffers = new byte[2][];

            for (int i = 0; i < buffers.Length; i++)
            {
                buffers[i] = reader.ReadBytes((int)CountCompression.Deserialize(reader));
            }

            actions[0] = () =>
            {
                using (MemoryStream ms = new MemoryStream(buffers[0]))
                    keyIndexerPersist.Load(new BinaryReader(ms), (idx, value) => { keys[idx] = value; }, count);
            };

            actions[1] = () =>
            {
                using (MemoryStream ms = new MemoryStream(buffers[1]))
                    recordIndexerPersist.Load(new BinaryReader(ms), (idx, value) => { records[idx] = value; }, count);
            };

            Parallel.Invoke(actions);

            var data = Locator.CreateDataContainer();
            var set  = (IOrderedSet <IData, IData>)data;

            if (!isOrdered)
            {
                for (int i = 0; i < count; i++)
                {
                    set.Add(keys[i], records[i]);
                }
            }
            else
            {
                KeyValuePair <IData, IData>[] orderedArray = new KeyValuePair <IData, IData> [count];
                for (int i = 0; i < orderedArray.Length; i++)
                {
                    orderedArray[i] = new KeyValuePair <IData, IData>(keys[i], records[i]);
                }

                set.AddOrdered(orderedArray, 0, orderedArray.Length);
            }

            return(data);
        }