22 std::unique_ptr<Partitioning<Sci::Position>>
starts;
23 std::unique_ptr<SplitVector<T>>
values;
26 values->SetValueAt(partition, T());
30 starts = Sci::make_unique<Partitioning<Sci::Position>>(8);
31 values = Sci::make_unique<SplitVector<T>>();
51 return starts->Partitions();
54 return starts->PositionFromPartition(element);
60 return starts->Partitions();
68 return values->ValueAt(partition);
73 template <
typename ParamType>
82 }
else if (
position == startPartition) {
85 starts->RemovePartition(partition);
93 values->SetValueAt(partition, std::forward<ParamType>(value));
97 values->Insert(partition + 1, std::forward<ParamType>(value));
106 const bool positionOccupied =
values->ValueAt(partition) != T();
108 if (partition == 0) {
110 if (positionOccupied) {
111 starts->InsertPartition(1, 0);
112 values->InsertEmpty(0, 1);
114 starts->InsertText(partition, insertLength);
116 if (positionOccupied) {
117 starts->InsertText(partition - 1, insertLength);
120 starts->InsertText(partition, insertLength);
124 starts->InsertText(partition, insertLength);
132 if (partition == 0) {
134 if (
starts->PositionFromPartition(1) == 1) {
138 starts->RemovePartition(partition + 1);
139 values->Delete(partition);
142 }
else if (partition ==
starts->Partitions()) {
145 throw std::runtime_error(
"SparseVector: deleting end partition.");
148 starts->RemovePartition(partition);
149 values->Delete(partition);
154 starts->InsertText(partition, -1);
164 assert(positionEnd <=
Length());
167 while ((
Elements() > 1) && (
starts->PositionFromPartition(1) <= deleteLength)) {
168 starts->RemovePartition(1);
171 starts->InsertText(0, -deleteLength);
177 const bool atPartitionStart =
position ==
starts->PositionFromPartition(partition);
178 const Sci::Position partitionDelete = partition + (atPartitionStart ? 0 : 1);
179 assert(partitionDelete > 0);
182 assert(
position <= positionAtIndex);
183 if (positionAtIndex >= positionEnd) {
186 assert(partitionDelete <=
Elements());
187 starts->RemovePartition(partitionDelete);
188 values->Delete(partitionDelete);
190 starts->InsertText(partition - (atPartitionStart ? 1 : 0), -deleteLength);
199 return partition + 1;
202#ifdef CHECK_CORRECTNESS
205 throw std::runtime_error(
"SparseVector: Partitions and values different lengths.");
void DeleteRange(Sci::Position position, Sci::Position deleteLength)
SparseVector(const SparseVector &)=delete
std::unique_ptr< SplitVector< T > > values
void SetValueAt(Sci::Position position, ParamType &&value)
Sci::Position ElementFromPosition(Sci::Position position) const noexcept
void DeletePosition(Sci::Position position)
Sci::Position Length() const noexcept
void operator=(const SparseVector &)=delete
Sci::Position Elements() const noexcept
void ClearValue(Sci::Position partition) noexcept
Sci::Position IndexAfter(Sci::Position position) const noexcept
void InsertSpace(Sci::Position position, Sci::Position insertLength)
SparseVector(SparseVector &&)=delete
Sci::Position PositionOfElement(Sci::Position element) const noexcept
void operator=(SparseVector &&)=delete
const T & ValueAt(Sci::Position position) const noexcept
std::unique_ptr< Partitioning< Sci::Position > > starts
Styling buffer using one element for each run rather than using a filled buffer.