walk thru multi_index

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

walk thru multi_index

Dmitriy Bure
Hello,
I'm very interested to use multi_index container in my work. But didn't found much documentation and\or examples. Maybe anyone could suggest a place to find it?
Basically now I'm trying to implement probably very simple thing. There is basic structure:


struct AvNode
{
  CNode* var;
  int context;
  MemoryPlace location;
  ...
};


And I'd like to have multi_index container with such nodes (all fields are non-equal). Something like this:

typedef multi_index_container<
  AvNode,
  indexed_by<
    ordered_non_unique<
      tag<varNcontextIndex>,
      composite_key<
        AvNode,
        BOOST_MULTI_INDEX_MEMBER(AvNode,CNode*,var),
        BOOST_MULTI_INDEX_MEMBER(AvNode,int,context)
      >
    >
  >
> AvNodeSet;


And then I need to iterate on this container. Better to say that I'd like to group elements in container by first two fields. Could you help me in this problem? In fact I have one solution but it's too large and non-fine:

AvNodeSet avNodes;

typedef index<AvNodeSet, varNcontextIndex>::type AvNodesSet2VarNcontext;
AvNodesSet2VarNcontext& avNodes2VarNcontext = boost::multi_index::get<varNcontextIndex>(avNodes);

AvNodesSet2VarNcontext::iterator it = avNodes2VarNcontext.begin();
while(it !=
avNodes2VarNcontext.end())
{
    CNode* var = it->var;
  
   
AvNodesSet2VarNcontext::iterator it2Var = it;
    while( (
it2Var != avNodes2VarNcontext.end()) && (it2Var ->var== var) )
    {
        int context = it2Var->context;

        FOO(make_pair(var, context));

        AvNodesSet2VarNcontext::iterator it2Context = it2Var;
        while( (
it2Context != avNodes2VarNcontext.end()) && (it2Context->context == context) )
        {
            ++it2Context;
        }
        it2Var = it2Context;
    }
    it = it2Var;
}

Hope for your help...
-- 
Best regards,
Dmitriy Bure [hidden email]
     
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: walk thru multi_index

Joaquin M LópezMuñoz
Hello Dmitriy,

Dmitriy Bure ha escrito:

Hello,
I'm very interested to use multi_index container in my work. But didn't found much documentation and\or examples. Maybe anyone could suggest a place to find it?
I assume you already have visited the official documentation page at

http://boost.org/libs/multi_index/

Other than this, I don't think you will find more info on Boost.MultiIndex on the net.
Do you find the aforementioned docs insufficient? I'm open to suggestions for
improvement.

 
Basically now I'm trying to implement probably very simple thing. There is basic structure:

struct AvNode
{
  CNode* var;
  int context;
  MemoryPlace location;
  ...
};

And I'd like to have multi_index container with such nodes (all fields are non-equal). Something like this:

typedef multi_index_container<
  AvNode,
  indexed_by<
    ordered_non_unique<
      tag<varNcontextIndex>,
      composite_key<
        AvNode,
        BOOST_MULTI_INDEX_MEMBER(AvNode,CNode*,var),
        BOOST_MULTI_INDEX_MEMBER(AvNode,int,context)
      >
    >
  >
> AvNodeSet;

And then I need to iterate on this container. Better to say that I'd like to group elements in container by first two fields. Could you help me in this problem? In fact I have one solution but it's too large and non-fine:
 

[...]

The loop you propose can be drastically simplified as follows:

for(
  AvNodesSet2VarNcontext::iterator it = avNodes2VarNcontext.begin();
  it != avNodes2VarNcontext.end();
  it = avNodes2VarNcontext.upper_bound(avNodes2VarNcontext.key_extractor()(*it)))
{
    FOO(make_pair(it->var, it->context));
}

