dillo
3.0.5
About: dillo is a small, fast, extensible Web browser particularly suitable for older or smaller computers and embedded systems (but only limited or no support for frames, CSS, JavaScript, Java).
![]() ![]() |
Container similar to lout::misc::SimpleVector, but some cases of insertion optimized (used for hyphenation). More...
#include <misc.hh>
Public Member Functions | |
NotSoSimpleVector (int initAlloc) | |
NotSoSimpleVector (const NotSoSimpleVector &o) | |
~NotSoSimpleVector () | |
int | size () const |
void | increase () |
void | setSize (int newSize) |
void | insert (int index, int numInsert) |
T * | getRef (int i) const |
Return the reference of one element. More... | |
T | get (int i) const |
Return the one element, explicitly. More... | |
T * | getFirstRef () const |
Return the reference of the first element (convenience method). More... | |
T | getFirst () const |
Return the first element, explicitly. More... | |
T * | getLastRef () const |
Return the reference of the last element (convenience method). More... | |
T | getLast () const |
Return the last element, explicitly. More... | |
void | set (int i, T t) |
Store an object in the vector. More... | |
Private Member Functions | |
void | resizeMain () |
void | resizeExtra () |
void | consolidate () |
Private Attributes | |
T * | arrayMain |
T * | arrayExtra1 |
T * | arrayExtra2 |
int | numMain |
int | numExtra |
int | numAllocMain |
int | numAllocExtra |
int | startExtra |
Container similar to lout::misc::SimpleVector, but some cases of insertion optimized (used for hyphenation).
For hyphenation, words are often split, so that some space must be inserted by the method NotSoSimpleVector::insert. Typically, some elements are inserted quite at the beginning (when the word at the end of the first or at the beginning of the second line is hyphenated), then, a bit further (end of second line/beginning of third line) and so on. In the first time, nearly all words must be moved; in the second time, a bit less, etc. After all, using a simple vector would result in O(n2) number of elements moved total. With this class, however, the number can be kept at O(n).
The basic idea is to keep an extra array (actually two, of which the second one is used temporarily), which is inserted in a logical way. Since there is only one extra array at max, reading is rather simple and fast (see NotSoSimpleVector::getRef): check whether the position is before, within, or after the extra array. The first insertion is also rather simple, when the extra array has to be created. The following sketch illustrates the most complex case, when an extra array exists, and something is inserted after it (the case for which this class has been optimized):
Dotted lines are used to keep the boxes aligned.
As you see, only a relatively small fraction of elements has to be moved.
There are some other cases, which have to be documented.
|
inline |
|
inline |
|
inline |
|
inlineprivate |
Definition at line 305 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::insert().
|
inline |
Return the one element, explicitly.
The element is copied, so for complex elements, you should rather used misc::SimpleVector::getRef.
|
inline |
|
inline |
Return the reference of the first element (convenience method).
Definition at line 450 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::getFirst().
|
inline |
|
inline |
Return the reference of the last element (convenience method).
Definition at line 465 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::getLast().
|
inline |
Return the reference of one element.
Definition at line 422 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::get(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::getFirstRef(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::getLastRef(), and lout::misc::NotSoSimpleVector< dw::Textblock::Word >::set().
|
inline |
|
inline |
Definition at line 366 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::insert().
|
inlineprivate |
Definition at line 285 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::insert(), and lout::misc::NotSoSimpleVector< dw::Textblock::Word >::NotSoSimpleVector().
|
inlineprivate |
|
inline |
Store an object in the vector.
Unlike in container::untyped::Vector and container::typed::Vector, you have to care about the size, so a call to misc::SimpleVector::increase or misc::SimpleVector::setSize may be necessary before.
|
inline |
Definition at line 359 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::increase().
|
inline |
Definition at line 355 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::getFirstRef(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::getLastRef(), and lout::misc::NotSoSimpleVector< dw::Textblock::Word >::increase().
|
private |
Definition at line 265 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::consolidate(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::insert(), and lout::misc::NotSoSimpleVector< dw::Textblock::Word >::resizeExtra().
|
private |
Definition at line 265 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::insert().
|
private |
Definition at line 265 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::consolidate(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::insert(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::NotSoSimpleVector(), and lout::misc::NotSoSimpleVector< dw::Textblock::Word >::resizeMain().
|
private |
Definition at line 266 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::NotSoSimpleVector().
|
private |
Definition at line 266 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::NotSoSimpleVector().
|
private |
Definition at line 266 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::consolidate(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::getRef(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::insert(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::NotSoSimpleVector(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::resizeExtra(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::setSize(), and lout::misc::NotSoSimpleVector< dw::Textblock::Word >::size().
|
private |
|
private |
Definition at line 266 of file misc.hh.
Referenced by lout::misc::NotSoSimpleVector< dw::Textblock::Word >::consolidate(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::getRef(), lout::misc::NotSoSimpleVector< dw::Textblock::Word >::insert(), and lout::misc::NotSoSimpleVector< dw::Textblock::Word >::NotSoSimpleVector().