..array member removal..

BlitzMax Forums/BlitzMax Programming/..array member removal..

Naughty Alien(Posted 2011) [#1]
..hi guys..what would be fastest possible way to remove array member, considering that:

-targeted array member index is not known
-each value stored in array is unique (not equal to any of other array member value)
-known is only value of array member needed to be removed

..passing trough array in order to find value and then remove it from an array is not an option..any other technique maybe ?


ziggy(Posted 2011) [#2]
Is the array sorted?


Naughty Alien(Posted 2011) [#3]
..nope..array is not sorted..


Oddball(Posted 2011) [#4]
If the object only ever has one entry in the array then have it store it's own index in a field.


H&K(Posted 2011) [#5]
The whole thing would be made alot easier if the value at the array could simply be change to NAN (say) rather than needing to remove that entry. (With the MASSIVE resizing overhead)

If the object only ever has one entry in the array then have it store it's own index in a field.
I may have missunderstood, however, I dont believe this will serve any useful purpose. He know the value only, which means once he had looped throu the array to find this value, he knows the index.
Infact I think its nonsensical all the time, the index of an array IS stored in the array as the index, once you know the index of the array whats the point of looking at a field of the array to find its index.

You might mean this;

If the numbers you want to store are consecutive then instead of storing the number in the array you store the index in which the number should be stored.

a[4,5,1,3,2]
This would mean that instead of what convention would say the number 1 ISNT stored in the third space, but rather in the forth space. However for any non trival amount of indexs its still as much work to remove a number as passing thoru the array to find the number and remove that entry.

(And this assumes you Dont bother making the array smaller, just let that entry = nan)

What you need is a map, I think, where the key IS the unique value.

Last edited 2011


Jesse(Posted 2011) [#6]
I am wondering under what circumstances would you have the array element and not the index number?


H&K(Posted 2011) [#7]
I did wonder, but it occurred to me that you might model a pack of cards in an array, then mix them up to give an order. (Not how I would do it, but I hope you will agree possible)

In this case you would know that the 6 of diamonds (eg 6+13*3), exists but would be unsure of its position in the array


Jesse(Posted 2011) [#8]
I did arrays for my solitaire game but I never ran into that problem. Maybe he has a good explanation but from my point of view(which don't mean much) as I see it, it's just bad program logic.

Last edited 2011


Czar Flavius(Posted 2011) [#9]
A map where the key is the object and its value is the index?

targeted array member index is not known - check

each value stored in array is unique - check

known is only value of array member needed to be removed - check


Jesse(Posted 2011) [#10]
yes, but why would you need to put it in a map/key if its in the array?
a more effective way would be what Oddball mentioned and even then I still have my doubts for its preferred use.

there is probably an obvious reason, I just don't see it.
Maybe if Naughty Alien was a bit more specific on what he is doing then maybe I will be able to agree with it.

Last edited 2011


H&K(Posted 2011) [#11]
A map where the key is the object and its value is the index?
Thats what I said ;)
What you need is a map, I think, where the key IS the unique value
Once we do that we dont need the array or the index anymore thou.

Jesse you are not the only one who thinks its bad design.

However as theory practice, I think we can say that the breif cannot be met, to be able to do it at all he needs to loop through the array each time. OR he need to dump the array and use a map.

[Some of the newer posters I think we should ask "Have you turned it on and off again", but someone of NAs posting length I think we have to assume that he knows its a really bad design and jump in after "have you updated the drivers]

Last edited 2011


Yeshu777(Posted 2011) [#12]

Jesse you are not the only one who thinks its bad design.



I think a little more info on what NA is trying to achieve would probably give more guidance.


Naughty Alien(Posted 2011) [#13]
..well..yes, Jesse made a point, but, put it on this way, I have no way to affect or control extracted array data or its creation process, I simply receive it as it is and that's all i have, data wise..its some data stream from CNC machine, so given data is something i simply cant control on any way, during creation, but just receive it in form as i have described already..