inline BOOST_DEDUCED_TYPENAME hash_unique_table<H, P, A, K>::emplace_return hash_unique_table<H, P, A, K>::emplace_impl(key_type const& k, Args&&... args) { // No side effects in this initial code std::size_t hash_value = this->hash_function()(k); bucket_ptr bucket = this->bucket_ptr_from_hash(hash_value); node_ptr pos = this->find_iterator(bucket, k); if (BOOST_UNORDERED_BORLAND_BOOL(pos)) { // Found an existing key, return it (no throw). return emplace_return(iterator_base(bucket, pos), false); } else { // Doesn't already exist, add to bucket. // Side effects only in this block. // Create the node before rehashing in case it throws an // exception (need strong safety in such a case). node_constructor a(*this); a.construct(std::forward<Args>(args)...); // reserve has basic exception safety if the hash function // throws, strong otherwise. if(this->reserve_for_insert(this->size_ + 1)) bucket = this->bucket_ptr_from_hash(hash_value); // Nothing after this point can throw. return emplace_return( iterator_base(bucket, add_node(a, bucket)), true); } }
inline BOOST_DEDUCED_TYPENAME hash_unique_table<H, P, A, K>::emplace_return hash_unique_table<H, P, A, K>::emplace_impl_with_node(node_constructor& a) { // No side effects in this initial code key_type const& k = this->get_key(a.value()); std::size_t hash_value = this->hash_function()(k); bucket_ptr bucket = this->bucket_ptr_from_hash(hash_value); node_ptr pos = this->find_iterator(bucket, k); if (BOOST_UNORDERED_BORLAND_BOOL(pos)) { // Found an existing key, return it (no throw). return emplace_return(iterator_base(bucket, pos), false); } else { // reserve has basic exception safety if the hash function // throws, strong otherwise. if(this->reserve_for_insert(this->size_ + 1)) bucket = this->bucket_ptr_from_hash(hash_value); // Nothing after this point can throw. return emplace_return( iterator_base(bucket, add_node(a, bucket)), true); } }
QuadTree::iterator_base QuadTree::goto_quadtree_child(const iterator_base & it, const QuadTreeLocation & location) { if(it.node==0) return iterator_base(0); for( sibling_iterator child_it= begin(it); child_it!=end(it); ++child_it) if( child_it->get_location()==location) return iterator_base(child_it); return iterator_base(0); }
QuadTree::iterator_base QuadTree::find_neighbor(const iterator_base & it, Location x) { std::stack<QuadTreeLocation> path; iterator_base q = it; while( !is_root(q) ) { QuadTreeLocation loc = q->get_location(); path.push(loc); q=parent(q); if( !loc.has_location(x) ) break; if( is_root(q) && loc.has_location(x) ) return iterator_base(0); }; while(!path.empty()) { QuadTreeLocation loc = path.top(); path.pop(); if(x==L || x==R) q = goto_quadtree_child(q, QuadTreeLocation::x_symmetry(loc)); if(x==T || x==B) q = goto_quadtree_child(q, QuadTreeLocation::y_symmetry(loc)); if(q.node==0 || is_child(q)) return q; } return q; }