title: compressed vector/array class with random data access
body: <p>I would like to make "compressed array"/"compressed vector" class (details below), that allows random data access with more or less constant time.</p>
  
  <p>"more or less constant time" means that although element access time isn't constant, it shouldn't keep increasing when I get closer to certain point of the array. I.e. container shouldn't do significantly more calculations (like "decompress everything once again to get last element", and "do almost nothing to get the first") to get one element. Can be probably achieved by splitting array into chunks of compressed data. I.e. accessing one element should take "averageTime" +- some deviation. I could say that I want best-case access time and worst-case access time to be relatively close to average access time.</p>
  
  <p>What are my options (suitable algorithms/already  available containers - if there are any)?</p>
  
  <p>Container details: </p>
  
  <ol>
  <li>Container acts as a linear array of identical elements (such as std::vector)</li>
  <li>Once container is initialized, data is constant and never changes. Container needs to provide read-only access.</li>
  <li>Container should behave like array/std::vector - i.e. values accessed via operator[], there is .size(), etc.</li>
  <li>It would be nice if I could make it as template class.  </li>
  <li>Access to data should be more or less constant-time. I don't need same access time for every element, but I shouldn't have to decompress everything to get last element. </li>
  </ol>
  
  <p>Usage example:<br>
  Binary search on data.</p>
  
  <p>Data details:<br>
  1. Data is structs mostly consisting of floats and a few ints. There are more floats than ints. No strings.<br>
  2. It is unlikely that there are many identical elements in array, so simply indexeing data won't be possible.<br>
  3. Size of one element is less than 100 bytes.<br>
  4. Total data size per container is between few kilobytes and a few megabytes.<br>
  5. Data is not sparse - it is continuous block of elements, all of them are assigned, there are no "empty slots". </p>
  
  <p>The goal of compression is to reduce amount of ram the block takes when compared to uncompressed representation as array, while keeping somewhat reasonable read access performance, and allowing to randomly access elements as array. I.e. data should be stored in compressed form internally, and I should be able to access it (read-only) as if it is a std::vector or similar container.</p>
  
  <p>Ideas/Opinions?</p>