1 /*
2  For general Scribus (>=1.3.2) copyright and licensing information please refer
3  to the COPYING file provided with the program. Following this notice may exist
4  a copyright and/or license notice that predates the release of Scribus 1.3.2
5  for which a new license (GPL+exception) is in place.
6  */
7 
8 #include <QDebug>
9 
10 #include "index.h"
11 
12 
13 
14 // find run with runStart <= pos < runEnd
search(int pos) const15 uint RunIndex::search(int pos) const
16 {
17 	std::vector<uint>::const_iterator it = std::upper_bound(runEnds.begin(), runEnds.end(), unsigned(pos));
18 	return it - runEnds.begin();
19 }
20 
21 
insert(int pos)22 uint RunIndex::insert(int pos)
23 {
24 	uint i = search(pos);
25 
26 	if (i >= runEnds.size())
27 	{
28 		runEnds.push_back(pos);
29 		return runEnds.size() - 1;
30 	}
31 	runEnds.insert(runEnds.begin() + i, pos);
32 	return i;
33 }
34 
35 
remove(uint idx)36 void RunIndex::remove (uint idx)
37 {
38 	assert ( idx < runEnds.size() );
39 
40 	runEnds.erase(runEnds.begin() + idx);
41 }
42 
43 
adjust(int pos,int delta)44 void RunIndex::adjust(int pos, int delta)
45 {
46 	uint idx = search(pos);
47 	for (uint i = idx; i < runEnds.size(); ++i)
48 	{
49 		runEnds[i] += delta;
50 	}
51 }
52 
53 
54