473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

FIFO buffer with fast lookup

Hello,

I'm wondering whether the STL defines a data structure with
the following features:

o provides push_front() and pop_back() (like std::list) to
implement a FIFO buffer.

o allows fast lookup (like std::map) so I can easily search
for a specific item in the buffer.

I suppose I could always use std::list and write my own search
function, but I'm asking in case I've overlooked something.

(The keys would be int, and the values would be character arrays.)

Regards.
Dec 10 '07 #1
2 7789
On Dec 10, 4:16 am, Spoon <root@localhostwrote:
Hello,

I'm wondering whether the STL defines a data structure with
the following features:

o provides push_front() and pop_back() (like std::list) to
implement a FIFO buffer.
Look at std::queue (http://www.sgi.com/tech/stl/queue.html),
std::deque (http://www.sgi.com/tech/stl/Deque.html).
o allows fast lookup (like std::map) so I can easily search
for a specific item in the buffer.

I suppose I could always use std::list and write my own search
function, but I'm asking in case I've overlooked something.

(The keys would be int, and the values would be character arrays.)

Regards.
Mixing FIFO and searching is rather strange. Standard STL containers
supports generic search algorithms, you can use on of them or write
your own. However, you may also use multiple containers. For example,
store your data in std::queue and provide some std::set or
std::hash_set for fast lookup.

Vlady.
Dec 10 '07 #2
Spoon wrote:
I'm wondering whether the STL defines a data structure with
the following features:

o provides push_front() and pop_back() (like std::list) to
implement a FIFO buffer.

o allows fast lookup (like std::map) so I can easily search
for a specific item in the buffer.

I suppose I could always use std::list and write my own search
function, but I'm asking in case I've overlooked something.
You could use a pair of containers, something like:

class fifo_map {

typedef std::list< item_type item_fifo;
typedef std::map< key_type, item_fifo::iterator lookup_table;

item_fifo the_fifo;
lookup_table the_table;

public:

void push_front ( key_type const & key, item_type const & item ) {
the_table[ key ] = the_fifo.insert( the_fifo.end(), item );
}

};

Note that iterators into a list are not invalidated by adding and removing
other elements.

If the map from keys to items is not unique, you would have to use a
multimap. Of course, hash-maps would also work.
Best

Kai-Uwe Bux
Dec 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Ville Vainio | last post by:
I need a dict (well, it would be optimal anyway) class that stores the keys as strings without coercing the case to upper or lower, but still provides fast lookup (i.e. uses hash table). >> d...
2
by: Michele Moccia | last post by:
How can I implement a "time critical" fifo in c++ ? I just have to manage sequences of raw bytes, no user defined types. An std::queue<unsigned char> or std::deque<unsigned char> seems to be slow....
8
by: Jack | last post by:
I want to implement a fixed-size FIFO queue for characters. I only want to use array not linked list. For example, const int N = 10; char c_array; The question is when the queue is full,...
5
by: Dinsdale | last post by:
I have an application that recieves text data via external input (i.e. serial) and displays it on the screen (we use carraige return as a delimiter). At this point I use a regular old text box and...
28
by: bwaichu | last post by:
Is it generally better to set-up a buffer (fixed sized array) and read and write to that buffer even if it is larger than what is being written to it? Or is it better to allocate memory and...
3
by: Polatrite | last post by:
I'm working on a project currently that needs to have a fast FIFO text box that displays output from a serial device. It also needs to have fast refresh rate as the data can stream in at about 50...
5
by: akenato | last post by:
Hi for me this is th first time that I use c++. I have to do this exercise. Somebody can help me? Thanx. Implement a FIFO-queue ( first in, first out ) as a ring buffer. Use a static array as the...
36
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used...
40
by: sazd1 | last post by:
Hi Student2 I am working on similar kind of thing for stock calculation but could not find any solution to my problem even after putting my problem to different forums. I saw your post that you...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.