int main () {
    VertexFs vfs("vertex_file");
    EdgeFs efs("edge_file", "reverse_edge_file", &vfs);

    cout << "NumVertices" << vfs.NumVertices() << endl;
    cout << "Num Labels" << vfs.NumLabels() << endl;

    for (int i = 0; i < vfs.NumLabels(); i += 1)
        cout << "Num Vertices Label " << i << ":" << vfs.NumVertices(i) << endl;

    for(int label_idx = 0; label_idx < vfs.NumLabels(); label_idx += 1) {
        cout << "Label Index :" << label_idx << " : ";
        UINT* vertex_ptr = vfs.GetVertexIterator(label_idx);
        for(int vertex_idx = 0; vertex_idx < vfs.NumVertices(label_idx); vertex_idx += 1) {
            cout << ' ' << vertex_ptr[vertex_idx];
        }
        cout << endl;
    }

    vector<VERTEX>* v;
    for (int vertex = 0; vertex < vfs.NumVertices(); vertex += 1) {
        cout << "Vertex:" << vertex << endl;
        cout << " In:" << efs.GetInDegree(vertex) << endl;
        cout << " Out:" << efs.GetOutDegree(vertex) << endl;

        for (int label = 0; label < 3; label += 1) {
            cout << "\tLabel" << label << ": " ;
            cout << "\tIn: " << efs.GetInDegree(vertex, label);
            cout << "\tOut: " << efs.GetOutDegree(vertex, label);
            v = efs.GetIndegreeVertices(vertex,label);
            cout << " In Vertices: ";
            for (int i = 0; i < v->size(); i += 1)
                cout << "-" << v->at(i);
            delete v;
            v = efs.GetOutdegreeVertices(vertex,label);
            cout << " Out Vertices: ";
            for (int i = 0; i < v->size(); i += 1)
                cout << "-" << v->at(i);
            delete v;
            UINT* begin = efs.OutgoingEdgeIterator(vertex,label);
            UINT* end = efs.OutgoingEdgeIteratorEnd(vertex,label);

            cout << " Out Vertices: ";
            while (begin != end) {
                cout <<  *(begin) << "-";
                //assert(efs.HasEdge(vertex, *(begin)));
                begin += 1;
            }
            cout << endl;
        }
    }
}
Beispiel #2
0
//
//string Sdr::loadCdx() {
//	string cpath = this->cdxpath();
//	if (!fexist(cpath.c_str())) {
//		return "cdx file not exist";
//	}
//	fstream cfs(cpath.c_str(), ios::in);
//	if (!cfs.is_open()) {
//		cfs.close();
//		return "open cdx file error:" + cpath;
//	}
//	char cbuf[100];
//	cfs.read(cbuf, CDX_HSIZE);
//	int ccount = byte2int(cbuf);
//	int offs_len = byte2int(cbuf + 4);
//	int csize = byte2int(cbuf + 8);
//	while (!cfs.eof()) {
//		cfs.read(cbuf, ccount + 4);
//		int esize = byte2int(cbuf + ccount);
//		cout << cbuf << "," << esize << endl;
//		char ibuf[offs_len];
//		for (int i = 0; i < esize; i++) {
//			cfs.read(ibuf, offs_len);
//		}
//	}
//	cout << csize << endl;
//	return "";
//}
//
string Sdr::createEdx(int ecount, bool oft64) {
    this->loadDictInfo();
	string epath = this->edxpath();
	string ipath = this->idxpath();
	if (fexist(epath.c_str())) {
		return "edx file already exist";
	}
	fstream ifs(ipath.c_str(), ios::in);
	if (!ifs.is_open()) {
		ifs.close();
		return "open .idx file error:" + ipath;
	}
	fstream efs(epath.c_str(), ios::out);
	if (!efs.is_open()) {
		efs.close();
		return "open edx file error:" + epath;
	}
	string sbuf;
	int offs_len = oft64 ? 8 : 4;
	int cbuf_len = ecount + offs_len;
	int rofts = this->lessVersion("3.0.0") ? 4 : 8;
	char cbuf[cbuf_len];
	memset(cbuf, 0, cbuf_len);
	char tbuf[16];
	long offset = 0;
	int esize = 0;
	int ssize = 0;
	long loft = 0;
	//
	efs.seekp(12);
	//read the first line.
	getline(ifs, sbuf, '\0');
	memset(cbuf, 0, cbuf_len);
	ssize = sbuf.length();
	memcpy(cbuf, sbuf.c_str(), ssize < ecount ? ssize : ecount);
	ifs.read(tbuf, rofts + 4);
	while (1) {
		loft = ifs.tellg();
		sbuf.clear();
		getline(ifs, sbuf, '\0');
		ifs.read(tbuf, rofts + 4);
		if (ccmp_c(cbuf, sbuf.c_str(), ecount) == 0 && !ifs.eof()) {
			continue;
		}
		if (oft64) {
			long2byte(offset, cbuf + ecount);
		} else {
			int2byte(offset, cbuf + ecount);
		}
		efs.write(cbuf, cbuf_len);
//		cout << cbuf << endl;
		//
		memset(cbuf, 0, cbuf_len);
		ssize = sbuf.length();
		memcpy(cbuf, sbuf.c_str(), ssize < ecount ? ssize : ecount);
		offset = loft;
		esize++;
		if (ifs.eof()) {
			break;
		}
	}
	int2byte(ecount, tbuf);
	int2byte(offs_len, tbuf + 4);
	int2byte(esize, tbuf + 8);
	efs.seekp(0);
	efs.write(tbuf, 12);
	efs.close();
	ifs.close();
	return "";
}