F´ Flight Software - C/C++ Documentation  NASA-v1.5.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 "Fw/Types/BasicTypes.hpp"
17 
18 namespace Os {
19 
27  class MaxHeap {
28 
29  public:
34  MaxHeap();
39  ~MaxHeap();
46  bool create(NATIVE_UINT_TYPE capacity);
56  bool push(NATIVE_INT_TYPE value, NATIVE_UINT_TYPE id);
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
Os
Definition: File.cpp:7
Os::MaxHeap::push
bool push(NATIVE_INT_TYPE value, NATIVE_UINT_TYPE id)
Push an item onto the heap.
Definition: MaxHeap.cpp:60
Os::MaxHeap::create
bool create(NATIVE_UINT_TYPE capacity)
MaxHeap creation.
Definition: MaxHeap.cpp:43
Os::MaxHeap::isEmpty
bool isEmpty()
Is the heap empty?
Definition: MaxHeap.cpp:143
Os::MaxHeap::getSize
NATIVE_UINT_TYPE getSize()
Get the current number of elements on the heap.
Definition: MaxHeap.cpp:148
Os::MaxHeap::~MaxHeap
~MaxHeap()
MaxHeap deconstructor.
Definition: MaxHeap.cpp:38
Os::MaxHeap
A stable max heap data structure.
Definition: MaxHeap.hpp:27
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
Os::MaxHeap::print
void print()
Print the contents of the heap to stdout.
Definition: MaxHeap.cpp:260
Os::MaxHeap::isFull
bool isFull()
Is the heap full?
Definition: MaxHeap.cpp:138
BasicTypes.hpp
Declares ISF basic types.
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Os::MaxHeap::pop
bool pop(NATIVE_INT_TYPE &value, NATIVE_UINT_TYPE &id)
Pop an item from the heap.
Definition: MaxHeap.cpp:109
Os::MaxHeap::MaxHeap
MaxHeap()
MaxHeap constructor.
Definition: MaxHeap.cpp:30