mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:57:35 +00:00
AK: Add CircularBuffer::find_copy_in_seekback()
This is useful for compressors, which quite frequently need to find a matching span of data within the seekback.
This commit is contained in:
parent
d194011570
commit
221b91ff61
3 changed files with 223 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Error.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
@ -36,6 +37,15 @@ public:
|
|||
|
||||
ErrorOr<size_t> copy_from_seekback(size_t distance, size_t length);
|
||||
|
||||
struct Match {
|
||||
size_t distance;
|
||||
size_t length;
|
||||
};
|
||||
/// This searches the seekback buffer (between read head and limit) for occurrences where it matches the next `length` bytes from the read buffer.
|
||||
/// Supplying any hints will only consider those distances, in case existing offsets need to be validated.
|
||||
/// Note that, since we only start searching at the read head, the length between read head and write head is excluded from the distance.
|
||||
ErrorOr<Vector<Match>> find_copy_in_seekback(size_t maximum_length, size_t minimum_length = 2, Optional<Vector<size_t> const&> distance_hints = {}) const;
|
||||
|
||||
[[nodiscard]] size_t empty_space() const;
|
||||
[[nodiscard]] size_t used_space() const;
|
||||
[[nodiscard]] size_t capacity() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue