mirror of
https://github.com/13hannes11/UU_la_parallel_programming_practical_assignments.git
synced 2024-09-04 00:50:58 +02:00
created build pipeline to allow unit testing
This commit is contained in:
58
Assignment_2/lib/Node.cpp
Normal file
58
Assignment_2/lib/Node.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
|
||||
class Node {
|
||||
protected:
|
||||
int data;
|
||||
bool is_dummy;
|
||||
std::mutex mut;
|
||||
|
||||
public:
|
||||
Node* next;
|
||||
bool deleted;
|
||||
|
||||
Node(int element);
|
||||
static Node* Dummy();
|
||||
// Dummy();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
bool is_smaller_than(int n);
|
||||
bool is_smaller_than(Node* n);
|
||||
bool is_equal(int n);
|
||||
};
|
||||
|
||||
|
||||
Node::Node(int element){
|
||||
data = element;
|
||||
is_dummy = false;
|
||||
deleted = false;
|
||||
}
|
||||
|
||||
Node* Node::Dummy(){
|
||||
Node* n = new Node(0);
|
||||
n->is_dummy = true;
|
||||
return n;
|
||||
}
|
||||
|
||||
bool Node::is_smaller_than(Node* n) {
|
||||
return this->is_smaller_than(n->data);
|
||||
}
|
||||
|
||||
bool Node::is_smaller_than(int n) {
|
||||
// Everything is smaller than a dummy -> false
|
||||
return this->data < n && !this->is_dummy;
|
||||
}
|
||||
|
||||
bool Node::is_equal(int n) {
|
||||
// Dummies are not equal to any number -> false
|
||||
return this->data == n && !this->is_dummy;
|
||||
}
|
||||
|
||||
void Node::lock() {
|
||||
this->mut.lock();
|
||||
}
|
||||
void Node::unlock() {
|
||||
this->mut.unlock();
|
||||
}
|
||||
Reference in New Issue
Block a user