Esempio n. 1
0
        /// <summary>
        /// Gets a block from the cache at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the block.</param>
        /// <returns>The cached sequence block.</returns>
        private CacheBox <byte[]> GetCacheBlock(int index)
        {
            CacheBox <byte[]> block = _virtualData.FirstOrDefault(C => index >= C.StartRange && index <= C.EndRange);

            if (block != null)
            {
                return(block);
            }
            else
            {
                int    startIndex = index - (index % BlockSize);
                byte[] seq        = _parser.ParseRange(startIndex, BlockSize, SequencePointerInstance);

                if (seq == null)
                {
                    return(null);
                }
                else
                {
                    block = new CacheBox <byte[]>(seq.Length)
                    {
                        StartRange = startIndex
                    };
                    block.EndRange = block.StartRange + seq.Length - 1;
                    block.Data     = seq;

                    _virtualData.Add(block);
                    return(block);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a block from the cache at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the block.</param>
        /// <returns>The cached sequence block.</returns>
        private CacheBox <byte[]> GetCacheBlock(int index)
        {
            CacheBox <byte[]> block = _virtualData.FirstOrDefault(C => index >= C.StartRange && index <= C.EndRange);

            if (block != null)
            {
                return(block);
            }
            else
            {
                int startIndex         = index;
                int blockStartingIndex = index - (index % BlockSize);
                int sequenceLength     = (int)(SequencePointerInstance.IndexOffsets[1] - SequencePointerInstance.IndexOffsets[0]);
                int count = sequenceLength > BlockSize ? BlockSize : sequenceLength;

                if (sequenceLength > BlockSize && _sidecarProvider != null)
                {
                    blockStartingIndex = _sidecarProvider.GetBlockToLoad(_sequenceIndex, index, ref startIndex, ref count);
                }
                else
                {
                    blockStartingIndex = 0;
                    startIndex         = 0;
                }

                byte[] seq = _parser.ParseRange(blockStartingIndex, count, SequencePointerInstance);

                if (seq == null)
                {
                    return(null);
                }
                else
                {
                    block = new CacheBox <byte[]>(seq.Length)
                    {
                        StartRange = startIndex
                    };
                    block.EndRange = block.StartRange + seq.Length - 1;
                    block.Data     = seq;

                    _virtualData.Add(block);
                    return(block);
                }
            }
        }