title: estimation of big comparison task
body: <p>I have a programming task from the university which requires finding shared strings of a constant length by comparing of hundreds of files (good files and bad files, smaller than one megabyte) byte by byte.</p>
  
  <p>Suppose I'm going for a total coverage of the comparisons, and I actually compare each file to other files, is it possible to actually complete this task within a few minutes?</p>
  
  <p>I've tried the naive algorithm and I've been improving on it for several days now, and I can't seem to drop under a few hours.</p>
  
  <p>What I did so far:</p>
  
  <h2>CPU:</h2>
  
  <p>I've locally bench-marked different comparisons and buffer sizes to see which fits my needs best.</p>
  
  <p>I don't keep the signature itself, only a reference to it (via a boolean array that has the same size of the file - also helps me not to compare again an index that has been ruled out).</p>
  
  <p>I'm currently installing callable comparison tasks into the system with hope it won't create too much overhead or synchronization issues.</p>
  
  <h2>Virtual Memory:</h2>
  
  <p>I'm determining buffer sizes according to the free memory available (<code>System.freeMemory()</code> - about 2GB after manually specifying it) to prevent thrashing and I've settled for a reasonable (to my view) trade-off between information saved per file</p>
  
  <h2>Algorithm:</h2>
  
  <p>I try and compare only a subset of the bytes in suspicious location after a static analysis of the files' structures (JAR files, I didn't go into bytecode, because I have no idea how to extrapolate relevance from bytecode - I only compare the "classes.dex").</p>
  
  <hr>
  
  <p>Given that this must be a common task, am I missing something very obvious? I've been told that hashing the signatures can be faster, but I doubt that's faster than waiting for the comparisons to end and storing them later, via the references (this is very fast once the comparisons themselves, which are the bottleneck, ends). To me hashing seems like a big VM hogging risk.</p>
  
  <p>It was told that this should run within "Reasonable time" and the aim is to find the best (smallest) superset (covers most bad files and no good files) of the files (or close to it). It seems to me that I'm way off after hearing some people that claim to have completed it.</p>
  
  <p>If more information is needed please ask, and I'll edit it into the post.</p>
  
  <hr>
  
  <p>I am planning on using <a href="http://concurrent-trees.googlecode.com/svn/concurrent-trees/javadoc/apidocs/com/googlecode/concurrenttrees/radixinverted/ConcurrentInvertedRadixTree.html" rel="nofollow">this</a> implementation of a Trie, in case I forget to update this, I hope you who runs into this can utilize it (or others in this project) for your needs!</p>