Boost logo

Boost :

From: Rozental, Gennadiy (gennadiy.rozental_at_[hidden])
Date: 2002-12-04 14:24:02


> > If anyone interested I have more generic solution, that
> includes both
> > fixed/pseudo-dynamic versions with the same interface and
> policy template
> > parameter managing search algorithms (if/else based,slist
> based linear
> > search,map based, array+lower_bound based). BTW it appears
> that array in
> > many cases does outperform map as Matt Austern states.
> >
>
> '... pseudo-dynamic ...' ?

it's dynamic cause in addition to fixed_sized interface it supports
add/remove pair operations.The reasons to use
dynamic mapping instead of map are:
1. Rare insertion frequent search - may be quicker
2. I got tired repeating the same logic: find, if iterator is invalid return
some invalid value. mappings automate this for me.
3. Fixed interface for all mappings.
 
> What's the syntax for declaring and using the table (or
> whatever you may
> call it)?
>
> // Johan

namespace mapping {
template<class Key, class Value, class ImplPolicy >
class fixed_sized;

// constructed by Key1,Value1,Key2,Value2 ... list plus "invalid value"

template<class Key, class Value, class ImplPolicy >
class dynamic;

// constrcted by "invalid_value"

};

mapping::fixed_sized<const_string,int,array_impl_policy> test_mapping1(
    "Key1", 1,
    "Key2", 2,
    "QWE", 3,
    0
);

mapping::dyanamic<const_string,int,map_impl_policy> test_mapping2(
    "Key1", 1,
    "Key2", 2,
    "QWE", 3,
    0
);

mapping::dynamic<const_string,int,map_impl_policy > test_mapping3( 0 );
test_mapping3.add( "Key1", 1 );
test_mapping3.add( "Key2", 2 );
test_mapping3.add( "QWE" , 3 );

Usage:
test_mapping1["Key1"]
test_mapping2["Key2"]
test_mapping3["QWE"]

Gennadiy.


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