title: Check for duplicated values in sortedMap
body: <p>I have a map initialized as</p>
  <pre><code>val cache: SortedMap&lt;String, String&gt; = sortedMapOf()
  </code></pre>
  <p>The map is used as a cache and can contain duplicated values with their own unique key. I want to check and count how many duplicated values there are in the cache. Note that the cache can contain millions of entries.</p>
  <p>As of now, I check for duplicates in this way</p>
  <pre><code>val uniqueValueSet = hashSetOf&lt;String&gt;()
  val numDuplicates = cache.filter {!uniqueValueSet.add(it.value)}.count()
  </code></pre>
  <p>However, I feel like this check is memory inefficient, where adding all the distinct values to a set creates an obsolete set with possibly millions of elements.</p>
  <p>Is there a better, and more optimized, way of checking duplicates between the values in a map?</p>