473,695 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fast linked list

Hi,

for my current application, I need a linked list in which I can access and
walk through at highest speed possible - adding/deleting/inserting elements
can be as slow as necessary. Now, which template out of the C/C++ standard
library should I use for this - std::list? Or is there a better
implementation out there?

thanks
Peter
Nov 17 '05 #1
14 1516
I would suggest using a CList object.

"Peter Schmitz" wrote:
Hi,

for my current application, I need a linked list in which I can access and
walk through at highest speed possible - adding/deleting/inserting elements
can be as slow as necessary. Now, which template out of the C/C++ standard
library should I use for this - std::list? Or is there a better
implementation out there?

thanks
Peter

Nov 17 '05 #2
Write your own... check CTypedPtrList if you need a little backup on it...
Its by far the best I have used without the need to bolt on extensions to
the classes.

- MR

"Peter Schmitz" <Pe**********@d iscussions.micr osoft.com> wrote in message
news:28******** *************** ***********@mic rosoft.com...
Hi,

for my current application, I need a linked list in which I can access and
walk through at highest speed possible - adding/deleting/inserting
elements
can be as slow as necessary. Now, which template out of the C/C++ standard
library should I use for this - std::list? Or is there a better
implementation out there?

thanks
Peter

Nov 17 '05 #3
Peter Schmitz wrote:
Hi,

for my current application, I need a linked list in which I can
access and walk through at highest speed possible -
By 'access' do you mean 'traverse' as in:

for( container::iter ator lItr = c.begin() ; lItr != c.end() ; ++lItr )
{
// do something with *lItr
}

adding/deleting/inserting elements can be as slow as necessary. Now,
These usage patterns do not require a linked list.
which template out of the C/C++ standard library should I use for
this - std::list? Or is there a better implementation out there?


std::vector would be a better option given your usage patterns, with the
added benefit of less memory consumption and fragmentation.

Jeff Flinn
Nov 17 '05 #4
Exactly. In my program I have to walk the complete linked list, beginning at
the head, then moving on to the next item until I reach the last item
(there's no need for random access to any items). This 'walking' and
accessing the structure behind the items needs to be as fast as possible.
Merry Christmas
Peter
"Jeff F" wrote:
Peter Schmitz wrote:
Hi,

for my current application, I need a linked list in which I can
access and walk through at highest speed possible -


By 'access' do you mean 'traverse' as in:

for( container::iter ator lItr = c.begin() ; lItr != c.end() ; ++lItr )
{
// do something with *lItr
}

adding/deleting/inserting elements can be as slow as necessary. Now,


These usage patterns do not require a linked list.
which template out of the C/C++ standard library should I use for
this - std::list? Or is there a better implementation out there?


std::vector would be a better option given your usage patterns, with the
added benefit of less memory consumption and fragmentation.

Jeff Flinn

Nov 17 '05 #5
"Peter Schmitz" <Pe**********@d iscussions.micr osoft.com> wrote in message
news:28******** *************** ***********@mic rosoft.com...
Hi,

for my current application, I need a linked list in which I can access and
walk through at highest speed possible - adding/deleting/inserting elements can be as slow as necessary. Now, which template out of the C/C++ standard
library should I use for this - std::list? Or is there a better
implementation out there?

thanks
Peter


CTypedPtrArray.

You can append, insert, delete (which are slow) and of course append.

Storing data as pointers minimizing assignment time.

You can binary search if you keep it sorted and you feel that's necessary.

I would imagine iterating would be very fast, although I've never compared
it to, say, CTypedPtrList.

I'm sure there are equivalent standard template library types out there.
Nov 17 '05 #6
Why don't you just use an array?

"Peter Schmitz" <Pe**********@d iscussions.micr osoft.com> wrote in message
news:28******** *************** ***********@mic rosoft.com...
Hi,

for my current application, I need a linked list in which I can access and
walk through at highest speed possible - adding/deleting/inserting
elements
can be as slow as necessary. Now, which template out of the C/C++ standard
library should I use for this - std::list? Or is there a better
implementation out there?

thanks
Peter

Nov 17 '05 #7
Ever tried adding things to a static array?...

- MR

"Bonj" <a@b.com> wrote in message news:32******** *****@individua l.net...
Why don't you just use an array?

"Peter Schmitz" <Pe**********@d iscussions.micr osoft.com> wrote in message
news:28******** *************** ***********@mic rosoft.com...
Hi,

for my current application, I need a linked list in which I can access
and
walk through at highest speed possible - adding/deleting/inserting
elements
can be as slow as necessary. Now, which template out of the C/C++
standard
library should I use for this - std::list? Or is there a better
implementation out there?

thanks
Peter


Nov 17 '05 #8
Mark,
Why don't you just use an array?


Ever tried adding things to a static array?...


Ever hear of dynamically allocated arrays?

I agree with Jeff F - if neither adding or removing elements have any speed requirements, why not just go with a vector? I don't think you can find any container with faster end-to-end traversal.

--
Best regards,
Kim Gräsman
Nov 17 '05 #9
Of course,

However, in my experience allocating large chunks of memory and copying the
contents is a hidiously slow process compared to a linked list.

While I understand that end-to-end enumeration is speed critical, this leads
me to presume that there must be a large amount of data and as such, arrays
would be somewhat slow in the process of adding. While not an essential
requirement as stated it must be considered for over-all system performance.

Typically, with some form of LL | DLL implimentation you already have your
next location available from the last, or you must call a function
(CTypedPtrList) .

I agree, vector would be quick, provided you allocated sufficent space
beforehand for all the elements because as you know, in such an event the
old array is deallocated and a new one is created each time.

While I understand LL's are my personal preference for situations like this,
as the processor (at least Intel) seems to work best allocating small
amounts of memory rather than huge chunks of it. But that is for the most
part irrelevant in this case.

As far as vector goes, yes, useful - its speed is in its pointer addition.
However, for end-to-end, you already know the next item of a Purely Linked
List as soon as you have the previous one, there is no need to recalculate
it from the base. Downside, an extra 4 bytes (LL) or 8 bytes (DLL).

- MR

"Kim Gräsman" <ki*@mvps.org > wrote in message
news:Oc******** ******@TK2MSFTN GP15.phx.gbl...
Mark,
Why don't you just use an array?


Ever tried adding things to a static array?...


Ever hear of dynamically allocated arrays?

I agree with Jeff F - if neither adding or removing elements have any speed
requirements, why not just go with a vector? I don't think you can find any
container with faster end-to-end traversal.

--
Best regards,
Kim Gräsman
Nov 17 '05 #10

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

Similar topics

5
859
by: Dream Catcher | last post by:
1. I don't know once the node is located, how to return that node. Should I return pointer to that node or should I return the struct of that node. 2. Also how to do the fn call in main for that LOCATE subroutine that returns a node???? Any help would be appreciated. Thanks
8
2887
by: Neil | last post by:
I have a very puzzling situation with a database. It's an Access 2000 mdb with a SQL 7 back end, with forms bound using ODBC linked tables. At our remote location (accessed via a T1 line) the time it took to go to a record was very slow. The go to mechanism was a box that the user typed the index value into a combo box, with very simple code attached: with me.RecordsetClone .FindFirst " = " & me.cboGoTo If Not .NoMatch Then Me.Bookmark...
10
15125
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy *enemydata; // Holds information about an enemy (in a game) // Its a double linked list node
6
4596
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any potential pitfalls I'd be extremely grateful. Cheers Steve
7
7406
by: simkn | last post by:
Hello, I'm writing a function that updates an array. That is, given an array, change each element. The trick is this: I can't change any elements until I've processed the entire array. For example, the manner in which I update element 1 depends on several other (randomly numbered) elements in the array. So, I can't change an element until I've figured out how every element changes.
12
3945
by: joshd | last post by:
Hello, Im sorry if this question has been asked before, but I did search before posting and couldnt find an answer to my problem. I have two classes each with corresponding linked lists, list1 and list2, each node within list1 has various data and needs to have a pointer to the corresponding node in list2, but I cant figure out how to do this. Could someone explain what I might be missing, or maybe point me in the direction of a good...
19
5416
by: Juha Nieminen | last post by:
If I'm not completely mistaken, the only reason why std::list::size() may be (and usually is) a linear-time operation is because they want std::list::splice() to be a constant-time operation, and if you execute the latter, the size of the resulting lists cannot be known without explicitly counting the sizes of the new lists. I was thinking: What if size() was an O(n) operation only *after* a splice() operation has been performed (and...
0
8625
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be anything from a short integer value to a complex struct type, also has a pointer to the next node in the single-linked list. That pointer will be NULL if the end of the single-linked list is encountered. The single-linked list travels only one...
7
5768
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it compiled no problem. But I can't find the what the problem is with templates? Please help. The main is in test-linked-list.cpp. There are two template classes. One is List1, the other one is ListNode. The codes are below: // test-linked-list.cpp :...
0
8623
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8562
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
9113
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8976
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
8830
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
7655
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6488
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
4339
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2265
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.