libcommonc++  0.7
BTree< K, V, ORDER > Class Template Reference

A balanced, n-ary tree data structure for storing key/value relationships. More...

#include <BTree.h++>

Classes

class  Iterator
 A BTree iterator. More...
 

Public Member Functions

 BTree (uint_t capacity)
 Construct a new BTree with the given maximum capacity. More...
 
virtual ~BTree ()
 Destructor. More...
 
bool put (const K key, const V data)
 Put a new item in the tree. More...
 
bool remove (const K key)
 Remove an item from the tree. More...
 
get (const K key)
 Get an item from the tree. More...
 
bool contains (const K key) const
 Determine if an item with the given key exists in the tree. More...
 
void dump (std::ostream &stream) const
 Dump a representation of the tree (keys only) to a stream. More...
 
void getKeys (std::list< K > &keys) const
 Get a list of all of the keys in the tree, in access-order. More...
 
void getValues (std::list< V > &values) const
 Get a list of all of the values in the tree, in access-order. More...
 
void clear ()
 Remove all items from the tree. More...
 
uint_t getCapacity () const
 Get the tree capacity. More...
 

Protected Member Functions

virtual void itemDropped (V data) const
 Called whenever an item is removed from the BTree to make room for another. More...
 

Detailed Description

template<typename K, typename V, int ORDER = 10>
class ccxx::BTree< K, V, ORDER >

A balanced, n-ary tree data structure for storing key/value relationships.

The BTree has a configurable order and maximum capacity. The items are ordered internally by last access time. When the maximum capacity has been reached, and a new item is added to the tree, the least-recently accessed item is automatically removed.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ BTree()

BTree ( uint_t  capacity)

Construct a new BTree with the given maximum capacity.

Parameters
capacityThe maximum number of items the tree will hold.

◆ ~BTree()

virtual ~BTree ( )
virtual

Destructor.

Member Function Documentation

◆ clear()

void clear ( )

Remove all items from the tree.

◆ contains()

bool contains ( const K  key) const

Determine if an item with the given key exists in the tree.

Parameters
keyThe key.
Returns
true if there is a matching key in the tree, false otherwise.

◆ dump()

void dump ( std::ostream &  stream) const

Dump a representation of the tree (keys only) to a stream.

Parameters
streamThe stream to write to.

◆ get()

V get ( const K  key)

Get an item from the tree.

Parameters
keyThe key.
Returns
The data associated with the key, otherwise a NULL value.

◆ getCapacity()

uint_t getCapacity ( ) const
inline

Get the tree capacity.

◆ getKeys()

void getKeys ( std::list< K > &  keys) const

Get a list of all of the keys in the tree, in access-order.

Parameters
keysThe list in which to store the keys.

◆ getValues()

void getValues ( std::list< V > &  values) const

Get a list of all of the values in the tree, in access-order.

Parameters
valuesThe list in which to store the values.

◆ itemDropped()

virtual void itemDropped ( data) const
protectedvirtual

Called whenever an item is removed from the BTree to make room for another.

Parameters
dataThe value that was removed.

◆ put()

bool put ( const K  key,
const V  data 
)

Put a new item in the tree.

Parameters
keyThe key.
dataThe data to associate with the key.

◆ remove()

bool remove ( const K  key)

Remove an item from the tree.

Parameters
keyThe key.

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