Changeset 2a482ee in mainline
- Timestamp:
- 2018-07-05T21:41:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- be9eb15
- Parents:
- 4d65515
- git-author:
- Dzejrou <dzejrou@…> (2018-04-29 00:38:10)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:22)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/internal/rbtree_policies.hpp
r4d65515 r2a482ee 37 37 struct rbtree_single_policy 38 38 { 39 // TODO: 39 template<class Tree, class Key> 40 static typename Tree::size_type count(const Tree& tree, const Key& key) 41 { 42 return tree.find(key) == tree.end() ? 0 : 1; 43 } 44 45 template<class Tree, class Key> 46 static pair< 47 typename Tree::node_type*, 48 typename Tree::node_type* 49 > erase(const Tree& tree, const Key& key) 50 { 51 // TODO: 52 } 53 54 template<class Tree, class Key> 55 static typename Tree::iterator lower_bound(const Tree& tree, const Key& key) 56 { 57 // TODO: 58 } 59 60 template<class Tree, class Key> 61 static typename Tree::iterator upper_bound(const Tree& tree, const Key& key) 62 { 63 // TODO: 64 } 65 66 template<class Tree, class Key> 67 static pair< 68 typename Tree::iterator, 69 typename Tree::iterator 70 > equal_range(const Tree& tree, const Key& key) 71 { 72 // TODO: 73 } 74 75 template<class Tree, class Key> 76 static pair< 77 typename Tree::const_iterator, 78 typename Tree::const_iterator 79 > equal_range_const(const Tree& tree, const Key& key) 80 { 81 // TODO: 82 } 83 84 /** 85 * Note: We have to duplicate code for emplace, insert(const&) 86 * and insert(&&) here, because the node (which makes distinction 87 * between the arguments) is only created if the value isn't 88 * in the tree already. 89 */ 90 91 template<class Tree, class... Args> 92 static pair< 93 typename Tree::iterator, bool 94 > emplace(Tree& tree, Args&&... args) 95 { 96 using value_type = typename Tree::value_type; 97 using iterator = typename Tree::iterator; 98 using node_type = typename Tree::node_type; 99 100 auto val = value_type{forward<Args>(args)...}; 101 auto parent = tree.find_parent_for_insertion(val); 102 if (!parent) 103 { 104 tree.root_ = new node_type{move(val)}; 105 106 return make_pair(iterator{tree.root_}, true); 107 } 108 109 if (tree.get_key(parent->value) == tree.get_key(val)) 110 return make_pair(iterator{parent}, false); 111 112 auto node = new node_type{move(val)}; 113 if (tree.keys_comp(tree.get_key(val), parent->value)) 114 parent->add_left_child(node); 115 else 116 parent->add_right_child(node); 117 118 return make_pair(iterator{node}, true); 119 } 40 120 41 121 template<class Tree, class Value>
Note:
See TracChangeset
for help on using the changeset viewer.