arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
PriorityQueue.h
1#pragma once
2#include "AudioTools/CoreAudio/AudioBasic/Collections/List.h"
3
4namespace audio_tools {
5
16template <class T>
18 public:
19 PriorityQueue(int (*compare)(T &v1, T &v2)) { compare_cb = compare; };
20
21 bool enqueue(T &&data) {
22 for (auto it = l.begin(); it != l.end(); ++it) {
23 if (compare_cb(*it, data) > 0) {
24 l.insert(it, data);
25 return true;
26 }
27 }
28 return l.push_back(data);
29 }
30
31 bool peek(T &data) {
32 if (l.end()->prior == nullptr) return false;
33 data = *(l.end()->prior);
34 return true;
35 }
36
37 bool dequeue(T &data) { return l.pop_front(data); }
38
39 size_t size() { return l.size(); }
40
41 bool clear() { return l.clear(); }
42
43 bool empty() { return l.empty(); }
44
45 void setAllocator(Allocator &allocator) { l.setAllocator(allocator); }
46
47 protected:
48 List<T> l;
49 int (*compare_cb)(T &v1, T &v2);
50};
51
52} // namespace audio_tools
Memory allocateator which uses malloc.
Definition Allocator.h:23
Double linked list.
Definition List.h:18
Priority Queue which is based on a List. The order of the elements is defined by a compare function w...
Definition PriorityQueue.h:17
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10