Fixes issue where negative numbers caused infinite loops
Fixes sparse set cardinality calculations that were accidentally broken by reusing capacity value as sp