From a12a739f053bd50ec6461b565afd865bc8e35403 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 4 Jan 2015 14:23:12 +0100 Subject: [PATCH] allow for iterative access to the snapshot data in the lookup table --- src/lib/diff/index-table.hpp | 18 +++++++++++++----- tests/library/diff/diff-index-table-test.cpp | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/lib/diff/index-table.hpp b/src/lib/diff/index-table.hpp index 292584fd3..c96df8a26 100644 --- a/src/lib/diff/index-table.hpp +++ b/src/lib/diff/index-table.hpp @@ -76,11 +76,19 @@ namespace diff{ } } - size_t - size() const - { - return data_.size(); - } + /* === forwarded sequence access === */ + + using iterator = typename std::vector::iterator; + using const_iterator = typename std::vector::const_iterator; + + iterator begin() { return data_.begin(); } + iterator end() { return data_.end(); } + const_iterator begin() const { return data_.begin(); } + const_iterator end() const { return data_.end(); } + + size_t size() const { return data_.size(); } + + VAL const& diff --git a/tests/library/diff/diff-index-table-test.cpp b/tests/library/diff/diff-index-table-test.cpp index bb1139e8f..36ca475cb 100644 --- a/tests/library/diff/diff-index-table-test.cpp +++ b/tests/library/diff/diff-index-table-test.cpp @@ -78,6 +78,7 @@ namespace test{ { simpleUsage(); verifySnapshot(); + sequenceIteration(); duplicateDetection(); copy_and_move(); } @@ -144,6 +145,19 @@ namespace test{ } + void + sequenceIteration() + { + DataSeq data({a5,a2,a1,a4,a3}); + + size_t i = 0; + for (auto elm : Index(data)) + { + CHECK (elm == data[i++]); + } + } + + void duplicateDetection() {