Handful of PR feedback.

This commit is contained in:
Michael Niksa 2021-03-25 12:25:26 -07:00
parent cdc5a6a747
commit 60ef914956
4 changed files with 38 additions and 11 deletions

View file

@ -24,10 +24,10 @@ Revision History:
#include "TextAttributeRun.hpp"
class ATTR_ROW final : public til::rle<TextAttribute, UINT>
class ATTR_ROW final : public til::rle<TextAttribute, unsigned int>
{
public:
using mybase = til::rle<TextAttribute, UINT>;
using mybase = til::rle<TextAttribute, unsigned int>;
using const_iterator = mybase::const_iterator;
using const_reverse_iterator = mybase::const_reverse_iterator;
@ -40,7 +40,7 @@ public:
std::vector<uint16_t> GetHyperlinks();
bool SetAttrToEnd(const UINT iStart, const TextAttribute attr);
bool SetAttrToEnd(const unsigned int iStart, const TextAttribute attr);
void ReplaceAttrs(const TextAttribute& toBeReplacedAttr, const TextAttribute& replaceWith) noexcept;
void Resize(const size_t newWidth);

View file

@ -30,7 +30,6 @@ PRECOMPILED_INCLUDE = ..\precomp.h
SOURCES= \
..\AttrRow.cpp \
..\AttrRowIterator.cpp \
..\cursor.cpp \
..\OutputCell.cpp \
..\OutputCellIterator.cpp \

View file

@ -198,7 +198,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
// Hold the accumulation.
difference_type accumulation = 0;
// Make ourselves a copy of the right side. We'll
// Make ourselves a copy of the right side.
auto tmp = right;
// While we're pointing to a run that is RIGHT of tmp...
@ -387,14 +387,18 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
};
};
template<typename T, typename S = size_t>
// Run Length Encoded data storage
// T = The type you wish to store
// S = The type of the counter value to use (max run length)
// N = (optional, default 1) The count of runs to store internally before heap alloc
template<typename T, typename S = size_t, unsigned int N = 1>
class rle
{
private:
boost::container::small_vector<std::pair<T, S>, 1> _list;
boost::container::small_vector<std::pair<T, S>, N> _list;
S _size;
rle(boost::container::small_vector<std::pair<T, S>, 1> list, S size) :
rle(boost::container::small_vector<std::pair<T, S>, N> list, S size) :
_list(list),
_size(size)
{
@ -407,14 +411,17 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
//using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
rle() :
_size(static_cast<S>(0))
{
}
rle(const S size, const T value) :
_size(size)
{
fill(value);
}
// Returns the total length of all runs as encoded.
S size() const noexcept
{

View file

@ -13,15 +13,34 @@ class RunLengthEncodingTests
{
TEST_CLASS(RunLengthEncodingTests);
// NOTE: In some cases, these tests are also about ensuring that the various scenarios
// for template usage can compile correctly and will have minimal exercised functionality
// at unit test runtime.
TEST_METHOD(ConstructEmpty)
{
til::rle<unsigned int> rle;
VERIFY_ARE_EQUAL(0, rle.size());
VERIFY_ARE_EQUAL(rle.cbegin(), rle.cend());
}
TEST_METHOD(ConstructDefaultLength)
{
til::rle<unsigned int> rle(86, 9);
auto foo = rle.begin();
VERIFY_ARE_EQUAL(86, rle.size());
}
TEST_METHOD(ConstructVerySmall)
{
const til::rle<unsigned short, unsigned char> rle(12, 37);
VERIFY_ARE_EQUAL(12, rle.size());
}
TEST_METHOD(ConstructWithMinimumLoadSize)
{
const til::rle<unsigned short, unsigned short> def;
const til::rle<unsigned short, unsigned short, 3> bigger;
VERIFY_IS_GREATER_THAN(sizeof(bigger), sizeof(def));
}
TEST_METHOD(Size)
@ -162,6 +181,8 @@ class RunLengthEncodingTests
expected.insert(49, 10, 5);
expected.insert(11, 15, 2);
expected.insert(81, 17, 3);
VERIFY_ARE_EQUAL(expected, actual);
}
TEST_METHOD(ResizeShrink)