diff options
| author | Neil <nyamatongwe@gmail.com> | 2019-12-01 19:53:48 +1100 |
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2019-12-01 19:53:48 +1100 |
| commit | 7153448eb8dfe267f96eb55aee683172f15cc283 (patch) | |
| tree | 026adfb64a1529bff16e9c49e1c1510c9184f560 /src/Partitioning.h | |
| parent | bce262ab46a8e485febb8e8b6311356ea7571af1 (diff) | |
| download | scintilla-mirror-7153448eb8dfe267f96eb55aee683172f15cc283.tar.gz | |
Backport: Fix a bug with deleting the first element in SparseVector that left an extra
empty partition.
Add extra checking to Partitioning and turn on checking for UnitTester.
Backport of changeset 7777:12fb0335514e.
Diffstat (limited to 'src/Partitioning.h')
| -rw-r--r-- | src/Partitioning.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Partitioning.h b/src/Partitioning.h index a92e55b53..e742952ab 100644 --- a/src/Partitioning.h +++ b/src/Partitioning.h @@ -110,6 +110,10 @@ public: return static_cast<T>(body->Length())-1; } + T Length() const noexcept { + return PositionFromPartition(Partitions()); + } + void InsertPartition(T partition, T pos) { if (stepPartition < partition) { ApplyStep(partition); @@ -196,6 +200,34 @@ public: void DeleteAll() { Allocate(body->GetGrowSize()); } + + void Check() const { +#ifdef CHECK_CORRECTNESS + if (Length() < 0) { + throw std::runtime_error("Partitioning: Length can not be negative."); + } + if (Partitions() < 1) { + throw std::runtime_error("Partitioning: Must always have 1 or more partitions."); + } + if (Length() == 0) { + if ((PositionFromPartition(0) != 0) || (PositionFromPartition(1) != 0)) { + throw std::runtime_error("Partitioning: Invalid empty partitioning."); + } + } else { + // Positions should be a strictly ascending sequence + for (T i = 0; i < Partitions(); i++) { + const T pos = PositionFromPartition(i); + const T posNext = PositionFromPartition(i+1); + if (pos > posNext) { + throw std::runtime_error("Partitioning: Negative partition."); + } else if (pos == posNext) { + throw std::runtime_error("Partitioning: Empty partition."); + } + } + } +#endif + } + }; |
