Sha256: 15cddc4f0be8f568b3e61b5dff07ac513e04e4fb47df17029afe92b3f411bff9

Contents?: true

Size: 916 Bytes

Versions: 57

Compression:

Stored size: 916 Bytes

Contents

#ifndef _PASSENGER_PRIORITY_QUEUE_H_
#define _PASSENGER_PRIORITY_QUEUE_H_

#include "fib.h"

namespace Passenger {

template<typename T>
class PriorityQueue {
private:
	struct fibheap heap;
	
public:
	typedef struct fibheap_el * Handle;
	
	PriorityQueue() {
		fh_initheap(&heap);
		heap.fh_keys = 1;
	}
	
	~PriorityQueue() {
		fh_destroyheap(&heap);
	}
	
	Handle push(T *item, int priority) {
		return fh_insertkey(&heap, priority, item);
	}
	
	T *pop() {
		return (T *) fh_extractmin(&heap);
	}
	
	T *top() const {
		return (T *) fh_min(const_cast<struct fibheap *>(&heap));
	}
	
	void decrease(Handle handle, int priority) {
		fh_replacekeydata(&heap, handle, priority, handle->fhe_data);
	}
	
	void erase(Handle handle) {
		fh_delete(&heap, handle);
	}
	
	void clear() {
		fh_destroyheap(&heap);
		fh_initheap(&heap);
		heap.fh_keys = 1;
	}
};

} // namespace Passenger

#endif /* _PASSENGER_PRIORITY_QUEUE_H_ */

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
passenger-4.0.60 ext/common/Utils/PriorityQueue.h
passenger-4.0.59 ext/common/Utils/PriorityQueue.h
passenger-4.0.58 ext/common/Utils/PriorityQueue.h
passenger-4.0.57 ext/common/Utils/PriorityQueue.h
passenger-4.0.56 ext/common/Utils/PriorityQueue.h
passenger-4.0.55 ext/common/Utils/PriorityQueue.h
passenger-4.0.53 ext/common/Utils/PriorityQueue.h
passenger-4.0.52 ext/common/Utils/PriorityQueue.h
passenger-4.0.51 ext/common/Utils/PriorityQueue.h
passenger-4.0.50 ext/common/Utils/PriorityQueue.h
passenger-4.0.49 ext/common/Utils/PriorityQueue.h
passenger-4.0.48 ext/common/Utils/PriorityQueue.h
passenger-4.0.46 ext/common/Utils/PriorityQueue.h
passenger-4.0.45 ext/common/Utils/PriorityQueue.h
passenger-4.0.44 ext/common/Utils/PriorityQueue.h
passenger-4.0.43 ext/common/Utils/PriorityQueue.h
passenger-4.0.42 ext/common/Utils/PriorityQueue.h
passenger-4.0.41 ext/common/Utils/PriorityQueue.h
passenger-4.0.40 ext/common/Utils/PriorityQueue.h
passenger-4.0.39 ext/common/Utils/PriorityQueue.h