def node_cmp(n1, n2):
    """ Sort nodes by cost """
    if n1.cost < n2.cost:
        return -1
    elif n1.cost > n2.cost:
        return 1
    # Returning 0 allows for stable sorting, i.e. equal objects stay in
    # the same order, which should provide a bit of a performance boost,
    # as well as a bit of consistency
    return 0