Jump to content
Sign in to follow this  
tradingcube

Using Arrays with no duplicated values

Recommended Posts

Hello, i'm new houdini, new to vex and not done any programming for a long time (most of the forum sighs)

Coming from a 3DS Max background I’m absolutely loving Houdini, and can really see the power VEX can have so trying to focus a good chunk of my learning time to get comfortable with it right from the start.

I've been building a very simple point infection model to get familiar with the various bits and pieces.

As part of this I’ve been storing point numbers to an array, using this in a solver and each frame more pt number get added. The only way i could see to do this was to take two arrays, combine them and then deduplicate, but this seemed a bit long winded and not very efficient. Searching around Stack overflow I noticed that in Javascript there was a find function and also this exists in VEX so instead have now used that to search the array and add any unique points on-the-fly.

I guess my question is whether this is actually the best way to do this?

It's little frustrating that find() isn’t listed on the https://www.sidefx.com/docs/houdini/vex/arrays.html page as I’d have probably tried it sooner. Which is why I’m wondering if there is a reason it's not on there?

Sorry bit long winded and hope this makes sense

These are the two options ive used:

using Find() and only writing if not already in the array

i[]@pointsArray1 = {0,2,7,8,10};
i[]@pointsArray2 = {0,3,5,7,8,11,15,16,10};

for (int i=0; i<len(i[]@pointsArray2);i++){
    if (!(find(i[]@pointsArray1, i[]@pointsArray2[i])>=0)) {
         push(i[]@pointsArray1,i[]@pointsArray2[i]);
    }
}

De duplicating the array post

i[]@pointsArray1 = {0,2,7,8,10};
i[]@pointsArray2 = {0,3,5,7,8,11,15,16,10};
i[]@newArray;

foreach (int num; i[]@pointsArray1){
    for(int i = 0; i<len(i[]@pointsArray2);i++){
        if(num == i[]@pointsArray2[i]){
        push(i[]@newArray,i[]@pointsArray2[i]);
        }    
    }
}

push(i[]@pointsArray1,i[]@pointsArray2);

for(int i = 0; i<len(i[]@newArray);i++){
removevalue(i[]@pointsArray1,i[]@newArray[i]);
}

thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×