remove old queue code
This commit is contained in:
@ -1,25 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* *
|
|
||||||
* C H A I N *
|
|
||||||
* *
|
|
||||||
*---------------------------------------------------------------------------*
|
|
||||||
* Beschreibung: Implementierung einer einfach verketteten Liste von *
|
|
||||||
* Chain Objekten. *
|
|
||||||
* *
|
|
||||||
* Autor: Olaf Spinczyk, TU Dortmund *
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef __Chain_include__
|
|
||||||
#define __Chain_include__
|
|
||||||
|
|
||||||
class Chain {
|
|
||||||
private:
|
|
||||||
Chain(const Chain& copy) = delete; // Verhindere Kopieren
|
|
||||||
|
|
||||||
public:
|
|
||||||
Chain* next;
|
|
||||||
|
|
||||||
Chain() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,95 +0,0 @@
|
|||||||
#include "Queue.h"
|
|
||||||
#include "kernel/Globals.h"
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
void Queue::enqueue(Chain* item) {
|
|
||||||
// kout << "Enqueue " << (unsigned int)item << endl;
|
|
||||||
|
|
||||||
*this->tail = item; // If queue is empty tail points to head pointer,
|
|
||||||
this->tail = &item->next; // otherwise to last next pointer
|
|
||||||
}
|
|
||||||
|
|
||||||
Chain* Queue::dequeue() {
|
|
||||||
if (this->isEmpty()) {
|
|
||||||
// This should not ever happen as the idle thread exists always
|
|
||||||
// kout << "Dequeue called on empty queue." << endl;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Chain* item = this->head;
|
|
||||||
this->head = this->head->next; // If *item was the only item this->head->next
|
|
||||||
// is equal to this->tail
|
|
||||||
|
|
||||||
if (this->isEmpty()) {
|
|
||||||
// Reset after last element was removed
|
|
||||||
this->head = 0;
|
|
||||||
this->tail = &this->head;
|
|
||||||
}
|
|
||||||
|
|
||||||
// kout << "Dequeue " << (unsigned int)item << endl;
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Queue::remove(Chain* item) {
|
|
||||||
if (this->isEmpty()) {
|
|
||||||
// kout << "Remove called on empty queue" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Chain* current = this->head;
|
|
||||||
Chain* lastnext = NULL;
|
|
||||||
while (current != item) {
|
|
||||||
if (current->next == *this->tail) {
|
|
||||||
// kout << "Element not in queue." << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastnext = current;
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
// std::cout << "Remove " << item->val << std::endl;
|
|
||||||
|
|
||||||
if (current == this->head) {
|
|
||||||
// current is first element
|
|
||||||
this->head = current->next;
|
|
||||||
} else if (current->next == *this->tail) {
|
|
||||||
// current is last element
|
|
||||||
this->tail = &lastnext->next;
|
|
||||||
} else {
|
|
||||||
// current is in the middle
|
|
||||||
lastnext->next = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->isEmpty()) {
|
|
||||||
// Reset after last element was removed
|
|
||||||
this->head = 0;
|
|
||||||
this->tail = &this->head;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Queue::print() const {
|
|
||||||
if (this->isEmpty()) {
|
|
||||||
// Queue is empty
|
|
||||||
kout << "List is empty!" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
kout << "List: ";
|
|
||||||
|
|
||||||
Chain* current = this->head;
|
|
||||||
kout << (unsigned int)current << " "; // At least one element in queue
|
|
||||||
|
|
||||||
while (current->next != *this->tail) {
|
|
||||||
// More than one element in queue
|
|
||||||
current = current->next;
|
|
||||||
kout << (unsigned int)current << " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
kout << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Queue::isEmpty() const {
|
|
||||||
return *this->tail == this->head;
|
|
||||||
}
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* *
|
|
||||||
* Q U E U E *
|
|
||||||
* *
|
|
||||||
*---------------------------------------------------------------------------*
|
|
||||||
* Beschreibung: Implementierung einer einfach verketteten Liste von *
|
|
||||||
* Chain Objekten. Die Implementierung ist etwas trickreich *
|
|
||||||
* 'tail' verweist naemlich nicht, wie oft ueblich, auf das *
|
|
||||||
* letzte Element der Liste, sondern auf den 'next' Zeiger *
|
|
||||||
* des letzten Elements, bzw., solange die Liste noch leer *
|
|
||||||
* ist, auf den 'head' Zeiger der Liste. Dadurch muss beim *
|
|
||||||
* Anfuegen eines Elements an die Liste nicht ueberprueft *
|
|
||||||
* werden, ob bereits Elemente in ihr enthalten sind. Beim *
|
|
||||||
* Entfernen von Elementen kann auf die Fallunterscheidung *
|
|
||||||
* allerdings nicht verzichtet werden. *
|
|
||||||
* *
|
|
||||||
* Autor: Olaf Spinczyk, TU Dortmund *
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef __Queue_include__
|
|
||||||
#define __Queue_include__
|
|
||||||
|
|
||||||
#include "lib/Chain.h"
|
|
||||||
|
|
||||||
class Queue {
|
|
||||||
private:
|
|
||||||
Queue(const Queue& copy) = delete; // Verhindere Kopieren
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Chain* head;
|
|
||||||
Chain** tail;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Queue() : head(0), tail(&head) {}
|
|
||||||
|
|
||||||
void enqueue(Chain* item);
|
|
||||||
Chain* dequeue();
|
|
||||||
void remove(Chain* item);
|
|
||||||
void print() const;
|
|
||||||
bool isEmpty() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user