bogus entries in map (std library)



 DEVELOP > c-Plus-Plus > bogus entries in map (std library)

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "suresh"
Date: 12 Dec 2007 12:24:16 PM
Object: bogus entries in map (std library)
Hi,
I am getting zero as value for some keys in my map which can never
happen as per my understanding of my code. These are the details:
I have defined an array of vectors, where each vector element is a
map, like this:
vector<map<string,int> entry>* fulldata ;
using new operator, fulldata is memory allocated and each vector's
size is made 10 by calling resize() function.
The maps are always updated using ++fulldata[i][j][key_string]; This
means that no key_string in the map can have corresponding zero
integer values.
But I get bogus entries in some maps with 0 values corresponding to
some valid key_string.
How can this happen? Interestingly this problem is noticed in the maps
stored in the 2nd position in the vector (for many vectors it is
seen). ie fulldata[i][2][key_string] is zero for many i values.
I am using debian etch with g++ version 4:4.1.1-15.
Thanks for any suggestions,
suresh
.

User: "Richard Herring"

Title: Re: bogus entries in map (std library) 13 Dec 2007 04:11:47 AM
In message
<01d6728f-6232-4e5c-b489-08951c07a6f1@e25g2000prg.googlegroups.com>,
suresh <suresh.amritapuri@gmail.com> writes

Hi,

I am getting zero as value for some keys in my map which can never
happen as per my understanding of my code. These are the details:

I have defined an array of vectors, where each vector element is a
map, like this:

vector<map<string,int> entry>* fulldata ;

using new operator

Why not just use a vector of vectors?
--
Richard Herring
.

User: "Mark P"

Title: Re: bogus entries in map (std library) 12 Dec 2007 02:56:13 PM
suresh wrote:

Hi,

I am getting zero as value for some keys in my map which can never
happen as per my understanding of my code. These are the details:

I have defined an array of vectors, where each vector element is a
map, like this:

vector<map<string,int> entry>* fulldata ;

Syntactically invalid statement...


using new operator, fulldata is memory allocated and each vector's
size is made 10 by calling resize() function.

The maps are always updated using ++fulldata[i][j][key_string]; This
means that no key_string in the map can have corresponding zero
integer values.

But I get bogus entries in some maps with 0 values corresponding to
some valid key_string.

How can this happen? Interestingly this problem is noticed in the maps
stored in the 2nd position in the vector (for many vectors it is
seen). ie fulldata[i][2][key_string] is zero for many i values.

I am using debian etch with g++ version 4:4.1.1-15.

Thanks for any suggestions,

suresh

How can we help you if you don't post any code? (Although Victor's
guess is probably a good one given the uselessly little information
you've provided.)
.
User: "suresh"

Title: Re: bogus entries in map (std library) 12 Dec 2007 11:22:02 PM
Hi Victor
Thanks for the reply. I read Stroustrup carefully and wrote a small
piece of code to confirm the indexing behaviour. Thanks.
Mark, sorry for the cut paste error in my code. Actually it was
written like this:
typedef map<string,int> entry;
vector<entry>* fulldata ;
Anyway I learned maps better now. Thank you both,
regards
suresh
On Dec 13, 1:56 am, Mark P <use...@fall2005REMOVE.fastmailCAPS.fm>
wrote:

suresh wrote:

Hi,


I am getting zero as value for some keys in my map which can never
happen as per my understanding of my code. These are the details:


I have defined an array of vectors, where each vector element is a
map, like this:


vector<map<string,int> entry>* fulldata ;


Syntactically invalid statement...





using new operator, fulldata is memory allocated and each vector's
size is made 10 by calling resize() function.


The maps are always updated using ++fulldata[i][j][key_string]; This
means that no key_string in the map can have corresponding zero
integer values.


But I get bogus entries in some maps with 0 values corresponding to
some valid key_string.


How can this happen? Interestingly this problem is noticed in the maps
stored in the 2nd position in the vector (for many vectors it is
seen). ie fulldata[i][2][key_string] is zero for many i values.


I am using debian etch with g++ version 4:4.1.1-15.


Thanks for any suggestions,


suresh


How can we help you if you don't post any code? (Although Victor's
guess is probably a good one given the uselessly little information
you've provided.)

.


User: "Victor Bazarov"

Title: Re: bogus entries in map (std library) 12 Dec 2007 12:27:46 PM
suresh wrote:

I am getting zero as value for some keys in my map which can never
happen as per my understanding of my code. These are the details:

I have defined an array of vectors, where each vector element is a
map, like this:

vector<map<string,int> entry>* fulldata ;

using new operator, fulldata is memory allocated and each vector's
size is made 10 by calling resize() function.

The maps are always updated using ++fulldata[i][j][key_string]; This
means that no key_string in the map can have corresponding zero
integer values.

But I get bogus entries in some maps with 0 values corresponding to
some valid key_string.

How can this happen? Interestingly this problem is noticed in the maps
stored in the 2nd position in the vector (for many vectors it is
seen). ie fulldata[i][2][key_string] is zero for many i values.

How do you know that there are "bogus entries"? Did you know that
using indexing on a map inserts a default-initialized value into
the map with the key you use do index?
map<int, double> whoa;
if (whoa[42] == 0) {
std::cerr << "BOGUS!!!";
}
Is that what you're doing?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.


  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