Re: ID scanner
On Jan 27, 5:47 pm, Chunekit Pong <worlman...@yahoo.com> wrote:
this is a general question in which i already have driver to get all
the IDs stream, I just need algorithm to assign timestamp to each IDs
OK. That wasn't very clear. I'm still not sure exactly what sort of
math you are trying to do on the timestamps, but T. Beckmann has
already given some ideas.
If I'm understanding correctly, maybe you could keep the regular map:
std::map<ID,timestamp>
Everytime you see the ID, update the timestamp, and also throw an
entry onto a separate queue (ID,timestamp).
so, if the IDs came in this order (with time stamp)
A,0
B,0
A,1
A,2
A,3
you'd have a map with two elements (A,3), (B,0).
Also, you'd have your list that had all of these element pairs.
Let's say, you want to drop any ID that has been gone for 3 seconds.
Then at every second, look at the front of the queue, and pop off
every element where timestamp is currentTime - 3. (in this case (A,0)
and (B,0).
For each of them, do a map look-up, and if m_map[ID] also equals
currentTime - 3, then remove it from the map.
in pseudocode:
const int dropDuration = 3;
while(currentTime - dropDuration >= queue.front().timeStamp)
{
if(queue.front().timeStamp == m_map[queue.front().ID]) { //
remove map element }
queue.pop();
}
Joe C