code: public static <T> ImmutableMultimap<T, Integer> itemToIndexMultimap(
        Iterable<T> iterable) {
      final ImmutableMultimap.Builder<T, Integer> ret = ImmutableMultimap.builder();
      int idx = 0;
      for (final T x : iterable) {
        ret.put(x, idx++);
      }
      return ret.build();
    }
docs: Transforms an Iterable<T> to a Map<T, Integer> where each item is mapped to its zero-indexed
  position(s) in the Iterable's sequence.