Home » U++ Library support » U++ Core » The right container
The right container [message #51177] |
Sat, 16 February 2019 17:54 |
|
koldo
Messages: 3394 Registered: August 2008
|
Senior Veteran |
|
|
I wanted to know the right U++ container for this.
Data type could be int or double.
Container<Data type> dat;
dat.SetCount(300);
dat[23] = 12;
dat.FindAdd(34);
Thank you.
Best regards
Iñaki
|
|
|
|
|
Re: The right container [message #51180 is a reply to message #51179] |
Sun, 17 February 2019 11:00 |
Novo
Messages: 1371 Registered: December 2006
|
Ultimate Contributor |
|
|
koldo wrote on Sun, 17 February 2019 04:35Thank you Novo. But I want to save one data, not two.
In this case
won't work.
An one-value alternative is Index<int>, but you will be unable to write the code line above.
If your range of indices is small and sparse, you can just use regular Vector.
Another approach is to store data in a Vector and sort it, after that you will be able to use algorithms on sorted ranges.
Hope this helps.
Regards,
Novo
|
|
|
|
|
|
Re: The right container [message #51239 is a reply to message #51236] |
Sun, 24 February 2019 18:29 |
|
koldo
Messages: 3394 Registered: August 2008
|
Senior Veteran |
|
|
Hi Mirek
It is used in a program that reads data from different file formats. In one of them the size is known in the beginning and data is filled randomly when reading the file. In other format data is got sequentially and you do not know total size until the end. It is possible to scan the file first to get the dimension, although it is not so efficient and a little more complex.
However do not worry, files are not huge and Vector with FindAdd works adequately.
Best regards
Iñaki
|
|
|
Goto Forum:
Current Time: Sat Sep 21 07:20:10 CEST 2024
Total time taken to generate the page: 0.04545 seconds
|