Exemplo n.º 1
0
 public BlockController(IServiceLocator serviceLocator)
 {
     this._serviceLocator  = serviceLocator;
     this._blockHelper     = serviceLocator.GetInstance <IBlockHelper>();
     this._blockSerializer = serviceLocator.GetInstance <IBlockSerializer>();
     this._pointController = serviceLocator.GetInstance <IPointController>();
 }
Exemplo n.º 2
0
        // Deserialize constructor
        internal Block(BinaryReader reader,
                       IBlockSerializer <T> valueSerializer,
                       int valueBytesCount,
                       int maxValues)
        {
            Depth = ReadDepth(reader);

            int count = reader.ReadInt32();

            if (count < 0 || count > maxValues)
            {
                throw new IOException();
            }

            int[] hashes = new int[count];
            for (int i = 0; i < count; ++i)
            {
                hashes[i] = reader.ReadInt32();
            }

            Records = new List <Record <T> >(count);
            for (int i = 0; i < count; ++i)
            {
                var value = valueSerializer.Deserialize(reader.ReadBytes(valueBytesCount));
                Records.Add(new Record <T>(hashes[i], value));
            }
        }
        public ExtendibleHashSet(string dataFilePath, IBlockSerializer <T> valueSerializer, int maxBlockValues,
                                 int maxSiblingMergeBlockValues, int maxTableDepth, int maxUnusedTableDepth)
        {
            if (maxBlockValues <= 0 ||
                maxSiblingMergeBlockValues < 0 ||
                maxTableDepth <= 0 ||
                maxUnusedTableDepth < 0)
            {
                throw new InvalidOperationException();
            }

            if (maxSiblingMergeBlockValues > maxBlockValues)
            {
                throw new InvalidOperationException();
            }
            // Create index stream now just to lock file.
            _indexFileStream = new FileStream
                               (
                dataFilePath + IndexFilePostfix,
                FileMode.Create,
                FileAccess.ReadWrite,
                FileShare.None
                               );

            _blockFileStream = new FileStream
                               (
                dataFilePath + BlockFilePostfix,
                FileMode.Create,
                FileAccess.ReadWrite,
                FileShare.None
                               );

            _blockStorage = new StreamBlockStorage <T>(
                _blockFileStream,
                valueSerializer,
                UpdateIndices,
                blocksCount: 0,
                maxBlockValues: maxBlockValues);

            _tableContext = new TableData <T>
                            (
                new BlockCollection <T>(_blockStorage),
                maxBlockValues: maxBlockValues,
                maxSiblingMergeBlockValues: maxSiblingMergeBlockValues,
                maxDepth: maxTableDepth,
                maxUnusedDepth: maxUnusedTableDepth
                            );
        }
Exemplo n.º 4
0
 public void SerializeTo(BinaryWriter writer,
                         IBlockSerializer <T> valueSerializer,
                         int valueBytesCount)
 {
     writer.Write(Depth);
     writer.Write(Records.Count);
     foreach (var hashedValue in Records)
     {
         writer.Write(hashedValue.Hash);
     }
     foreach (var hashedValue in Records)
     {
         var valueBytes = valueSerializer.Serialize(hashedValue.Data);
         if (valueBytes.Length != valueBytesCount)
         {
             throw new InvalidOperationException("Unexpected Data bytes count.");
         }
         writer.Write(valueBytes);
     }
 }
Exemplo n.º 5
0
        internal StreamBlockStorage(Stream stream,
                                    IBlockSerializer <T> valueSerializer,
                                    Action <int, int> updateIndices,
                                    int blocksCount,
                                    int maxBlockValues)
        {
            _stream          = stream;
            _valueSerializer = valueSerializer;
            _updateIndices   = updateIndices;
            _blocksCount     = blocksCount;
            _maxValues       = maxBlockValues;

            _reader = new BinaryReader(stream);
            _writer = new BinaryWriter(stream);

            _valueBytes = valueSerializer.BlockSize;
            _blockBytes = Block <T> .GetSerializedBytesCount(_valueBytes, maxBlockValues);

            if (stream.Length != (long)blocksCount * _blockBytes)
            {
                throw new IOException();
            }
        }
        /// <summary>
        /// Nacitanie dat o tabulkach a indexe zo suborov
        /// Deserializacny konstruktor
        /// </summary>
        /// <param name="dataFilePath"></param>
        /// <param name="valueSerializer"></param>
        public ExtendibleHashSet(
            string dataFilePath,
            IBlockSerializer <T> valueSerializer)
        {
            _indexFileStream = new FileStream
                               (
                dataFilePath + IndexFilePostfix,
                FileMode.Open,
                FileAccess.ReadWrite,
                FileShare.None
                               );

            _blockFileStream = new FileStream
                               (
                dataFilePath + BlockFilePostfix,
                FileMode.Open,
                FileAccess.ReadWrite,
                FileShare.None
                               );

            var indexReader = new BinaryReader(_indexFileStream);

            // Table context

            int maxBucketValues             = indexReader.ReadInt32();
            int maxSiblingMergeBucketValues = indexReader.ReadInt32();
            int maxTableDepth       = indexReader.ReadInt32();
            int maxUnusedTableDepth = indexReader.ReadInt32();

            if (maxBucketValues <= 0 ||
                maxSiblingMergeBucketValues < 0 ||
                maxTableDepth <= 0 ||
                maxUnusedTableDepth < 0)
            {
                throw new IOException();
            }

            if (maxSiblingMergeBucketValues > maxBucketValues)
            {
                throw new IOException();
            }

            // Block storage info

            int blocksCount = indexReader.ReadInt32();

            if (blocksCount < 0)
            {
                throw new IOException();
            }

            _blockStorage = new StreamBlockStorage <T>(
                _blockFileStream,
                valueSerializer,
                UpdateIndices,
                blocksCount: blocksCount,
                maxBlockValues: maxBucketValues);

            // Block collection

            var blockCollection = new BlockCollection <T>(_blockStorage, indexReader);

            // Tables

            _tableContext = new TableData <T>
                            (
                blockCollection,
                maxBlockValues: maxBucketValues,
                maxSiblingMergeBlockValues: maxSiblingMergeBucketValues,
                maxDepth: maxTableDepth,
                maxUnusedDepth: maxUnusedTableDepth
                            );

            int tablesCount = indexReader.ReadInt32();

            if (tablesCount < 0)
            {
                throw new IOException();
            }

            if (tablesCount == 0 ? blocksCount > 0 : blocksCount == 0)
            {
                throw new IOException();
            }

            for (int i = 0; i < tablesCount; ++i)
            {
                _tables.Add(new Table <T>(indexReader, _tableContext, blocksCount));
            }
        }