set<int> having FIFO behaviour

L

Luca

I have the need of a container of integers showing both the
characteristics of an associative container (all integer elements
different from each other) and the FIFO behaviour.

Do you know if there is a ready-made container for that or if I have
to use - for example - a set<int> and produce by myself FIFO
behaviour, or maybe I can use a queue<int> adding code for preventing
the insertion od duplicate integers

Thank you

Luca
 
R

Ron Natalie

Luca said:
I have the need of a container of integers showing both the
characteristics of an associative container (all integer elements
different from each other) and the FIFO behaviour.

Do you know if there is a ready-made container for that or if I have
to use - for example - a set<int> and produce by myself FIFO
behaviour, or maybe I can use a queue<int> adding code for preventing
the insertion od duplicate integers

You can't order a set other than the way implied by the comparison function
it is created with (usually Less). The easiest way is what you suggest
in the second paragraph. One easy way to check for duplication is to
use both the queue and set. Check the set prioir to insert, insert into
both if not found. Delete from the set when you delete from the queue.
 
J

Jerry Coffin

I have the need of a container of integers showing both the
characteristics of an associative container (all integer elements
different from each other) and the FIFO behaviour.

It sounds like a priority queue should work for you.
 
K

Koenings Bernhard

Hi Luca!

Luca said:
I have the need of a container of integers showing both the
characteristics of an associative container (all integer elements
different from each other) and the FIFO behaviour.

Do you know if there is a ready-made container for that or if I have
to use - for example - a set<int> and produce by myself FIFO
behaviour, or maybe I can use a queue<int> adding code for preventing
the insertion od duplicate integers

Try using list as container. But there's a problem with the uniqueness. You
have to call the 'unique' method after each insert, that may result in bad
performance

HTH
Bernhard
 
K

Kevin Goodsell

Koenings said:
Try using list as container. But there's a problem with the uniqueness. You
have to call the 'unique' method after each insert, that may result in bad
performance

I don't think that will work. 'unique' can only find duplicates that are
adjacent, implying that you must usually sort the container first. This
would destroy the existing order.

-Kevin
 

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
474,142
Messages
2,570,820
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top