From f5f9d9ba273a0ea0739eb50cf4e32abc9dafd205 Mon Sep 17 00:00:00 2001 From: Dominik Kempa Date: Sat, 9 Jan 2021 09:41:28 -0800 Subject: [PATCH] Put the code in src/ + update READMEs --- no-parent-pointer/README | 13 ------- .../no-parent-pointer}/Makefile | 0 src/no-parent-pointer/README | 10 ++++++ .../no-parent-pointer}/main.cpp | 0 .../no-parent-pointer}/zip_tree.hpp | 36 +++++++++++++++++-- .../correctness-tests/Makefile | 0 .../correctness-tests/README | 10 ++++++ .../correctness-tests/main.cpp | 0 .../correctness-tests}/zip_tree.hpp | 36 +++++++++++++++++-- .../with-parent-pointer}/speed-tests/Makefile | 0 src/with-parent-pointer/speed-tests/README | 24 +++++++++++++ .../with-parent-pointer}/speed-tests/main.cpp | 0 .../speed-tests}/zip_tree.hpp | 36 +++++++++++++++++-- with-parent-pointer/correctness-tests/README | 13 ------- with-parent-pointer/speed-tests/README | 31 ---------------- 15 files changed, 146 insertions(+), 63 deletions(-) delete mode 100644 no-parent-pointer/README rename {no-parent-pointer => src/no-parent-pointer}/Makefile (100%) create mode 100644 src/no-parent-pointer/README rename {no-parent-pointer => src/no-parent-pointer}/main.cpp (100%) rename {no-parent-pointer => src/no-parent-pointer}/zip_tree.hpp (90%) rename {with-parent-pointer => src/with-parent-pointer}/correctness-tests/Makefile (100%) create mode 100644 src/with-parent-pointer/correctness-tests/README rename {with-parent-pointer => src/with-parent-pointer}/correctness-tests/main.cpp (100%) rename {with-parent-pointer/speed-tests => src/with-parent-pointer/correctness-tests}/zip_tree.hpp (93%) rename {with-parent-pointer => src/with-parent-pointer}/speed-tests/Makefile (100%) create mode 100644 src/with-parent-pointer/speed-tests/README rename {with-parent-pointer => src/with-parent-pointer}/speed-tests/main.cpp (100%) rename {with-parent-pointer/correctness-tests => src/with-parent-pointer/speed-tests}/zip_tree.hpp (93%) delete mode 100644 with-parent-pointer/correctness-tests/README delete mode 100644 with-parent-pointer/speed-tests/README diff --git a/no-parent-pointer/README b/no-parent-pointer/README deleted file mode 100644 index 49b297c..0000000 --- a/no-parent-pointer/README +++ /dev/null @@ -1,13 +0,0 @@ -To test the tree type - - $ make - -and then - - $ ./test - -It checks the correctness of the code. -I tried running it under valgrind and -it does not report any leaks. - -- Dominik diff --git a/no-parent-pointer/Makefile b/src/no-parent-pointer/Makefile similarity index 100% rename from no-parent-pointer/Makefile rename to src/no-parent-pointer/Makefile diff --git a/src/no-parent-pointer/README b/src/no-parent-pointer/README new file mode 100644 index 0000000..9b8bfe6 --- /dev/null +++ b/src/no-parent-pointer/README @@ -0,0 +1,10 @@ +To test the tree type + + $ make + +and then + + $ ./test + +It checks the correctness of the code. Tests until valgrind (with the +--leak-check=full flag) report no leaks. diff --git a/no-parent-pointer/main.cpp b/src/no-parent-pointer/main.cpp similarity index 100% rename from no-parent-pointer/main.cpp rename to src/no-parent-pointer/main.cpp diff --git a/no-parent-pointer/zip_tree.hpp b/src/no-parent-pointer/zip_tree.hpp similarity index 90% rename from no-parent-pointer/zip_tree.hpp rename to src/no-parent-pointer/zip_tree.hpp index c08703e..073d696 100644 --- a/no-parent-pointer/zip_tree.hpp +++ b/src/no-parent-pointer/zip_tree.hpp @@ -1,3 +1,35 @@ +/** + * @file zip_tree.hpp + * @section LICENCE + * + * Implementation of the Zip Tree without parent pointer, v0.1.0 + * See: https://github.com/dominikkempa/zip-tree + * + * Copyright (C) 2018-2020 + * Dominik Kempa + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + **/ + #ifndef __ZIP_TREE_HPP_INCLUDED #define __ZIP_TREE_HPP_INCLUDED @@ -7,7 +39,7 @@ //============================================================================= -// Node of a zip-tree. +// Node of a Zip Tree. //============================================================================= template class node { @@ -47,7 +79,7 @@ class node { }; //============================================================================= -// Simple implementation of zip-tree. It works with any key_type as +// Simple implementation of Zip Tree. It works with any key_type as // long as objects of key_type can be compared using "<" operator. //============================================================================= template diff --git a/with-parent-pointer/correctness-tests/Makefile b/src/with-parent-pointer/correctness-tests/Makefile similarity index 100% rename from with-parent-pointer/correctness-tests/Makefile rename to src/with-parent-pointer/correctness-tests/Makefile diff --git a/src/with-parent-pointer/correctness-tests/README b/src/with-parent-pointer/correctness-tests/README new file mode 100644 index 0000000..9b8bfe6 --- /dev/null +++ b/src/with-parent-pointer/correctness-tests/README @@ -0,0 +1,10 @@ +To test the tree type + + $ make + +and then + + $ ./test + +It checks the correctness of the code. Tests until valgrind (with the +--leak-check=full flag) report no leaks. diff --git a/with-parent-pointer/correctness-tests/main.cpp b/src/with-parent-pointer/correctness-tests/main.cpp similarity index 100% rename from with-parent-pointer/correctness-tests/main.cpp rename to src/with-parent-pointer/correctness-tests/main.cpp diff --git a/with-parent-pointer/speed-tests/zip_tree.hpp b/src/with-parent-pointer/correctness-tests/zip_tree.hpp similarity index 93% rename from with-parent-pointer/speed-tests/zip_tree.hpp rename to src/with-parent-pointer/correctness-tests/zip_tree.hpp index 3289ff4..741a24d 100644 --- a/with-parent-pointer/speed-tests/zip_tree.hpp +++ b/src/with-parent-pointer/correctness-tests/zip_tree.hpp @@ -1,3 +1,35 @@ +/** + * @file zip_tree.hpp + * @section LICENCE + * + * Implementation of the Zip Tree with parent pointer, v0.1.0 + * See: https://github.com/dominikkempa/zip-tree + * + * Copyright (C) 2018-2020 + * Dominik Kempa + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + **/ + #ifndef __ZIP_TREE_HPP_INCLUDED #define __ZIP_TREE_HPP_INCLUDED @@ -7,7 +39,7 @@ //============================================================================= -// Node of a zip-tree. +// Node of a Zip Tree. //============================================================================= template class node { @@ -50,7 +82,7 @@ class node { }; //============================================================================= -// Simple implementation of zip-tree. It works with any key_type as +// Simple implementation of Zip Tree. It works with any key_type as // long as objects of key_type can be compared using "<" operator. //============================================================================= template diff --git a/with-parent-pointer/speed-tests/Makefile b/src/with-parent-pointer/speed-tests/Makefile similarity index 100% rename from with-parent-pointer/speed-tests/Makefile rename to src/with-parent-pointer/speed-tests/Makefile diff --git a/src/with-parent-pointer/speed-tests/README b/src/with-parent-pointer/speed-tests/README new file mode 100644 index 0000000..524e314 --- /dev/null +++ b/src/with-parent-pointer/speed-tests/README @@ -0,0 +1,24 @@ +To run performance tests type + + $ make + +and then + + $ ./test + +The results for this preliminary implementation of Zip Trees are +already very interesting. On my computer the insertion into Zip Trees +(in random order) is only about 50% slower than for Red-Black +trees. Interestingly, insertion in sorted order is usually slightly +faster for Zip Trees. + +As for searching and deleting, on my machine the Zip Trees are only +about 15-25% slower than Red-Black trees. + +Perhaps further engineering of Zip Trees can yield some improvements, +e.g., eliminating recursion in the insertion. I studied a bit the +Reb-Black tree implementation in the C++ standard library and found +that most functions are re-written into iterative versions, e.g., see +the _Rb_tree_insert_and_rebalance function in + +github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/src/c++98/tree.cc diff --git a/with-parent-pointer/speed-tests/main.cpp b/src/with-parent-pointer/speed-tests/main.cpp similarity index 100% rename from with-parent-pointer/speed-tests/main.cpp rename to src/with-parent-pointer/speed-tests/main.cpp diff --git a/with-parent-pointer/correctness-tests/zip_tree.hpp b/src/with-parent-pointer/speed-tests/zip_tree.hpp similarity index 93% rename from with-parent-pointer/correctness-tests/zip_tree.hpp rename to src/with-parent-pointer/speed-tests/zip_tree.hpp index 3289ff4..741a24d 100644 --- a/with-parent-pointer/correctness-tests/zip_tree.hpp +++ b/src/with-parent-pointer/speed-tests/zip_tree.hpp @@ -1,3 +1,35 @@ +/** + * @file zip_tree.hpp + * @section LICENCE + * + * Implementation of the Zip Tree with parent pointer, v0.1.0 + * See: https://github.com/dominikkempa/zip-tree + * + * Copyright (C) 2018-2020 + * Dominik Kempa + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + **/ + #ifndef __ZIP_TREE_HPP_INCLUDED #define __ZIP_TREE_HPP_INCLUDED @@ -7,7 +39,7 @@ //============================================================================= -// Node of a zip-tree. +// Node of a Zip Tree. //============================================================================= template class node { @@ -50,7 +82,7 @@ class node { }; //============================================================================= -// Simple implementation of zip-tree. It works with any key_type as +// Simple implementation of Zip Tree. It works with any key_type as // long as objects of key_type can be compared using "<" operator. //============================================================================= template diff --git a/with-parent-pointer/correctness-tests/README b/with-parent-pointer/correctness-tests/README deleted file mode 100644 index 49b297c..0000000 --- a/with-parent-pointer/correctness-tests/README +++ /dev/null @@ -1,13 +0,0 @@ -To test the tree type - - $ make - -and then - - $ ./test - -It checks the correctness of the code. -I tried running it under valgrind and -it does not report any leaks. - -- Dominik diff --git a/with-parent-pointer/speed-tests/README b/with-parent-pointer/speed-tests/README deleted file mode 100644 index 6e3cd5e..0000000 --- a/with-parent-pointer/speed-tests/README +++ /dev/null @@ -1,31 +0,0 @@ -To run performance tests type - - $ make - -and then - - $ ./test - -The results for this preliminary implementation -of zip-trees are already very interesting. On my -computer the insertion into zip-trees (in random -order) is only about 50% slower than for red-back -trees. Interestingly, insertion in sorted order -is usually slightly faster for zip-trees. - -As for searching and deleting, on my machine -zip-trees are only about 15-25% slower than -red black trees. - -Perhaps further engineering of zip-trees can -yield some improvements, e.g., eliminating -recursion in the insertion. I studied a bit -the reb-black implementation in the C++ standard -library and found that most functions are -re-written into iterative versions, e.g., -see the _Rb_tree_insert_and_rebalance function in - -https://github.com/gcc-mirror/gcc/blob -/master/libstdc++-v3/src/c++98/tree.cc - -- Dominik