set<int> having FIFO behaviour

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luca

    set<int> having FIFO behaviour

    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
  • Ron Natalie

    #2
    Re: set&lt;int&gt; having FIFO behaviour


    "Luca" <lcdll@libero.i t> wrote in message news:a97dd389.0 309230603.30712 c1e@posting.goo gle.com...[color=blue]
    > 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[/color]

    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.


    Comment

    • Jerry Coffin

      #3
      Re: set&lt;int&gt; having FIFO behaviour

      In article <a97dd389.03092 30603.30712c1e@ posting.google. com>,
      lcdll@libero.it says...[color=blue]
      > 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.[/color]

      It sounds like a priority queue should work for you.

      --
      Later,
      Jerry.

      The universe is a figment of its own imagination.

      Comment

      • Koenings Bernhard

        #4
        Re: set&lt;int&gt; having FIFO behaviour

        Hi Luca!

        "Luca" <lcdll@libero.i t> schrieb im Newsbeitrag
        news:a97dd389.0 309230603.30712 c1e@posting.goo gle.com...[color=blue]
        > 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
        >[/color]

        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


        Comment

        • Kevin Goodsell

          #5
          Re: set&lt;int&gt; having FIFO behaviour

          Koenings Bernhard wrote:
          [color=blue]
          >
          > 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
          >[/color]

          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
          --
          My email address is valid, but changes periodically.
          To contact me please use the address from a recent posting.

          Comment

          Working...