Skip to content

Commit

Permalink
Introduce til::rle - a run length encoded vector
Browse files Browse the repository at this point in the history
## Summary of the Pull Request

Introduces `til::rle`, a vector-like container which stores elements of
type T in a run length encoded format. This allows efficient compaction
of repeated elements within the vector.

## References

* #8000 - Supports buffer rewrite work. A re-use of `til::rle` will be
  useful as a column counter as we pursue NxM storage and presentation.
* #3075 - The new iterators allow skipping forward by multiple units,
  which wasn't possible under `TextBuffer-/OutputCellIterator`.
  Additionally it also allows a bulk insertions.
* #8787 and #410 - High probability this should be `pmr`-ified
  like `bitmap` for things like `chafa` and `cacafire`
  which are changing the run length frequently.

## PR Checklist

* [x] Closes #8741
* [x] I work here.
* [x] Tests added.
* [x] Tests passed.

## Validation Steps Performed

* [x] Ran `cacafire` in `OpenConsole.exe` and it looked beautiful
* [x] Ran new suite of `RunLengthEncodingTests.cpp`

Co-authored-by: Michael Niksa <miniksa@microsoft.com>
  • Loading branch information
lhecker and miniksa committed May 14, 2021
1 parent bbe8275 commit 4b0eeef
Show file tree
Hide file tree
Showing 25 changed files with 1,763 additions and 1,686 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/allow/allow.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Apc
apc
clickable
copyable
dalet
Dcs
dcs
Expand Down
565 changes: 30 additions & 535 deletions src/buffer/out/AttrRow.cpp

Large diffs are not rendered by default.

43 changes: 13 additions & 30 deletions src/buffer/out/AttrRow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ Revision History:

#pragma once

#include "TextAttributeRun.hpp"
#include "AttrRowIterator.hpp"
#include "til/rle.h"
#include "TextAttribute.hpp"

class ATTR_ROW final
{
using rle_vector = til::small_rle<TextAttribute, uint16_t, 1>;

public:
using const_iterator = typename AttrRowIterator;
using const_iterator = rle_vector::const_iterator;

ATTR_ROW(const UINT cchRowWidth, const TextAttribute attr)
noexcept;
ATTR_ROW(uint16_t width, TextAttribute attr);

~ATTR_ROW() = default;

Expand All @@ -39,28 +40,13 @@ class ATTR_ROW final
noexcept = default;
ATTR_ROW& operator=(ATTR_ROW&&) noexcept = default;

TextAttribute GetAttrByColumn(const size_t column) const;
TextAttribute GetAttrByColumn(const size_t column,
size_t* const pApplies) const;

size_t GetNumberOfRuns() const noexcept;

size_t FindAttrIndex(const size_t index,
size_t* const pApplies) const;

std::vector<uint16_t> GetHyperlinks();

bool SetAttrToEnd(const UINT iStart, const TextAttribute attr);
void ReplaceAttrs(const TextAttribute& toBeReplacedAttr, const TextAttribute& replaceWith) noexcept;

void Resize(const size_t newWidth);

[[nodiscard]] HRESULT InsertAttrRuns(const gsl::span<const TextAttributeRun> newAttrs,
const size_t iStart,
const size_t iEnd,
const size_t cBufferWidth);
TextAttribute GetAttrByColumn(uint16_t column) const;
std::vector<uint16_t> GetHyperlinks() const;

static std::vector<TextAttributeRun> PackAttrs(const std::vector<TextAttribute>& attrs);
bool SetAttrToEnd(uint16_t beginIndex, TextAttribute attr);
void ReplaceAttrs(const TextAttribute& toBeReplacedAttr, const TextAttribute& replaceWith);
void Resize(uint16_t newWidth);
void Replace(uint16_t beginIndex, uint16_t endIndex, const TextAttribute& newAttr);

const_iterator begin() const noexcept;
const_iterator end() const noexcept;
Expand All @@ -69,17 +55,14 @@ class ATTR_ROW final
const_iterator cend() const noexcept;

friend bool operator==(const ATTR_ROW& a, const ATTR_ROW& b) noexcept;
friend class AttrRowIterator;
friend class ROW;

private:
void Reset(const TextAttribute attr);

boost::container::small_vector<TextAttributeRun, 1> _list;
size_t _cchRowWidth;
rle_vector _data;

#ifdef UNIT_TESTING
friend class AttrRowTests;
friend class CommonState;
#endif
};
136 changes: 0 additions & 136 deletions src/buffer/out/AttrRowIterator.cpp

This file was deleted.

80 changes: 0 additions & 80 deletions src/buffer/out/AttrRowIterator.hpp

This file was deleted.

Loading

0 comments on commit 4b0eeef

Please sign in to comment.