CookMem 1.4.0
A C++ memory context / allocator
Loading...
Searching...
No Matches
cookmem::PtrAVLTree Class Reference

#include <avltree.h>

Public Member Functions

 PtrAVLTree ()
 
 ~PtrAVLTree ()
 
void add (void *ptr, std::size_t size)
 
void * remove (std::size_t &size, std::size_t limit=~static_cast< std::size_t >(0))
 
void remove (void *ptr)
 
bool contains (void *ptr)
 
bool canGrowInPlace (void *ptr, std::size_t newSize)
 
bool isEmpty ()
 
void printGraph ()
 

Detailed Description

This is an internally used AVL tree that uses the pointer passed in store the information.

Constructor & Destructor Documentation

◆ PtrAVLTree()

cookmem::PtrAVLTree::PtrAVLTree ( )
inline

Default constructor.

◆ ~PtrAVLTree()

cookmem::PtrAVLTree::~PtrAVLTree ( )
inline

Well, we do not do destructor maintenance.

Member Function Documentation

◆ add()

void cookmem::PtrAVLTree::add ( void *  ptr,
std::size_t  size 
)
inline

Add a pointer to the search tree.

Note that the size of the pointer must be at least (7 * sizeof(size_t)).

Parameters
ptrthe pointer to be added to the AVL tree.
sizethe size of the pointer

◆ canGrowInPlace()

bool cookmem::PtrAVLTree::canGrowInPlace ( void *  ptr,
std::size_t  newSize 
)
inline

Check if a node in the tree can take a larger size without changing its position in the tree. If so, the caller can update the size in place instead of removing the node and adding it back.

Parameters
ptrthe pointer stored in the tree.
newSizethe new size, which must be larger than the current size.
Returns
true if the size can be updated in place.

◆ contains()

bool cookmem::PtrAVLTree::contains ( void *  ptr)
inline

Check if the pointer is stored in the tree.

Parameters
ptrthe pointer to be searched.

◆ isEmpty()

bool cookmem::PtrAVLTree::isEmpty ( )
inline

Check if the tree is empty.

Returns
true if the tree is empty. false otherwise.

◆ printGraph()

void cookmem::PtrAVLTree::printGraph ( )
inline

Debugging function that prints the tree nodes to GraphViz format.

◆ remove() [1/2]

void * cookmem::PtrAVLTree::remove ( std::size_t &  size,
std::size_t  limit = ~static_cast<std::size_t> (0) 
)
inline

Remove a node based on the size information. The node obtained has the size that at least the size obtained.

Parameters
[in,out]sizesearch key. If the node is found, the actual size of the pointer is returned.
limitthe node must be smaller than this value. Otherwise nothing is removed.
Returns
the node matching the search key that is at least the size of the provided. This node is also removed from the tree.

◆ remove() [2/2]

void cookmem::PtrAVLTree::remove ( void *  ptr)
inline

Remove a node based on the pointer info.

Parameters
ptrthe pointer to be removed from the tree

The documentation for this class was generated from the following file: