This offering is not approved or endorsed by Silicon Graphics International Corp.,
the producer of the OpenFOAM® software and owner of the OpenFOAM® trade mark.
top
logo


Welcome, Guest
Please Login or Register.  Lost Password?
Core Development Group Forum: The nuts and bolts of OpenFOAM®: underlying architecture, software engineering, basic operations
Go to bottomPage: 1
TOPIC: DLList [] operator
#4
DLList [] operator 1 Year, 10 Months ago Karma: 0
DLList<Type T> is weird. If I want to access the n-th item, I can't use the [] operator because its not implemented (scalar for an example):

Code:


DLList<scalar> myDynamic;

myDynamic.append(1);
myDynamic.append(2);
myDynamic.append(3);
...



If i do this for the 2nd item:
Code:

Info << myDynamic[2] << endl; 


it breaks....

so I need to go like this for the n-th item:

Code:


DLList<scalar>::const_iterator myIt = myDynamic.begin()
for (label i = 0; i < n; i++,++myIt); 

Info << *myIt << endl;



This works and will write out the n-th element on the screen. This is inherent to the linked lists, I know, but would it be a good thing if a method [] is added that does this thing? It would reduce code duplication.
Tomislav Maric
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#8
Re:DLList [] operator 1 Year, 10 Months ago Karma: 0
Hi tomislav,

isn't the entire point of a linked list to access the data not through a random access [] operator but through the "linking" ?
If you need to use the [] operator then I think you are probably using the wrong container for your application. Please correct me if I am wrong.

Jacques
Jacques Papper
Fresh Boarder
Posts: 1
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#9
Re:DLList [] operator 1 Year, 10 Months ago Karma: 0
Hi jackpap,

the thing is that I have variable data that needs to be stored, so there is no point in allocating a huge chunk of memory. The objects I'm storing have certain data that are used for calculations and for object recognition. The other way would be to waste a LOT of memory (create a HUGE list and then use [] on this list, which then resized dynamically, or a surplus is left).

Besides, how would a user find a specific item in the LList by (some) value it holds? He would have to traverse the list anyway (which my code snippet is doing). This then imposes a conclusion that if I have dynamically allocated memory whose size depends on my CFD code, I can never access anything in the middle of the list [for the beginning and the end I have the first() and the last method()]. With DLList I'm storing exactly the number of items I need. This is usually less then 10% of the data in needed for the static List (to be sure that everything will fit).

The [] operator (it is defined the way it is allowed to be, of course) v.s. having to allocate an order of magnitude more memory. Or are the LLists just to be used as a part of some heap/stack functionality?
Tomislav Maric
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#49
Re:DLList [] operator 1 Year, 7 Months ago Karma: 1
What you're looking for is a HashTable. Pretty much mature stuff that's been around for quite a while.
Sandeep Menon
Fresh Boarder
Posts: 8
graphgraph
User Offline Click here to see the profile of this user
Sandeep Menon
University of Massachusetts Amherst
The administrator has disabled public write access.
 
Go to topPage: 1
Joomla SEO powered by JoomSEF


bottom
top

OpenFOAM®-Extend World

You need to upgrade your Flash Player

bottom
Legal | Imprint
©Copyright 2012 The OpenFOAM® Extend Project 

Powered by Joomla! Designed by Joomla Templates, ecommerce web hosting, Thanks to J! Developer Goran Gligorin for support! Joomla SEF URLs by Artio. Powered by Staff Master v0.9.8 Valid: XHTML and CSS

Friends Online