Jump to content

Deleting elements from an array


Recommended Posts

arSomeArray[2][15] == arSubArrayA

arSomeArray[2][20] == arSubArrayB <---- trying to delete this

arSomeArray[2][25] == arSubArrayC

 

I want the result to be

arSomeArray[2][15] == arSubArrayA

arSomeArray[2][25] == arSubArrayC

 

(side note the 15, 20, and 25 are keys to a map array so those keys don't change like a regular array would and I can have the skips in numbers)

 

 

IF I wanted to delete that entry,

should I....

let arSomeArray[2][20] := ar_null <--- if I am understanding this right... I am Nulling out the arSubArrayB

ar_erase arSomeArray[2] 20 <--- now I am erasing the Key

 

 

or just...

ar_erase arSomeArray[2] 20

 

 

 

I've tried both ways and don't get an error

I've done this as well

short vCount

let vCount := ar_erase arSomeArray[2] 20

msgex "vCount = %g", vCount

 

But it returns a 1 either way.

 

I don't want to end up in a situation like this

arSomeArray[2][15] == arSubArrayA

(nothing) == arSubArrayB <---- this sub array still exists but it don't have an 'owner?' so to speak and no way to erase it any more

arSomeArray[2][25] == arSubArrayC

Link to comment
Share on other sites

(if memory serves...)

 

ar_erase arSomeArray[2] 20 <--- now I am erasing the Key

 

Removes the entry (both key and value). As I understand it, this is what you want

 

 

let arSomeArray[2][20] := ar_null <--- if I am understanding this right... I am Nulling out the arSubArrayB

 

This does not change the array. arSomeArray[2][20] remains in the array, now pointing to a null array.

If this entry was the last reference to arSubArrayB, it will be destroyed. If not, arSubArrayB will continue to exist and other references to it continue to be valid.

This is not necessary if you use ar_erase arSomeArray[2] 20

 

let vCount := ar_erase arSomeArray[2] 20

 

ar_erase returns the number of entryes deleted. E.g. ar_erase arSomeArray[2] 16:99 would return 2 after erasing the two elements in that range (15 and 25)

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...