def calculate_clusters(reactions, distance, threshold):
    """
    Calculate the clusters of reactions based on their distances
    :param reactions: A list of all the reactions
    :type reactions: list
    :param distance: The hash of reaction/reaction and distances
    :type distance: dict
    :param threshold: The threshold to consider clustering
    :type threshold: float
    :return: A hash of the reactions and the clusters to which they belong and the size of the clusters
    :rtype: (dict, int)
    """
    # Cluster the distances using single linkage clustering
    cluster = {}
    current_cluster = 0
    for r in reactions:
        # first test if this reaction is linked to an existing cluster
        if r not in distance:
            cluster[r] = current_cluster
            current_cluster += 1
            continue
        for s in cluster:
            if s not in distance[r]:
                continue
            if distance[r][s] < threshold:
                cluster[r] = cluster[s]
                break
        if r not in cluster:
            cluster[r] = current_cluster
            current_cluster += 1

    return cluster, current_cluster - 1