Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. An algorithm question

An algorithm question

Scheduled Pinned Locked Moved C / C++ / MFC
hardwarealgorithmstutorialquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    econy
    wrote on last edited by
    #1

    I have an application ,need to read hardware IO, each IO data be coded to an unsigned integer, 4 digits - 7 digits. Quantity of all possible integers is 240, every integer is unique for example:

    1000,1002, 120008, 1318001,14702 , 4003...

    After coding step, the coded integers need to be send out in a sequence.

    12002 <- 4001 <- 10089 <- 5007 <- ...

    Quantity of integers are limited to 128, but, the quantity number is not fixed. Perhaps send-cycle1 is 4 integers, send-cycle2 is 120 integers, send-cycle3 is 2 integers, send-cycle4 is 0 integer. ... And during cycle period, maybe there are duplicated data be read,but, sending sequence should not take duplicated data. Logic is :

    read data -> already in sequence, discard/ new data -> sequence

    I wonder what data structure is good for the above logic and application.

    L CPalliniC S 3 Replies Last reply
    0
    • E econy

      I have an application ,need to read hardware IO, each IO data be coded to an unsigned integer, 4 digits - 7 digits. Quantity of all possible integers is 240, every integer is unique for example:

      1000,1002, 120008, 1318001,14702 , 4003...

      After coding step, the coded integers need to be send out in a sequence.

      12002 <- 4001 <- 10089 <- 5007 <- ...

      Quantity of integers are limited to 128, but, the quantity number is not fixed. Perhaps send-cycle1 is 4 integers, send-cycle2 is 120 integers, send-cycle3 is 2 integers, send-cycle4 is 0 integer. ... And during cycle period, maybe there are duplicated data be read,but, sending sequence should not take duplicated data. Logic is :

      read data -> already in sequence, discard/ new data -> sequence

      I wonder what data structure is good for the above logic and application.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use one of the STL containers such as hash_set[^] or set[^].

      E 1 Reply Last reply
      0
      • L Lost User

        Use one of the STL containers such as hash_set[^] or set[^].

        E Offline
        E Offline
        econy
        wrote on last edited by
        #3

        MCU platform, use Hahset is not a good choice.

        1 Reply Last reply
        0
        • E econy

          I have an application ,need to read hardware IO, each IO data be coded to an unsigned integer, 4 digits - 7 digits. Quantity of all possible integers is 240, every integer is unique for example:

          1000,1002, 120008, 1318001,14702 , 4003...

          After coding step, the coded integers need to be send out in a sequence.

          12002 <- 4001 <- 10089 <- 5007 <- ...

          Quantity of integers are limited to 128, but, the quantity number is not fixed. Perhaps send-cycle1 is 4 integers, send-cycle2 is 120 integers, send-cycle3 is 2 integers, send-cycle4 is 0 integer. ... And during cycle period, maybe there are duplicated data be read,but, sending sequence should not take duplicated data. Logic is :

          read data -> already in sequence, discard/ new data -> sequence

          I wonder what data structure is good for the above logic and application.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          In order to get better help you should detail your scenario. For instance, I have no idea of what you mean with

          Quote:

          After coding step, the coded integers need to be send out in a sequence. 12002 <- 4001 <- 10089 <- 5007 <- ...

          Veni, vidi, vici.

          In testa che avete, signor di Ceprano?

          E 1 Reply Last reply
          0
          • CPalliniC CPallini

            In order to get better help you should detail your scenario. For instance, I have no idea of what you mean with

            Quote:

            After coding step, the coded integers need to be send out in a sequence. 12002 <- 4001 <- 10089 <- 5007 <- ...

            Veni, vidi, vici.

            E Offline
            E Offline
            econy
            wrote on last edited by
            #5

            Sorry, I mean, I want to send 12007, then 5007, right number after left number.

            C 1 Reply Last reply
            0
            • E econy

              Sorry, I mean, I want to send 12007, then 5007, right number after left number.

              C Offline
              C Offline
              chaau
              wrote on last edited by
              #6

              Is it a LIFO pattern? In this case std::stack[^] is your answer

              1 Reply Last reply
              0
              • E econy

                I have an application ,need to read hardware IO, each IO data be coded to an unsigned integer, 4 digits - 7 digits. Quantity of all possible integers is 240, every integer is unique for example:

                1000,1002, 120008, 1318001,14702 , 4003...

                After coding step, the coded integers need to be send out in a sequence.

                12002 <- 4001 <- 10089 <- 5007 <- ...

                Quantity of integers are limited to 128, but, the quantity number is not fixed. Perhaps send-cycle1 is 4 integers, send-cycle2 is 120 integers, send-cycle3 is 2 integers, send-cycle4 is 0 integer. ... And during cycle period, maybe there are duplicated data be read,but, sending sequence should not take duplicated data. Logic is :

                read data -> already in sequence, discard/ new data -> sequence

                I wonder what data structure is good for the above logic and application.

                S Offline
                S Offline
                Stefan_Lang
                wrote on last edited by
                #7

                econy wrote:

                I wonder what data structure is good for the above logic and application.

                The problem in this question is that you didn't actually tell us a lot about the logic and application. You only told us about the scope of input values, and that these values are gathered in batches and processed (filtering out duplicates) before sending out. You didn't tell us if anything of this is time-critical, or you're working with restricted amounts of memory - should we try to optimize for either? Also, is it more important for the receiver to receive the data in a timely manner, requiring on-the-fly processing so you can send out the batch right after the end of the cycle - or can you afford to delay the processing until after receiving the last input of the cycle, before sending it out? The answer to these questions will influence what algorithm to use, and the algorithm will influence what data structures to use.

                GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto) Point in case: http://www.infoq.com/news/2014/02/apple_gotofail_lessons[^]

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups