Add function countByValue() and countByKey().

It seems pretty useful functions for the user too. Just added it as a public function with a simple test.