Back to Basics Casting(B*)pa; double d = *(double*)(pb); return (int)d; }struct tree { bool has_leaves = true;}; struct car {int model_year = 1982; }; void prune(tree* t) { t->has_leaves = false; } void drive(const car* c ) } int main() { const tree oak; car mustang; drive(&mustang); //normal function call prune((tree*)&oak); //pruning a const tree drive((car*)&oak); // driving a tree prune((tree*)&mustang); // pruning float drive((car*)&f); // driving a float return 0; }struct tree { bool has_leaves = true;}; struct car {int model_year = 1982; }; void prune(tree* t) { t->has_leaves = false; } void drive(const car* c )0 码力 | 117 页 | 1.57 MB | 6 月前3
Rethinking Task Based Concurrency and Parallelism for Low Latency C++array of Work Contracts (each with their own logic and, if needed, data, queue, etc) ○ A Signal Tree (which has as many leaf nodes as there are work contracts in the group) ● Threads are brought to Execute Logic(Data) Thread Thread Pool Thread ThreadThread Thread Thread Back Front The Signal Tree: ● Lock Free with most operations also wait free ○ Allows MT traversal without locks and therefore array of Work Contracts (each with their own logic and, if needed, data, queue, etc) ○ A Signal Tree (which has as many leaf nodes as there are work contracts in the group) ● Threads are brought to0 码力 | 142 页 | 2.80 MB | 6 月前3
Data Structures That Make Video Games Go Round● Recursively subdivided into 8 spaces.● Our level starts of as the root node. ● A node in the tree can represent a game entity or a quadrant itself. ● Any time a quadrant has more than 4 entities How to construct a quadtree for a level?● Our level starts of as the root node. ● A node in the tree can represent a game entity or a quadrant itself. ● Any time a quadrant has more than 4 entities How to construct a quadtree for a level?● Our level starts of as the root node. ● A node in the tree can represent a game entity or a quadrant itself. ● Any time a quadrant has more than 4 entities0 码力 | 196 页 | 3.03 MB | 6 月前3
BehaviorTree.CPP: Task Planning for Robots and Virtual Agents● I love C++, and I learnt a lot thanks to CPPCon videos!How did I end up developing a Behavior Tree Library?Behavior Trees in the Game Industry Used for instance in the Unreal EngineThe role of Behavior ● The “tick” is the signal that we propagate from the root to the leaves. ● The leaves of the tree are the Actions. I.e. the user-defined code that should be executed. ● Conditions are Actions that Composability 3. ReusabilityNodes and Trees These are your reusable Tree Nodes, written in C++ This is your specific Behavior Tree, written in XMLC++ Nodes implementation class ApproachEnemy : public0 码力 | 59 页 | 7.97 MB | 6 月前3
COMPOSABLE C++lengths in a rose tree. Consider how to sum the lengths in a rose tree. templatestruct rose_tree : variant tree >> { using variant tree >>::variant; };HIERARCHICAL mixed with the operation. The traversal is mixed with the operation. auto total_length(const rose_tree & t) -> int { return visit( overloaded{ [] (const string& leaf) -> int { return "where": reduce_tree reduce_tree embodies the traversal. embodies the traversal. template auto reduce_tree(const rose_tree & t, TInit i 0 码力 | 124 页 | 8.28 MB | 6 月前3
Compile-Time Compression and Resource Generation with C++20compression Output struct: Mapping of Key -> bit stream location/length Compressed bitstream Hu�man tree encoded into array Lookup -> iterator over compressed data 10 . 1/ enum class Key { String_1, String_2 build a tree bottom up from least used to most used Bit pattern assigned by walking down the tree Most common symbols have shortest bit pattern 10 . 5/ "this is an example of a hu�man tree" https://en frequency table Build Hu�man tree Build char -> bitstream cache Build encoded bit stream Build index -> bit position / string length lookup Package Hu�man tree to array Combine Hu�man tree, bit stream and index0 码力 | 59 页 | 1.86 MB | 6 月前3
Hello 算法 1.1.0 C++ 版res; } 观察以上代码,我们在函数内递归调用了两个函数,这意味着从一个调用产生了两个调用分支。如图 2‑6 所 示,这样不断递归调用下去,最终将产生一棵层数为 ? 的递归树(recursion tree)。 图 2‑6 斐波那契数列的递归树 从本质上看,递归体现了“将问题分解为更小子问题”的思维范式,这种分治策略至关重要。 ‧ 从算法角度看,搜索、排序、回溯、分治、动态规划等许多重要算法策略直接或间接地应用了这种思维 Abstract 参天大树充满生命力,根深叶茂,分枝扶疏。 它为我们展现了数据分治的生动形态。 第 7 章 树 hello‑algo.com 138 7.1 二叉树 二叉树(binary tree)是一种非线性数据结构,代表“祖先”与“后代”之间的派生关系,体现了“一分为二” 的分治逻辑。与链表类似,二叉树的基本单元是节点,每个节点包含值、左子节点引用和右子节点引用。 /* 二叉树节点结构体 义为“经过的节点的数量”。在这种情况下,高度和深度都需要加 1 。 7.1.2 二叉树基本操作 1. 初始化二叉树 与链表类似,首先初始化节点,然后构建引用(指针)。 // === File: binary_tree.cpp === /* 初始化二叉树 */ // 初始化节点 TreeNode* n1 = new TreeNode(1); TreeNode* n2 = new TreeNode(2);0 码力 | 379 页 | 18.47 MB | 1 年前3
Hello 算法 1.0.0 C++版} 观察以上代码,我们在函数内递归调用了两个函数,这意味着从一个调用产生了两个调用分支。如图 2‑6 所 示,这样不断递归调用下去,最终将产生一棵层数为 ? 的「递归树 recursion tree」。 图 2‑6 斐波那契数列的递归树 从本质上看,递归体现了“将问题分解为更小子问题”的思维范式,这种分治策略至关重要。 ‧ 从算法角度看,搜索、排序、回溯、分治、动态规划等许多重要算法策略直接或间接地应用了这种思维 章 树 � 参天大树充满生命力,根深叶茂,分枝扶疏。 它为我们展现了数据分治的生动形态。 第 7 章 树 hello‑algo.com 138 7.1 二叉树 「二叉树 binary tree」是一种非线性数据结构,代表“祖先”与“后代”之间的派生关系,体现了“一分为二” 的分治逻辑。与链表类似,二叉树的基本单元是节点,每个节点包含值、左子节点引用和右子节点引用。 /* 二叉树节点结构体 会将其定义为“经过的节点的数量”。在这种情况下,高度和深度都需要加 1 。 7.1.2 二叉树基本操作 1. 初始化二叉树 与链表类似,首先初始化节点,然后构建引用(指针)。 // === File: binary_tree.cpp === /* 初始化二叉树 */ // 初始化节点 TreeNode* n1 = new TreeNode(1); TreeNode* n2 = new TreeNode(2);0 码力 | 378 页 | 17.59 MB | 1 年前3
Hello 算法 1.2.0 简体中文 C++ 版res; } 观察以上代码,我们在函数内递归调用了两个函数,这意味着从一个调用产生了两个调用分支。如图 2‑6 所 示,这样不断递归调用下去,最终将产生一棵层数为 ? 的递归树(recursion tree)。 图 2‑6 斐波那契数列的递归树 从本质上看,递归体现了“将问题分解为更小子问题”的思维范式,这种分治策略至关重要。 ‧ 从算法角度看,搜索、排序、回溯、分治、动态规划等许多重要算法策略直接或间接地应用了这种思维 Abstract 参天大树充满生命力,根深叶茂,分枝扶疏。 它为我们展现了数据分治的生动形态。 第 7 章 树 www.hello‑algo.com 138 7.1 二叉树 二叉树(binary tree)是一种非线性数据结构,代表“祖先”与“后代”之间的派生关系,体现了“一分为二” 的分治逻辑。与链表类似,二叉树的基本单元是节点,每个节点包含值、左子节点引用和右子节点引用。 /* 二叉树节点结构体 义为“经过的节点的数量”。在这种情况下,高度和深度都需要加 1 。 7.1.2 二叉树基本操作 1. 初始化二叉树 与链表类似,首先初始化节点,然后构建引用(指针)。 // === File: binary_tree.cpp === /* 初始化二叉树 */ // 初始化节点 TreeNode* n1 = new TreeNode(1); TreeNode* n2 = new TreeNode(2);0 码力 | 379 页 | 18.48 MB | 10 月前3
Hello 算法 1.0.0b1 C++版希函数增加了计算 量。 ‧ 在工业界中,Java 的 HashMap 采用链式地址、Python 的 Dict 采用开放寻址。 91 7. 树 7.1. 二叉树 「二叉树 Binary Tree」是一种非线性数据结构,代表着祖先与后代之间的派生关系,体现着“一分为二”的分 治逻辑。类似于链表,二叉树也是以结点为单位存储的,结点包含「值」和两个「指针」。 /* 链表结点结构体 */ struct 定义为“走过结点的数量”,此时高度或深度都需要 + 1 。 7.1.2. 二叉树基本操作 初始化二叉树。与链表类似,先初始化结点,再构建引用指向(即指针)。 // === File: binary_tree.cpp === /* 初始化二叉树 */ // 初始化结点 7. 树 hello‑algo.com 93 TreeNode* n1 = new TreeNode(1); TreeNode* n2->right = n5; 插入与删除结点。与链表类似,插入与删除结点都可以通过修改指针实现。 Figure 7‑3. 在二叉树中插入与删除结点 // === File: binary_tree.cpp === /* 插入与删除结点 */ TreeNode* P = new TreeNode(0); // 在 n1 -> n2 中间插入结点 P n1->left = P; P->left0 码力 | 187 页 | 14.71 MB | 1 年前3
共 127 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13













