6 #ifndef TURI_SARRAY_READER_BUFFER 7 #define TURI_SARRAY_READER_BUFFER 10 #include <core/storage/sframe_data/sframe_constants.hpp> 46 class sarray_reader_buffer {
50 sarray_reader_buffer() =
default;
55 size_t row_start,
size_t row_end,
57 init(reader, row_start, row_end, buffer_size);
65 size_t row_start,
size_t row_end,
68 m_reader_weak = m_reader.get();
71 m_original_row_start = row_start;
72 m_row_start = row_start;
73 m_row_end = std::min(row_end, m_reader_weak->
size());
74 m_buffer_size = internal_buffer_size;
88 size_t row_start,
size_t row_end,
90 m_reader_weak = reader_weak;
93 m_original_row_start = row_start;
94 m_row_start = row_start;
95 m_row_end = std::min(row_end, m_reader_weak->
size());
96 m_buffer_size = internal_buffer_size;
107 inline std::vector<value_type>&
get_buffer() {
return m_buffer;}
110 inline size_t size() {
return m_row_end - m_original_row_start;}
124 std::vector<value_type> m_buffer;
127 std::shared_ptr<reader_type> m_reader;
128 reader_type* m_reader_weak =
nullptr;
131 size_t m_buffer_pos = 0;
133 size_t m_original_row_start = 0;
135 size_t m_row_start = 0;
137 size_t m_row_end = 0;
139 size_t m_buffer_size = 0;
147 if (m_buffer_pos == m_buffer.size()) {
151 DASSERT_LT(m_buffer_pos, m_buffer.size());
153 return std::move(m_buffer[m_buffer_pos++]);
161 return m_iter < m_row_end;
167 size_t size_of_refill = std::min<size_t>(m_row_end - m_row_start, m_buffer_size);
168 m_reader_weak->
read_rows(m_row_start, m_row_start + size_of_refill, m_buffer);
169 m_row_start += size_of_refill;
176 m_row_start = m_original_row_start;
177 m_iter = m_original_row_start;
void init(std::shared_ptr< typename sarray< T >::reader_type > &reader, size_t row_start, size_t row_end, size_t internal_buffer_size=DEFAULT_SARRAY_READER_BUFFER_SIZE)
std::vector< value_type > & get_buffer()
Return the buffer.
void init(typename sarray< T >::reader_type *reader_weak, size_t row_start, size_t row_end, size_t internal_buffer_size=DEFAULT_SARRAY_READER_BUFFER_SIZE)
value_type && next()
Return the next element in the reader.
bool has_next()
Return true if the reader has more element.
sarray_reader_buffer(std::shared_ptr< typename sarray< T >::reader_type > reader, size_t row_start, size_t row_end, size_t buffer_size=DEFAULT_SARRAY_READER_BUFFER_SIZE)
Construct from sarray reader with begin and end row.
const size_t DEFAULT_SARRAY_READER_BUFFER_SIZE
size_t read_rows(size_t row_start, size_t row_end, std::vector< T > &out_obj)
size_t size()
Return the Number of elements between row_start and row_end.