Turi Create  4.0
turi::sarray_reader_buffer< T > Class Template Reference

#include <core/storage/sframe_data/sarray_reader_buffer.hpp>

Public Member Functions

 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.
 
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)
 
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. More...
 
bool has_next ()
 Return true if the reader has more element. More...
 
std::vector< value_type > & get_buffer ()
 Return the buffer.
 
size_t size ()
 Return the Number of elements between row_start and row_end.
 
void clear ()
 

Detailed Description

template<typename T>
class turi::sarray_reader_buffer< T >

A buffered reader reading from a range of an sarray<T>.

sarray<flexible_type> mysarray = ...;
// Reader for the first thousand lines
sarray_reader_buffer<flexible_type> reader(mysarray, 0, 1000);
while(reader.has_next()) {
flexible_type val = reader.next();
... do some thing with val ...
}
// Reader for the entire sarray
reader = sarray_reader_buffer<flexible_type>(mysarray, 0, (size_t)(-1));
...

Internally, the reader maintains a vector as buffer, and when reading reaches the end of the buffer, refill the buffer by reading from sarray.

Definition at line 36 of file gl_sarray.hpp.

Member Function Documentation

◆ clear()

template<typename T >
void turi::sarray_reader_buffer< T >::clear ( )

Resets the buffer to the initial starting conditions. Reading from the buffer again will start from row_start.

Definition at line 174 of file sarray_reader_buffer.hpp.

◆ has_next()

template<typename T >
bool turi::sarray_reader_buffer< T >::has_next ( )

Return true if the reader has more element.

Return true if the chunk has remaining element.

Definition at line 160 of file sarray_reader_buffer.hpp.

◆ init() [1/2]

template<typename T>
void turi::sarray_reader_buffer< T >::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 
)
inline

Construction of a reader_buffer where the reader_buffer owns a reference to the underlying reader.

Definition at line 64 of file sarray_reader_buffer.hpp.

◆ init() [2/2]

template<typename T>
void turi::sarray_reader_buffer< T >::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 
)
inline

Construction of a reader_buffer where the reader_buffer DOES NOT own a reference to the underlying reader.

Note
This is quite unsafe to use since its not even a weak_ptr but a raw pointer. The user has to be careful to ensure that the sarray_reader's lifespan exceeds that of the reader_buffer. This is provided only to support a circular case where the sarray_reader itself uses sarray_reader_buffer for buffering.

Definition at line 87 of file sarray_reader_buffer.hpp.


The documentation for this class was generated from the following files: