title: Massive Python set of integers using too much memory
body: <p><strong>Setup</strong></p>
  
  <ul>
  <li>Python 2.6</li>
  <li>Ubuntu x64</li>
  </ul>
  
  <p>I have a set of unique integers with values between 1 and 50 million. New integers are added at random e.g. <code>numberset.add(random.randint(1, 50000000))</code>. I need to be able to quickly add new integers and quickly check if an integer is already present.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>After a while, the set grows too large for my low memory system and I experience <code>MemoryError</code>s.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How can I achieve this while using less memory? What's the fastest way to do this using the disk without reconfiguring the system e.g. swapfiles? Should I use a database file like sqlite? Is there a library that will compress the integers in memory?</p>