Пример #1
0
        public IReadOnlyList <IRow> GetRows(IEnumerable <int> rowIndex)
        {
            // split the queries into blocks
            int temp;
            Dictionary <int, int> temp2;
            var blockMatch = new Dictionary <int, Dictionary <int, int> >();

            foreach (var row in rowIndex.OrderBy(r => r))
            {
                var block = row / BLOCK_SIZE;
                if (!blockMatch.TryGetValue(block, out temp2))
                {
                    blockMatch.Add(block, temp2 = new Dictionary <int, int>());
                }
                if (temp2.TryGetValue(row, out temp))
                {
                    temp2[row] = temp + 1;
                }
                else
                {
                    temp2.Add(row, 1);
                }
            }

            var ret = new List <IRow>();

            lock (_mutex) {
                var reader = new BinaryReader(_stream, Encoding.UTF8, true);
                foreach (var block in blockMatch.OrderBy(b => b.Key))
                {
                    _stream.Seek(_index[block.Key], SeekOrigin.Begin);
                    var match = block.Value;

                    for (int i = block.Key * BLOCK_SIZE, len = i + BLOCK_SIZE; i < len && _stream.Position < _stream.Length; i++)
                    {
                        if (match.TryGetValue(i, out temp))
                        {
                            var row = new DataTableRow(this, _ReadRow(reader), _rowConverter);
                            for (var j = 0; j < temp; j++)
                            {
                                ret.Add(row);
                            }
                        }
                        else
                        {
                            _SkipRow(reader);
                        }
                    }
                }
            }
            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Adds a new row
        /// </summary>
        /// <param name="data">The data in the row</param>
        public IRow AddRow(IEnumerable <object> data)
        {
            var row = new DataTableRow(this, data.ToArray(), _rowConverter);

            _data.Add(row);

            var data2 = row.Data;

            for (int i = 0, len = data2.Count; i < len && i < _column.Count; i++)
            {
                _column[i].Add(data2[i]);
            }
            return(row);
        }
Пример #3
0
 protected void _Iterate(Func <DataTableRow, bool> callback)
 {
     lock (_mutex) {
         _stream.Seek(_dataOffset, SeekOrigin.Begin);
         var reader = new BinaryReader(_stream, Encoding.UTF8, true);
         while (_stream.Position < _stream.Length)
         {
             var row = new DataTableRow(this, _ReadRow(reader), _rowConverter);
             if (!callback(row))
             {
                 break;
             }
         }
     }
 }