The point here is how using upper_bound() let you jump to the next
different value. Please notice the use of key_extractor(), since in Boost.MultiIndex
upper_bound() and similar lookup functions do not accept whole elements
(AvNode's in this case) but rather the keys on which the index works on: so,
"avNodes2VarNcontext.upper_bound(*it)" wouldn't compile. The following
variation is probably simplier to understand, though it incurs some temporary
object constructions:

for(
  AvNodesSet2VarNcontext::iterator it = avNodes2VarNcontext.begin();
  it != avNodes2VarNcontext.end();
  it = avNodes2VarNcontext.upper_bound(boost::make_tuple(it->var,it->context)))
{
    FOO(make_pair(it->var, it->context));
}

When invoking upper_bound(), we construct a tuple containing the current
values for the composite key. This latter variation lends itself to easy
modification, for instance the following groups elements only by
the first value of the composite_key (that is, AvNode::var):

for(
  AvNodesSet2VarNcontext::iterator it = avNodes2VarNcontext.begin();
  it != avNodes2VarNcontext.end();
  it = avNodes2VarNcontext.upper_bound(boost::make_tuple(it->var)))
{
    FOO(make_pair(it->var, it->context));
}

Hope this helps. Don't hesitate to come back if you need further help,
and thanks for using Boost.MultiIndex.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Reply | Threaded
Open this post in threaded view
|

Re: walk thru multi_index

Evan Carew
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joaquín,

They are a little lite. I had to ask for help as well to get started.
In my case, I defined a fact pattern I needed help with and someone
kindly gave me an example, which I am now using.

Evan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFD4lXApxCQXwV2bJARAsaxAJ9rF9IBfLTUWKwh8DCUHPnCj/5gkACgmj/q
NpcBmDY2hDI+IF+ZAWQPUb0=
=EfPx
-----END PGP SIGNATURE-----

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: walk thru multi_index

Joaquin M LópezMuñoz
In reply to this post by Dmitriy Bure
[About the documentation of Boost.MultiIndex,
Evan says:]

----- Mensaje original -----
De: Evan Carew <[hidden email]>
Fecha: Jueves, Febrero 2, 2006 7:56 pm
Asunto: Re: [Boost-users] walk thru multi_index

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Joaquín,
>
> They are a little lite. I had to ask for help as well to get started.
> In my case, I defined a fact pattern I needed help with and someone
> kindly gave me an example, which I am now using.
>

Could you elaborate on that pattern? If it's general
enough, I can look for a way to have it explained
in the docs.

When receiving specific reports about the docs I usually
try to use the feedback --for instance, you complained some
weeks ago about the lack of a explicit mention to
index_iterator<> and family, and I added it to the docs
for Boost 1.34 (you can check the preview version at the
Vault.)

Other than this, I'm sorry you found the documentation
somewhat light. I've made sure every feature of the lib
is treated, but I try also to keep the tutorial compact,
and sometimes the style can be terser than desired.
Also, sometimes people have questions wich are actually
not related to Boost.MultiIndex --the very same problem
posed by Dmitriy Bure, for instance, is more of an
associative container issue, not specifically related
to multi_index_container.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo

> Version: GnuPG v1.4.1 (GNU/Linux)
>
> iD8DBQFD4lXApxCQXwV2bJARAsaxAJ9rF9IBfLTUWKwh8DCUHPnCj/5gkACgmj/q
> NpcBmDY2hDI+IF+ZAWQPUb0=
> =EfPx
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Adding compiler option /clr to Boost build

Ben Khosrownia
Hi All:

I am trying to add the compiler option /clr to the
build system of Boost and rebuild Boost using that
option. I see the config.hpp and user.hpp files but do
not know exactly which section I need to add this to.

Any help would be truly appreciated.

Thank you;

Ben


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Adding compiler option /clr to Boost build

Bronek Kozicki
Ben Khosrownia <[hidden email]> wrote:
> Hi All:
>
> I am trying to add the compiler option /clr to the
> build system of Boost and rebuild Boost using that
> option. I see the config.hpp and user.hpp files but do
> not know exactly which section I need to add this to.

You may use this toolset (poor, but working)
http://b.kozicki.pl/boost_rtest/head/vc-8_0_clr-tools.jam


B.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Adding compiler option /clr to Boost build

Ben Khosrownia
Thank you for your response.

I am sorry but I don't undrestand where the following
statements should be placed:

extends-toolset vc-8_0 ; flags vc-8_0_clr C++FLAGS :
/EHa /clr /wd4561 /D_SCL_SECURE_NO_DEPRECATE ;

Thank you

Ben

--- Bronek Kozicki <[hidden email]> wrote:

> Ben Khosrownia <[hidden email]> wrote:
> > Hi All:
> >
> > I am trying to add the compiler option /clr to the
> > build system of Boost and rebuild Boost using that
> > option. I see the config.hpp and user.hpp files
> but do
> > not know exactly which section I need to add this
> to.
>
> You may use this toolset (poor, but working)
>
http://b.kozicki.pl/boost_rtest/head/vc-8_0_clr-tools.jam
>
>
> B.
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
>
http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users