02-26-2024 04:51 PM
Sorry if this already exists, can't search the forums for some reason.
In addition this may be a unique use case that is normally not needed.
For my use case, I just wanted the first element of a set, I did not care for its value, just the first element so I could operate on it. I realized there is no "Index Map/Set" analogous to the "Index Array" function, so attached is a VIM that mimics "Index Array" for maps and sets. It is 0 based just like the Index Array Function, that is, index 0 gives the first element.
Version 2021 attached. (It can be improved but here's a first pass. For example specifying an index greater than the size of the set/map will return the last element of the set/map.)
02-26-2024 05:37 PM
@mcduff wrote:
It can be improved but here's a first pass. For example specifying an index greater than the size of the set/map will return the last element of the set/map.
It already does this since the For loop won't run for more iterations than the autoindexing tunnel, regardless of the N input.
I'm curious though- what's your use case for needing a certain numbered element in a Set or Map? I could see the use case of running through each element in a set/map one at a time, but converting it to an array handles that just fine. I'm sure there's some use case I haven't thought of though.
02-26-2024 05:53 PM - edited 02-26-2024 05:57 PM
@BertMcMahan wrote:
It already does this since the For loop won't run for more iterations than the autoindexing tunnel, regardless of the N input.
I thought if you specify an out of bounds index for Index Array it returns the "default Value".
@BertMcMahan wrote:I'm curious though- what's your use case for needing a certain numbered element in a Set or Map? I could see the use case of running through each element in a set/map one at a time, but converting it to an array handles that just fine. I'm sure there's some use case I haven't thought of though.
My use case could also probably be improved. I have a Array of Files that need to be processed. While they are being processed newly generated files could be added to the array for processing. So I was trying to think of the easiest way to keep track of files that I processed while also adding to the array, so I decided to make a "Set of Files". If there are new files, I could add to the set, and after processing a file I could remove it from the set. I did not want to remove items from the "Path Array" as that is used for a UI display among other things. I could keep track of items processed but it seemed simpler to make a set and process till it was empty; a map with processed flag would also work. So I did not need a key, only an index. (That would also be true also if using a Map with a processed flag.) But as said earlier there is probably a better way.
EDIT: I don't think I answered your question. I don't want a FOR loop going through the whole array and processing everything. I want to process 1 element at a time, then decide what to do next, that is, process another file, add more files to be processed, exit the loop, etc.
02-26-2024 06:37 PM - edited 02-26-2024 06:38 PM
If you just want to pull a single value from the set and you don't care which one, you could use 'Read Set Max & Min' and then remove that value from the set.
02-26-2024 06:42 PM
@Lavezza wrote:
If you just want to pull a single value from the set and you don't care which one, you could use 'Read Set Max & Min' and then remove that value from the set.
Clever use. Did not think of that.
02-27-2024 11:09 AM
@mcduff wrote:
@BertMcMahan wrote:
It already does this since the For loop won't run for more iterations than the autoindexing tunnel, regardless of the N input.
I thought if you specify an out of bounds index for Index Array it returns the "default Value".
D'oh, I misunderstood your post. I thought that was your desired modification, not your description of the current behavior. You are correct that it returns the default value.
Would a queue perhaps meet your needs? I doubt speed is an issue, since it sounds like your bottleneck is the file processing, but converting the set to an array over and over each time seems like a waste. Then again the compiler may be able to do some tricks to not actually need to copy any memory over.