code: def simhash(features, hashbits=32):
      if hashbits == 32:
          hashfn = hash
      else:
          hashfn = lambda s: _hash(s, hashbits)
  
      vs = [0] * hashbits
      for feature, weight in features:
          h = hashfn(feature)
          for i in xrange(hashbits):
              if h & (1 << i):
                  vs[i] += weight
              else:
                  vs[i] -= weight
  
      out = 0
      for i, v in enumerate(vs):
          if v > 0:
              out |= 1 << i
      return out
  
imports: from __future__ import division
  import random
  from collections import defaultdict
  from math import log
  from whoosh.compat import xrange, iteritems
label_desc: Use image node_id 2 for calling a global function with example usage: simhash(features, hashbits) and returns: out