Improving CounterMap's totalCount() implementation to constant time