Example #1
0
        public String8Raw ReadRaw(ArraySelector selector)
        {
            if (selector.Equals(_currentRaw.Selector))
            {
                return(_currentRaw);
            }
            bool includesFirstString = (selector.StartIndexInclusive == 0);

            _currentRaw.Selector = selector;

            // Read the string positions
            _currentRaw.Positions = _positionsReader.Read(ArraySelector.All(Count).Slice((includesFirstString ? 0 : selector.StartIndexInclusive - 1), selector.EndIndexExclusive));
            if (_currentRaw.Positions.Selector.Indices != null)
            {
                throw new NotImplementedException("String8TypeProvider requires positions to be read contiguously.");
            }
            int[] positionArray = (int[])_currentRaw.Positions.Array;

            // Get the full byte range of all of the strings
            int firstStringStart = (includesFirstString ? 0 : positionArray[_currentRaw.Positions.Index(0)]);
            int lastStringEnd    = positionArray[_currentRaw.Positions.Index(_currentRaw.Positions.Count - 1)];

            // Read the raw string bytes
            _currentRaw.Bytes = _bytesReader.Read(ArraySelector.All(int.MaxValue).Slice(firstStringStart, lastStringEnd));
            if (_currentRaw.Bytes.Selector.Indices != null)
            {
                throw new NotImplementedException("String8TypeProvider requires positions to be read contiguously.");
            }

            return(_currentRaw);
        }
Example #2
0
        public XArray Read(ArraySelector selector)
        {
            if (selector.Indices != null)
            {
                throw new NotImplementedException();
            }

            // Return the previous xarray if re-requested
            if (selector.Equals(_currentSelector))
            {
                return(_currentArray);
            }

            // Allocate the result array
            Allocator.AllocateToSize(ref _array, selector.Count);

            // Read items in pages of 64k
            int byteStart = _bytesPerItem * selector.StartIndexInclusive;
            int byteEnd   = _bytesPerItem * selector.EndIndexExclusive;
            int bytesRead = 0;

            for (int currentByteIndex = byteStart; currentByteIndex < byteEnd; currentByteIndex += ReadPageSize)
            {
                int    currentByteEnd = Math.Min(byteEnd, currentByteIndex + ReadPageSize);
                XArray bytexarray     = _byteReader.Read(ArraySelector.All(int.MaxValue).Slice(currentByteIndex, currentByteEnd));
                Buffer.BlockCopy(bytexarray.Array, 0, _array, bytesRead, bytexarray.Count);
                bytesRead += currentByteEnd - currentByteIndex;
            }

            // Cache and return the current xarray
            _currentArray    = XArray.All(_array, selector.Count);
            _currentSelector = selector;
            return(_currentArray);
        }
        public XArray Read(ArraySelector selector)
        {
            if (selector.Equals(_currentSelector))
            {
                return(_currentArray);
            }

            _currentArray    = _converter(_innerReader.Read(selector));
            _currentSelector = selector;
            return(_currentArray);
        }
Example #4
0
        public XArray Read(ArraySelector selector)
        {
            if (selector.Indices != null)
            {
                return(ReadIndices(selector));
            }
            if (selector.Count == 0)
            {
                return(XArray.All(_resultArray, 0));
            }

            // Return previous xarray if re-requested
            if (selector.Equals(_currentSelector))
            {
                return(_currentArray);
            }

            Allocator.AllocateToSize(ref _resultArray, selector.Count);
            bool includesFirstString = (selector.StartIndexInclusive == 0);

            // Read the string positions and bytes
            ReadRaw(selector);

            // Update the String8 array to point to them
            byte[] textArray        = (byte[])_currentRaw.Bytes.Array;
            int[]  positionArray    = (int[])_currentRaw.Positions.Array;
            int    firstStringStart = (includesFirstString ? 0 : positionArray[_currentRaw.Positions.Index(0)]);
            int    positionOffset   = _currentRaw.Positions.Index((includesFirstString ? 0 : 1));
            int    textOffset       = firstStringStart - _currentRaw.Bytes.Index(0);

            int previousStringEnd = firstStringStart - textOffset;

            for (int i = 0; i < selector.Count; ++i)
            {
                int valueEnd = positionArray[i + positionOffset] - textOffset;
                _resultArray[i]   = new String8(textArray, previousStringEnd, valueEnd - previousStringEnd);
                previousStringEnd = valueEnd;
            }

            // Cache the xarray and return it
            _currentArray    = XArray.All(_resultArray, selector.Count);
            _currentSelector = selector;
            return(_currentArray);
        }
        public XArray Read(ArraySelector selector)
        {
            // Return the cached xarray if re-requested
            if (selector.Equals(_currentSelector))
            {
                return(_currentArray);
            }

            // Read the values themselves
            XArray values = _valueReader.Read(selector);

            // Read the null markers
            XArray nulls = _nullReader.Read(selector);

            // Cache and return the values and null markers together
            _currentArray    = XArray.All(values.Array, -1, (bool[])nulls.Array).Reselect(values.Selector);
            _currentSelector = selector;
            return(_currentArray);
        }