Inkscape
Vector Graphics Editor
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
redblacktree.h
Go to the documentation of this file.
1
41#ifndef SEEN_LIB2GEOM_REDBLACKTREE_H
42#define SEEN_LIB2GEOM_REDBLACKTREE_H
43
44#include <vector>
45//#include <cassert>
46#include <limits>
47#include <cfloat>
48
49#include <2geom/d2.h>
50#include <2geom/interval.h>
51
52namespace Geom{
53
54class RedBlack{
55public:
56 Interval interval; // Key of the redblack tree will be the min of the interval
58 bool isRed;
59 Coord subtree_max; // subtree_max = max( x->left->subtree_max, x->right->subtree_max, x->high )
60 int data;
61
62 RedBlack(): left(0), right(0), parent(0), isRed(false), subtree_max(0.0), data(0) {
63 Interval interval(0.0, 0.0);
64 }
65/*
66 RedBlack(Coord min, Coord max): left(0), right(0), parent(0), isRed(false), subtree_max(0.0), data(0) {
67 Interval interval( min, max );
68 }
69*/
70 inline Coord key(){ return interval.min(); };
71 inline Coord high(){ return interval.max(); };
72};
73
74
76public:
78
80
81 void insert(Rect const &r, int shape, int dimension);
82 void insert(Coord dimension_min, Coord dimension_max, int shape);
83
84 void erase(Rect const &r);
85 void erase(int shape);
86
87 RedBlack* search(Rect const &r, int dimension);
90
91 void print_tree();
92private:
96
97 void left_rotate(RedBlack* x);
98 void right_rotate(RedBlack* x);
99 void tree_insert(RedBlack* x);
100
101 void update_max(RedBlack* x);
102
103 RedBlack* erase(RedBlack* x); // TODO why rerutn pointer? to collect garbage ???
104 void erase_fixup(RedBlack* x);
105
106};
107
108} // end namespace Geom
109
110#endif // !SEEN_LIB2GEOM_REDBLACKTREE_H
111
112/*
113 Local Variables:
114 mode:c++
115 c-file-style:"stroustrup"
116 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
117 indent-tabs-mode:nil
118 fill-column:99
119 End:
120*/
121// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
constexpr C min() const
constexpr C max() const
Range of real numbers that is never empty.
Definition interval.h:59
Axis aligned, non-empty rectangle.
Definition rect.h:92
void update_max(RedBlack *x)
void left_rotate(RedBlack *x)
void erase_fixup(RedBlack *x)
RedBlack * tree_successor(RedBlack *x)
RedBlack * search(Coord a, Coord b)
RedBlack * tree_minimum(RedBlack *x)
void insert(Rect const &r, int shape, int dimension)
RedBlack * search(Rect const &r, int dimension)
void inorder_tree_walk(RedBlack *x)
void right_rotate(RedBlack *x)
void tree_insert(RedBlack *x)
void erase(Rect const &r)
void erase(int shape)
RedBlack * right
RedBlack * left
Interval interval
RedBlack * parent
Lifts one dimensional objects into 2D.
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
Simple closed interval class.
Various utility functions.
Definition affine.h:22