|
Boost : |
Subject: Re: [boost] flyweight - gsoc idea - multikey-value flyweight
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2016-02-16 13:53:42
Le 16/02/2016 16:00, Joaquin M LópezMuñoz a écrit :
> Vicente J. Botet Escriba <vicente.botet <at> wanadoo.fr> writes:
>
>> Le 15/02/2016 07:51, Joaquin M LópezMuñoz a écrit :
>>> Vicente J. Botet Escriba <vicente.botet <at> wanadoo.fr> writes:
>>>
>>>> Hi Joaquin,
>>>>
>>>> I have a use case where I have several keys to the same flyweight.
>> [...]
>>
>> Let say you are writing an application that manage with some entities.
>> You have two kind of operator that use a specific protocol and each
>> protocol identify these entities using a key MOi. Suppose that you
>> application use a library that has an interface that use different keys
>> to identify these same entities, because it is using an internal
>> protocol. You want also to have some CLI for debugging purposes that
>> uses strings to identify these same entities.
>>
>> All these keys are isomorphic so you can move from one key to the other
>> using a specific algorithm[...]
> OK, let's sketch these ideas. Let's say
>
<snip>
> All of this allows us to do
>
> int main()
> {
> multi_flyweight f1{124};
> multi_flyweight f2{char{124}};
> multi_flyweight f3{f2.get()};
> multi_flyweight f4{f1};
>
> std::cout<<f1.get().value<<"\n";
> std::cout<<f2.get().value<<"\n";
> std::cout<<f3.get().value<<"\n";
> std::cout<<f4.get().value<<"\n";
> std::cout<<(f1==f2)<<"\n";
> std::cout<<(f2==f3)<<"\n";
> std::cout<<(f3==f4)<<"\n";
> }
>
> with output
>
> key2_from_key1
> value_from_key1
> 124
> 124
> 124
> 124
> 1
> 1
> 1
>
> which effectively shows that key and value creation is minimized, and
> the resulting semantics is what we were after. You can play with a
> complete example at
>
> http://coliru.stacked-crooked.com/a/6dab2c556433fb03
>
> Does this approach your use case?
Form the functional point of view, yes, this is what I want. However we
need a generic class and ensure that the size is really fly weight.
> Some points:
>
> * This can be easily generalized to N keys with some metaprogramming.
I believe even for 2 key we will need some meta-programming.
> * Note that we haven't changed the internals of Boost.Flyweight to
> use something like a multi-key factory (which is probably what you
> had in mind). Instead, this is all done on top of the existing library,
> which has the obvious drawback (among others) that
> sizeof(multi_flyweight)==2*sizeof(void*), where sizeof(flyweight) is
> typically sizeof(void*). Whether this is acceptable or not depends
> really on the use cases, I'd say.
No, I want really a fly weight. If I have N key the multi_flyweight will
not be fly weight anymore.
sizeof(multi_flyweight)==N*sizeof(void*)
> * Rewriting this in the most efficient way through multi-key factories
> (likely based on Boost.MultiIndex) can be done but requires introducing
> whole new concepts into the framework --current factories are by
> definition one-key, so they simply can't be used for this.
Agreed. Maybe, we can have a separated multi_flyweight class that takes
care of this additional case.
I see that the implementation is already using multi-index ;-)
> * Is this a desireable extension to Boost.Flyweight? I don't have a
> strong opinion myself, others' most welcome.
I have no problem if this is in another library or class. What interest
me is the functionality with the best performances in space and time.
> * Is this a good candidate for GSoC? If the answer to the above is yes,
> I'd say this is certainly in the good ambition/impact ratio window for
> a GSoC project, and I'd be happy to mentor.
Glad to hear that. I believe this makes a good GSoC project. I could
help you if needed.
Do you mind to add an entry on the wiki
https://svn.boost.org/trac/boost/wiki/SoC2016?
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk