Fix includes, add attribution headers, remove unused constructor

This commit is contained in:
John 2022-04-22 21:41:19 -05:00
parent 952c318619
commit 710807dde7
6 changed files with 25 additions and 35 deletions

View File

@ -1,7 +1,7 @@
# +-------------+---------+-----------------------+ # +-------------+---------+-----------------------+
# | John Breaux | jab0910 | JohnBreaux@my.unt.edu | # | John Breaux | jab0910 | JohnBreaux@my.unt.edu |
# +-------------+---------+-----------------------+ # +-------------+---------+-----------------------+
# | Created 2022-04-04 Edited 2022-04-16 | # | Created 2022-04-04 Edited 2022-04-22 |
# +-----------------------------------------------+ # +-----------------------------------------------+
# ---------- Variables listed below --------- # # ---------- Variables listed below --------- #

View File

@ -1,9 +1,14 @@
#ifndef PROJECT2_GRAPH_HPP_INCLUDED
#define PROJECT2_GRAPH_HPP_INCLUDED
#include <string> // string
#include <vector> // vector<int>, vector<vector<int>
class graph { class graph {
public: public:
// Constructors // Constructors
graph() {} graph() {}
graph(const int processes, const int resources);
// Initializers: // Initializers:
// Read a graph from a file // Read a graph from a file
void read(std::string filename); void read(std::string filename);
@ -30,3 +35,5 @@ private:
struct m matrix; // Tell me, Mr. Anderson, what good is a phone call if you are unable to speak? struct m matrix; // Tell me, Mr. Anderson, what good is a phone call if you are unable to speak?
bool is_blocked(int process_id); bool is_blocked(int process_id);
}; };
#endif

View File

@ -1,27 +1,10 @@
#include <cstdlib> /* +-------------+---------+-----------------------+
#include <string> | John Breaux | jab0910 | JohnBreaux@my.unt.edu |
#include <vector> +-------------+---------+-----------------------+
| Created 2022-04-17 |
+-----------------------------------------------+ */
#include "graph.hpp" #include "graph.hpp"
graph::graph (const int processes, const int resources) {
num_processes = processes;
num_resources = resources;
matrix.x = processes + resources;
matrix.y = matrix.x;
// Reserve correct number of entries to minimize reallocation
matrix.data.reserve(matrix.x);
for (int x = 0; x < matrix.x; x++) {
// Make a new x (vector<int>)
matrix.data.push_back({});
// Reserve correct number of entries
matrix.data[x].reserve(matrix.y);
for (int y = 0; y < matrix.y; y++) {
// Make a new y (int)
matrix.data[x].push_back({});
}
}
}
void graph::print () { void graph::print () {
printf("np: %d\tnr: %d\n", num_processes, num_resources); printf("np: %d\tnr: %d\n", num_processes, num_resources);
printf("resource_counts:\n"); for (auto e: resource_counts) printf("%d\t", e); printf("\n"); printf("resource_counts:\n"); for (auto e: resource_counts) printf("%d\t", e); printf("\n");

View File

@ -4,9 +4,6 @@
+-------------+---------+-----------------------+ +-------------+---------+-----------------------+
| Created 2022-04-16 | | Created 2022-04-16 |
+-----------------------------------------------+ */ +-----------------------------------------------+ */
#include <cstdio>
#include <string>
#include <vector>
#include "graph.hpp" // Graph reduction/Knot detection, struct adjmatrix #include "graph.hpp" // Graph reduction/Knot detection, struct adjmatrix
int main(int argc, char** argv) { int main(int argc, char** argv) {

View File

@ -1,8 +1,9 @@
//TODO: Include C file IO header (stdio.h? Whatever it is) /* +-------------+---------+-----------------------+
#include <iostream> | John Breaux | jab0910 | JohnBreaux@my.unt.edu |
+-------------+---------+-----------------------+
| Created 2022-04-17 |
+-----------------------------------------------+ */
#include <fstream> #include <fstream>
#include <string>
#include <vector>
#include <regex> #include <regex>
#include "graph.hpp" #include "graph.hpp"

View File

@ -1,6 +1,8 @@
#include <cstdlib> /* +-------------+---------+-----------------------+
#include <string> | John Breaux | jab0910 | JohnBreaux@my.unt.edu |
#include <vector> +-------------+---------+-----------------------+
| Created 2022-04-22 |
+-----------------------------------------------+ */
#include "graph.hpp" #include "graph.hpp"
/* reducible: /* reducible: