473,657 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7808
On Dec 10, 4:16 am, Spoon <root@localhost wrote:
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::iter ator 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
1915
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 = CiDict() >> d 12
2
8995
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. I've compared that to a platform depended solution (i tried to use a MS Window pipe in the same process to create a fifo and it's very faster). Many thanks Michele Moccia --
8
14193
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, there are ten characters in the
5
3262
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 when the text size gets too big I truncate the string and re-set the TextBox.Text property. This solution is very crappy as it creates a flickering scroll bar when I re-set the text. Scrolling is also difficult because the position in the text...
28
3864
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 realloc it for the size of the what is being written each time? In other words, what is the decision factor between deciding to use a fixed size buffer or allocating memory space and reallocing the size? I don't think the code below is optimal...
3
2495
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 samples a second. I'm a new C#/managed/.NET developer, so pardon me if I don't understand some principals. A friend recommended I look into a queue, but the overhead involved in queuing up the incoming lines, converting them to an array, then...
5
4387
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 data structure. The program needs to be able to add elements to the end of the queue, tell the value of the oldest element and remove from the queue. The capacity n of the ring buffer is 10000 elements. The program must handle the following...
36
3795
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 to read text or handle arrays of arbitrary length. I don't have the expertise in C of many folks here so I feel like I'm offering a small furry animal for sacrifice to a big armour plated one... but will offer it anyway. Please do suggest...
40
7973
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 have solved this problem of stock calculation. i need help for that too. I am using vb express and MsAccess as database. I am trying to write a query for the calculation of Stock. My tables are as under: PurchaseTable(PTId, PDate,ItemId,...
0
8312
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.