from copy import deepcopy
import curves as c
from sys import stderr
#from micc.cgraph import cdfs


def shift(path):
    '''
    init

    '''
    temp = path.index(min(path))
    return path[temp:] + path[:temp]


def invert(path):
    '''
    init

    '''
    return shift(path[::-1])


def contains(small, big):
    print type(small), type(big)
    for i in xrange(len(big)-len(small)+1):
        for j in xrange(len(small)):
            if big[i+j] != small[j]:
                break
        else:
            return i, i+len(small)
    return False


class Graph:

    def add_node(self, node):
        self.nodes[node] = []

    def __init__(self, edges, rep_num=2):
        self.edges = edges
        self.rep_num = rep_num
        self.nodes = {}
        self.counter = 0
        self.loops = []
        self.gammas = []
        self.nodes_to_faces = {}
        self.rep_num = rep_num

    def compute_loops(self, n, genus):
        edges = self.edges[0]
        fourgons = [i[1] for i in edges if i[0] == 4]
        non_fourgons = [i[1] for i in edges if i[0] != 4]
        keys = self.nodes_to_faces.keys()
        for i,face in enumerate(non_fourgons):
            for node in face:
                if not node in keys:
                    self.nodes_to_faces[node] = [i]