difference between sets

A

Anonymous

I am writing a method that will send a message to another object, based
on changes (if any) bewtween two sets of data.

I anticipate that this method will be called about 50k-100k times - i.e.
it needs to check if there has been any change in a set of data a very
large number of times.

The way I am currently thinking of implementing this is to store a local
copy of the set, and then check for a difference between the local copy
and the newly received set - and then send the appropriate message based
on the difference.

Because of the large number of times this function will be executed - I
thuink it is likely to be a bottleneck - since I'm not too familiar with
std::set, I thought it best to ask in here for advice - i.e. :

1). Are there any gotchas I need to be aware of when using std::set in
the manner described above ?
2). Is there a more elegant (and faster?) way of recognising if the
contents of a set has changed?
 
G

Guest

I am writing a method that will send a message to another object, based
on changes (if any) bewtween two sets of data.

Who owns these two sets?
The way I am currently thinking of implementing this is to store a local
copy of the set, and then check for a difference between the local copy
and the newly received set - and then send the appropriate message based
on the difference.

Can you not just watch for changes to either of those sets?
Because of the large number of times this function will be executed - I
thuink it is likely to be a bottleneck - since I'm not too familiar with
std::set, I thought it best to ask in here for advice - i.e. :

1). Are there any gotchas I need to be aware of when using std::set in
the manner described above ?

I am not sure in what manner you are planning on using the sets. If you
just want to compare two sets then there is nothing to worry about.
2). Is there a more elegant (and faster?) way of recognising if the
contents of a set has changed?

As I said earlier, watching for changes instead of checking for them
would be more efficient.
 
Z

zhang

I am writing a method that will send a message to another object, based
on changes (if any) bewtween two sets of data.

I anticipate that this method will be called about 50k-100k times - i.e.
it needs to check if there has been any change in a set of data a very
large number of times.

The way I am currently thinking of implementing this is to store a local
copy of the set, and then check for a difference between the local copy
and the newly received set - and then send the appropriate message based
on the difference.

Because of the large number of times this function will be executed - I
thuink it is likely to be a bottleneck - since I'm not too familiar with
std::set, I thought it best to ask in here for advice - i.e. :

1). Are there any gotchas I need to be aware of when using std::set in
the manner described above ?
2). Is there a more elegant (and faster?) way of recognising if the
contents of a set has changed?

The scenario looks very much like what Observer design pattern should
be
applied to. You could try this out using Observer pattern.

Cheers,
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top