Prakticke aspekty vývoje softwaru: Projekt 1 – Testování  1.0
Projekt zaměřený na osvojení praktik testování včetně technik test driven development, black box testing a white box testing.
red_black_tree.h
Zobrazit dokumentaci tohoto souboru.
1 //======== Copyright (c) 2018, FIT VUT Brno, All rights reserved. ============//
2 //
3 // Purpose: Red-Black Self balancing Tree public interface
4 //
5 // $NoKeywords: $ivs_project_1 $red_black_tree.h
6 // $Authors: Filip Vaverka <ivaverka@fit.vutbr.cz>
7 // David Grochol <igrochol@fit.vutbr.cz>
8 // $Date: $2018-02-08
9 //============================================================================//
18 #pragma once
19 
20 #ifndef RED_BLACK_TREE_H_
21 #define RED_BLACK_TREE_H_
22 
23 #include <utility>
24 #include <vector>
25 
26 #include "red_black_tree_lib.h"
27 
35 {
36 public:
41  enum Color_t {
42  RED = ::Color_t::RED,
43  BLACK = ::Color_t::BLACK
44  };
45 
50  typedef ::Node_t Node_t;
51  /*{
52  Node_t *pParent; ///< Ukazatel na rodice uzlu, nebo NULL v pripade korene.
53  Node_t *pLeft; ///< Ukazatel na leveho potomka uzlu, nebo NULL pro listovy uzel.
54  Node_t *pRight; ///< Ukazatel na praveho potomka uzlu, nebo NULL pro listovy uzel.
55  Color_t color; ///< Barva uzlu (Color_t), tj. RED nebo BLACK.
56 
57  int key; ///< Hodnota/klic tohoto uzlu.
58  };*/
59 
65  BTCreate(&m_pRoot);
66  }
67 
73  BTDestroy(&m_pRoot);
74  }
75 
85  std::pair<bool, Node_t *> InsertNode(int key) {
86 
87  Node_t *pNewNode = NULL;
88  bool bIsNew = BTInsertNode(&m_pRoot, key, &pNewNode);
89 
90  return std::make_pair(bIsNew, pNewNode);
91  }
92 
102  void InsertNodes(const std::vector<int> &keys,
103  std::vector<std::pair<bool, Node_t *> > &outNewNodes) {
104  outNewNodes.clear();
105 
106  std::vector<Node_t *> newNodes(keys.size());
107  std::vector<int> newNodesState(keys.size());
108  BTInsertNodeMany(&m_pRoot, keys.size(), &keys[0], &newNodes[0],
109  &newNodesState[0]);
110 
111  for(size_t i = 0; i < keys.size(); ++i)
112  outNewNodes.push_back(std::make_pair(newNodesState[i] != 0, newNodes[i]));
113  }
114 
121  bool DeleteNode(int key) {
122  return BTDeleteNode(&m_pRoot, key);
123  }
124 
132  Node_t *FindNode(int key) const {
133  return BTFindNode(m_pRoot, key);
134  }
135 
142  void GetLeafNodes(std::vector<Node_t *> &outLeafNodes) {
143  size_t count = 0;
144 
145  BTGetLeafNodes(m_pRoot, &count, NULL);
146 
147  outLeafNodes.resize(count);
148 
149  if(count > 0)
150  BTGetLeafNodes(m_pRoot, &count, &outLeafNodes[0]);
151  }
152 
159  void GetAllNodes(std::vector<Node_t *> &outAllNodes) {
160  size_t count = 0;
161 
162  BTGetAllNodes(m_pRoot, &count, NULL);
163 
164  outAllNodes.resize(count);
165 
166  if(count > 0)
167  BTGetAllNodes(m_pRoot, &count, &outAllNodes[0]);
168  }
169 
177  void GetNonLeafNodes(std::vector<Node_t *> &outNonLeafNodes) {
178  size_t count = 0;
179 
180  BTGetNonLeafNodes(m_pRoot, &count, NULL);
181 
182  outNonLeafNodes.resize(count);
183 
184  if(count > 0)
185  BTGetNonLeafNodes(m_pRoot, &count, &outNonLeafNodes[0]);
186  }
187 
192  Node_t *GetRoot() { return m_pRoot; }
193 
194 protected:
196 };
197 
198 
199 #endif // RED_BLACK_TREE_H_
BinaryTree::DeleteNode
bool DeleteNode(int key)
DeleteNode Pokusi se odstranit uzel s hodnotou "key".
Definition: red_black_tree.h:121
BinaryTree::Color_t
Color_t
The Color_t enum Barva uzlu stromu.
Definition: red_black_tree.h:41
BinaryTree
The BinaryTree class Samo-vyvazujici se binarni strom, kde hodnoty jsou ulozeny pouze ve vnitrnich uz...
Definition: red_black_tree.h:34
BinaryTree::GetAllNodes
void GetAllNodes(std::vector< Node_t * > &outAllNodes)
GetAllNodes Projde cely strom a sestavi pole ukazatelu na vsechny uzly ve stromu.
Definition: red_black_tree.h:159
Node_t
The Node_t struct Struktura uzlu stromu.
Definition: red_black_tree_lib.h:42
BinaryTree::BinaryTree
BinaryTree()
BinaryTree Konstruktor prazdneho binarniho stromu.
Definition: red_black_tree.h:64
BinaryTree::m_pRoot
Node_t * m_pRoot
Ukazatel na koren stromu.
Definition: red_black_tree.h:195
BinaryTree::Node_t
::Node_t Node_t
The Node_t struct Struktura uzlu stromu.
Definition: red_black_tree.h:50
BinaryTree::GetNonLeafNodes
void GetNonLeafNodes(std::vector< Node_t * > &outNonLeafNodes)
GetNonLeafNodes Projde cely strom a sestavi pole ukazatelu na vsechny NE-listove uzly stromu (tedy s ...
Definition: red_black_tree.h:177
BinaryTree::~BinaryTree
~BinaryTree()
BinaryTree Destruktor binarniho stromu, odstrani vsechny uzly v nem obsazene.
Definition: red_black_tree.h:72
BinaryTree::InsertNodes
void InsertNodes(const std::vector< int > &keys, std::vector< std::pair< bool, Node_t * > > &outNewNodes)
InsertNodes Pokusi se vlozit uzly ze seznamu "keys", nebo nalezne, ty ktere jiz existuji.
Definition: red_black_tree.h:102
BinaryTree::InsertNode
std::pair< bool, Node_t * > InsertNode(int key)
InsertNode Pokusi se vlozit novy uzel s hodnotou "key", nebo nalezne jiz existujici uzel s touto hodn...
Definition: red_black_tree.h:85
BinaryTree::GetRoot
Node_t * GetRoot()
GetRoot.
Definition: red_black_tree.h:192
BinaryTree::FindNode
Node_t * FindNode(int key) const
FindNode Pokusi se nalezt uzel s hodnotou "key".
Definition: red_black_tree.h:132
BinaryTree::GetLeafNodes
void GetLeafNodes(std::vector< Node_t * > &outLeafNodes)
GetLeafNodes Projde cely strom a sestavi pole listovych uzlu, ktere nemaji potomky.
Definition: red_black_tree.h:142