コード例 #1
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Gets the edge label of an edge between vertices u and v.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @return the edge label between u and v
 */
string Graph::getEdgeLabel(Vertex u, Vertex v) const
{
    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    return graph.at(u).at(v).label;
}
コード例 #2
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Gets an edge between two vertices.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @return the edge between u and v
 */
Edge Graph::getEdge(Vertex u, Vertex v) const
{
    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    return graph.at(u).at(v);
}
コード例 #3
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Sets the weight of an edge between two vertices.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @param weight - the weight to set the edge
 */
void Graph::setEdgeWeight(Vertex u, Vertex v, int weight)
{
    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    graph[u][v].weight = weight;
    graph[v][u].weight = weight;
}
コード例 #4
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Removes an edge between two vertices.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 */
void Graph::removeEdge(Vertex u, Vertex v)
{
    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    graph[u].erase(graph[u].find(v));
    graph[v].erase(graph[v].find(u));
}
コード例 #5
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Sets the edge label of an edge between vertices u and v.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 */
void Graph::setEdgeLabel(Vertex u, Vertex v, string label)
{
    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    graph[u][v].label = label;
    graph[v][u].label = label;
}
コード例 #6
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Gets the weight of an edge between two vertices.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @return the weight of the edge
 */
int Graph::getEdgeWeight(Vertex u, Vertex v) const
{
    if (!weighted)
        error("can't get edge weights on non-weighted graphs!");

    assertExists(u, __func__);
    assertExists(v, __func__);
    assertConnected(u, v, __func__);
    return graph.at(u).at(v).weight;
}
コード例 #7
0
void copyFiles(const string & sourceFolder, const string & destFolder, const vector<string> & files)
{
	assertExists(destFolder);
	for (size_t i = 0; i < files.size(); i++)
	{
		string sourceFile = sourceFolder + files[i];
		assertExists(sourceFile);
		copyFile(sourceFile, destFolder);
	}
}
コード例 #8
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Inserts an edge between two vertices.
 * A boolean is returned for use with the random graph generation.
 * Hence, an error is not thrown when it fails to insert an edge.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @return whether inserting the edge was successful
 */
bool Graph::insertEdge(Vertex u, Vertex v)
{
    assertExists(u, __func__);
    assertExists(v, __func__);

    EdgeMap uEdges = graph[u];

    // "fail" silently for random graph generation
    if (uEdges.find(v) != uEdges.end())
        return false;

    Edge uEdge(u, v, -1, "");
    graph[u].insert(make_pair(v, uEdge));

    Edge vEdge(v, u, -1, "");
    graph[v].insert(make_pair(u, vEdge));

    return true;
}
コード例 #9
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Gets all adjacent vertices to the parameter vertex.
 * @param v - the vertex to get neighbors from
 * @return a vector of vertices
 */
vector<Vertex> Graph::getAdjacent(Vertex v) const
{
    assertExists(v, "getAdjacent");

    vector<Vertex> ret;
    EdgeMap edges = graph.at(v);
    EdgeMap::iterator it;
    for (it = edges.begin(); it != edges.end(); ++it)
        ret.push_back(it->second.dest);

    return ret;
}
コード例 #10
0
void copyFile(const string & source, const string & dest)
{
	assertExists(source);
	vector<string> folders = tokenize(dest, '/');
	string currdir = "";
	for (size_t i = 0; i < folders.size() - 1; i++)
	{
		currdir += folders[i] + '/';
		if (!exists(currdir))
			exec("mkdir", currdir.c_str());
	}
	exec("cp", source.c_str(), dest.c_str());
}
コード例 #11
0
void rename_main(const string & file, const string & newname)
{
	if (newname[0] != '_')
	{
		cerr << "INTERNAL ERROR: " __FILE__ << ":" << __LINE__
		     << "newname argument to rename_main must begin with an underscore to ensure replacement safety" << endl;
		exit(-2);
	}
	assertExists(file);
	exec( "sed", "-i",
	      ( "s/int[\\r\\n \\t][\\r\\n \\t]*main(.*)/int " + newname +
		    "(int argc, char ** argv)/" ).c_str(),
	      file.c_str() );
}
コード例 #12
0
void linkDirs(const string & sourceFolder, const string & destFolder, const vector<string> & dirs)
{
	assertExists(destFolder);
	for (size_t i = 0; i < dirs.size(); i++)
	{
		string source = sourceFolder + dirs[i];
		string target = destFolder   + dirs[i];

		// Check for redundant monad/ directory
		// This allows the monad/ dir to be safely renamed
		if (replaceFirst(source, "/../monad/","/"))
			replaceFirst(target, "/monad/","/");

		assertExists(destFolder + source + '/');

		if (symlink(source.c_str(), target.c_str()) != 0)
		{
			cerr << "symlink failed: " << target << ": ";
			perror(NULL);
			exit(-1);
		}
	}
}
コード例 #13
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Removes a given vertex from the graph.
 * @param v - the vertex to remove
 */
void Graph::removeVertex(Vertex v)
{
    assertExists(v, __func__);

    // first, remove all references to the vertex in every other edge list
    // luckily, we can call getAdjacent and work backwards
    //  instead of traversing the whole hash table
    vector<Vertex> adjacent = getAdjacent(v);
    vector<Vertex>::iterator it;
    for (it = adjacent.begin(); it != adjacent.end(); ++it)
        removeEdge(*it, v);

    // now that all references are gone, we can delete the vertex
    graph.erase(v);
    vertexLabels.erase(v);
}
コード例 #14
0
void protectFiles(const string & folder, const vector<string> & files)
{
#if 0 // (debug)
	for (size_t i = 0; i < files.size(); i++)
	{
		string file = folder + files[i];
		assertExists(file);

		if (chmod(file.c_str(), S_IRUSR) != 0)
		{
			perror("chmod failed");
			exit(-1);
		}
	}
#endif
}
コード例 #15
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Gets the label of a vertex.
 * @param v - vertex to get label from
 * @return the vertex label
 */
string Graph::getVertexLabel(Vertex v) const
{
    assertExists(v, __func__);
    return vertexLabels.at(v);
}
コード例 #16
0
ファイル: graph.cpp プロジェクト: liu298/DataStructure-Lab
/**
 * Labels a vertex with a string.
 * This is a method.
 * @param v - the vertex to label
 * @param label - label of the vertex to change
 */
void Graph::setVertexLabel(Vertex v, string label)
{
    assertExists(v, __func__);
    vertexLabels[v] = label;
}