//! \brief A class that assembles a series of excerpts from a byte stream (possibly out of order, //! possibly overlapping) into an in-order byte stream. classStreamReassembler { private: // Your code here -- add private members as necessary. std::set<SubString> _buffer{}; size_t _unassembled_bytes{0}; size_t _head_pos{0}; bool _is_eof{false}; ByteStream _output; //!< The reassembled in-order byte stream size_t _capacity; //!< The maximum number of bytes
voidStreamReassembler::merge_substring(SubString &ssd){ if (ssd._size == 0) return; do { // next auto iter = _buffer.lower_bound(ssd); std::optional<size_t> res{}; while (iter != _buffer.end() && (res = ssd.merge(*iter)) != std::nullopt) { _unassembled_bytes -= res.value(); _buffer.erase(iter); iter = _buffer.lower_bound(ssd); } // pre if (iter == _buffer.begin()) break; iter--;
while (iter != _buffer.end() && (res = ssd.merge(*iter)) != std::nullopt) { _unassembled_bytes -= res.value(); _buffer.erase(iter); iter = _buffer.lower_bound(ssd); if (iter == _buffer.begin()) break; iter--; } } while(false); _buffer.insert(ssd); }