std::map initialization - reserving hashtable size



 DEVELOP > c-Plus-Plus > std::map initialization - reserving hashtable size

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 01 Aug 2007 06:57:25 PM
Object: std::map initialization - reserving hashtable size
Hi -
I am using the map stl and is there a way I could specify the hash
table size in the map in the beginning - (similar to
vector.reserve(size) ). Is there a way I could specify the entries at
the beginning.
Is there an implementation-independent hint that I could give to
map so that it performs better when I add more entries to it.
.

User: "Barry"

Title: Re: std::map initialization - reserving hashtable size 02 Aug 2007 12:31:30 AM
wrote:

Hi -
I am using the map stl and is there a way I could specify the hash
table size in the map in the beginning - (similar to

std::map usually use Rb tree to implement, as map is ordered

vector.reserve(size) ). Is there a way I could specify the entries at
the beginning.

Is there an implementation-independent hint that I could give to
map so that it performs better when I add more entries to it.

.

User: "Victor Bazarov"

Title: Re: std::map initialization - reserving hashtable size 01 Aug 2007 07:29:04 PM
wrote:

Hi -
I am using the map stl and is there a way I could specify the hash
table size in the map in the beginning - (similar to
vector.reserve(size) ). Is there a way I could specify the entries at
the beginning.

If those are questions, the answer is "no".

Is there an implementation-independent hint that I could give to
map so that it performs better when I add more entries to it.

No.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.

User: "James Kanze"

Title: Re: std::map initialization - reserving hashtable size 02 Aug 2007 06:58:47 AM
On Aug 2, 1:57 am,
wrote:

I am using the map stl and is there a way I could specify the hash
table size in the map in the beginning - (similar to
vector.reserve(size) ).

std::map doesn't use a hash table, so it's not relevant.
std::map is a node based container, which means that each entry
is a separate allocation. Knowing the size up front couldn't
affect its performance.

Is there a way I could specify the entries at
the beginning.

Yes. Use the two iterator constructor. Something like:
typedef std::map< int, int > Map ;
struct MapInit
{
int key ;
int value ;
operator Map::value_type() const
{
return Map::value_type( key, value ) ;
}
} ;
MapInit const initTable[] =3D
{
{ 1, 2 },
{ 3, 4 },
// ...
} ;
Map myMap( begin( initTable ), end( initTable ) ) ;
(You'll need the usual begin and end function templates for
this:
template< typename T, size_t N >
T*
begin( T (&array)[ N ] )
{
return array ;
}
template< typename T, size_t N >
T*
end( T (&array)[ N ] )
{
return array + N ;
}

Is there an implementation-independent hint that I could give to
map so that it performs better when I add more entries to it.

If you know where the element is to go, you can tell the map
that when you insert it. This can save a few comparisons.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER