code: def facettupletrees(table, key, start='start', stop='stop', value=None):
      
  
      import intervaltree
      it = iter(table)
      hdr = next(it)
      flds = list(map(text_type, hdr))
      assert start in flds, 'start field not recognised'
      assert stop in flds, 'stop field not recognised'
      getstart = itemgetter(flds.index(start))
      getstop = itemgetter(flds.index(stop))
      if value is None:
          getvalue = tuple
      else:
          valueindices = asindices(hdr, value)
          assert len(valueindices) > 0, 'invalid value field specification'
          getvalue = itemgetter(*valueindices)
      keyindices = asindices(hdr, key)
      assert len(keyindices) > 0, 'invalid key'
      getkey = itemgetter(*keyindices)
  
      trees = dict()
      for row in it:
          k = getkey(row)
          if k not in trees:
              trees[k] = intervaltree.IntervalTree()
          trees[k].addi(getstart(row), getstop(row), getvalue(row))
      return trees
docs: Construct faceted interval trees for the given table, where each node in
      the tree is a row of the table.