146# include <gsl/gsl_rng.h>
185 cout <<
"(" << node->get_key() <<
"," << node->get_data() <<
")";
193 return x != 0
and not (x & (x - 1));
200template <
typename Key>
209template <
template <
typename,
class>
class TreeType,
215 cout <<
"Sampling at 2^" <<
k <<
" = " << n <<
" ..." <<
endl;
219 cout <<
" Computing height ..." <<
endl;
221 cout <<
" done = " << height <<
endl
223 <<
" Computing IPL ..." <<
endl;
225 cout <<
" done = " <<
ipl <<
endl
229 using Chrono = std::chrono::high_resolution_clock;
239 while (tree.search(value) !=
nullptr)
249 (
void) tree.insert(p);
308 <<
" height = " << height <<
endl
318template <
template <
typename ,
class >
class TreeType>
324 static const size_t N = 64;
326 int height[
N],
ipl[
N];
329 for (
unsigned int i = 0; i < n; i++)
352 printf(
"#2^k n h ipc [min ins med sigma max] [min ins med sigma max]\n");
353 for (
int i = 0; i <
num_pow; ++i)
357 printf(
"%02d %08d %02d %08d %02.2f %02.2f %02.2f %02.2f %02.2f"
358 " %02.2f %02.2f %02.2f %02.2f %02.2f\n",
359 i, (
int)
pow(2, i), height[i],
ipl[i],
383template <
template <
typename,
class>
class Tree>
419 return bench.type == type;
442static char doc[] =
"timeAllTree -- Benchmark Aleph tree implementations";
443static char argDoc[] =
"-n num_nodes -m seed_for_random [tree options]\n";
472 "Specify the number of nodes to be generated", 0
476 "Specify the seed for randon number generator", 0
496 if (state->argv[state->next] ==
nullptr)
499 if (*end !=
'\0' && *end !=
'\n')
543 if (state->argv[state->next] ==
nullptr)
546 if (*end !=
'\0' && *end !=
'\n')
562 cout <<
"timeAllTree -- benchmark Aleph-w binary search tree implementations\n"
564 <<
"Grows a tree to n keys (sampling at each power of 2) and reports\n"
565 <<
"height, internal path length (IPL), and insertion/removal timing\n"
566 <<
"statistics (min / avg / median / sigma / max).\n"
569 <<
" " <<
argv[0] <<
" <tree-flags> [-n num_nodes] [-m seed]\n"
571 <<
"Tree type flags (at least one required, or use --all):\n"
572 <<
" -b, --bin Unbalanced BST (BinTree)\n"
573 <<
" -a, --avl AVL tree\n"
574 <<
" --avlrk AVL tree (ranked)\n"
575 <<
" -s, --splay Splay tree\n"
576 <<
" --splayrk Splay tree (ranked)\n"
577 <<
" -r, --redblack Red-black tree\n"
578 <<
" --redblackrk Red-black tree (ranked)\n"
579 <<
" --tdrb Top-down red-black tree\n"
580 <<
" --tdrbrk Top-down red-black tree (ranked)\n"
581 <<
" -p, --treap Treap\n"
582 <<
" --treaprk Treap (ranked)\n"
583 <<
" -d, --rand Randomized tree\n"
584 <<
" -l, --all Benchmark all tree types\n"
587 <<
" -n num_nodes Number of keys to insert (default: 1000)\n"
588 <<
" -m seed RNG seed (default: current time)\n"
591 <<
" " <<
argv[0] <<
" --all -n 10000 -m 42\n"
592 <<
" " <<
argv[0] <<
" -a -r -n 50000\n"
593 <<
" " <<
argv[0] <<
" --avlrk --treaprk -n 20000 -m 456\n";
602 unsigned long n = pars.
n;
607 std::vector<const TreeBenchmark *>
benches;
622 AH_ERROR((
"No valid tree types selected"));
628 cout <<
"timeAllTree<" <<
bench->label <<
"> "
632 cout <<
"timeAllTree<" <<
bench->label <<
"> "
636 catch (exception & e)
638 cout <<
"**** Exception: " << e.what() <<
endl;
#define AH_ERROR(format, args...)
Print an error message (always enabled).
WeightedDigraph::Node Node
Node for QuadTree spatial data structure.
QuadTree - Hierarchical spatial index for 2D points.
Point * search(const Point &p) noexcept
Search for a point in the tree.
Point * insert(Node *&r, const Point &p)
Recursive insert helper.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_log_function > > log(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sqrt_function > > sqrt(const __gmp_expr< T, U > &expr)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_pow_function > > pow(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
size_t internal_path_length(Node *p) noexcept
Compute the internal path length.
void destroyRec(Node *&root) noexcept
Free recursively all the memory occupied by the tree root
size_t computeHeightRec(Node *root) noexcept
Compute recursively the height of root
and
Check uniqueness with explicit hash + equality functors.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
@ Tree
Basic arc (in spanning tree).
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
bool operator()(const Sample &t1, const Sample &t2) const
std::vector< TreeType > selected
Parameters(int _n, int _seed)
void(* runner)(unsigned long, gsl_rng *)
static void printNode(Node *node, int, int)
tuple< int, double > Sample
bool is_two_power(const unsigned int x)
static const TreeBenchmark * find_benchmark(TreeType type)
const char * argp_program_version
static error_t parser_opt(int key, char *, struct argp_state *state)
void run_tree(unsigned long n, gsl_rng *r)
tuple< Stat, Stat, int, int > sample_tree(TreeType< Key, Compare > &tree, gsl_rng *r, int n, int k)
tuple< double, double, double, double, double > Stat
const char * argp_program_bug_address
static const std::array< TreeBenchmark, 12 > kBenchmarks
static struct argp_option options[]
static struct argp argDefs
constexpr int Num_Samples
AVL tree with rank (order statistics).
AVL tree implementation (height-balanced BST).
Utility functions for binary tree operations.
Generic unbalanced binary search tree.
Dynamic key-value map based on balanced binary search trees.
Randomized binary search tree.
Red-Black tree with rank (order statistics).
Red-Black tree implementation (bottom-up balancing).
Comprehensive sorting algorithms and search utilities for Aleph-w.
Top-down splay tree with rank support.
Top-down splay tree implementation (without rank support).
Top-down Red-Black tree with rank support.
Top-down Red-Black tree implementation.
Treap with rank (order statistics).
Treap: randomized BST combining tree and heap properties.