Automatic date update in version.in
[binutils-gdb.git] / gprofng / src / PRBTree.h
blob1a6f07f1cddb496393cf99a8e5601fb661f9046b
1 /* Copyright (C) 2021 Free Software Foundation, Inc.
2 Contributed by Oracle.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 // The Persistent Red-Black Tree
25 #ifndef _PRBTREE_H
26 #define _PRBTREE_H
28 #include "dbe_types.h"
29 template <class ITEM> class Vector;
31 // The number of pointers in a node must be set greater than 2.
32 // The higher the number the faster the search seems to be and
33 // the more memory the tree takes.
34 #define NPTRS 5
36 class PRBTree
38 public:
40 typedef Vaddr Key_t;
41 typedef hrtime_t Time_t;
43 PRBTree ();
44 ~PRBTree ();
46 bool insert (Key_t key, Time_t ts, void *item);
47 bool remove (Key_t key, Time_t ts);
48 void *locate (Key_t key, Time_t ts);
49 void *locate_exact_match (Key_t key, Time_t ts);
50 void *locate_up (Key_t key, Time_t ts);
51 Vector<void *> *values ();
53 private:
55 enum Color
57 Red,
58 Black
61 enum Direction
63 None,
64 Left,
65 Right
68 struct LMap
70 Key_t key;
71 void *item;
72 LMap *parent;
73 LMap *chld[NPTRS];
74 Time_t time[NPTRS];
75 char dir[NPTRS];
76 char color;
77 LMap *next;
79 LMap (Key_t _key, void *_item);
80 LMap (const LMap& lm);
82 friend struct LMap;
84 LMap *mlist; // The master list of all nodes
85 Vector<LMap*> *roots;
86 Vector<Time_t> *times;
87 Vector<void *> *vals;
88 LMap *root;
89 Time_t rtts; // root timestamp
90 Time_t curts; // last update timestamp
92 LMap *rb_locate (Key_t key, Time_t ts, bool low);
93 LMap *rb_new_node (Key_t key, void *item);
94 LMap *rb_new_node (LMap *lm);
95 LMap *rb_copy_node (LMap *lm, Direction d);
96 LMap *rb_fix_chld (LMap *prnt, LMap *lm, Direction d);
97 LMap *rb_rotate (LMap *x, Direction d);
98 void rb_remove_fixup (LMap *x, LMap *prnt, Direction d0);
100 static LMap *rb_child (LMap *lm, Direction d, Time_t ts);
101 static Direction rb_which_chld (LMap *lm);
102 static LMap *rb_neighbor (LMap *lm, Time_t ts);
106 #endif /* _PRBTREE_H */