On Tue, Apr 04, 2000 at 01:21:12AM +0200, Lars Gullik Bj&resh;nnes wrote:
> Dekel Tsur <[EMAIL PROTECTED]> writes:
> | On Mon, Apr 03, 2000 at 10:34:35PM +0200, Lars Gullik Bj&resh;nnes wrote:
> | > +inline bool operator<(LyXParagraph::InsetTable const & a,
> | > +                     LyXParagraph::InsetTable const & b)
> | > +{
> | > +        return a.pos < b.pos;
> | > +}
> | > 
> | > This one looks conceptually wrong.
> | > When comparing two InsetTables you need to take pos into account.
> | > Instead of using this operator< (I assume you add this because of
> | > lowerbound) create an appropriate functor
> | > 
> | > struct compare_insettable_pos {
> | > public:
> | >   inline bool operator()(LyXParagraph::InsetTable const & a,
> | >                          LyXParagraph::InsetTable const & b) const
> | >   {
> | >           return a.pos < b.pos;
> | >   }
> | > }
> | 
> | I used the former to save some typing. Why should I use the latter?
> 
> As I said... to be conceptually more correct.
> Also if we sometime in the future would like to compare InsetTables in
> other ways taking the inset into account.

There are more important things to do with the time it would take to do the
changes.
You can alway make the changes in the future, if needed.

> And you didn't save a lot of typing either. I am sure you even can
> figure out a name for the functor that is shorter than
> "InsetTable(pos, 0)".

You do need the InsetTable(pos, 0) even if you use a function object.

> | 
> | > btw. why a vector for InsetTable? I would thing that a list suited the
> | > sorted/kept sorted sequence a lot better.
> | 
> | Because lowerbound() takes logarithmic time for a sorted vector, but it is
> | linear time for a sorted list.
> 
> hmm da hmm... 
> 
> but insertion is O(n)... what about a std::set?
> 

When we insert a new inset to the list, we need to update the positions of
the other insets, so it will take linear time even if insetlist is stored
using a list
(std::map can also be used [not std::set] but it isn't better than a vector).

Reply via email to