Problem with inserting custom types into STL map

U

uartem

Hello, this is my problem:

I have a map:

typedef map<string, bfdb_record> BFDB;

where:

typedef struct
{
size_t seq_no;
StdBloomFilter bf;
} bfdb_record;

where:

class StdBloomFilter : public BloomFilter
{
private:
vector<bool> __filter;
size_t __size;
public:
StdBloomFilter():__filter(0),__size(0){};
StdBloomFilter(size_t _size): __filter(_size), __size(_size) {};
StdBloomFilter(const StdBloomFilter& _source);

virtual ~StdBloomFilter(){};

operator CountingBloomFilter();
StdBloomFilter& operator=(const StdBloomFilter&);

void set(size_t _pos);
bool test(size_t _pos) const;

void clear();
size_t size() const;
void merge(const StdBloomFilter& _source);

string to_string();
};

now I want to insert structure into my map:

__db.insert(make_pair(_id,_info));
or
__db[_id] = _info;
or
__db.insert(BFDB::value_type(_id, _info));

I get a runtime error:

8 [main] LE 2560 _cygtls::handle_exceptions: Exception:
STATUS_ACCESS_VIOLATION
985 [main] LE 2560 open_stackdumpfile: Dumping stack trace to
LE.exe.stackdump

Is something in StdBloomFilter missing. If I change bf to int type in
the bfdb_record struct then everything works, but that is not what I
need!!!

Please help
 
I

Ian Collins

Hello, this is my problem:

I have a map:

typedef map<string, bfdb_record> BFDB;

where:

typedef struct
{
size_t seq_no;
StdBloomFilter bf;
} bfdb_record;
That's C. You want

struct bfdb_record
{
size_t seq_no;
StdBloomFilter bf;
};

Are you sure you want to copy the entire StdBloomFilter object each time
you do an insert?
where:

class StdBloomFilter : public BloomFilter
{
private:
vector<bool> __filter;
size_t __size;

Those are illegal names, anything starting with double underscore is
reserved.
now I want to insert structure into my map:

__db.insert(make_pair(_id,_info));
or
__db[_id] = _info;
or
__db.insert(BFDB::value_type(_id, _info));

I get a runtime error:
What does your StdBloomFilter copy constructor do?
 
U

uartem

StdBloomFilter& StdBloomFilter::eek:perator=(const StdBloomFilter&
_source)
{
this->__size=_source.__size;
this->__filter =_source.__filter;
}

And what should it do? These are no pointers. These should be copies
by value, right? It was not working, so I added this dummy copy
constructor, but it still does not work.
 
I

Ian Collins

(e-mail address removed) wrote:

Please quote the appropriate context, this post makes no sense on its own.
StdBloomFilter& StdBloomFilter::eek:perator=(const StdBloomFilter&
_source)
{
this->__size=_source.__size;
this->__filter =_source.__filter;

You realy should get rid of these illegal names.
}

And what should it do? These are no pointers. These should be copies
by value, right? It was not working, so I added this dummy copy
constructor, but it still does not work.
Run you code under a debugger and see what it is doing. You don't show
the base class, so the problem may well be in there.
 
U

uartem

(e-mail address removed) wrote:

Please quote the appropriate context, this post makes no sense on its own.


You realy should get rid of these illegal names.



Run you code under a debugger and see what it is doing. You don't show
the base class, so the problem may well be in there.

I can put StdBloomFilter object into a vector<StdBloomFilter> and I
tried to get rid of any base class - does not help. Base class is an
abstract interface.
 
I

Ian Collins

*Please* don't quote signatures - the bit after the "-- ".
I can put StdBloomFilter object into a vector<StdBloomFilter> and I
tried to get rid of any base class - does not help. Base class is an
abstract interface.
What did your debugger show?
 
U

uartem

*Please* don't quote signatures - the bit after the "-- ".


What did your debugger show?

This is what I can catch:

mi_cmd_var_create: unable to create variable object
Single stepping until exit from function ntdll!
LdrDisableThreadCalloutsForDll,
which has no line number information.
Single stepping until exit from function ntdll!
LdrFindCreateProcessManifest,
which has no line number information.
Single stepping until exit from function ntdll!RtlCheckRegistryKey,
which has no line number information.

I compile it in gcc. I installed cygwin on a Windows system and I
debug it in Eclipse. So, this is all I managed to get out of it.
 
I

Ian Collins

*Please* *Please* don't quote signatures - the bit after the "-- ".
This is what I can catch:

I compile it in gcc. I installed cygwin on a Windows system and I
debug it in Eclipse. So, this is all I managed to get out of it.
You should be able to see the last line in your code.

I assume you have implemented the assignment operator as well?
 
U

uartem

*Please* *Please* don't quote signatures - the bit after the "-- ".



You should be able to see the last line in your code.

I assume you have implemented the assignment operator as well?
--
Ian Collins.

Well the assignment is smth like:
bool BFDatabase::update(const string& _id, const bfdb_record& _info)
{
BFDB::iterator iter = __db.find(_id);

if (iter==__db.end())
{
//__db.insert(make_pair(_id,_info));
__db[_id] = _info;
//__db.insert(BFDB::value_type(_id, _info));
return true;
}
return false;
}

But the problem is the following:

This works:
StdBloomFilter bf(100);
vector<StdBloomFilter> vec;
vec.push_back(bf);

And this does not:
map<int,StdBloomFilter> m;
m.insert(make_pair(5,bf));
 
R

Ralph D. Ungermann

StdBloomFilter& StdBloomFilter::eek:perator=(const StdBloomFilter&
_source) [...]
It was not working, so I added this dummy copy
constructor,

This is not the copy ctor. Show us your

StdBloomFilter::StdBloomFilter( const StdBloomFilter& );
 
R

red floyd

Hello, this is my problem:

I have a map:

typedef map<string, bfdb_record> BFDB;

where:

typedef struct
{
size_t seq_no;
StdBloomFilter bf;
} bfdb_record;

where:

class StdBloomFilter : public BloomFilter
{
private:
vector<bool> __filter;

Stop right there. You have just created an ill-formed program. Any
identifier with two consecutive underscores is reserved to the
implementation; you may not use it for your own purposes.
>[remainder redacted]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top