On Tue, May 15, 2007 at 04:28:10PM +0200, Abdelrazak Younes wrote:
> Abdelrazak Younes wrote:
> >Ozgur Ugras BARAN wrote:
> >>This small patch prevents LOF, LOT always selects the last entry.
> >>LOT/LOF still does not follow the cursor, yet, but for this, we need
> >>serious update in TocBackend.
> >
> >Not that much work IMO. The problem is the way we search for the toc
> >item is very crude. Look at the comment in TocBackend::item():
> >
> >// A good solution for Items inside insets would be to do:
> >//
> >//if (std::distance(it->par_it_, current) <= 0)
> >// return it;
> >//
> >// But for an unknown reason, std::distance(current, it->par_it_) always
> >// returns a positive value and std::distance(it->par_it_, current)
> >// takes forever...
> >// So for now, we do:
> >if (it->par_it_.pit() <= par_it_text.pit())
> > return it;
> >
> >This is not correct and will work only for top-level items. So if
> >someone could implement an <= operator for ParConstIterator, that would
> >solve our problem. Jean-Marc, Andre, your the experts in this field,
> >could you implement this:
> >
> >bool operator<=(ParConstIterator const &, ParConstIterator const &);
>
> I've done it but I am not sure I got it right. JMarc?
>
> Abdel.
>
> Index: DocIterator.cpp
> ===================================================================
> --- DocIterator.cpp (revision 18303)
> +++ DocIterator.cpp (working copy)
> @@ -553,7 +553,20 @@
> }
>
>
> +bool operator<=(DocIterator const & di1, DocIterator const & di2)
> +{
> + size_t const n1 = di1.slices_.size();
> + size_t const n2 = di2.slices_.size();
> + for (size_t i = 0 ; i < n1; ++i) {
> + if (i >= n2)
> + return false;
> + if (di1.slices_[i].pit() <= di2.slices_[i].pit())
> + return true;
> + }
> + return false;
> +}
The canonical solution wold look like the following (completely
untested!)
bool operator<(DocIterator const & di1, DocIterator const & di2)
{
size_t const n1 = di1.slices_.size();
size_t const n2 = di2.slices_.size();
for (size_t i = 0; i < n1 && i < n2; ++i) {
Slice const & sl1 = di1.slices_[i];
Slice const & sl2 = di2.slices_[i];
if (sl1.idx() != sl2.idx())
return sl1.idx() < sl2.idx();
if (sl1.pit() != sl2.pit())
return sl1.pit() < sl2.pit()
if (sl1.pos() != sl2.pos())
return sl1.pos() < sl2.pos()
}
return n1 < n2;
}
bool operator<=(DocIterator const & di1, DocIterator const & di2)
{
return !(di2 < di1);
}