[WIP] Add r_set_cardinality()

This will add `r_set_cardinality` functionality with tests for each layer.
This was obviously not run through astyle. The brace has to be on the same line as the `while` statement!