In our vvvv martix group chat @toyshung asked how to count occurrences in a spread in VL.
there is a simple solution for all primitive types like Float32, Vectors, Matrix and most types that we have imported from .NET or other libraries. it’s as simple as that:
create a dictionary and increment the value for each entry if its found again.
however, if you patch your own classes and records in VL, the dictionary doesn’t exactly know how to compare two instances of your type. it will just check for “reference equality”. that means it looks for the same location in memory, which will be false in most cases. let’s consider a little example record like this:
if you want to compare the actual content of two instances, you have to provide a so called “equality comparer” to the dictionary that checks whether two instances are same, in the way you want to compare them:
importing the IEqualityComparer from .NET and create it as a region is as slick as that:
see the patch for the concrete implementation, needs a recent vvvv alpha:
Count Occurrences VL.zip (15.8 KB)