def _prefixes(ids, minsize=0):
    """
    Return a mapping of ids to prefixes.

    Each prefix is the shortest possible substring of the ID that
    uniquely identifies it among the given group of IDs.
    """
    prefixes = {}
    for id_ in ids:
        others = set(ids).difference([id_])
        found = False
        # iteratively test if id prefix is long enough to be unique
        for i in range(minsize + 1, len(id_)+1):
            prefix = id_[:i]
            # The pf-prefix kwarg silences a pylint cell-var-from-loop warning.
            # This is safe since prefix is set on the previous line. It would
            # also work to use id_[:i] directly in loop, but I find that a bit
            # harder to read.
            if not any(map(lambda other, pf=prefix: other.startswith(pf), others)):
                prefixes[id_] = prefix
                found = True
                break
        if not found:
            raise KeyError("Unresolvable hash collision occurred.")
    return prefixes