valueset with a seek method

What would you like to see in CSPro?
Forum rules
New release: CSPro 8.0
Post Reply
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

valueset with a seek method

Post 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
Best
Ari
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: valueset with a seek method

Post 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.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: valueset with a seek method

Post 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;
Last edited by Gregory Martin on November 11th, 2021, 8:50 am, edited 3 times in total.
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Re: valueset with a seek method

Post 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
Best
Ari
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: valueset with a seek method

Post 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
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Re: valueset with a seek method

Post 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.
Best
Ari
Post Reply