[WIP] Add r_set_cardinality()

This will add `r_set_cardinality` functionality with tests for each layer.
You can implement the whole function with a ternary operator (`?:`), which results in 1 line instead of 5.