import math


def get_degree_sequence(node_degrees, num_buckets, k_neighbors, max_degree):
    """
    Turn lists of neighbors into a degree sequence
    :param node_degrees: the degree of each node in a graph
    :param max_degree: max degree in all input graphs
    :param num_buckets: degree (node feature) binning
    :param k_neighbors: node's neighbors at a given layer
    :return: length-D list of ints (counts of nodes of each degree), where D is max degree in graph
    """
    if num_buckets is not None:
        degrees_vector = [0] * int(math.log(max_degree, num_buckets) + 1)
    else:
        degrees_vector = [0] * (max_degree + 1)

    # For each node in k-hop neighbors, count its degree
    for node in k_neighbors:
        weight = 1  # unweighted graphs supported here
        degree = node_degrees[node]
        # print("get_degree_sequence  %d %d", node, degree)
        if num_buckets is not None:
            try:
                degrees_vector[int(math.log(degree, num_buckets))] += weight
            except:
                print("Node %d has degree %d and will not contribute to feature distribution" % (node, degree))
        else:
            degrees_vector[degree] += weight
    return degrees_vector