Boost logo

Boost :

From: Soren Frank Andersen (sfa_at_[hidden])
Date: 2002-02-28 06:03:06


> -----Original Message-----
> From: Douglas Gregor [mailto:gregod_at_[hidden]]
> Sent: 27. februar 2002 17:33
>
> On Tuesday 26 February 2002 01:10 pm, you wrote:
> > I thing it would be better if you could connect several slots with
> > the same name. And then disconnect them all with one disconnect call.
> >
> > ...
>
> I think I agree with you.
> ...
> It also makes much better sense that there is an ordering between
> groups, but not between members of the same group.

I thing there also need to be some kind of ordering between unnamed
slots. It is just to hard to make sure your program works with
all possible calling sequences.

>
> > It is really nice that the connection time for unnamed signals is
> > O(1), I was not aware of this. It would be nice if we could keep
> > it this way.
> >
> > If it is possible to connect with a priority value, It is not
> > important to sort by name.
> >
> > I guess this will help with the O(lg n) connection time for
> > unnamed connections with default priority?
> >
> > I would prefer a ordering by name.
>
> Unabashedly putting my implementor's cap on, it is hard to get the O(1)
> insertions for unnamed slots and have priority or name-based
> ordering. Doing this would essentially require two separate data
> structures: one for unnamed slots that allows O(1) insertion and one
> for named slots that is kept ordered. The slot call iterator can bridge
> the two data structures (using, e.g., a version of the Union View
> from the View Template Library). Then we would have two structures
> such as:
>
> typedef std::multimap<SlotName, std::pair<connection, any> >
> named_slots_map;
> typedef std::list<std::pair<connection, any> > unnamed_slots_list;
>

What about just a std::multimap< ... > and keeping a iterator to the
last unnamed connection. Something like the following will give
O(1) insert time for unnamed signals:

// unnamed connect
connect( slot ) {
        if ( last_unnamed == multimap.end() ) {
                last_unnamed = multimap.insert(
                        pair( unnamed_value, slot )
                );
        } else {
                last_unnamed = multimap.insert(
                        last_unnamed,
                        pair( unnamed_value, slot )
                );
        }
}

// named connect
connect( name, slot ) {
        multimap.insert( pair( name, slot ) );
}

I also thing this will give a FIFO ordering of unnamed connections.
But I an not sure, my STL documentation is not clear about this.
The code can be modified to give a LIFO ordering if you prefer.

> What would users prefer? The first option, that would guarantee O(1)
> insertion time for unnamed slots, O(lg n) insertion time for named
> slots, but complicate (and somewhat slow down) the calling of slots?
> Or the second option, that would guarantee O(lg n) insertion time
> for all slots but provide a simpler implementation that might be
> (slightly) more efficient when calling slots?

I it is hard to decide, as Asger Alstrup said, it depends...
I hope we don't have to decide.

Another solution would be to have two signal types, one that support
named connections and one that don't. This way you don't pay for
some thing you don't need.

Besides from the calling sequence I thing the named connection
signal can be build on top of a unnamed signal.
The named-connection signal just have to store the connection
objects in a std::multimap.

Soren


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk