mirror of
https://github.com/13hannes11/UU_la_parallel_programming_practical_assignments.git
synced 2024-09-04 00:50:58 +02:00
improved FineList
This commit is contained in:
@@ -58,7 +58,7 @@ bool FineSet::rmv(int element) {
|
|||||||
c->lock();
|
c->lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c->data == element) {
|
if (c->is_equal(element)) {
|
||||||
p->next = c->next;
|
p->next = c->next;
|
||||||
|
|
||||||
c->unlock();
|
c->unlock();
|
||||||
|
|||||||
@@ -1,22 +1,29 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
class Node {
|
class Node {
|
||||||
public:
|
protected:
|
||||||
int data;
|
int data;
|
||||||
bool is_dummy;
|
bool is_dummy;
|
||||||
Node* next;
|
std::mutex mut;
|
||||||
std::mutex mut;
|
|
||||||
public:
|
public:
|
||||||
|
Node* next;
|
||||||
|
|
||||||
Node(int element);
|
Node(int element);
|
||||||
static Node* Dummy();
|
static Node* Dummy();
|
||||||
|
// Dummy();
|
||||||
|
|
||||||
void lock();
|
void lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
bool is_smaller_than(int n);
|
bool is_smaller_than(int n);
|
||||||
|
bool is_smaller_than(Node* n);
|
||||||
bool is_equal(int n);
|
bool is_equal(int n);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Node::Node(int element){
|
Node::Node(int element){
|
||||||
this->data = element;
|
data = element;
|
||||||
this->is_dummy = false;
|
is_dummy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* Node::Dummy(){
|
Node* Node::Dummy(){
|
||||||
@@ -25,6 +32,10 @@ Node* Node::Dummy(){
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Node::is_smaller_than(Node* n) {
|
||||||
|
return this->is_smaller_than(n->data);
|
||||||
|
}
|
||||||
|
|
||||||
bool Node::is_smaller_than(int n) {
|
bool Node::is_smaller_than(int n) {
|
||||||
// Everything is smaller than a dummy -> false
|
// Everything is smaller than a dummy -> false
|
||||||
return this->data < n && !this->is_dummy;
|
return this->data < n && !this->is_dummy;
|
||||||
|
|||||||
Reference in New Issue
Block a user