From 54f38e6702c860af9363ca1125740321ec5da192 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Wed, 12 Feb 2014 11:49:41 +0000 Subject: [PATCH] [era_invalidate] Change to output ranges. --- era/era_invalidate.cc | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/era/era_invalidate.cc b/era/era_invalidate.cc index 9e63578..42bf67b 100644 --- a/era/era_invalidate.cc +++ b/era/era_invalidate.cc @@ -94,6 +94,20 @@ namespace { //-------------------------------- + template + pair next_run(Iterator &it, Iterator end) { + uint32_t b, e; + + b = *it++; + e = b + 1; + while (it != end && *it == e) { + e++; + it++; + } + + return make_pair(b, e); + } + void emit_blocks(ostream &out, set const &blocks) { indented_stream o(out); @@ -102,10 +116,17 @@ namespace { o.inc(); { - set::const_iterator it; - for (it = blocks.begin(); it != blocks.end(); ++it) { + set::const_iterator it = blocks.begin(); + while (it != blocks.end()) { o.indent(); - o << "" << endl; + + pair range = next_run(it, blocks.end()); + if (range.second - range.first == 1) + o << "" << endl; + + else + o << "" << endl; } } o.dec();