import collections


def group_fields_by_root(field_locations):
    """Given a list of field_locations group together those that hang from the
    same parent.

    Parameters
    ----------
    field_locations: List[FieldLocation]

    Returns
    -------
    dict
        Dictionary mapping PageTree node numbers to a list of FieldLocation
    """
    groups = collections.defaultdict(list)
    for field_location in field_locations:
        groups[field_location.item[field_location.root]].append(field_location)
    return groups