Hello,
I am trying to build a dynamic set/list of data which should be sorted
as each element is inserted. The main criteria in this list is the
speed, the time it takes to insert a element, and the time it takes to
retrive it. Therefore I was wondering between STL Vectors, Maps, and
Set, what would be the most efficient way to do this, and how can it
be done easily.
Also, if I were to use STL Vectors, is there anyway that I can get the
desired functionality of sorting on insertion, with efficiency.
Thanks,
Kushal 2 4939
Kushal wrote in news:4b**************************@posting.google.c om: Hello,
I am trying to build a dynamic set/list of data which should be sorted as each element is inserted. The main criteria in this list is the speed, the time it takes to insert a element, and the time it takes to retrive it.
Unfortunatly you "main criteria" it 2 criteria you should realy decide
which is most important.
Therefore I was wondering between STL Vectors, Maps, and Set, what would be the most efficient way to do this, and how can it be done easily.
The only real difference between a map and a set is wether you
want to store a single object/key (std::set) ar a key an a value
(std::map) otherwise they have identical insert and search capabilities. Also, if I were to use STL Vectors, is there anyway that I can get the desired functionality of sorting on insertion, with efficiency.
Yup, but you have to do a binary search on the vector which has
the same complexity as set/map's insert, so you gain nothing,
additionally you have to copy elements that have already been
inserted "out of the way", so you end up with something worse
than using set/map.
HTH.
Rob.
-- http://www.victim-prime.dsl.pipex.com/
On 30 Jan 2004 07:45:01 -0800, ku************@hotmail.com (Kushal)
wrote: Hello,
I am trying to build a dynamic set/list of data which should be sorted as each element is inserted. The main criteria in this list is the speed, the time it takes to insert a element, and the time it takes to retrive it. Therefore I was wondering between STL Vectors, Maps, and Set, what would be the most efficient way to do this, and how can it be done easily.
std::set is tailor made for this. It is likely to be the most
efficient container when insertions are common, although lookup speed
is slower than for vector. Also, if I were to use STL Vectors, is there anyway that I can get the desired functionality of sorting on insertion, with efficiency.
Not with much efficiency, no. You can find the place to insert using
std::lower_bound (O(log n)), but then inserting the element is (O(n))
in assignments or similar.
You could have a vector to store the elements in in insertion order,
and then a vector of indices into that vector that you keep in the
sort order. That's a possibility if your elements are expensive to
copy.
Tom
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: spar |
last post by:
I'm converting a Perl script to Python and have run into something I'm
not sure how to do in Python.
In Perl, I am running through a couple loops and inserting values
directly into a complex...
|
by: John |
last post by:
Hi:
I'd like to implement a simple map, which is a 2-D plane with many
points, e.g., 100. The points are not evenly distributed, i.e., some
points may have two neighbor points; some may have 5...
|
by: Raghavendra Mahuli |
last post by:
i need to store a lot of integers(say 10,000) in a datastructure.
The constraints are:
1. It should be fast.
2. It should be orderded or sorted.
3.Insterting and deleting should be fast.
4. The...
|
by: Curious |
last post by:
Hi,
I am searching for a data structure that stores key-value pairs in it.
This data structure is to hold large amounts of key-value pairs, and so
needs to be efficient both in insertion and...
|
by: dtefran3 |
last post by:
The problem
Implement a SortedList class which stores a list of int data in ascending order.
Program requirements
The public interface of your class is as follows:
class SortedList{
public:...
|
by: sakcee |
last post by:
Hi
I hope that I can learn from your experience . I want to know if you
have seen a perticular problem and used a perticular data structure ,
and why?
I usually end up using just arrays,...
|
by: desktop |
last post by:
In the C++ standard page 472 it says that you can construct a std::set
in linear time if the constructor gets a sorted sequence of elements.
But how is this possible when insert takes logarithmic...
|
by: KevinADC |
last post by:
Introduction
In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
|
by: Harold Howe |
last post by:
Howdy all,
The msdn help says this about SorteList<k,v>:
"If the list is populated all at once from sorted data, SortedList is
faster than SortedDictionary."
My question is this: how do I...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
| | |