[WIP] Add r_set_cardinality()

This will add `r_set_cardinality` functionality with tests for each layer.
Be a bit more verbose here, please.