File tree Expand file tree Collapse file tree 6 files changed +61
-6
lines changed Expand file tree Collapse file tree 6 files changed +61
-6
lines changed Original file line number Diff line number Diff line change
1
+ 2022-02-13 Kasper Peeters <
[email protected] >
2
+
3
+ * Include <string> to avoid compilation errors.
4
+
1
5
2020-11-07 Kasper Peeters <
[email protected] >
2
6
3
7
* Release 3.17
Original file line number Diff line number Diff line change @@ -108,7 +108,26 @@ keep effect for a single increment or decrement of the
108
108
iterator. Finally, whether or not an iterator is actually pointing at
109
109
a node (i.e.~ is not an "end" iterator) can be tested using the
110
110
`` is_valid(iterator) `` member of the tree class.
111
-
111
+
112
+ - ** Paths** :
113
+
114
+ Tree iterators, like those for all STL containers, are tied to the
115
+ container, and cannot simply be used to "access an element at the
116
+ same location in a different tree" (they are, in essence, wrappers
117
+ for pointers to memory locations). If you want a representation of
118
+ the iterator which is independent of the particular location where
119
+ your tree is located in memory, use the following two methods:
120
+
121
+ `` path_from_iterator(iterator, top) `` : obtain a `` path_t `` object
122
+ from an iterator, relative to the iterator `` top `` .
123
+
124
+ `` iterator_from_path(path, top) `` : the inverse of the above, that
125
+ is, obtain an iterator from a `` path_t `` object.
126
+
127
+ Paths are simply vectors of integers, indicating which child branch
128
+ to follow at every depth of the tree. See `` src/sample_path.cc `` for
129
+ an example.
130
+
112
131
113
132
Basic operations
114
133
----------------
Original file line number Diff line number Diff line change 4
4
test2
5
5
test3
6
6
test4
7
+ sample_path
8
+ test_tree
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ test2: test2.o
13
13
test_tree : test_tree.o
14
14
g++ -o test_tree test_tree.o
15
15
16
+ sample_path : sample_path.o
17
+ g++ -o sample_path sample_path.o
18
+
16
19
run_tests : test1 test1.req
17
20
./test1 > test1.res
18
21
@diff test1.res test1.req
Original file line number Diff line number Diff line change
1
+
2
+ #include " tree.hh"
3
+ #include < iostream>
4
+
5
+ // Sample to demonstrate how to turn a tree iterator into a
6
+ // path_t, which is a vector of integers indicating which
7
+ // child is taken at any depth.
8
+
9
+ int main (int argc, char **argv)
10
+ {
11
+ tree<std::string> tr;
12
+
13
+ tr.set_head (" head" );
14
+ auto i1 = tr.append_child (tr.begin (), " one" );
15
+ auto i2 = tr.append_child (tr.begin (), " two" );
16
+ auto i3 = tr.append_child (tr.begin (), " three" );
17
+ auto i4 = tr.append_child (i2, " four" );
18
+ auto i5 = tr.append_child (i2, " five" );
19
+
20
+ auto path = tr.path_from_iterator (i5, tr.begin ());
21
+ for (auto & p: path)
22
+ std::cerr << p << " /" ;
23
+ std::cerr << std::endl; // prints '0/1/1/'
24
+
25
+ auto fnd = tr.iterator_from_path (path, tr.begin ());
26
+ std::cerr << *fnd << std::endl; // prints 'five'
27
+ }
Original file line number Diff line number Diff line change 9
9
10
10
/* * \mainpage tree.hh
11
11
\author Kasper Peeters
12
- \version 3.17
13
- \date 07-Nov-2020
12
+ \version 3.18
13
+ \date 13-Feb-2021
14
14
\see http://tree.phi-sci.com/
15
15
\see http://github.com/kpeeters/tree.hh/
16
16
34
34
#include < queue>
35
35
#include < algorithm>
36
36
#include < cstddef>
37
-
37
+ # include < string >
38
38
39
39
// / A node in the tree, combining links to other nodes as well as the actual data.
40
40
template <class T >
@@ -86,7 +86,7 @@ class navigation_error : public std::logic_error {
86
86
// std::cerr << boost::stacktrace::stacktrace() << std::endl;
87
87
// str << boost::stacktrace::stacktrace();
88
88
// stacktrace=str.str();
89
- };
89
+ }
90
90
91
91
// virtual const char *what() const noexcept override
92
92
// {
@@ -503,7 +503,7 @@ class tree {
503
503
template <class StrictWeakOrdering >
504
504
class compare_nodes {
505
505
public:
506
- compare_nodes (StrictWeakOrdering comp) : comp_(comp) {};
506
+ compare_nodes (StrictWeakOrdering comp) : comp_(comp) {}
507
507
508
508
bool operator ()(const tree_node *a, const tree_node *b)
509
509
{
You can’t perform that action at this time.
0 commit comments