mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:27:35 +00:00
AK: Move parts for searching CircularBuffer into a new class
We will be adding extra logic to the CircularBuffer to optimize searching, but this would negatively impact the performance of CircularBuffer users that don't need that functionality.
This commit is contained in:
parent
40c0dd67dd
commit
9e82ad758e
6 changed files with 50 additions and 16 deletions
|
@ -35,15 +35,6 @@ 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;
|
||||
|
@ -53,7 +44,7 @@ public:
|
|||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
protected:
|
||||
CircularBuffer(ByteBuffer);
|
||||
|
||||
[[nodiscard]] bool is_wrapping_around() const;
|
||||
|
@ -69,4 +60,22 @@ private:
|
|||
size_t m_seekback_limit {};
|
||||
};
|
||||
|
||||
class SearchableCircularBuffer : public CircularBuffer {
|
||||
public:
|
||||
static ErrorOr<SearchableCircularBuffer> create_empty(size_t size);
|
||||
static ErrorOr<SearchableCircularBuffer> create_initialized(ByteBuffer);
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
SearchableCircularBuffer(ByteBuffer);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue