Removing multiple items from a coll based on matching criteria (string etc) - possible?

warp1's icon

This to me should be fairly basic but I can't figure out if it's even possible. For a 'coll' object, I'd like to be able to send the 'remove' message not based on index # but based on matching text. Essentially I'd like to manipulate the coll contents using text identifiers, but since the coll contents are dynamic I cannot use the indices. Is there any way to do this?

warp1's icon

I should clarify that I would want this to be a single operation (as in 'remove all indices that have the word 'loud' in them, at once).

Source Audio's icon

Max Patch
Copy patch and select New From Clipboard in Max.

warp1's icon

This works great @SourceAudio! Thank you. I will likely have 10,000 index entries in my coll. Should I then simply replace 'del 100' with 'del 10000'?

Source Audio's icon

that delay will trigger at the end of dump to renumber the indexes.
no need to make it longer

one thing - you might want to insert fromsymbol
in front of match in case you search also for items contained
in symbols, like search aaa which could be stored like this :

33, 34.567 "aaa bbb ccc" 2 3 treat 55;

Max Patch
Copy patch and select New From Clipboard in Max.

also sel might be faster then match
I reuploaded last patch, had a mistake inside, it is ok now

Luigi Castelli's icon

If you are planning to have as many as 10,000 entries, I wouldn't use a [coll] object then, but a [dict].
[coll] uses a linked-list implementation under the hood, which is not really made to handle a large number of entries. With 10,000 or more entries, operations on [coll]'s data could potentially become very slow. A [dict] is a much more efficient and general data structure that I would almost always use over [coll].
As an added benefit, in a [dict] it will be simpler/faster to delete an entry based on text matching.

warp1's icon

Funny you mention @luigi - I am pushing the output from [dict] to coll in order to be able to use it with jit.cellblock for the UI of the patch.

warp1's icon

Also @sourceAudio I supppose it would be better if I had some way to remove all except the word I'm matching for, since that's the intended function. It's meant to act as a filter so if I query 'loud' it should actually remove everything that is 'not loud'.

Source Audio's icon

it would be better to ask from the beginning, what "intended" function is.
you can reverse the match, pass only matched coll lines
to another coll or something like that