Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2007-08-08 15:14:16


Tobias Schwinger wrote:
> However, I've been wondering whether it would be possible to make the
> "hook interface" easier to use and less demanding in terms of names that
> are injected into client code. So I started experimenting a bit and the
> attachment is what I came up with. I believe that scheme might actually
> work (not sure, though)...
>
> [code]
>

Very interesting, although I don't fully understand the goal. If the
goal is to avoid name injection, I could rework hooks to group all the
name definitions in a single internal structure and avoid code bloat.

What I found interesting is the non-intrusive Intrusive version (nice
definition ;-)). Using ADL, there is a way to obtain the hook from the
value. However, Intrusive uses a two level architecture, where node
algorithms only know about nodes (which in the singly linked list case
is just an structure holding a single pointer) and containers know also
about values (values hold nodes/hooks as base or members).

This guarantees that template bloat is minimized, because instantiated
algorithms are the same for all values using the same hook. Containers
transform nodes to values and the inverse (using static_cast for base
hooks or calculating the offset of the hook in the value in member hooks).

Although your example is not directly applicable to current Intrusive
code, you suggest a very nice possibility: storing nodes(hooks)
independently from values. The programmer could just offer a way to get
the node from the value and the inverse when not using any base or
member hook.

In the two-level Intrusive architecture your example would need two maps
(we could just use boost::bimap) to transform independently stored nodes
(slist_node_mgmt_data in your example) to values and the inverse operation.

I don't know when I'll have time to investigate a bit this issue, but
this non-intrusiveness sounds nice. Imagine I have an array of values I
can't touch and I want to store some elements in an intrusive rbtree. I
can't modify the definition, but I could just offer an additional rbtree
hook array and the mapping functions [pseudo-code, it surely will
contain errors]:

MyUntouchableValue values[NumValue];
set_hook hooks [NumValue];

const set_hook &value_to_hook(const MyUntouchableValue &v)
{ return hooks[&v - values]; }

const MyUntouchableValue &hook_to_value(const set_hook &h)
{ return values[&h - hooks]; }

The transformation is blazingly fast and very useful to create new
"non-intrusive" containers. Maybe we should call them "extrusive" hooks.

I don't know how should we configure the intrusive containers set to say
"there is no hook in the value, and I want you to use the following
transformation functions to obtain the hook/node used by algorithms". I
don't know if transformation function should better be packed in a class
and stored in the container (so that transformation functions are not
global functions but maybe stateful functors). A lot of questions, but I
think it's a fresh, great idea. Thanks!

Regards,

Ion


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