@not_implemented_for('directed')
def enumerate_all_cliques(G):
 index = {}
 nbrs = {}
 for u in G:
  index[u] = len(index)
  nbrs[u] = {v for v in G[u] if (v not in index)}
 queue = deque((([u], sorted(nbrs[u], key=index.__getitem__)) for u in G))
 while queue:
  (base, cnbrs) = map(list, queue.popleft())
  (yield base)
  for (i, u) in enumerate(cnbrs):
   queue.append((chain(base, [u]), filter(nbrs[u].__contains__, islice(cnbrs, (i + 1), None))))

@ not_implemented_for ( 'directed' ) def enumerate_all_cliques ( G ) : index = { } nbrs = { } for u in G : index [ u ] = len ( index ) nbrs [ u ] = { v for v in G [ u ] if ( v not in index ) } queue = deque ( ( ( [ u ] , sorted ( nbrs [ u ] , key = index . __getitem__ ) ) for u in G ) ) while queue : ( base , cnbrs ) = map ( list , queue . popleft ( ) ) ( yield base ) for ( i , u ) in enumerate ( cnbrs ) : queue . append ( ( chain ( base , [ u ] ) , filter ( nbrs [ u ] . __contains__ , islice ( cnbrs , ( i + 1 ) , None ) ) ) )
returns all cliques in an undirected graph .