+ int bestrow = 0;
+ bool foundid = false;
+
+ // this loop finds the last *nonempty* row whith the same id
+ // and position <= pos
+ for (unsigned r = 0, n = rowlist.size(); r != n; ++r) {
+ if (rowlist[r].id() == id && rowlist[r].pos() <= pos) {
+ foundid = true;
+ if (rowlist[bestrow].id() != id || rowlist[r].pos() > rowlist[bestrow].pos())
+ bestrow = r;
+ } else if (foundid)
+ break;
+ }
+ if (!foundid)
+ return rowlist.size();
+ return bestrow;