日期:2014-05-16 浏览次数:20481 次
/* * gSpan algorithm implemented by coolypf * http://blog.csdn.net/coolypf */ #define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <time.h> #include <vector> #include <map> #include <set> using namespace std; const int LABEL_MAX = 100; int min_support; int nr_graph; struct Graph { vector<int> node_label; vector<int> *edge_next, *edge_label; vector<int> gs; void removeEdge(int x, int a, int y) { for (size_t i = 0; i < node_label.size(); ++i) { int t; if (node_label[i] == x) t = y; else if (node_label[i] == y) t = x; else continue; for (size_t j = 0; j < edge_next[i].size(); ++j) { if (edge_label[i][j] == a && node_label[edge_next[i][j]] == t) { /* remove edge */ edge_label[i][j] = edge_label[i].back(); edge_label[i].pop_back(); edge_next[i][j] = edge_next[i].back(); edge_next[i].pop_back(); j--; } } } } bool hasEdge(int x, int a, int y) { for (size_t i = 0; i < node_label.size(); ++i) { int t; if (node_label[i] == x) t = y; else if (node_label[i] == y) t = x; else continue; for (size_t j = 0; j < edge_next[i].size(); ++j) if (edge_label[i][j] == a && node_label[edge_next[i][j]] == t) return true; } return false;