Lines Matching refs:offset

39 bool ChunkStream::WriteData(size_t offset, void* buffer, size_t size) {
40 if (SIZE_MAX - size < offset)
43 if (data_.size() < offset + size)
44 data_.resize(offset + size);
46 memcpy(&data_[offset], buffer, size);
49 chunks_[offset] = size;
53 std::map<size_t, size_t>::iterator start = chunks_.upper_bound(offset);
55 --start; // start now points to the key equal or lower than offset.
56 if (start->first + start->second < offset)
59 std::map<size_t, size_t>::iterator end = chunks_.upper_bound(offset + size);
61 chunks_[offset] = size;
67 size_t new_offset = std::min<size_t>(start->first, offset);
69 std::max<size_t>(end->first + end->second, offset + size) - new_offset;
78 bool ChunkStream::ReadData(size_t offset, size_t size, void* buffer) const {
79 if (!IsRangeAvailable(offset, size))
82 memcpy(buffer, &data_[offset], size);
87 size_t offset, size_t size,
89 if (IsRangeAvailable(offset, size))
94 ranges->push_back(std::pair<size_t, size_t>(offset, size));
98 std::map<size_t, size_t>::const_iterator start = chunks_.upper_bound(offset);
100 --start; // start now points to the key equal or lower than offset.
101 if (start->first + start->second < offset)
105 chunks_.upper_bound(offset + size);
107 ranges->push_back(std::pair<size_t, size_t>(offset, size));
111 size_t cur_offset = offset;
124 if (cur_offset < offset + size)
126 offset + size - cur_offset));
131 bool ChunkStream::IsRangeAvailable(size_t offset, size_t size) const {
135 if (SIZE_MAX - size < offset)
138 std::map<size_t, size_t>::const_iterator it = chunks_.upper_bound(offset);
140 return false; // No chunks includes offset byte.
142 --it; // Now it starts equal or before offset.
143 return (it->first + it->second) >= (offset + size);
153 size_t ChunkStream::GetLastByteBefore(size_t offset) const {
156 std::map<size_t, size_t>::const_iterator it = chunks_.upper_bound(offset);
163 size_t ChunkStream::GetFirstByteAfter(size_t offset) const {
166 std::map<size_t, size_t>::const_iterator it = chunks_.upper_bound(offset);