key-indexed counting implementation