Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the new .peek_back() function in TPIE #374

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/adiar/file_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ namespace adiar
}

private:
bool _has_peeked = false;
T _peeked;
bool _negate = false;

typename tpie::file_stream<T> _stream;
Expand Down Expand Up @@ -100,20 +98,15 @@ namespace adiar
////////////////////////////////////////////////////////////////////////////
bool can_pull()
{
return _has_peeked
|| (REVERSE ? _stream.can_read_back() : _stream.can_read());
return REVERSE ? _stream.can_read_back() : _stream.can_read();
}

////////////////////////////////////////////////////////////////////////////
/// \brief Obtain the next element (and move the read head)
////////////////////////////////////////////////////////////////////////////
const T pull()
{
if (_has_peeked) {
_has_peeked = false;
return _peeked;
}
T t = REVERSE ? _stream.read_back() : _stream.read();
const T t = REVERSE ? _stream.read_back() : _stream.read();
return _negate ? !t : t;
}

Expand All @@ -122,11 +115,8 @@ namespace adiar
////////////////////////////////////////////////////////////////////////////
const T peek()
{
if (!_has_peeked) {
_peeked = pull();
_has_peeked = true;
}
return _peeked;
const T t = REVERSE ? _stream.peek_back() : _stream.peek();
return _negate ? !t : t;
}

////////////////////////////////////////////////////////////////////////////
Expand Down