Re: Which STL should I use?




"Alex Blekhman" <xfkt@xxxxxxxxx>
???????:eugkmvNAHHA.5060@xxxxxxxxxxxxxxxxxxxxxxx
"Jacky Luk" wrote:
In this situation, which STL component should be used?

Two corrections. STL is an old name that stands for "Standard Template
Library". Many people still use it, however, the correct term is "Standard
C++ Library". Also, the correct term is "container", not "component".
Standard C++ Library can be divided into four major logical parts:

0. C Runtime Library. The legacy inherited from C language. It contains
functions like "fopen" and "printf".

1. Containers and iterators. This part comprises of classes, which
allow to store user defined objects in collections. Examples: std::vector,
std::list, std::map. Various iterator classes allow to manipulate content
of containers.

2. Algorithms. This part contains useful implementations of popular
algorithms. These algorithms work on containers using iterators. Examples:
std::copy, std::find, std::count.

3. Streams. This part was standalone addition to STL until recently.
Now streams are part of Standard C++ Library. Streams allow to perform
input/output operations. Examples: std::ofstream, std::strstream.

Here's entry point for Standard C++ Library in MSDN:

"Standard C++ Library Reference"
http://msdn2.microsoft.com/en-us/library/cscc687y(VS.80).aspx

1) add/update records quite frequently, but only when the program
initializes.

Not enough information. std::list allows fast addition/removal of elements
but slow random access to an element. std::vector provides fast access to
an element but slow addition/removal (especially in the middle and
beginning of container). std::deque tries to take best of both worlds
providing relatively fast access to an element and addition/removal
from/to ends of container.

2) need to compare values with older records, almost always

It depends on an object. If contained object is trivial, then sometimes
simple call to memcmp on two vectors will do the job. With other
containers you will need to compare each element with the other.

3) need direct access all the time

Fast random access is the advantage of std::vector and std::deque
containers.

I have been struggling with lists and maps?
Or there is a better solution?

What are criterions of better solution? Access speed? Memory layout?
Other?

I need fast access speed while allow a sorted list of data
say
std::map<string, id> mapdata

Initialization:
mapdata[string("Keanu Reeves")] = 1;

Finding items with hi speed
artist = mapdata.find (1);

That's all I need to do!
Thanks





HTH
Alex


.



Relevant Pages

  • Re: Tuna fish
    ... It has been at least a year since I've purchased tuna. ... The cans have ... (i also only just recently noticed the rectangular plastic lidded containers ... standard package sizes, to be accompanied by howls of rage by the ...
    (rec.crafts.metalworking)
  • Re: Unified Ada library
    ... :> developers who think that the STL could only have been written in C++, ... Could you comment on the importance of iterators and generic ... we cannot present a standard interface to containers ...
    (comp.lang.ada)
  • Re: diffrences between compilators
    ... |>|>| The STL is the STL is the STL. ... |>| algorithms portion of the C++ Standard Library" than it is with just "The ... | The portion of the standard C++ library concerning containers, ... Vendors like STLport, SGI, and Dinkumware offer such libraries. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Newbie question :) be kind...
    ... measuring system as a thing in itself, ... Consider the standard intermodal shipping containers. ... I liased with New Zealad Railways to move containers around the country. ... Most tunnels would clear the ...
    (rec.models.railroad)
  • Re: Identifying potions from memory
    ... The modern world comes with labels because the containers are all standardised and repeatedly purchased with the product. ... Same for potions, really. ... you'd find it even more likely that there might not be a standard labelling system. ...
    (rec.games.frp.dnd)