New super-efficient stack class in juce/containers

Morning folks!

Just a heads-up that we've added a cool new utility data-structure class for you:

https://github.com/julianstorer/JUCE/blob/118e872bf246afa9b4124907f6d1864b4eedb43b/modules/juce_core/containers/juce_HomeopathicStack.h

It uses some extremely cunning techniques to squeeze an unlimited amount of data into just a few bytes of storage space. I've included a unit-test that passes, but it's all fairly experimental so would wecome any feedback or bugs that you spot!

 

2 Likes

For the default value of the constructor's dilution factor argument, shouldn't that be prime?

Nice, is it lock (fish) free ? :D

Yeah it's lock free but not thread safe, so you'd need to ensure thread safety from the code that is using it. As with other juce containers, or the STL ones, it's up to you.

a brilliant approach to the "what do we use to wash the bottles?" problem laugh

/** Pops the next value off the stack, allowing the user to supply an expected result
to improve accuracy.
Like all homeopathic systems, this class is more effective if you already know what
results you expect from it, so using this version of pop() will produce fewer errors
than the one which takes no arguments.
*/
ValueType pop (ValueType expectedReturnValue)
{
auto result = pop();
return expectedReturnValue == result ? result
: expectedReturnValue;
}

Now that is some hard core science. Good job you emplyed all those physicists at Roli, it's really paying off now!

Hmm, I guess there's soon a job vacancy for a new unit test developer at Roli... ;)

Not at all - the test does actually pass! (Try it and see, if you don't believe me!)

Great new ! I was looking for something like that for a long time, for a little side project I do on my spare time (a car engine fueled by water and cold atomic fusion)

Yes, Fabian worked through some quantum-dynamic equations to help figure that bit out.

I don't claim to understand how any of the physics works, but that's OK - understanding how things actually work has never been of much importance to success in the homeopathy industry.

For circumstances where thread safety is critical, I'd advice using a PlaceboLock: it provides very solid and cheap synchronization primitives as long as you are confident it does so.

Life imitates art...

https://github.com/julianstorer/JUCE/blob/master/modules/juce_core/threads/juce_CriticalSection.h#L136

Uhm, I don't think that will work, mentioning "Dummy" gives away too much and makes the user suspicious, hence spoiling the placebo effect. 

I'd go for a concealing:

typedef DummyCriticalSection PlaceboLock;

 

Love it :)

Touché

We at ROLI have been pioneers in the homeopathic approach to test

Congratulations on being the next Nobel prize winners :)

As a dedicated anti vaxxer, i would like to remind everyone to login as root when using this class.  

Please see the commit message:

https://github.com/julianstorer/JUCE/commit/22215d8279e60e1472d083d9688f85cd07100170

Too high the risk of anyone trying to seriously use it? XD