aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/SparseVector.h7
-rw-r--r--test/unit/testSparseVector.cxx14
2 files changed, 21 insertions, 0 deletions
diff --git a/src/SparseVector.h b/src/SparseVector.h
index 01d651f0d..ccee58df5 100644
--- a/src/SparseVector.h
+++ b/src/SparseVector.h
@@ -189,6 +189,13 @@ public:
}
Check();
}
+ Sci::Position PositionNext(Sci::Position start) const noexcept {
+ const Sci::Position element = ElementFromPosition(start);
+ if (element < Elements()) {
+ return PositionOfElement(element + 1);
+ }
+ return Length() + 1; // Out of bounds to terminate
+ }
Sci::Position IndexAfter(Sci::Position position) const noexcept {
assert(position < Length());
if (position < 0)
diff --git a/test/unit/testSparseVector.cxx b/test/unit/testSparseVector.cxx
index 5b50d24e4..763fa027c 100644
--- a/test/unit/testSparseVector.cxx
+++ b/test/unit/testSparseVector.cxx
@@ -383,6 +383,20 @@ TEST_CASE("SparseTextInt") {
REQUIRE(5 == st.PositionOfElement(2));
REQUIRE(2 == st.IndexAfter(4));
}
+
+ SECTION("PositionNext") {
+ st.InsertSpace(0, 5);
+ REQUIRE(1 == st.Elements());
+ REQUIRE(5 == st.PositionNext(-1));
+ REQUIRE(5 == st.PositionNext(0));
+ REQUIRE(6 == st.PositionNext(5));
+ st.SetValueAt(3, 3);
+ REQUIRE(2 == st.Elements());
+ REQUIRE(3 == st.PositionNext(-1));
+ REQUIRE(3 == st.PositionNext(0));
+ REQUIRE(5 == st.PositionNext(3));
+ REQUIRE(6 == st.PositionNext(5));
+ }
}
TEST_CASE("SparseTextString") {