Skip to content

Commit d51fb5b

Browse files
committed
Initial commit
0 parents  commit d51fb5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+13090
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
src/btree
2+
src/kd_tree
3+
src/orthtree

.vscode/settings.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"files.associations": {
3+
"array": "cpp",
4+
"*.tcc": "cpp",
5+
"cctype": "cpp",
6+
"chrono": "cpp",
7+
"clocale": "cpp",
8+
"cmath": "cpp",
9+
"cstdint": "cpp",
10+
"cstdio": "cpp",
11+
"cstdlib": "cpp",
12+
"cstring": "cpp",
13+
"ctime": "cpp",
14+
"cwchar": "cpp",
15+
"cwctype": "cpp",
16+
"exception": "cpp",
17+
"functional": "cpp",
18+
"initializer_list": "cpp",
19+
"iosfwd": "cpp",
20+
"iostream": "cpp",
21+
"istream": "cpp",
22+
"limits": "cpp",
23+
"memory": "cpp",
24+
"new": "cpp",
25+
"numeric": "cpp",
26+
"optional": "cpp",
27+
"ostream": "cpp",
28+
"ratio": "cpp",
29+
"stdexcept": "cpp",
30+
"streambuf": "cpp",
31+
"string_view": "cpp",
32+
"system_error": "cpp",
33+
"tuple": "cpp",
34+
"type_traits": "cpp",
35+
"typeinfo": "cpp",
36+
"utility": "cpp",
37+
"variant": "cpp",
38+
"cstddef": "cpp",
39+
"fstream": "cpp",
40+
"iomanip": "cpp",
41+
"sstream": "cpp"
42+
}
43+
}

