def convert_node_labels_to_integers(G, first_label=0, ordering="default",
                                    label_attribute=None):
    N = G.number_of_nodes() + first_label
    if ordering == "default":
        mapping = dict(zip(G.nodes(), range(first_label, N)))
    elif ordering == "sorted":
        nlist = G.nodes()
        nlist.sort()
        mapping = dict(zip(nlist, range(first_label, N)))
    elif ordering == "increasing degree":
        dv_pairs = [(d, n) for (n, d) in G.degree_iter()]
        dv_pairs.sort()
        mapping = dict(zip([n for d, n in dv_pairs], range(first_label, N)))
    elif ordering == "decreasing degree":
        dv_pairs = [(d, n) for (n, d) in G.degree_iter()]
        dv_pairs.sort()
        dv_pairs.reverse()
        mapping = dict(zip([n for d, n in dv_pairs], range(first_label, N)))
    else:
        raise nx.NetworkXError('Unknown node ordering: {0}'.format(ordering))
    H = relabel_nodes(G, mapping)
    H.name = "(" + G.name + ")_with_int_labels"
    if label_attribute is not None:
        nx.set_node_attributes(H, label_attribute,
                               dict((v, k) for k, v in mapping.items()))
    return H