F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaxHeap.hpp
Go to the documentation of this file.
1// ======================================================================
2// \title MaxHeap.hpp
3// \author dinkel
4// \brief An implementation of a stable max heap data structure
5//
6// \copyright
7// Copyright 2009-2015, by the California Institute of Technology.
8// ALL RIGHTS RESERVED. United States Government Sponsorship
9// acknowledged.
10//
11// ======================================================================
12
13#ifndef OS_PTHREADS_MAX_HEAP_HPP
14#define OS_PTHREADS_MAX_HEAP_HPP
15
16#include <FpConfig.hpp>
17
18namespace Os {
19
27 class MaxHeap {
28
29 public:
34 MaxHeap();
39 ~MaxHeap();
46 bool create(NATIVE_UINT_TYPE capacity);
66 bool pop(NATIVE_INT_TYPE& value, NATIVE_UINT_TYPE& id);
72 bool isFull();
78 bool isEmpty();
89 void print();
90
91 private:
92 // Private functions:
93 // Ensure the heap meets the heap property:
94 void heapify();
95 // Swap two elements on the heap:
96 void swap(NATIVE_UINT_TYPE a, NATIVE_UINT_TYPE b);
97 // Return the max between two elements on the heap:
99
100 // The data structure for a node on the heap:
101 struct Node {
102 NATIVE_INT_TYPE value; // the priority of the node
103 NATIVE_UINT_TYPE order; // order in which node was pushed
104 NATIVE_UINT_TYPE id; // unique id for this node
105 };
106
107 // Private members:
108 Node* heap; // the heap itself
109 NATIVE_UINT_TYPE size; // the current size of the heap
110 NATIVE_UINT_TYPE order; // the current count of heap pushes
111 NATIVE_UINT_TYPE capacity; // the maximum capacity of the heap
112 };
113
114}
115
116#endif // OS_PTHREADS_MAX_HEAP_HPP
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
C++-compatible configuration header for fprime configuration.
A stable max heap data structure.
Definition MaxHeap.hpp:27
bool isFull()
Is the heap full?
Definition MaxHeap.cpp:140
~MaxHeap()
MaxHeap deconstructor.
Definition MaxHeap.cpp:40
bool push(NATIVE_INT_TYPE value, NATIVE_UINT_TYPE id)
Push an item onto the heap.
Definition MaxHeap.cpp:62
MaxHeap()
MaxHeap constructor.
Definition MaxHeap.cpp:32
bool create(NATIVE_UINT_TYPE capacity)
MaxHeap creation.
Definition MaxHeap.cpp:45
void print()
Print the contents of the heap to stdout.
Definition MaxHeap.cpp:262
bool pop(NATIVE_INT_TYPE &value, NATIVE_UINT_TYPE &id)
Pop an item from the heap.
Definition MaxHeap.cpp:111
bool isEmpty()
Is the heap empty?
Definition MaxHeap.cpp:145
NATIVE_UINT_TYPE getSize()
Get the current number of elements on the heap.
Definition MaxHeap.cpp:150
Definition File.cpp:6