How to write code to place timer values in order from low to high

I realized a while after I posted that was probably your intent. I didn’t look closely & thought if-else-F was 0, not 8 and for some reason was assuming clock was connected to flip-flop-TGL instead of SET. This should work for your program, but is probably not ideal as a general solution.

One option would be to test if new number is less than old OR old number is equal 0. This would cause 0 to always be replaced by new value, but means 0 will never be stored if it is a valid value (would not be in your case, but for generic min-buffer, it could be a problem).

Another idea I had was to have node store state to know if it has a valid value. This gets more complicated, since you won’t want to pass an invalid value to the next node & you need to remember if value has been stored.

For any of these solutions, something we have over-looked is you probably want a way to reset your buffers so you can start looking for a new set of min/max numbers.

Pretty ugly, and doesn’t add code to reset MEM when output is not VALID (what should it be set to???):


flip-flop starts as 0/false, indicating MEM is not valid. gate at the bottom prevents CHAIN from sending a pulse if MEM was not valid–we don’t want next node thinking it is getting a valid number. I kept DONE just for completeness…you may need some other action following buffer update even if it didn’t have a valid value.

Abusing casting in C++, you can use OVF value to indicate current value is not valid, removing the need for VLD output pin.
image

node {
    // Internal state variables defined at this level persists across evaluations
    float ovf = (unsigned int) -1;

    void evaluate(Context ctx) {        
        if (isSettingUp() || isInputDirty<input_RST>(ctx)) {
            emitValue<output_MEM>(ctx, ovf);
            emitValue<output_PASS>(ctx, ovf);
        }
        if (isInputDirty<input_PUSH>(ctx)){
            auto New = getValue<input_NEW>(ctx);
            auto Old = getValue<output_MEM>(ctx);
            if (Old == ovf || New < Old) {
                emitValue<output_MEM>(ctx, New);
                emitValue<output_PASS>(ctx, Old);
            } else {
                emitValue<output_MEM>(ctx, Old);
                emitValue<output_PASS>(ctx, New);
            }
            if (Old != ovf) {
                emitValue<output_CHAIN>(ctx, true);
            }
            emitValue<output_DONE>(ctx, true);
        }
    }
}

Comparing min-buffer with min-buff-code after 2 pushes: