Page 1 of 1

valueset with a seek method

Posted: November 10th, 2021, 9:14 am
by AriSilva
Hi folks,
I´m building a valueset on the fly, depending on a large list of elements. The real example is I have a list of sector tracks, and each sector belongs to a certain STRATA. I want to build the valueset of all the stratas of a certain area, but as they appear several times in the list, I have to check if the strata is already in the valueset before adding it. And this is not possible since it does not have the seek method as the "regular" lists.
So, to circumvent the problem I have to create a temporary list with the possible values, and then, at the end, copy them to the final valueset.
Is there another solution for this tiny problem?
Best
Ari

Re: valueset with a seek method

Posted: November 10th, 2021, 10:03 am
by aaronw
My approach would be similar to yours. I might loop through the large list and construct a list of seen strata. For each next strata in the large list, I would call a user-defined function that checks whether the strata is in my constructed list or not. If it is then skip the strata, otherwise add it.

I don't believe a seek method adds any functionality that can't already be done with a loop. A seek method is maybe a little more convenient.

Re: valueset with a seek method

Posted: November 10th, 2021, 7:36 pm
by Gregory Martin
There is a seek method for value sets, you just have to access the underlying codes list. For example:
if vs.codes.seek(5) = 0 then
   
vs.add("Five", 5);
endif;

Re: valueset with a seek method

Posted: November 11th, 2021, 6:43 am
by AriSilva
Thanks, Greg and aaronw, I agree with those comments of yours, although the valuset.seek is neater, And more integrated with the list methods.
And Greg, by the way, in your example, don´t you think it should have a "not" in the seek checking?
if not vs.codes.seek(5) then
vs.add("Five", 5);
endif;
Best
Ari

Re: valueset with a seek method

Posted: November 11th, 2021, 8:48 am
by Gregory Martin
Right, I'll change the example.

Another way to conveniently keep track of additions would be to use a hashmap with the hashmap.contains function: https://www.csprousers.org/help/CSPro/h ... ction.html

Re: valueset with a seek method

Posted: November 14th, 2021, 9:48 am
by AriSilva
I really did not played with hashmaps, I´m still in the "lists" era, migrating from the arrays jurassic park erea.
Looking at the documentation now I can see lots of possibilities of using the hashmaps instead of lists/arrays.
Thank you very much to point me that way.