[Csnd] New array opcode idea: in_array
Date | 2017-10-14 13:06 |
From | Kevin Welsh |
Subject | [Csnd] New array opcode idea: in_array |
I saw there were some new additions recently, so I figured I'd share a UDO I wrote that I think might also be useful.
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
in_array takes in a variable (in this case krate) and an irate array and checks the array to see if the provided value is in the array, returning a count of it's appearances in the array. I mostly use this for tracking flags as a group, for example in cabbage I might have an array listing all the filter modes that should show the resonance control. When a mode change is detected, if the new mode appears in the array the resonance controls get displayed, otherwise they get hidden. ; search array for value, return number of instances found opcode in_array,k,ki[] kval, iarray[] xin klen lenarray iarray kptr = 0 kfound = 0 while (kptr<klen) do if (kval == iarray[kptr]) then kfound = kfound+1 endif kptr = kptr+1 od xout kfound endop |
Date | 2017-10-14 13:35 |
From | Victor Lazzarini |
Subject | Re: [Csnd] New array opcode idea: in_array |
Very useful. Maybe you could add to the UDO database
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2017-10-14 21:40 |
From | Kevin Welsh |
Subject | Re: [Csnd] New array opcode idea: in_array |
Ok, cool. Not sure if that was the right place, or if I did it correctly; I don't use github very much... but it should be submitted to the csudo repository in the arrays folder. If not, I probably just need to find the right button to initiate a push ;) But any thoughts to adding it as a builtin? It seems pretty common and standard to me. I know PHP and JS (or was it JQuery?) have it builtin. It adds a simple way to use arrays in a pretty handy way, and I can probably provide an example for the docs etc if needed too (tho I'll have to trim out some cabbage) On Sat, Oct 14, 2017 at 8:35 AM, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
|
Date | 2017-10-15 14:20 |
From | Aaron Krister Johnson |
Subject | Re: [Csnd] New array opcode idea: in_array |
I'm wondering if there is a constant time membership operation (using hashing) that is available to Csound? Something like a dictionary in Python, where membership can be checked without having to check each member, a linear-time operation. -AKJ On Sat, Oct 14, 2017 at 3:40 PM, Kevin Welsh <tgrey1@gmail.com> wrote:
|
Date | 2017-10-15 15:25 |
From | John ff |
Subject | Re: [Csnd] New array opcode idea: in_array |
No, arrays are not sets in csound. Sent from TypeApp On Oct 15, 2017, 14:21, at 14:21, Aaron Krister Johnson |
Date | 2017-10-15 15:30 |
From | Guillermo Senna |
Subject | Re: [Csnd] New array opcode idea: in_array |
But Csound arrays aren't sets so we would need a new container, wouldn't we? Having said that, we easily implemented binary search for Daria using Victor's C++ interface and std::upper_bound. Cheers. On 15/10/17 10:20, Aaron Krister Johnson wrote: > I'm wondering if there is a constant time membership operation (using > hashing) that is available to Csound? Something like a dictionary in > Python, where membership can be checked without having to check each > member, a linear-time operation. > > -AKJ > > > Aaron Krister Johnson > http://www.untwelve.org > > On Sat, Oct 14, 2017 at 3:40 PM, Kevin Welsh |