.vscode/tasks.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{ "taskName": "Compile examples", "type": "shell", "group": "build", "command": "make clean all -C docs/examples" },
5+
{ "taskName": "Do tests", "type": "shell", "group": "test", "command": "make tests -C test && test/test" },
6+
{ "taskName": "Compile tests", "type": "shell", "group": "test", "command": "make tests -C test" },
7+
{ "taskName": "Run tests", "type": "shell", "group": "test", "command": "test/test" } ]
8+
}

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# gmd-tree-library: STL-like Tree Library for C++
2+
3+
**gmd-tree-library** is a templated container library built in C++. It contains several types of trees, acting as replacements for the *set*, *multiset*, *map*, and *multimap* containers of the STL. Its public interface is similar to the one found in the STL, with some extra functionality, specially on type conversion and iterators.
4+
5+
## Usage
6+
7+
**Requirements:** To use this library, a C++17 version of the compiler is required.
8+
9+
This library adopts the single include policy. To use it, download the [latest release](https://github.com/gmardau/gmd-tree-library/releases) and place *src/* and *tree* in the desired location. Everything else can be removed. Finally, include the file *tree* in your project.
10+
11+
[**API Reference**](https://github.com/gmardau/gmd-tree-library/blob/master/docs/wiki/tree.md)
12+
13+
**Examples:** Example files can be found in docs/examples.
14+
15+
## Future Development
16+
17+
At the time of writing, the library contains only Binary trees. In future releases this library is expected to include Space Partitioning trees (namely KD-trees and Orthrees (n-analogue of quadtrees)) and B-trees.
18+
19+
## License
20+
21+
**gmd-tree-library** is released under the [GNU General Public License v3.0](https://github.com/gmardau/gmd-tree-library/blob/master/LICENSE).
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
3+
using intpair = std::pair<int, int>;
4+
std::ostream& operator<<(std::ostream& os, const intpair& i) {
5+
os << i.first << ',' << i.second; return os;
6+
}
7+
8+
int main(const int, const char **)
9+
{
10+
gmd::binary_tree_map<gmd::tree_avl, int, int> a{{3,1}, {1,2}, {2,3}};
11+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
12+
13+
std::cout << "access value of key 2: " << a[2] << '\n';
14+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
15+
16+
std::cout << "setting value of key 3: " << (a[3] = 3) << '\n';
17+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
18+
19+
std::cout << "access value of key 4: " << a[4] << '\n';
20+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
21+
22+
std::cout << "setting value of key 5: " << (a[5] = 5) << '\n';
23+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
24+
25+
return 0;
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
3+
using intpair = std::pair<int, int>;
4+
std::ostream& operator<<(std::ostream& os, const intpair& i) {
5+
os << i.first << ',' << i.second; return os;
6+
}
7+
8+
int main(const int, const char **)
9+
{
10+
// (1) Copy assignment
11+
gmd::binary_tree_map<gmd::tree_avl, int, int> a{{3,0}, {5,0}, {2,0}};
12+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
13+
gmd::binary_tree_map<gmd::tree_avl, int, int> b; b = a;
14+
std::cout << "b: "; for(intpair &x: b) std::cout << x << ' '; std::cout << '\n';
15+
16+
// (2) Move assignment
17+
gmd::binary_tree_multimap<gmd::tree_avl, int, int> c{{1,0}, {6,0}, {1, 1}};
18+
std::cout << "c: "; for(intpair &x: c) std::cout << x << ' '; std::cout << '\n';
19+
gmd::binary_tree_map<gmd::tree_rb, int, int> d; d = std::move(c);
20+
std::cout << "c: "; for(intpair &x: c) std::cout << x << ' '; std::cout << '\n';
21+
std::cout << "d: "; for(intpair &x: d) std::cout << x << ' '; std::cout << '\n';
22+
23+
// (3) Initializer list assignment
24+
a = {{7,0}, {4,0}};
25+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
26+
27+
return 0;
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
3+
using intpair = std::pair<int, int>;
4+
std::ostream& operator<<(std::ostream& os, const intpair& i) {
5+
os << i.first << ',' << i.second; return os;
6+
}
7+
8+
int main(const int, const char **)
9+
{
10+
gmd::binary_tree_map<gmd::tree_avl, int, int> a{{3,1}, {1,2}, {2,3}};
11+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
12+
13+
std::cout << "access value of key 2: " << a.at(2) << '\n';
14+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
15+
16+
std::cout << "setting value of key 3: " << (a.at(3) = 3) << '\n';
17+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
18+
19+
try {
20+
std::cout << "access value of key 4: " << a.at(4) << '\n';
21+
} catch (std::exception &e) {
22+
std::cout << e.what() << '\n';
23+
}
24+
25+
return 0;
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
3+
using intpair = std::pair<int, int>;
4+
std::ostream& operator<<(std::ostream& os, const intpair& i) {
5+
os << i.first << ',' << i.second; return os;
6+
}
7+
8+
int main(const int, const char **)
9+
{
10+
gmd::binary_tree_map<gmd::tree_avl, int, int> a;
11+
12+
std::cout << "empty: " << (a.empty() ? "true" : "false") << "\n";
13+
std::cout << "size: " << a.size() << "\n";
14+
a.insert({{3,0}, {1,0}, {2,0}});
15+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
16+
std::cout << "empty: " << (a.empty() ? "true" : "false") << "\n";
17+
std::cout << "size: " << a.size() << "\n";
18+
19+
std::cout << "max_size: " << a.max_size() << "\n";
20+
21+
return 0;
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <iostream>
2+
3+
using intpair = std::pair<int, int>;
4+
std::ostream& operator<<(std::ostream& os, const intpair& i) {
5+
os << i.first << ',' << i.second; return os;
6+
}
7+
8+
int main(const int, const char **)
9+
{
10+
gmd::binary_tree_map<gmd::tree_avl, int, int> a{{4,0}, {2,0}, {3,0}, {1,0}};
11+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
12+
13+
a.clear();
14+
std::cout << "a: "; for(intpair &x: a) std::cout << x << ' '; std::cout << '\n';
15+
std::cout << "size: " << a.size() << "\n";
16+
17+
return 0;
18+
}

0 commit comments

Comments
 (0)