Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/unordered/detail/table.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying | 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | 6 |
7 #ifndef BOOST_UNORDERED_DETAIL_ALL_HPP_INCLUDED | 7 #ifndef BOOST_UNORDERED_DETAIL_ALL_HPP_INCLUDED |
8 #define BOOST_UNORDERED_DETAIL_ALL_HPP_INCLUDED | 8 #define BOOST_UNORDERED_DETAIL_ALL_HPP_INCLUDED |
9 | |
10 #include <boost/config.hpp> | |
11 #if defined(BOOST_HAS_PRAGMA_ONCE) | |
12 #pragma once | |
13 #endif | |
9 | 14 |
10 #include <boost/unordered/detail/buckets.hpp> | 15 #include <boost/unordered/detail/buckets.hpp> |
11 #include <boost/unordered/detail/util.hpp> | 16 #include <boost/unordered/detail/util.hpp> |
12 #include <boost/type_traits/aligned_storage.hpp> | 17 #include <boost/type_traits/aligned_storage.hpp> |
13 #include <boost/type_traits/alignment_of.hpp> | 18 #include <boost/type_traits/alignment_of.hpp> |
51 typedef ValueType value_type; | 56 typedef ValueType value_type; |
52 | 57 |
53 typename boost::aligned_storage< | 58 typename boost::aligned_storage< |
54 sizeof(value_type), | 59 sizeof(value_type), |
55 boost::alignment_of<value_type>::value>::type data_; | 60 boost::alignment_of<value_type>::value>::type data_; |
61 | |
62 value_base() : | |
63 data_() | |
64 {} | |
56 | 65 |
57 void* address() { | 66 void* address() { |
58 return this; | 67 return this; |
59 } | 68 } |
60 | 69 |
180 node_constructor; | 189 node_constructor; |
181 | 190 |
182 typedef boost::unordered::iterator_detail:: | 191 typedef boost::unordered::iterator_detail:: |
183 iterator<node> iterator; | 192 iterator<node> iterator; |
184 typedef boost::unordered::iterator_detail:: | 193 typedef boost::unordered::iterator_detail:: |
185 c_iterator<node, const_node_pointer> c_iterator; | 194 c_iterator<node> c_iterator; |
186 typedef boost::unordered::iterator_detail:: | 195 typedef boost::unordered::iterator_detail:: |
187 l_iterator<node, policy> l_iterator; | 196 l_iterator<node, policy> l_iterator; |
188 typedef boost::unordered::iterator_detail:: | 197 typedef boost::unordered::iterator_detail:: |
189 cl_iterator<node, const_node_pointer, policy> cl_iterator; | 198 cl_iterator<node, policy> cl_iterator; |
190 | 199 |
191 //////////////////////////////////////////////////////////////////////// | 200 //////////////////////////////////////////////////////////////////////// |
192 // Members | 201 // Members |
193 | 202 |
194 boost::unordered::detail::compressed<bucket_allocator, node_allocator> | 203 boost::unordered::detail::compressed<bucket_allocator, node_allocator> |
255 if (!size_) return iterator(); | 264 if (!size_) return iterator(); |
256 link_pointer prev = get_previous_start(bucket_index); | 265 link_pointer prev = get_previous_start(bucket_index); |
257 return prev ? iterator(prev->next_) : iterator(); | 266 return prev ? iterator(prev->next_) : iterator(); |
258 } | 267 } |
259 | 268 |
260 std::size_t hash_to_bucket(std::size_t hash) const | 269 std::size_t hash_to_bucket(std::size_t hash_value) const |
261 { | 270 { |
262 return policy::to_bucket(bucket_count_, hash); | 271 return policy::to_bucket(bucket_count_, hash_value); |
263 } | 272 } |
264 | 273 |
265 float load_factor() const | 274 float load_factor() const |
266 { | 275 { |
267 BOOST_ASSERT(bucket_count_ != 0); | 276 BOOST_ASSERT(bucket_count_ != 0); |
332 // count > size / mlf_ | 341 // count > size / mlf_ |
333 | 342 |
334 return policy::new_bucket_count( | 343 return policy::new_bucket_count( |
335 boost::unordered::detail::double_to_size(floor( | 344 boost::unordered::detail::double_to_size(floor( |
336 static_cast<double>(size) / | 345 static_cast<double>(size) / |
337 static_cast<double>(mlf_))) + 1); | 346 static_cast<double>(mlf_)) + 1)); |
338 } | 347 } |
339 | 348 |
340 //////////////////////////////////////////////////////////////////////// | 349 //////////////////////////////////////////////////////////////////////// |
341 // Constructors | 350 // Constructors |
342 | 351 |
393 | 402 |
394 void init(table const& x) | 403 void init(table const& x) |
395 { | 404 { |
396 if (x.size_) { | 405 if (x.size_) { |
397 create_buckets(bucket_count_); | 406 create_buckets(bucket_count_); |
398 copy_nodes<node_allocator> copy(node_alloc()); | 407 copy_nodes<node_allocator> node_creator(node_alloc()); |
399 table_impl::fill_buckets(x.begin(), *this, copy); | 408 table_impl::fill_buckets(x.begin(), *this, node_creator); |
400 } | 409 } |
401 } | 410 } |
402 | 411 |
403 void move_init(table& x) | 412 void move_init(table& x) |
404 { | 413 { |
407 } | 416 } |
408 else if(x.size_) { | 417 else if(x.size_) { |
409 // TODO: Could pick new bucket size? | 418 // TODO: Could pick new bucket size? |
410 create_buckets(bucket_count_); | 419 create_buckets(bucket_count_); |
411 | 420 |
412 move_nodes<node_allocator> move(node_alloc()); | 421 move_nodes<node_allocator> node_creator(node_alloc()); |
413 node_holder<node_allocator> nodes(x); | 422 node_holder<node_allocator> nodes(x); |
414 table_impl::fill_buckets(nodes.begin(), *this, move); | 423 table_impl::fill_buckets(nodes.begin(), *this, node_creator); |
415 } | 424 } |
416 } | 425 } |
417 | 426 |
418 //////////////////////////////////////////////////////////////////////// | 427 //////////////////////////////////////////////////////////////////////// |
419 // Create buckets | 428 // Create buckets |
489 std::swap(max_load_, x.max_load_); | 498 std::swap(max_load_, x.max_load_); |
490 op1.commit(); | 499 op1.commit(); |
491 op2.commit(); | 500 op2.commit(); |
492 } | 501 } |
493 | 502 |
503 // Only call with nodes allocated with the currect allocator, or | |
504 // one that is equal to it. (Can't assert because other's | |
505 // allocators might have already been moved). | |
494 void move_buckets_from(table& other) | 506 void move_buckets_from(table& other) |
495 { | 507 { |
496 BOOST_ASSERT(node_alloc() == other.node_alloc()); | |
497 BOOST_ASSERT(!buckets_); | 508 BOOST_ASSERT(!buckets_); |
498 buckets_ = other.buckets_; | 509 buckets_ = other.buckets_; |
499 bucket_count_ = other.bucket_count_; | 510 bucket_count_ = other.bucket_count_; |
500 size_ = other.size_; | 511 size_ = other.size_; |
501 other.buckets_ = bucket_pointer(); | 512 other.buckets_ = bucket_pointer(); |
516 node_pointer n = static_cast<node_pointer>(prev->next_); | 527 node_pointer n = static_cast<node_pointer>(prev->next_); |
517 prev->next_ = n->next_; | 528 prev->next_ = n->next_; |
518 | 529 |
519 boost::unordered::detail::func::destroy_value_impl(node_alloc(), | 530 boost::unordered::detail::func::destroy_value_impl(node_alloc(), |
520 n->value_ptr()); | 531 n->value_ptr()); |
521 node_allocator_traits::destroy(node_alloc(), | 532 boost::unordered::detail::func::destroy(boost::addressof(*n)); |
522 boost::addressof(*n)); | |
523 node_allocator_traits::deallocate(node_alloc(), n, 1); | 533 node_allocator_traits::deallocate(node_alloc(), n, 1); |
524 --size_; | 534 --size_; |
525 } | 535 } |
526 | 536 |
527 std::size_t delete_nodes(link_pointer prev, link_pointer end) | 537 std::size_t delete_nodes(link_pointer prev, link_pointer end) |
544 if (size_) delete_nodes(get_previous_start(), link_pointer()); | 554 if (size_) delete_nodes(get_previous_start(), link_pointer()); |
545 | 555 |
546 if (bucket::extra_node) { | 556 if (bucket::extra_node) { |
547 node_pointer n = static_cast<node_pointer>( | 557 node_pointer n = static_cast<node_pointer>( |
548 get_bucket(bucket_count_)->next_); | 558 get_bucket(bucket_count_)->next_); |
549 node_allocator_traits::destroy(node_alloc(), | 559 boost::unordered::detail::func::destroy( |
550 boost::addressof(*n)); | 560 boost::addressof(*n)); |
551 node_allocator_traits::deallocate(node_alloc(), n, 1); | 561 node_allocator_traits::deallocate(node_alloc(), n, 1); |
552 } | 562 } |
553 | 563 |
554 destroy_buckets(); | 564 destroy_buckets(); |
581 void destroy_buckets() | 591 void destroy_buckets() |
582 { | 592 { |
583 bucket_pointer end = get_bucket(bucket_count_ + 1); | 593 bucket_pointer end = get_bucket(bucket_count_ + 1); |
584 for(bucket_pointer it = buckets_; it != end; ++it) | 594 for(bucket_pointer it = buckets_; it != end; ++it) |
585 { | 595 { |
586 bucket_allocator_traits::destroy(bucket_alloc(), | 596 boost::unordered::detail::func::destroy( |
587 boost::addressof(*it)); | 597 boost::addressof(*it)); |
588 } | 598 } |
589 | 599 |
590 bucket_allocator_traits::deallocate(bucket_alloc(), | 600 bucket_allocator_traits::deallocate(bucket_alloc(), |
591 buckets_, bucket_count_ + 1); | 601 buckets_, bucket_count_ + 1); |
653 } | 663 } |
654 | 664 |
655 // assign_nodes takes ownership of the container's elements, | 665 // assign_nodes takes ownership of the container's elements, |
656 // assigning to them if possible, and deleting any that are | 666 // assigning to them if possible, and deleting any that are |
657 // left over. | 667 // left over. |
658 assign_nodes<table> assign(*this); | 668 assign_nodes<table> node_creator(*this); |
659 table_impl::fill_buckets(x.begin(), *this, assign); | 669 table_impl::fill_buckets(x.begin(), *this, node_creator); |
660 } | 670 } |
661 | 671 |
662 void assign(table const& x, true_type) | 672 void assign(table const& x, true_type) |
663 { | 673 { |
664 if (node_alloc() == x.node_alloc()) { | 674 if (node_alloc() == x.node_alloc()) { |
680 max_load_ = 0; | 690 max_load_ = 0; |
681 | 691 |
682 // Finally copy the elements. | 692 // Finally copy the elements. |
683 if (x.size_) { | 693 if (x.size_) { |
684 create_buckets(bucket_count_); | 694 create_buckets(bucket_count_); |
685 copy_nodes<node_allocator> copy(node_alloc()); | 695 copy_nodes<node_allocator> node_creator(node_alloc()); |
686 table_impl::fill_buckets(x.begin(), *this, copy); | 696 table_impl::fill_buckets(x.begin(), *this, node_creator); |
687 } | 697 } |
688 } | 698 } |
689 } | 699 } |
690 | 700 |
691 void move_assign(table& x) | 701 void move_assign(table& x) |
700 } | 710 } |
701 | 711 |
702 void move_assign(table& x, true_type) | 712 void move_assign(table& x, true_type) |
703 { | 713 { |
704 delete_buckets(); | 714 delete_buckets(); |
715 set_hash_functions new_func_this(*this, x); | |
705 allocators_.move_assign(x.allocators_); | 716 allocators_.move_assign(x.allocators_); |
706 move_assign_no_alloc(x); | 717 // No throw from here. |
718 mlf_ = x.mlf_; | |
719 max_load_ = x.max_load_; | |
720 move_buckets_from(x); | |
721 new_func_this.commit(); | |
707 } | 722 } |
708 | 723 |
709 void move_assign(table& x, false_type) | 724 void move_assign(table& x, false_type) |
710 { | 725 { |
711 if (node_alloc() == x.node_alloc()) { | 726 if (node_alloc() == x.node_alloc()) { |
712 delete_buckets(); | 727 delete_buckets(); |
713 move_assign_no_alloc(x); | 728 set_hash_functions new_func_this(*this, x); |
729 // No throw from here. | |
730 mlf_ = x.mlf_; | |
731 max_load_ = x.max_load_; | |
732 move_buckets_from(x); | |
733 new_func_this.commit(); | |
714 } | 734 } |
715 else { | 735 else { |
716 set_hash_functions new_func_this(*this, x); | 736 set_hash_functions new_func_this(*this, x); |
717 new_func_this.commit(); | 737 new_func_this.commit(); |
718 mlf_ = x.mlf_; | 738 mlf_ = x.mlf_; |
728 } | 748 } |
729 | 749 |
730 // move_assign_nodes takes ownership of the container's | 750 // move_assign_nodes takes ownership of the container's |
731 // elements, assigning to them if possible, and deleting | 751 // elements, assigning to them if possible, and deleting |
732 // any that are left over. | 752 // any that are left over. |
733 move_assign_nodes<table> assign(*this); | 753 move_assign_nodes<table> node_creator(*this); |
734 node_holder<node_allocator> nodes(x); | 754 node_holder<node_allocator> nodes(x); |
735 table_impl::fill_buckets(nodes.begin(), *this, assign); | 755 table_impl::fill_buckets(nodes.begin(), *this, node_creator); |
736 } | 756 } |
737 } | |
738 | |
739 void move_assign_no_alloc(table& x) | |
740 { | |
741 set_hash_functions new_func_this(*this, x); | |
742 // No throw from here. | |
743 mlf_ = x.mlf_; | |
744 max_load_ = x.max_load_; | |
745 move_buckets_from(x); | |
746 new_func_this.commit(); | |
747 } | 757 } |
748 | 758 |
749 // Accessors | 759 // Accessors |
750 | 760 |
751 key_type const& get_key(value_type const& x) const | 761 key_type const& get_key(value_type const& x) const |