Flip the keys and values of the multimap.
164594
public static <K, V> HashBagMultimap<V, K> flip(BagMultimap<K, V> bagMultimap)
    {
        final HashBagMultimap<V, K> result = new HashBagMultimap<V, K>();
        bagMultimap.forEachKeyMultiValues(new Procedure2<K, Iterable<V>>()
        {
            public void value(final K key, Iterable<V> values)
            {
                Iterate.forEach(values, new Procedure<V>()
                {
                    public void value(V value)
                    {
                        result.put(value, key);
                    }
                });
            }
        });
        return result;
    }
134316
public static <X, Y> Map<Y, X> invert(Map<X, Y> map) {
    Map<Y, X> invertedMap = new HashMap<Y, X>();
    for (Map.Entry<X, Y> entry : map.entrySet()) {
      X key = entry.getKey();
      Y value = entry.getValue();
      invertedMap.put(value, key);
    }
    return invertedMap;
  }
1235454
def get_keys(self, keymap):
        """"""
        keys = dict(modifiers=[], regular=[])

        # loop on keymap bytes
        for keymap_index, keymap_byte in enumerate(keymap):
            try:
                keymap_values = self._keymap_values_dict[keymap_index]
            except KeyError:
                continue

            # loop on keymap_values for that keymap byte
            for key, value in keymap_values.items():
                if not keymap_byte & key:
                    continue
                elif value in self._modifiers:
                    keys['modifiers'].append(value)
                elif not keys['regular']:
                    keys['regular'].append(value)

        return keys
777396
function multiMapSet(multimap, key, value) {
  if (!multimap.has(key)) {
    multimap.set(key, new Set());
  }
  const values = multimap.get(key);
  if (!values.has(value)) {
    values.add(value);
    return true;
  }
  return false;
}
974818
private static Multimap<?, ?> annotateEmptyStringsMultimap(Multimap<?, ?> multimap) {
    if (multimap.containsKey("") || multimap.containsValue("")) {
      ListMultimap<Object, Object> annotatedMultimap = LinkedListMultimap.create();
      for (Entry<?, ?> entry : multimap.entries()) {
        Object key = "".equals(entry.getKey()) ? HUMAN_UNDERSTANDABLE_EMPTY_STRING : entry.getKey();
        Object value =
            "".equals(entry.getValue()) ? HUMAN_UNDERSTANDABLE_EMPTY_STRING : entry.getValue();
        annotatedMultimap.put(key, value);
      }
      return annotatedMultimap;
    } else {
      return multimap;
    }
  }
181463
def update_mappings(self):
        """"""
        self.pos2id = dict((v, k) for k, v in self.id2pos.iteritems())
        assert len(self.pos2id) == len(self.id2pos), "duplicate ids or positions detected"
891190
function invert () {
        if (Immutable.Iterable.isIterable(toValues)) {
          toValues = toValues.map(mapInvertValues);
        } else {
          toValues = mapInvertValues(toValues);
        }

        return self;
      }
712296
public static <K, V> ListMultimap<K, V> newLinkedHashListMultimap(Multimap<K, V> multimap) {
		int keySetSize = multimap.keySet().size();
		int expectedKeys = Math.max(keySetSize, 2);
		ListMultimap<K, V> result = newLinkedHashListMultimap(expectedKeys,	Math.max(3, multimap.size() / expectedKeys));
		result.putAll(multimap);
		return result;
	}
1285399
private static <K,V> void combineMaps(Map<K,V> m1, Map<K,V> m2)
    {
    	for (Map.Entry<K,V> me : m2.entrySet()) {
            K key = me.getKey();
            /* Int. subset has precedence, but let's guess most of
             * the time there are no collisions:
             */
            V old = m1.put(key, me.getValue());
            // Oops, got value! Let's put it back
            if (old != null) {
                m1.put(key, old);
            }
        }
    }
56831
public static <K, V> MultiValueMap<K, V> toMultiValueMap(Map<K, List<V>> map) {
		return new MultiValueMapAdapter<K, V>(map);

	}
886967
def flip(f):
    """"""
    ensure_callable(f)

    result = lambda *args, **kwargs: f(*reversed(args), **kwargs)
    functools.update_wrapper(result, f, ('__name__', '__module__'))
    return result
1344969
public void putAll(Map m)
    {
        Iterator i = m.entrySet().iterator();
        boolean multi=m instanceof MultiMap;
        while(i.hasNext())
        {
            Map.Entry entry =
                (Map.Entry)i.next();
            if (multi)
                super.put(entry.getKey(),LazyList.clone(entry.getValue()));
            else
                put(entry.getKey(),entry.getValue());
        }
    }
824837
public SetMultimap<A, B> getKeyValueMultimap() {
    SetMultimap<A, B> map = HashMultimap.create();
    for (A key : keySet()) {
      for (B value : getValues(key)) {
        map.put(key, value);
      }
    }
    return map;
  }
856382
private static void swap(double[] keys, int[] vals, int j, int i) {
    double td = keys[j];
    keys[j] = keys[i];
    keys[i] = td;
    int ti = vals[j];
    vals[j] = vals[i];
    vals[i] = ti;
  }
288410
public static <K, V> Map<K, V> newCombinedMap(K[] keys,
            V[] values) {
        HashMap<K, V> map = new HashMap<>();
        for (int i = 0; i < keys.length; i++)
            map.put(keys[i], getValueOfIndex(values, i));
        return map;
    }
993119
public static <K> ImmutableSet<K> allMultimapKeys(final Iterable<? extends Multimap<K, ?>> multimaps) {
    final ImmutableSet.Builder<K> builder = ImmutableSet.builder();

    for (final Multimap<K, ?> multimap : multimaps) {
      builder.addAll(multimap.keySet());
    }

    return builder.build();
  }
38632
def flip( *dimensions )
      field = ( 0 ... dimension ).collect do |i|
        if dimensions.member? i
          Hornetseye::lazy( *shape ) { |*args| shape[i] - 1 - args[i] }
        else
          Hornetseye::lazy( *shape ) { |*args| args[i] }
        end
      end
      warp *( field + [ :safe => false ] )
    end