dynamic list (variable size)
Hello,
I have a list of scalars with unknown size at declaration time. During the simulation I want to remove given elements from the list at different times. I know that you can define a DynamicList (DynamicList<scalar> test;) and then add some values (test.append(value)), clear the list (test.clear()) or maybe delete the last introduced value. The thing is if I need to delete some elements from the list It occurs to me to make a temporal copy with the new size or something like that. So my question is... what is the best strategy to declare a list of scalars which is expected to delete some given elements (and then varying the size of the list)? How can I do it effectively? Thank you in advanced. Regards. edit: the post is similar was treated before here and there's an interesting reply: Quote:
|
Depends. What is the size of your list, how often will you be deleting elements and how many will you remove?
|
Hello Laurance.
The list has a size in a range 100-1000 and I need to remove 1 element each time I check a condition. Every timestep It can happen for around 10-70% of the size of the list. (Eg: size 300, 40 elements to remove in a timestep). Thank you for your hints. |
That's quite small. I'd either use a HashTable if you have to remove elements individually, or if you can remove them as a block then do this:
Code:
PackedBoolList elemToRemove(l.size()); |
I don't have experience using HashTable, I actually need to remove elements individually from Dynamic and Sortable lists. I'm going to review everything with this new feedback.
Thanks. |
Here is how I did it to have a pairs of labels and scalars defined as a HashTable. With this new method I can efficiently remove an element. There's a strange issue, I'm using the findLower function but the problem comes when I erase a element of the HashTable the findLower still points to the removed index. I have checked that the element was erased correctly (apparently at least debugging) and the the size reduced.
I show an example: Code:
HashTable<scalar, label> testHash_; Code:
testHash: The topic of the post has been resolved for me, thank you very much! Still I have that thing but maybe I made a mistake. |
All times are GMT -4. The time now is 11:07. |