title: How to generate unique ids for RecyclerView, in case of 2 ids per item?
body: <h2>Background</h2>
  
  <p>Suppose I have a RecyclerView, which has items that can only be unique if you look at 2 ids they have, but not just one of them.</p>
  
  <p>The first Id is the primary one. Usually there aren't 2 items that have the same primary ID, but sometimes it might occur, which is why there is a secondary ID.</p>
  
  <p>In my </p>
  
  <h2>The problem</h2>
  
  <p>The RecyclerView adapter needs to have a "long" type being returned:</p>
  
  <p><a href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#getItemId(int)" rel="noreferrer">https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#getItemId(int)</a></p>
  
  <h2>What I've tried</h2>
  
  <p>The easy way to overcome this, is to have a HashMap and a counter.</p>
  
  <p>The HashMap will contain the combined-keys, and the value will be the id that should be returned. The counter is used to generated the next id in case of a new combined key. The combined key can be a "Pair" class in this case. </p>
  
  <p>Suppose each item in the RecyclerView data has 2 long-type keys:</p>
  
  <pre><code>HashMap&lt;Pair&lt;Long,Long&gt;,Long&gt; keyToIdMap=new HashMap();
  long idGenerator=0;
  </code></pre>
  
  <p>this is what to do in getItemId :</p>
  
  <pre><code>Pair&lt;Long,Long&gt; combinedKey=new Pair(item.getPrimaryId(), item.getSecondary());
  Long uniqueId=keyToIdMap.get(combinedKey);
  if(uniqueId==null) 
    keyToIdMap.put(combinedKey,uniqueId=idGenerator++);
  return uniqueId;
  </code></pre>
  
  <p>This has the drawback of taking more and more memory. Not much though, and it's very small and proportional to the data you already have, but still...</p>
  
  <p>However, this has the advantage of being able to handle all types of IDs, and you can use even more IDs as you wish (just need something similar to Pair).</p>
  
  <p>Another advantage is that it will use all IDs starting from 0.</p>
  
  <h2>The question</h2>
  
  <p>Is there perhaps a better way to achieve this?</p>
  
  <p>Maybe a mathematical way? I remember I learned in the past of using prime numbers for similar tasks. Will it work here somehow?</p>