STL Memory Versioning
Public Types | Public Member Functions | List of all members
vs::_vs_tree< _Key, _Comp > Class Template Reference

serves as stl-like interface from node to vs_tree; handles allocations in construction and destruction. More...

#include <vs_tree.h>

Public Types

typedef _vs_tree_iterator< _Key, _Comp > iterator
 
typedef _vs_tree_node< _Key, _Comp >::_Ptr_type _Ptr_type
 
typedef _vs_tree_node< _Key, _Comp >::size_type size_type
 
typedef _Key value_type
 

Public Member Functions

 _vs_tree ()=default
 
 _vs_tree (const _vs_tree &_tree)
 
 ~_vs_tree ()
 
iterator begin ()
 
iterator end ()
 
iterator begin () const
 
iterator end () const
 
const _Key & top ()
 
iterator find (const _Key &_x) const
 simple recursive implementation of find More...
 
iterator find_subtree (const _Key &_x, const _Ptr_type &node, _Comp comp=_Comp{}) const
 
size_type height () const
 
size_type size () const
 
void push (const _Key &_value)
 

Detailed Description

template<typename _Key, typename _Comp = std::less<_Key>>
class vs::_vs_tree< _Key, _Comp >

serves as stl-like interface from node to vs_tree; handles allocations in construction and destruction.

Definition at line 266 of file vs_tree.h.

Member Typedef Documentation

◆ _Ptr_type

template<typename _Key , typename _Comp = std::less<_Key>>
typedef _vs_tree_node<_Key, _Comp>::_Ptr_type vs::_vs_tree< _Key, _Comp >::_Ptr_type

Definition at line 272 of file vs_tree.h.

◆ iterator

template<typename _Key , typename _Comp = std::less<_Key>>
typedef _vs_tree_iterator<_Key, _Comp> vs::_vs_tree< _Key, _Comp >::iterator

Definition at line 271 of file vs_tree.h.

◆ size_type

template<typename _Key , typename _Comp = std::less<_Key>>
typedef _vs_tree_node<_Key, _Comp>::size_type vs::_vs_tree< _Key, _Comp >::size_type

Definition at line 273 of file vs_tree.h.

◆ value_type

template<typename _Key , typename _Comp = std::less<_Key>>
typedef _Key vs::_vs_tree< _Key, _Comp >::value_type

Definition at line 276 of file vs_tree.h.

Constructor & Destructor Documentation

◆ _vs_tree() [1/2]

template<typename _Key , typename _Comp = std::less<_Key>>
vs::_vs_tree< _Key, _Comp >::_vs_tree ( )
default

◆ _vs_tree() [2/2]

template<typename _Key , typename _Comp = std::less<_Key>>
vs::_vs_tree< _Key, _Comp >::_vs_tree ( const _vs_tree< _Key, _Comp > &  _tree)
inline

Definition at line 329 of file vs_tree.h.

330  {
331  if (_tree.head) {
332  this->head = new _vs_tree_node(*(_tree.head));
333  copy_subtree(this->head, _tree.head);
334  }
335 
336  }

◆ ~_vs_tree()

template<typename _Key , typename _Comp = std::less<_Key>>
vs::_vs_tree< _Key, _Comp >::~_vs_tree ( )
inline

Definition at line 338 of file vs_tree.h.

339  {
340  std::cout << "deleting " << this << std::endl;
341  if (head)
342  delete_subtree(head);
343 
344  head = nullptr;
345  }

Member Function Documentation

◆ begin() [1/2]

template<typename _Key , typename _Comp = std::less<_Key>>
iterator vs::_vs_tree< _Key, _Comp >::begin ( )
inline

Definition at line 350 of file vs_tree.h.

351  {
352  return iterator(this->head);
353  }
_vs_tree_iterator< _Key, _Comp > iterator
Definition: vs_tree.h:271

◆ begin() [2/2]

template<typename _Key , typename _Comp = std::less<_Key>>
iterator vs::_vs_tree< _Key, _Comp >::begin ( ) const
inline

Definition at line 361 of file vs_tree.h.

362  {
363  return iterator(this->head);
364  }

◆ end() [1/2]

template<typename _Key , typename _Comp = std::less<_Key>>
iterator vs::_vs_tree< _Key, _Comp >::end ( )
inline

Definition at line 355 of file vs_tree.h.

356  {
357  return iterator(nullptr);
358  }

◆ end() [2/2]

template<typename _Key , typename _Comp = std::less<_Key>>
iterator vs::_vs_tree< _Key, _Comp >::end ( ) const
inline

Definition at line 366 of file vs_tree.h.

367  {
368  return iterator(nullptr);
369  }

◆ find()

template<typename _Key , typename _Comp = std::less<_Key>>
iterator vs::_vs_tree< _Key, _Comp >::find ( const _Key &  _x) const
inline

simple recursive implementation of find

Definition at line 381 of file vs_tree.h.

382  {
383  return find_subtree(_x, head);
384  }
iterator find_subtree(const _Key &_x, const _Ptr_type &node, _Comp comp=_Comp{}) const
Definition: vs_tree.h:387

◆ find_subtree()

template<typename _Key , typename _Comp = std::less<_Key>>
iterator vs::_vs_tree< _Key, _Comp >::find_subtree ( const _Key &  _x,
const _Ptr_type node,
_Comp  comp = _Comp{} 
) const
inline

Definition at line 387 of file vs_tree.h.

387  {}) const
388  {
389  if (node->value == _x)
390  return iterator(node);
391 
392  if (comp(_x, node->value))
393  {
394  if (node->left)
395  return find_subtree(_x, node->left);
396  else
397  return end();
398  }
399  else
400  {
401  if (node->right)
402  return find_subtree(_x, node->right);
403  else
404  return end();
405  }
406  }
iterator end()
Definition: vs_tree.h:355

◆ height()

template<typename _Key , typename _Comp = std::less<_Key>>
size_type vs::_vs_tree< _Key, _Comp >::height ( ) const
inline

Definition at line 409 of file vs_tree.h.

410  { return _height; }

◆ push()

template<typename _Key , typename _Comp = std::less<_Key>>
void vs::_vs_tree< _Key, _Comp >::push ( const _Key &  _value)
inline

Definition at line 419 of file vs_tree.h.

420  {
421  if (head)
422  head = head->node_insert(_value);
423  else
424  head = new _vs_tree_node<_Key, _Comp>(_value);
425 
426  _height = head->height + 1;
427  _size++;
428  }
_Ptr_type node_insert(const _Key &_value, _Comp comp=_Comp{})
Fall down recursively, insert and rebalance on the way up.
Definition: vs_tree.h:112
size_type height
Definition: vs_tree.h:34

◆ size()

template<typename _Key , typename _Comp = std::less<_Key>>
size_type vs::_vs_tree< _Key, _Comp >::size ( ) const
inline

Definition at line 413 of file vs_tree.h.

414  { return _size; }

◆ top()

template<typename _Key , typename _Comp = std::less<_Key>>
const _Key& vs::_vs_tree< _Key, _Comp >::top ( )
inline

Definition at line 372 of file vs_tree.h.

373  {
374  return *begin();
375  }
iterator begin()
Definition: vs_tree.h:350

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