Add r_set_cardinality()

This will add `r_set_cardinality` functionality with tests for each layer.