improved FineList

This commit is contained in:
2020-12-30 21:13:44 +01:00
parent a5eb49bc2e
commit 83e1a4c031
2 changed files with 19 additions and 8 deletions

View File

@@ -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();

View File

@@ -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;