title: Java Long to int conversion skipping gaps between longs
body: <p>I'm working on a school project where I'm building a geographical map from nodes.
  These nodes are loaded from an XML format from OpenStreetMap.org.</p>
  <p>There are a lot of these nodes, and therefor I have to optimize memory whenever possible. One such optimization would be storing their id's as int instead of long.</p>
  <p>The nodes have their ID values far beyond what Integers support, therefor I cannot directly create objects from them utilizing int or Integer.
  However, I am going to use around 40.000.000 nodes in total (which is less than the total amount of Integers possible).</p>
  <p>My question is therefor if there is an intelligent way to apply a mathematical function to the Long values, that will turn them into ints. I need to be able to use this function once on all nodes when I save them in memory, and then later on when something refers to them by their original long value from the XML, I'll need to (again) find their new Integer value by the function.
  I've attempted the following:</p>
  <p><code>int myInt = (int) myLong-Integer.MIN_VALUE</code>... in order to bring the long value back into the int spectrum, however the longs are still too large to support integer format after this.</p>
  <p>I've also attempted keeping a Map of &quot;Long -&gt; Integer&quot;, that I can lookup the long in, in order to get the int value. However this is nonsensical since I would then STILL be storing the Longs in memory (which is exactly what we are trying to prevent).</p>
  <p>EDIT:
  As comments below asked for, the range of long values are indeed more than 4 billion apart. I don't have the exact Maxvalue and Minvalue available right now but the difference between them are about twice as large as the amount of available integers. (Therefor no simple subtraction would work)</p>
  <p>EDIT2: Found the data:
  <a href="https://i.stack.imgur.com/IgY6R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IgY6R.png" alt="enter image description here" /></a></p>