Interval tree.
More...
#include <IntervalTree.h>
inet::IntervalTree::IntervalTree |
( |
| ) |
|
the following are used for the query function
59 nil =
new IntervalTreeNode;
65 root =
new IntervalTreeNode;
simtime_t high
Definition: IntervalTree.h:93
unsigned int recursion_node_stack_size
Definition: IntervalTree.h:181
IntervalTreeNode * nil
Definition: IntervalTree.h:158
it_recursion_node * recursion_node_stack
Definition: IntervalTree.h:182
IntervalTreeNode * parent
Definition: IntervalTree.h:104
IntervalTreeNode * right
Definition: IntervalTree.h:102
IntervalTreeNode * root
Definition: IntervalTree.h:156
simtime_t key
Definition: IntervalTree.h:91
bool red
red or black node: if red = false then the node is black
Definition: IntervalTree.h:98
simtime_t max_high
Definition: IntervalTree.h:95
unsigned int recursion_node_stack_top
Definition: IntervalTree.h:184
IntervalTreeNode * left
Definition: IntervalTree.h:100
const Interval * stored_interval
interval stored in the node
Definition: IntervalTree.h:89
IntervalTreeNode * start_node
Definition: IntervalTree.h:113
inet::IntervalTree::~IntervalTree |
( |
| ) |
|
81 std::deque<IntervalTreeNode*> nodes_to_free;
87 nodes_to_free.push_back(x->left);
91 nodes_to_free.push_back(x->right);
95 while (nodes_to_free.size() > 0)
97 x = nodes_to_free.back();
98 nodes_to_free.pop_back();
101 nodes_to_free.push_back(x->left);
105 nodes_to_free.push_back(x->right);
IntervalTreeNode * nil
Definition: IntervalTree.h:158
it_recursion_node * recursion_node_stack
Definition: IntervalTree.h:182
IntervalTreeNode * root
Definition: IntervalTree.h:156
IntervalTreeNode * left
Definition: IntervalTree.h:100
348 IntervalTreeNode* root_left_node =
root->
left;
350 while ((!x->red) && (root_left_node != x))
352 if (x == x->parent->left)
358 x->parent->red =
true;
360 w = x->parent->right;
362 if ((!w->right->red) && (!w->left->red))
371 w->left->red =
false;
374 w = x->parent->right;
376 w->red = x->parent->red;
377 x->parent->red =
false;
378 w->right->red =
false;
389 x->parent->red =
true;
393 if ((!w->right->red) && (!w->left->red))
402 w->right->red =
false;
407 w->red = x->parent->red;
408 x->parent->red =
false;
409 w->left->red =
false;
IntervalTreeNode * parent
Definition: IntervalTree.h:104
IntervalTreeNode * right
Definition: IntervalTree.h:102
IntervalTreeNode * root
Definition: IntervalTree.h:156
void leftRotate(IntervalTreeNode *node)
left rotation of tree node
Definition: IntervalTree.cc:115
bool red
red or black node: if red = false then the node is black
Definition: IntervalTree.h:98
IntervalTreeNode * left
Definition: IntervalTree.h:100
void rightRotate(IntervalTreeNode *node)
right rotation of tree node
Definition: IntervalTree.cc:139
Delete one node of the interval tree.
y should not be nil in this case y is the node to splice out and x is its child
Referenced by inet::physicallayer::VectorCommunicationCache::removeNonInterferingTransmissions(), and inet::physicallayer::MapCommunicationCache::removeTransmission().
447 const Interval* node_to_delete = z->stored_interval;
451 if (
root == (x->parent = y->parent))
457 if (y == y->parent->left)
471 y->
max_high = -SimTime::getMaxTime();
474 y->parent = z->parent;
475 z->left->parent = z->right->parent = y;
476 if (z == z->parent->left)
479 z->parent->right = y;
499 return node_to_delete;
void fixupMaxHigh(IntervalTreeNode *node)
Travels up to the root fixing the max_high fields after an insertion or deletion. ...
Definition: IntervalTree.cc:186
IntervalTreeNode * nil
Definition: IntervalTree.h:158
void deleteFixup(IntervalTreeNode *node)
Definition: IntervalTree.cc:345
IntervalTreeNode * parent
Definition: IntervalTree.h:104
IntervalTreeNode * right
Definition: IntervalTree.h:102
IntervalTreeNode * getSuccessor(IntervalTreeNode *node) const
Get the successor of a given node.
Definition: IntervalTree.cc:272
IntervalTreeNode * root
Definition: IntervalTree.h:156
simtime_t max_high
Definition: IntervalTree.h:95
IntervalTreeNode * left
Definition: IntervalTree.h:100
if(!(yy_init))
Definition: lexer.cc:1644
void inet::IntervalTree::deleteNode |
( |
const Interval * |
ivl | ) |
|
delete node stored a given interval
IntervalTreeNode * nil
Definition: IntervalTree.h:158
const Interval * deleteNode(IntervalTreeNode *node)
Delete one node of the interval tree.
Definition: IntervalTree.cc:443
IntervalTreeNode * recursiveSearch(IntervalTreeNode *node, const Interval *ivl) const
recursively find the node corresponding to the interval
Definition: IntervalTree.cc:425
IntervalTreeNode * root
Definition: IntervalTree.h:156
Travels up to the root fixing the max_high fields after an insertion or deletion.
190 x->max_high =
std::max(x->high,
std::max(x->left->max_high, x->right->max_high));
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
IntervalTreeNode * root
Definition: IntervalTree.h:156
267 while (x->right !=
nil)
IntervalTreeNode * nil
Definition: IntervalTree.h:158
260 while (x->left !=
nil)
IntervalTreeNode * nil
Definition: IntervalTree.h:158
get the predecessor of a given node
299 while (y !=
nil && x == y->
left)
IntervalTreeNode * nil
Definition: IntervalTree.h:158
IntervalTreeNode * getMaximum(IntervalTreeNode *node) const
Definition: IntervalTree.cc:265
IntervalTreeNode * left
Definition: IntervalTree.h:100
Get the successor of a given node.
IntervalTreeNode * nil
Definition: IntervalTree.h:158
IntervalTreeNode * right
Definition: IntervalTree.h:102
IntervalTreeNode * getMinimum(IntervalTreeNode *node) const
Definition: IntervalTree.cc:258
Insert one node of the interval tree.
use sentinel instead of checking for root
Referenced by inet::physicallayer::CommunicationCacheBase::setCachedInterval().
199 IntervalTreeNode* new_node;
201 x =
new IntervalTreeNode(new_interval);
206 while (x->parent->red)
209 if (x->parent == x->parent->parent->left)
211 y = x->parent->parent->right;
214 x->parent->red =
false;
216 x->parent->parent->red =
true;
217 x = x->parent->parent;
221 if (x == x->parent->right)
226 x->parent->red =
false;
227 x->parent->parent->red =
true;
233 y = x->parent->parent->left;
236 x->parent->red =
false;
238 x->parent->parent->red =
true;
239 x = x->parent->parent;
243 if (x == x->parent->left)
248 x->parent->red =
false;
249 x->parent->parent->red =
true;
void fixupMaxHigh(IntervalTreeNode *node)
Travels up to the root fixing the max_high fields after an insertion or deletion. ...
Definition: IntervalTree.cc:186
void recursiveInsert(IntervalTreeNode *node)
recursively insert a node
Definition: IntervalTree.cc:163
IntervalTreeNode * root
Definition: IntervalTree.h:156
void leftRotate(IntervalTreeNode *node)
left rotation of tree node
Definition: IntervalTree.cc:115
bool red
red or black node: if red = false then the node is black
Definition: IntervalTree.h:98
IntervalTreeNode * left
Definition: IntervalTree.h:100
void rightRotate(IntervalTreeNode *node)
right rotation of tree node
Definition: IntervalTree.cc:139
left rotation of tree node
125 y->parent = x->parent;
127 if (x == x->parent->left)
130 x->parent->right = y;
135 x->max_high =
std::max(x->left->max_high,
std::max(x->right->max_high, x->high));
IntervalTreeNode * nil
Definition: IntervalTree.h:158
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
void inet::IntervalTree::print |
( |
| ) |
const |
Print the whole interval tree.
void recursivePrint(IntervalTreeNode *node) const
recursively print a subtree
Definition: IntervalTree.cc:330
IntervalTreeNode * root
Definition: IntervalTree.h:156
IntervalTreeNode * left
Definition: IntervalTree.h:100
std::deque< const Interval * > inet::IntervalTree::query |
( |
simtime_t |
low, |
|
|
simtime_t |
high |
|
) |
| |
Return result for a given query.
Referenced by inet::physicallayer::CommunicationCacheBase::computeInterferingTransmissions().
517 std::deque<const Interval*> result_stack;
519 bool run = (x !=
nil);
525 if (
overlap(low, high, x->key, x->high))
527 result_stack.push_back(x->stored_interval);
530 if (x->left->max_high >= low)
unsigned int parent_index
Definition: IntervalTree.h:115
bool overlap(simtime_t a1, simtime_t a2, simtime_t b1, simtime_t b2)
returns 1 if the intervals overlap, and 0 otherwise
Definition: IntervalTree.cc:503
unsigned int recursion_node_stack_size
Definition: IntervalTree.h:181
IntervalTreeNode * nil
Definition: IntervalTree.h:158
it_recursion_node * recursion_node_stack
Definition: IntervalTree.h:182
IntervalTreeNode * right
Definition: IntervalTree.h:102
IntervalTreeNode * root
Definition: IntervalTree.h:156
unsigned int current_parent
Definition: IntervalTree.h:183
unsigned int recursion_node_stack_top
Definition: IntervalTree.h:184
IntervalTreeNode * left
Definition: IntervalTree.h:100
bool try_right_branch
Definition: IntervalTree.h:117
IntervalTreeNode * start_node
Definition: IntervalTree.h:113
recursively insert a node
Inserts z into the tree as if it were a regular binary tree.
168 z->left = z->right =
nil;
180 if ((y ==
root) || (y->key > z->key))
IntervalTreeNode * nil
Definition: IntervalTree.h:158
IntervalTreeNode * parent
Definition: IntervalTree.h:104
IntervalTreeNode * right
Definition: IntervalTree.h:102
IntervalTreeNode * root
Definition: IntervalTree.h:156
IntervalTreeNode * left
Definition: IntervalTree.h:100
recursively print a subtree
IntervalTreeNode * nil
Definition: IntervalTree.h:158
void recursivePrint(IntervalTreeNode *node) const
recursively print a subtree
Definition: IntervalTree.cc:330
IntervalTreeNode * root
Definition: IntervalTree.h:156
recursively find the node corresponding to the interval
429 if (node->stored_interval == ivl)
IntervalTreeNode * nil
Definition: IntervalTree.h:158
IntervalTreeNode * recursiveSearch(IntervalTreeNode *node, const Interval *ivl) const
recursively find the node corresponding to the interval
Definition: IntervalTree.cc:425
right rotation of tree node
147 x->right->parent = y;
149 x->parent = y->parent;
150 if (y == y->parent->left)
153 y->parent->right = x;
158 y->max_high =
std::max(y->left->max_high,
std::max(y->right->max_high, y->high));
IntervalTreeNode * nil
Definition: IntervalTree.h:158
IntervalTreeNode * right
Definition: IntervalTree.h:102
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
friend class IntervalTreeTest |
|
friend |
unsigned int inet::IntervalTree::current_parent = 0 |
|
private |
unsigned int inet::IntervalTree::recursion_node_stack_size = 0 |
|
private |
unsigned int inet::IntervalTree::recursion_node_stack_top = 0 |
|
private |
The documentation for this class was generated from the following files: