diff options
Diffstat (limited to 'gcc-4.9/libstdc++-v3/include/ext')
285 files changed, 61349 insertions, 0 deletions
diff --git a/gcc-4.9/libstdc++-v3/include/ext/algorithm b/gcc-4.9/libstdc++-v3/include/ext/algorithm new file mode 100644 index 0000000..2731e67 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/algorithm @@ -0,0 +1,603 @@ +// Algorithm extensions -*- C++ -*- + +// Copyright (C) 2001-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * + * Copyright (c) 1994 + * Hewlett-Packard Company + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Hewlett-Packard Company makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * + * Copyright (c) 1996 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/** @file ext/algorithm + * This file is a GNU extension to the Standard C++ Library (possibly + * containing extensions from the HP/SGI STL subset). + */ + +#ifndef _EXT_ALGORITHM +#define _EXT_ALGORITHM 1 + +#pragma GCC system_header + +#include <algorithm> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::ptrdiff_t; + using std::min; + using std::pair; + using std::input_iterator_tag; + using std::random_access_iterator_tag; + using std::iterator_traits; + + //-------------------------------------------------- + // copy_n (not part of the C++ standard) + + template<typename _InputIterator, typename _Size, typename _OutputIterator> + pair<_InputIterator, _OutputIterator> + __copy_n(_InputIterator __first, _Size __count, + _OutputIterator __result, + input_iterator_tag) + { + for ( ; __count > 0; --__count) + { + *__result = *__first; + ++__first; + ++__result; + } + return pair<_InputIterator, _OutputIterator>(__first, __result); + } + + template<typename _RAIterator, typename _Size, typename _OutputIterator> + inline pair<_RAIterator, _OutputIterator> + __copy_n(_RAIterator __first, _Size __count, + _OutputIterator __result, + random_access_iterator_tag) + { + _RAIterator __last = __first + __count; + return pair<_RAIterator, _OutputIterator>(__last, std::copy(__first, + __last, + __result)); + } + + /** + * @brief Copies the range [first,first+count) into [result,result+count). + * @param __first An input iterator. + * @param __count The number of elements to copy. + * @param __result An output iterator. + * @return A std::pair composed of first+count and result+count. + * + * This is an SGI extension. + * This inline function will boil down to a call to @c memmove whenever + * possible. Failing that, if random access iterators are passed, then the + * loop count will be known (and therefore a candidate for compiler + * optimizations such as unrolling). + * @ingroup SGIextensions + */ + template<typename _InputIterator, typename _Size, typename _OutputIterator> + inline pair<_InputIterator, _OutputIterator> + copy_n(_InputIterator __first, _Size __count, _OutputIterator __result) + { + // concept requirements + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + typename iterator_traits<_InputIterator>::value_type>) + + return __gnu_cxx::__copy_n(__first, __count, __result, + std::__iterator_category(__first)); + } + + template<typename _InputIterator1, typename _InputIterator2> + int + __lexicographical_compare_3way(_InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, + _InputIterator2 __last2) + { + while (__first1 != __last1 && __first2 != __last2) + { + if (*__first1 < *__first2) + return -1; + if (*__first2 < *__first1) + return 1; + ++__first1; + ++__first2; + } + if (__first2 == __last2) + return !(__first1 == __last1); + else + return -1; + } + + inline int + __lexicographical_compare_3way(const unsigned char* __first1, + const unsigned char* __last1, + const unsigned char* __first2, + const unsigned char* __last2) + { + const ptrdiff_t __len1 = __last1 - __first1; + const ptrdiff_t __len2 = __last2 - __first2; + const int __result = __builtin_memcmp(__first1, __first2, + min(__len1, __len2)); + return __result != 0 ? __result + : (__len1 == __len2 ? 0 : (__len1 < __len2 ? -1 : 1)); + } + + inline int + __lexicographical_compare_3way(const char* __first1, const char* __last1, + const char* __first2, const char* __last2) + { +#if CHAR_MAX == SCHAR_MAX + return __lexicographical_compare_3way((const signed char*) __first1, + (const signed char*) __last1, + (const signed char*) __first2, + (const signed char*) __last2); +#else + return __lexicographical_compare_3way((const unsigned char*) __first1, + (const unsigned char*) __last1, + (const unsigned char*) __first2, + (const unsigned char*) __last2); +#endif + } + + /** + * @brief @c memcmp on steroids. + * @param __first1 An input iterator. + * @param __last1 An input iterator. + * @param __first2 An input iterator. + * @param __last2 An input iterator. + * @return An int, as with @c memcmp. + * + * The return value will be less than zero if the first range is + * <em>lexigraphically less than</em> the second, greater than zero + * if the second range is <em>lexigraphically less than</em> the + * first, and zero otherwise. + * This is an SGI extension. + * @ingroup SGIextensions + */ + template<typename _InputIterator1, typename _InputIterator2> + int + lexicographical_compare_3way(_InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, + _InputIterator2 __last2) + { + // concept requirements + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) + __glibcxx_function_requires(_LessThanComparableConcept< + typename iterator_traits<_InputIterator1>::value_type>) + __glibcxx_function_requires(_LessThanComparableConcept< + typename iterator_traits<_InputIterator2>::value_type>) + __glibcxx_requires_valid_range(__first1, __last1); + __glibcxx_requires_valid_range(__first2, __last2); + + return __lexicographical_compare_3way(__first1, __last1, __first2, + __last2); + } + + // count and count_if: this version, whose return type is void, was present + // in the HP STL, and is retained as an extension for backward compatibility. + template<typename _InputIterator, typename _Tp, typename _Size> + void + count(_InputIterator __first, _InputIterator __last, + const _Tp& __value, + _Size& __n) + { + // concept requirements + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) + __glibcxx_function_requires(_EqualityComparableConcept< + typename iterator_traits<_InputIterator>::value_type >) + __glibcxx_function_requires(_EqualityComparableConcept<_Tp>) + __glibcxx_requires_valid_range(__first, __last); + + for ( ; __first != __last; ++__first) + if (*__first == __value) + ++__n; + } + + template<typename _InputIterator, typename _Predicate, typename _Size> + void + count_if(_InputIterator __first, _InputIterator __last, + _Predicate __pred, + _Size& __n) + { + // concept requirements + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) + __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, + typename iterator_traits<_InputIterator>::value_type>) + __glibcxx_requires_valid_range(__first, __last); + + for ( ; __first != __last; ++__first) + if (__pred(*__first)) + ++__n; + } + + // random_sample and random_sample_n (extensions, not part of the standard). + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template<typename _ForwardIterator, typename _OutputIterator, + typename _Distance> + _OutputIterator + random_sample_n(_ForwardIterator __first, _ForwardIterator __last, + _OutputIterator __out, const _Distance __n) + { + // concept requirements + __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + typename iterator_traits<_ForwardIterator>::value_type>) + __glibcxx_requires_valid_range(__first, __last); + + _Distance __remaining = std::distance(__first, __last); + _Distance __m = min(__n, __remaining); + + while (__m > 0) + { + if ((std::rand() % __remaining) < __m) + { + *__out = *__first; + ++__out; + --__m; + } + --__remaining; + ++__first; + } + return __out; + } + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template<typename _ForwardIterator, typename _OutputIterator, + typename _Distance, typename _RandomNumberGenerator> + _OutputIterator + random_sample_n(_ForwardIterator __first, _ForwardIterator __last, + _OutputIterator __out, const _Distance __n, + _RandomNumberGenerator& __rand) + { + // concept requirements + __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + typename iterator_traits<_ForwardIterator>::value_type>) + __glibcxx_function_requires(_UnaryFunctionConcept< + _RandomNumberGenerator, _Distance, _Distance>) + __glibcxx_requires_valid_range(__first, __last); + + _Distance __remaining = std::distance(__first, __last); + _Distance __m = min(__n, __remaining); + + while (__m > 0) + { + if (__rand(__remaining) < __m) + { + *__out = *__first; + ++__out; + --__m; + } + --__remaining; + ++__first; + } + return __out; + } + + template<typename _InputIterator, typename _RandomAccessIterator, + typename _Distance> + _RandomAccessIterator + __random_sample(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __out, + const _Distance __n) + { + _Distance __m = 0; + _Distance __t = __n; + for ( ; __first != __last && __m < __n; ++__m, ++__first) + __out[__m] = *__first; + + while (__first != __last) + { + ++__t; + _Distance __M = std::rand() % (__t); + if (__M < __n) + __out[__M] = *__first; + ++__first; + } + return __out + __m; + } + + template<typename _InputIterator, typename _RandomAccessIterator, + typename _RandomNumberGenerator, typename _Distance> + _RandomAccessIterator + __random_sample(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __out, + _RandomNumberGenerator& __rand, + const _Distance __n) + { + // concept requirements + __glibcxx_function_requires(_UnaryFunctionConcept< + _RandomNumberGenerator, _Distance, _Distance>) + + _Distance __m = 0; + _Distance __t = __n; + for ( ; __first != __last && __m < __n; ++__m, ++__first) + __out[__m] = *__first; + + while (__first != __last) + { + ++__t; + _Distance __M = __rand(__t); + if (__M < __n) + __out[__M] = *__first; + ++__first; + } + return __out + __m; + } + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template<typename _InputIterator, typename _RandomAccessIterator> + inline _RandomAccessIterator + random_sample(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __out_first, + _RandomAccessIterator __out_last) + { + // concept requirements + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) + __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< + _RandomAccessIterator>) + __glibcxx_requires_valid_range(__first, __last); + __glibcxx_requires_valid_range(__out_first, __out_last); + + return __random_sample(__first, __last, + __out_first, __out_last - __out_first); + } + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template<typename _InputIterator, typename _RandomAccessIterator, + typename _RandomNumberGenerator> + inline _RandomAccessIterator + random_sample(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __out_first, + _RandomAccessIterator __out_last, + _RandomNumberGenerator& __rand) + { + // concept requirements + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) + __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< + _RandomAccessIterator>) + __glibcxx_requires_valid_range(__first, __last); + __glibcxx_requires_valid_range(__out_first, __out_last); + + return __random_sample(__first, __last, + __out_first, __rand, + __out_last - __out_first); + } + +#if __cplusplus >= 201103L + using std::is_heap; +#else + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template<typename _RandomAccessIterator> + inline bool + is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) + { + // concept requirements + __glibcxx_function_requires(_RandomAccessIteratorConcept< + _RandomAccessIterator>) + __glibcxx_function_requires(_LessThanComparableConcept< + typename iterator_traits<_RandomAccessIterator>::value_type>) + __glibcxx_requires_valid_range(__first, __last); + + return std::__is_heap(__first, __last - __first); + } + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template<typename _RandomAccessIterator, typename _StrictWeakOrdering> + inline bool + is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, + _StrictWeakOrdering __comp) + { + // concept requirements + __glibcxx_function_requires(_RandomAccessIteratorConcept< + _RandomAccessIterator>) + __glibcxx_function_requires(_BinaryPredicateConcept<_StrictWeakOrdering, + typename iterator_traits<_RandomAccessIterator>::value_type, + typename iterator_traits<_RandomAccessIterator>::value_type>) + __glibcxx_requires_valid_range(__first, __last); + + return std::__is_heap(__first, __comp, __last - __first); + } +#endif + +#if __cplusplus >= 201103L + using std::is_sorted; +#else + // is_sorted, a predicated testing whether a range is sorted in + // nondescending order. This is an extension, not part of the C++ + // standard. + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template<typename _ForwardIterator> + bool + is_sorted(_ForwardIterator __first, _ForwardIterator __last) + { + // concept requirements + __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) + __glibcxx_function_requires(_LessThanComparableConcept< + typename iterator_traits<_ForwardIterator>::value_type>) + __glibcxx_requires_valid_range(__first, __last); + + if (__first == __last) + return true; + + _ForwardIterator __next = __first; + for (++__next; __next != __last; __first = __next, ++__next) + if (*__next < *__first) + return false; + return true; + } + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template<typename _ForwardIterator, typename _StrictWeakOrdering> + bool + is_sorted(_ForwardIterator __first, _ForwardIterator __last, + _StrictWeakOrdering __comp) + { + // concept requirements + __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) + __glibcxx_function_requires(_BinaryPredicateConcept<_StrictWeakOrdering, + typename iterator_traits<_ForwardIterator>::value_type, + typename iterator_traits<_ForwardIterator>::value_type>) + __glibcxx_requires_valid_range(__first, __last); + + if (__first == __last) + return true; + + _ForwardIterator __next = __first; + for (++__next; __next != __last; __first = __next, ++__next) + if (__comp(*__next, *__first)) + return false; + return true; + } +#endif // C++11 + + /** + * @brief Find the median of three values. + * @param __a A value. + * @param __b A value. + * @param __c A value. + * @return One of @p a, @p b or @p c. + * + * If @c {l,m,n} is some convolution of @p {a,b,c} such that @c l<=m<=n + * then the value returned will be @c m. + * This is an SGI extension. + * @ingroup SGIextensions + */ + template<typename _Tp> + const _Tp& + __median(const _Tp& __a, const _Tp& __b, const _Tp& __c) + { + // concept requirements + __glibcxx_function_requires(_LessThanComparableConcept<_Tp>) + if (__a < __b) + if (__b < __c) + return __b; + else if (__a < __c) + return __c; + else + return __a; + else if (__a < __c) + return __a; + else if (__b < __c) + return __c; + else + return __b; + } + + /** + * @brief Find the median of three values using a predicate for comparison. + * @param __a A value. + * @param __b A value. + * @param __c A value. + * @param __comp A binary predicate. + * @return One of @p a, @p b or @p c. + * + * If @c {l,m,n} is some convolution of @p {a,b,c} such that @p comp(l,m) + * and @p comp(m,n) are both true then the value returned will be @c m. + * This is an SGI extension. + * @ingroup SGIextensions + */ + template<typename _Tp, typename _Compare> + const _Tp& + __median(const _Tp& __a, const _Tp& __b, const _Tp& __c, _Compare __comp) + { + // concept requirements + __glibcxx_function_requires(_BinaryFunctionConcept<_Compare, bool, + _Tp, _Tp>) + if (__comp(__a, __b)) + if (__comp(__b, __c)) + return __b; + else if (__comp(__a, __c)) + return __c; + else + return __a; + else if (__comp(__a, __c)) + return __a; + else if (__comp(__b, __c)) + return __c; + else + return __b; + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif /* _EXT_ALGORITHM */ diff --git a/gcc-4.9/libstdc++-v3/include/ext/aligned_buffer.h b/gcc-4.9/libstdc++-v3/include/ext/aligned_buffer.h new file mode 100644 index 0000000..861de5b --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/aligned_buffer.h @@ -0,0 +1,73 @@ +// Aligned memory buffer -*- C++ -*- + +// Copyright (C) 2013-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/aligned_buffer.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _ALIGNED_BUFFER_H +#define _ALIGNED_BUFFER_H 1 + +#pragma GCC system_header + +#if __cplusplus >= 201103L +# include <type_traits> +#else +# include <bits/c++0x_warning.h> +#endif + +namespace __gnu_cxx +{ + template<typename _Tp> + struct __aligned_buffer + : std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value> + { + typename + std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value>::type + _M_storage; + + void* + _M_addr() noexcept + { + return static_cast<void*>(&_M_storage); + } + + const void* + _M_addr() const noexcept + { + return static_cast<const void*>(&_M_storage); + } + + _Tp* + _M_ptr() noexcept + { return static_cast<_Tp*>(_M_addr()); } + + const _Tp* + _M_ptr() const noexcept + { return static_cast<const _Tp*>(_M_addr()); } + }; + +} // namespace + +#endif /* _ALIGNED_BUFFER_H */ diff --git a/gcc-4.9/libstdc++-v3/include/ext/alloc_traits.h b/gcc-4.9/libstdc++-v3/include/ext/alloc_traits.h new file mode 100644 index 0000000..14fbc43 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/alloc_traits.h @@ -0,0 +1,215 @@ +// Allocator traits -*- C++ -*- + +// Copyright (C) 2011-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/alloc_traits.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _EXT_ALLOC_TRAITS_H +#define _EXT_ALLOC_TRAITS_H 1 + +#pragma GCC system_header + +#if __cplusplus >= 201103L +# include <bits/move.h> +# include <bits/alloc_traits.h> +#else +# include <bits/allocator.h> // for __alloc_swap +#endif + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +#if __cplusplus >= 201103L + template<typename _Alloc> + struct __allocator_always_compares_equal : std::false_type { }; + + template<typename _Tp> + struct __allocator_always_compares_equal<std::allocator<_Tp>> + : std::true_type { }; + + template<typename, typename> struct array_allocator; + + template<typename _Tp, typename _Array> + struct __allocator_always_compares_equal<array_allocator<_Tp, _Array>> + : std::true_type { }; + + template<typename> struct bitmap_allocator; + + template<typename _Tp> + struct __allocator_always_compares_equal<bitmap_allocator<_Tp>> + : std::true_type { }; + + template<typename> struct malloc_allocator; + + template<typename _Tp> + struct __allocator_always_compares_equal<malloc_allocator<_Tp>> + : std::true_type { }; + + template<typename> struct mt_allocator; + + template<typename _Tp> + struct __allocator_always_compares_equal<mt_allocator<_Tp>> + : std::true_type { }; + + template<typename> struct new_allocator; + + template<typename _Tp> + struct __allocator_always_compares_equal<new_allocator<_Tp>> + : std::true_type { }; + + template<typename> struct pool_allocator; + + template<typename _Tp> + struct __allocator_always_compares_equal<pool_allocator<_Tp>> + : std::true_type { }; +#endif + +/** + * @brief Uniform interface to C++98 and C++0x allocators. + * @ingroup allocators +*/ +template<typename _Alloc> + struct __alloc_traits +#if __cplusplus >= 201103L + : std::allocator_traits<_Alloc> +#endif + { + typedef _Alloc allocator_type; +#if __cplusplus >= 201103L + typedef std::allocator_traits<_Alloc> _Base_type; + typedef typename _Base_type::value_type value_type; + typedef typename _Base_type::pointer pointer; + typedef typename _Base_type::const_pointer const_pointer; + typedef typename _Base_type::size_type size_type; + typedef typename _Base_type::difference_type difference_type; + // C++11 allocators do not define reference or const_reference + typedef value_type& reference; + typedef const value_type& const_reference; + using _Base_type::allocate; + using _Base_type::deallocate; + using _Base_type::construct; + using _Base_type::destroy; + using _Base_type::max_size; + + private: + template<typename _Ptr> + using __is_custom_pointer + = std::__and_<std::is_same<pointer, _Ptr>, + std::__not_<std::is_pointer<_Ptr>>>; + + public: + // overload construct for non-standard pointer types + template<typename _Ptr, typename... _Args> + static typename std::enable_if<__is_custom_pointer<_Ptr>::value>::type + construct(_Alloc& __a, _Ptr __p, _Args&&... __args) + { + _Base_type::construct(__a, std::addressof(*__p), + std::forward<_Args>(__args)...); + } + + // overload destroy for non-standard pointer types + template<typename _Ptr> + static typename std::enable_if<__is_custom_pointer<_Ptr>::value>::type + destroy(_Alloc& __a, _Ptr __p) + { _Base_type::destroy(__a, std::addressof(*__p)); } + + static _Alloc _S_select_on_copy(const _Alloc& __a) + { return _Base_type::select_on_container_copy_construction(__a); } + + static void _S_on_swap(_Alloc& __a, _Alloc& __b) + { std::__alloc_on_swap(__a, __b); } + + static constexpr bool _S_propagate_on_copy_assign() + { return _Base_type::propagate_on_container_copy_assignment::value; } + + static constexpr bool _S_propagate_on_move_assign() + { return _Base_type::propagate_on_container_move_assignment::value; } + + static constexpr bool _S_propagate_on_swap() + { return _Base_type::propagate_on_container_swap::value; } + + static constexpr bool _S_always_equal() + { return __allocator_always_compares_equal<_Alloc>::value; } + + static constexpr bool _S_nothrow_move() + { return _S_propagate_on_move_assign() || _S_always_equal(); } + + static constexpr bool _S_nothrow_swap() + { + using std::swap; + return !_S_propagate_on_swap() + || noexcept(swap(std::declval<_Alloc&>(), std::declval<_Alloc&>())); + } + + template<typename _Tp> + struct rebind + { typedef typename _Base_type::template rebind_alloc<_Tp> other; }; +#else + + typedef typename _Alloc::pointer pointer; + typedef typename _Alloc::const_pointer const_pointer; + typedef typename _Alloc::value_type value_type; + typedef typename _Alloc::reference reference; + typedef typename _Alloc::const_reference const_reference; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + + static pointer + allocate(_Alloc& __a, size_type __n) + { return __a.allocate(__n); } + + static void deallocate(_Alloc& __a, pointer __p, size_type __n) + { __a.deallocate(__p, __n); } + + template<typename _Tp> + static void construct(_Alloc& __a, pointer __p, const _Tp& __arg) + { __a.construct(__p, __arg); } + + static void destroy(_Alloc& __a, pointer __p) + { __a.destroy(__p); } + + static size_type max_size(const _Alloc& __a) + { return __a.max_size(); } + + static const _Alloc& _S_select_on_copy(const _Alloc& __a) { return __a; } + + static void _S_on_swap(_Alloc& __a, _Alloc& __b) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<_Alloc>::_S_do_it(__a, __b); + } + + template<typename _Tp> + struct rebind + { typedef typename _Alloc::template rebind<_Tp>::other other; }; +#endif + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/array_allocator.h b/gcc-4.9/libstdc++-v3/include/ext/array_allocator.h new file mode 100644 index 0000000..f807495 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/array_allocator.h @@ -0,0 +1,174 @@ +// array allocator -*- C++ -*- + +// Copyright (C) 2004-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/array_allocator.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _ARRAY_ALLOCATOR_H +#define _ARRAY_ALLOCATOR_H 1 + +#include <bits/c++config.h> +#include <new> +#include <bits/functexcept.h> +#include <tr1/array> +#include <bits/move.h> +#if __cplusplus >= 201103L +#include <type_traits> +#endif + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::size_t; + using std::ptrdiff_t; + + /// Base class. + template<typename _Tp> + class array_allocator_base + { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + + pointer + address(reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + const_pointer + address(const_reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + void + deallocate(pointer, size_type) + { + // Does nothing. + } + + size_type + max_size() const _GLIBCXX_USE_NOEXCEPT + { return size_t(-1) / sizeof(_Tp); } + +#if __cplusplus >= 201103L + template<typename _Up, typename... _Args> + void + construct(_Up* __p, _Args&&... __args) + { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } + + template<typename _Up> + void + destroy(_Up* __p) { __p->~_Up(); } +#else + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 402. wrong new expression in [some_] allocator::construct + void + construct(pointer __p, const _Tp& __val) + { ::new((void *)__p) value_type(__val); } + + void + destroy(pointer __p) { __p->~_Tp(); } +#endif + } _GLIBCXX_DEPRECATED; + + /** + * @brief An allocator that uses previously allocated memory. + * This memory can be externally, globally, or otherwise allocated. + * @ingroup allocators + */ + template<typename _Tp, typename _Array = std::tr1::array<_Tp, 1> > + class array_allocator : public array_allocator_base<_Tp> + { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + typedef _Array array_type; + +#if __cplusplus >= 201103L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2103. std::allocator propagate_on_container_move_assignment + typedef std::true_type propagate_on_container_move_assignment; +#endif + + private: + array_type* _M_array; + size_type _M_used; + + public: + template<typename _Tp1, typename _Array1 = _Array> + struct rebind + { + typedef array_allocator<_Tp1, _Array1> other _GLIBCXX_DEPRECATED; + } _GLIBCXX_DEPRECATED; + + array_allocator(array_type* __array = 0) _GLIBCXX_USE_NOEXCEPT + : _M_array(__array), _M_used(size_type()) { } + + array_allocator(const array_allocator& __o) _GLIBCXX_USE_NOEXCEPT + : _M_array(__o._M_array), _M_used(__o._M_used) { } + + template<typename _Tp1, typename _Array1> + array_allocator(const array_allocator<_Tp1, _Array1>&) + _GLIBCXX_USE_NOEXCEPT + : _M_array(0), _M_used(size_type()) { } + + ~array_allocator() _GLIBCXX_USE_NOEXCEPT { } + + pointer + allocate(size_type __n, const void* = 0) + { + if (_M_array == 0 || _M_used + __n > _M_array->size()) + std::__throw_bad_alloc(); + pointer __ret = _M_array->begin() + _M_used; + _M_used += __n; + return __ret; + } + } _GLIBCXX_DEPRECATED; + + template<typename _Tp, typename _Array> + inline bool + operator==(const array_allocator<_Tp, _Array>&, + const array_allocator<_Tp, _Array>&) + { return true; } + + template<typename _Tp, typename _Array> + inline bool + operator!=(const array_allocator<_Tp, _Array>&, + const array_allocator<_Tp, _Array>&) + { return false; } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/atomicity.h b/gcc-4.9/libstdc++-v3/include/ext/atomicity.h new file mode 100644 index 0000000..bada709 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/atomicity.h @@ -0,0 +1,117 @@ +// Support for atomic operations -*- C++ -*- + +// Copyright (C) 2004-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/atomicity.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_ATOMICITY_H +#define _GLIBCXX_ATOMICITY_H 1 + +#pragma GCC system_header + +#include <bits/c++config.h> +#include <bits/gthr.h> +#include <bits/atomic_word.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // Functions for portable atomic access. + // To abstract locking primitives across all thread policies, use: + // __exchange_and_add_dispatch + // __atomic_add_dispatch +#ifdef _GLIBCXX_ATOMIC_BUILTINS + static inline _Atomic_word + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { return __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); } + + static inline void + __atomic_add(volatile _Atomic_word* __mem, int __val) + { __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); } +#else + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word*, int) throw (); + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word*, int) throw (); +#endif + + static inline _Atomic_word + __exchange_and_add_single(_Atomic_word* __mem, int __val) + { + _Atomic_word __result = *__mem; + *__mem += __val; + return __result; + } + + static inline void + __atomic_add_single(_Atomic_word* __mem, int __val) + { *__mem += __val; } + + static inline _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add_dispatch(_Atomic_word* __mem, int __val) + { +#ifdef __GTHREADS + if (__gthread_active_p()) + return __exchange_and_add(__mem, __val); + else + return __exchange_and_add_single(__mem, __val); +#else + return __exchange_and_add_single(__mem, __val); +#endif + } + + static inline void + __attribute__ ((__unused__)) + __atomic_add_dispatch(_Atomic_word* __mem, int __val) + { +#ifdef __GTHREADS + if (__gthread_active_p()) + __atomic_add(__mem, __val); + else + __atomic_add_single(__mem, __val); +#else + __atomic_add_single(__mem, __val); +#endif + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +// Even if the CPU doesn't need a memory barrier, we need to ensure +// that the compiler doesn't reorder memory accesses across the +// barriers. +#ifndef _GLIBCXX_READ_MEM_BARRIER +#define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("":::"memory") +#endif +#ifndef _GLIBCXX_WRITE_MEM_BARRIER +#define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("":::"memory") +#endif + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/bitmap_allocator.h b/gcc-4.9/libstdc++-v3/include/ext/bitmap_allocator.h new file mode 100644 index 0000000..2bfbbf5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/bitmap_allocator.h @@ -0,0 +1,1119 @@ +// Bitmap Allocator. -*- C++ -*- + +// Copyright (C) 2004-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/bitmap_allocator.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _BITMAP_ALLOCATOR_H +#define _BITMAP_ALLOCATOR_H 1 + +#include <utility> // For std::pair. +#include <bits/functexcept.h> // For __throw_bad_alloc(). +#include <functional> // For greater_equal, and less_equal. +#include <new> // For operator new. +#include <debug/debug.h> // _GLIBCXX_DEBUG_ASSERT +#include <ext/concurrence.h> +#include <bits/move.h> + +/** @brief The constant in the expression below is the alignment + * required in bytes. + */ +#define _BALLOC_ALIGN_BYTES 8 + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ + using std::size_t; + using std::ptrdiff_t; + + namespace __detail + { + _GLIBCXX_BEGIN_NAMESPACE_VERSION + /** @class __mini_vector bitmap_allocator.h bitmap_allocator.h + * + * @brief __mini_vector<> is a stripped down version of the + * full-fledged std::vector<>. + * + * It is to be used only for built-in types or PODs. Notable + * differences are: + * + * 1. Not all accessor functions are present. + * 2. Used ONLY for PODs. + * 3. No Allocator template argument. Uses ::operator new() to get + * memory, and ::operator delete() to free it. + * Caveat: The dtor does NOT free the memory allocated, so this a + * memory-leaking vector! + */ + template<typename _Tp> + class __mini_vector + { + __mini_vector(const __mini_vector&); + __mini_vector& operator=(const __mini_vector&); + + public: + typedef _Tp value_type; + typedef _Tp* pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef pointer iterator; + + private: + pointer _M_start; + pointer _M_finish; + pointer _M_end_of_storage; + + size_type + _M_space_left() const throw() + { return _M_end_of_storage - _M_finish; } + + pointer + allocate(size_type __n) + { return static_cast<pointer>(::operator new(__n * sizeof(_Tp))); } + + void + deallocate(pointer __p, size_type) + { ::operator delete(__p); } + + public: + // Members used: size(), push_back(), pop_back(), + // insert(iterator, const_reference), erase(iterator), + // begin(), end(), back(), operator[]. + + __mini_vector() + : _M_start(0), _M_finish(0), _M_end_of_storage(0) { } + + size_type + size() const throw() + { return _M_finish - _M_start; } + + iterator + begin() const throw() + { return this->_M_start; } + + iterator + end() const throw() + { return this->_M_finish; } + + reference + back() const throw() + { return *(this->end() - 1); } + + reference + operator[](const size_type __pos) const throw() + { return this->_M_start[__pos]; } + + void + insert(iterator __pos, const_reference __x); + + void + push_back(const_reference __x) + { + if (this->_M_space_left()) + { + *this->end() = __x; + ++this->_M_finish; + } + else + this->insert(this->end(), __x); + } + + void + pop_back() throw() + { --this->_M_finish; } + + void + erase(iterator __pos) throw(); + + void + clear() throw() + { this->_M_finish = this->_M_start; } + }; + + // Out of line function definitions. + template<typename _Tp> + void __mini_vector<_Tp>:: + insert(iterator __pos, const_reference __x) + { + if (this->_M_space_left()) + { + size_type __to_move = this->_M_finish - __pos; + iterator __dest = this->end(); + iterator __src = this->end() - 1; + + ++this->_M_finish; + while (__to_move) + { + *__dest = *__src; + --__dest; --__src; --__to_move; + } + *__pos = __x; + } + else + { + size_type __new_size = this->size() ? this->size() * 2 : 1; + iterator __new_start = this->allocate(__new_size); + iterator __first = this->begin(); + iterator __start = __new_start; + while (__first != __pos) + { + *__start = *__first; + ++__start; ++__first; + } + *__start = __x; + ++__start; + while (__first != this->end()) + { + *__start = *__first; + ++__start; ++__first; + } + if (this->_M_start) + this->deallocate(this->_M_start, this->size()); + + this->_M_start = __new_start; + this->_M_finish = __start; + this->_M_end_of_storage = this->_M_start + __new_size; + } + } + + template<typename _Tp> + void __mini_vector<_Tp>:: + erase(iterator __pos) throw() + { + while (__pos + 1 != this->end()) + { + *__pos = __pos[1]; + ++__pos; + } + --this->_M_finish; + } + + + template<typename _Tp> + struct __mv_iter_traits + { + typedef typename _Tp::value_type value_type; + typedef typename _Tp::difference_type difference_type; + }; + + template<typename _Tp> + struct __mv_iter_traits<_Tp*> + { + typedef _Tp value_type; + typedef ptrdiff_t difference_type; + }; + + enum + { + bits_per_byte = 8, + bits_per_block = sizeof(size_t) * size_t(bits_per_byte) + }; + + template<typename _ForwardIterator, typename _Tp, typename _Compare> + _ForwardIterator + __lower_bound(_ForwardIterator __first, _ForwardIterator __last, + const _Tp& __val, _Compare __comp) + { + typedef typename __mv_iter_traits<_ForwardIterator>::difference_type + _DistanceType; + + _DistanceType __len = __last - __first; + _DistanceType __half; + _ForwardIterator __middle; + + while (__len > 0) + { + __half = __len >> 1; + __middle = __first; + __middle += __half; + if (__comp(*__middle, __val)) + { + __first = __middle; + ++__first; + __len = __len - __half - 1; + } + else + __len = __half; + } + return __first; + } + + /** @brief The number of Blocks pointed to by the address pair + * passed to the function. + */ + template<typename _AddrPair> + inline size_t + __num_blocks(_AddrPair __ap) + { return (__ap.second - __ap.first) + 1; } + + /** @brief The number of Bit-maps pointed to by the address pair + * passed to the function. + */ + template<typename _AddrPair> + inline size_t + __num_bitmaps(_AddrPair __ap) + { return __num_blocks(__ap) / size_t(bits_per_block); } + + // _Tp should be a pointer type. + template<typename _Tp> + class _Inclusive_between + : public std::unary_function<typename std::pair<_Tp, _Tp>, bool> + { + typedef _Tp pointer; + pointer _M_ptr_value; + typedef typename std::pair<_Tp, _Tp> _Block_pair; + + public: + _Inclusive_between(pointer __ptr) : _M_ptr_value(__ptr) + { } + + bool + operator()(_Block_pair __bp) const throw() + { + if (std::less_equal<pointer>()(_M_ptr_value, __bp.second) + && std::greater_equal<pointer>()(_M_ptr_value, __bp.first)) + return true; + else + return false; + } + }; + + // Used to pass a Functor to functions by reference. + template<typename _Functor> + class _Functor_Ref + : public std::unary_function<typename _Functor::argument_type, + typename _Functor::result_type> + { + _Functor& _M_fref; + + public: + typedef typename _Functor::argument_type argument_type; + typedef typename _Functor::result_type result_type; + + _Functor_Ref(_Functor& __fref) : _M_fref(__fref) + { } + + result_type + operator()(argument_type __arg) + { return _M_fref(__arg); } + }; + + /** @class _Ffit_finder bitmap_allocator.h bitmap_allocator.h + * + * @brief The class which acts as a predicate for applying the + * first-fit memory allocation policy for the bitmap allocator. + */ + // _Tp should be a pointer type, and _Alloc is the Allocator for + // the vector. + template<typename _Tp> + class _Ffit_finder + : public std::unary_function<typename std::pair<_Tp, _Tp>, bool> + { + typedef typename std::pair<_Tp, _Tp> _Block_pair; + typedef typename __detail::__mini_vector<_Block_pair> _BPVector; + typedef typename _BPVector::difference_type _Counter_type; + + size_t* _M_pbitmap; + _Counter_type _M_data_offset; + + public: + _Ffit_finder() : _M_pbitmap(0), _M_data_offset(0) + { } + + bool + operator()(_Block_pair __bp) throw() + { + // Set the _rover to the last physical location bitmap, + // which is the bitmap which belongs to the first free + // block. Thus, the bitmaps are in exact reverse order of + // the actual memory layout. So, we count down the bitmaps, + // which is the same as moving up the memory. + + // If the used count stored at the start of the Bit Map headers + // is equal to the number of Objects that the current Block can + // store, then there is definitely no space for another single + // object, so just return false. + _Counter_type __diff = __detail::__num_bitmaps(__bp); + + if (*(reinterpret_cast<size_t*> + (__bp.first) - (__diff + 1)) == __detail::__num_blocks(__bp)) + return false; + + size_t* __rover = reinterpret_cast<size_t*>(__bp.first) - 1; + + for (_Counter_type __i = 0; __i < __diff; ++__i) + { + _M_data_offset = __i; + if (*__rover) + { + _M_pbitmap = __rover; + return true; + } + --__rover; + } + return false; + } + + size_t* + _M_get() const throw() + { return _M_pbitmap; } + + _Counter_type + _M_offset() const throw() + { return _M_data_offset * size_t(bits_per_block); } + }; + + /** @class _Bitmap_counter bitmap_allocator.h bitmap_allocator.h + * + * @brief The bitmap counter which acts as the bitmap + * manipulator, and manages the bit-manipulation functions and + * the searching and identification functions on the bit-map. + */ + // _Tp should be a pointer type. + template<typename _Tp> + class _Bitmap_counter + { + typedef typename + __detail::__mini_vector<typename std::pair<_Tp, _Tp> > _BPVector; + typedef typename _BPVector::size_type _Index_type; + typedef _Tp pointer; + + _BPVector& _M_vbp; + size_t* _M_curr_bmap; + size_t* _M_last_bmap_in_block; + _Index_type _M_curr_index; + + public: + // Use the 2nd parameter with care. Make sure that such an + // entry exists in the vector before passing that particular + // index to this ctor. + _Bitmap_counter(_BPVector& Rvbp, long __index = -1) : _M_vbp(Rvbp) + { this->_M_reset(__index); } + + void + _M_reset(long __index = -1) throw() + { + if (__index == -1) + { + _M_curr_bmap = 0; + _M_curr_index = static_cast<_Index_type>(-1); + return; + } + + _M_curr_index = __index; + _M_curr_bmap = reinterpret_cast<size_t*> + (_M_vbp[_M_curr_index].first) - 1; + + _GLIBCXX_DEBUG_ASSERT(__index <= (long)_M_vbp.size() - 1); + + _M_last_bmap_in_block = _M_curr_bmap + - ((_M_vbp[_M_curr_index].second + - _M_vbp[_M_curr_index].first + 1) + / size_t(bits_per_block) - 1); + } + + // Dangerous Function! Use with extreme care. Pass to this + // function ONLY those values that are known to be correct, + // otherwise this will mess up big time. + void + _M_set_internal_bitmap(size_t* __new_internal_marker) throw() + { _M_curr_bmap = __new_internal_marker; } + + bool + _M_finished() const throw() + { return(_M_curr_bmap == 0); } + + _Bitmap_counter& + operator++() throw() + { + if (_M_curr_bmap == _M_last_bmap_in_block) + { + if (++_M_curr_index == _M_vbp.size()) + _M_curr_bmap = 0; + else + this->_M_reset(_M_curr_index); + } + else + --_M_curr_bmap; + return *this; + } + + size_t* + _M_get() const throw() + { return _M_curr_bmap; } + + pointer + _M_base() const throw() + { return _M_vbp[_M_curr_index].first; } + + _Index_type + _M_offset() const throw() + { + return size_t(bits_per_block) + * ((reinterpret_cast<size_t*>(this->_M_base()) + - _M_curr_bmap) - 1); + } + + _Index_type + _M_where() const throw() + { return _M_curr_index; } + }; + + /** @brief Mark a memory address as allocated by re-setting the + * corresponding bit in the bit-map. + */ + inline void + __bit_allocate(size_t* __pbmap, size_t __pos) throw() + { + size_t __mask = 1 << __pos; + __mask = ~__mask; + *__pbmap &= __mask; + } + + /** @brief Mark a memory address as free by setting the + * corresponding bit in the bit-map. + */ + inline void + __bit_free(size_t* __pbmap, size_t __pos) throw() + { + size_t __mask = 1 << __pos; + *__pbmap |= __mask; + } + + _GLIBCXX_END_NAMESPACE_VERSION + } // namespace __detail + +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** @brief Generic Version of the bsf instruction. + */ + inline size_t + _Bit_scan_forward(size_t __num) + { return static_cast<size_t>(__builtin_ctzl(__num)); } + + /** @class free_list bitmap_allocator.h bitmap_allocator.h + * + * @brief The free list class for managing chunks of memory to be + * given to and returned by the bitmap_allocator. + */ + class free_list + { + public: + typedef size_t* value_type; + typedef __detail::__mini_vector<value_type> vector_type; + typedef vector_type::iterator iterator; + typedef __mutex __mutex_type; + + private: + struct _LT_pointer_compare + { + bool + operator()(const size_t* __pui, + const size_t __cui) const throw() + { return *__pui < __cui; } + }; + +#if defined __GTHREADS + __mutex_type& + _M_get_mutex() + { + static __mutex_type _S_mutex; + return _S_mutex; + } +#endif + + vector_type& + _M_get_free_list() + { + static vector_type _S_free_list; + return _S_free_list; + } + + /** @brief Performs validation of memory based on their size. + * + * @param __addr The pointer to the memory block to be + * validated. + * + * Validates the memory block passed to this function and + * appropriately performs the action of managing the free list of + * blocks by adding this block to the free list or deleting this + * or larger blocks from the free list. + */ + void + _M_validate(size_t* __addr) throw() + { + vector_type& __free_list = _M_get_free_list(); + const vector_type::size_type __max_size = 64; + if (__free_list.size() >= __max_size) + { + // Ok, the threshold value has been reached. We determine + // which block to remove from the list of free blocks. + if (*__addr >= *__free_list.back()) + { + // Ok, the new block is greater than or equal to the + // last block in the list of free blocks. We just free + // the new block. + ::operator delete(static_cast<void*>(__addr)); + return; + } + else + { + // Deallocate the last block in the list of free lists, + // and insert the new one in its correct position. + ::operator delete(static_cast<void*>(__free_list.back())); + __free_list.pop_back(); + } + } + + // Just add the block to the list of free lists unconditionally. + iterator __temp = __detail::__lower_bound + (__free_list.begin(), __free_list.end(), + *__addr, _LT_pointer_compare()); + + // We may insert the new free list before _temp; + __free_list.insert(__temp, __addr); + } + + /** @brief Decides whether the wastage of memory is acceptable for + * the current memory request and returns accordingly. + * + * @param __block_size The size of the block available in the free + * list. + * + * @param __required_size The required size of the memory block. + * + * @return true if the wastage incurred is acceptable, else returns + * false. + */ + bool + _M_should_i_give(size_t __block_size, + size_t __required_size) throw() + { + const size_t __max_wastage_percentage = 36; + if (__block_size >= __required_size && + (((__block_size - __required_size) * 100 / __block_size) + < __max_wastage_percentage)) + return true; + else + return false; + } + + public: + /** @brief This function returns the block of memory to the + * internal free list. + * + * @param __addr The pointer to the memory block that was given + * by a call to the _M_get function. + */ + inline void + _M_insert(size_t* __addr) throw() + { +#if defined __GTHREADS + __scoped_lock __bfl_lock(_M_get_mutex()); +#endif + // Call _M_validate to decide what should be done with + // this particular free list. + this->_M_validate(reinterpret_cast<size_t*>(__addr) - 1); + // See discussion as to why this is 1! + } + + /** @brief This function gets a block of memory of the specified + * size from the free list. + * + * @param __sz The size in bytes of the memory required. + * + * @return A pointer to the new memory block of size at least + * equal to that requested. + */ + size_t* + _M_get(size_t __sz) throw(std::bad_alloc); + + /** @brief This function just clears the internal Free List, and + * gives back all the memory to the OS. + */ + void + _M_clear(); + }; + + + // Forward declare the class. + template<typename _Tp> + class bitmap_allocator; + + // Specialize for void: + template<> + class bitmap_allocator<void> + { + public: + typedef void* pointer; + typedef const void* const_pointer; + + // Reference-to-void members are impossible. + typedef void value_type; + template<typename _Tp1> + struct rebind + { + typedef bitmap_allocator<_Tp1> other; + }; + }; + + /** + * @brief Bitmap Allocator, primary template. + * @ingroup allocators + */ + template<typename _Tp> + class bitmap_allocator : private free_list + { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + typedef free_list::__mutex_type __mutex_type; + + template<typename _Tp1> + struct rebind + { + typedef bitmap_allocator<_Tp1> other; + }; + +#if __cplusplus >= 201103L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2103. propagate_on_container_move_assignment + typedef std::true_type propagate_on_container_move_assignment; +#endif + + private: + template<size_t _BSize, size_t _AlignSize> + struct aligned_size + { + enum + { + modulus = _BSize % _AlignSize, + value = _BSize + (modulus ? _AlignSize - (modulus) : 0) + }; + }; + + struct _Alloc_block + { + char __M_unused[aligned_size<sizeof(value_type), + _BALLOC_ALIGN_BYTES>::value]; + }; + + + typedef typename std::pair<_Alloc_block*, _Alloc_block*> _Block_pair; + + typedef typename __detail::__mini_vector<_Block_pair> _BPVector; + typedef typename _BPVector::iterator _BPiter; + + template<typename _Predicate> + static _BPiter + _S_find(_Predicate __p) + { + _BPiter __first = _S_mem_blocks.begin(); + while (__first != _S_mem_blocks.end() && !__p(*__first)) + ++__first; + return __first; + } + +#if defined _GLIBCXX_DEBUG + // Complexity: O(lg(N)). Where, N is the number of block of size + // sizeof(value_type). + void + _S_check_for_free_blocks() throw() + { + typedef typename __detail::_Ffit_finder<_Alloc_block*> _FFF; + _BPiter __bpi = _S_find(_FFF()); + + _GLIBCXX_DEBUG_ASSERT(__bpi == _S_mem_blocks.end()); + } +#endif + + /** @brief Responsible for exponentially growing the internal + * memory pool. + * + * @throw std::bad_alloc. If memory can not be allocated. + * + * Complexity: O(1), but internally depends upon the + * complexity of the function free_list::_M_get. The part where + * the bitmap headers are written has complexity: O(X),where X + * is the number of blocks of size sizeof(value_type) within + * the newly acquired block. Having a tight bound. + */ + void + _S_refill_pool() throw(std::bad_alloc) + { +#if defined _GLIBCXX_DEBUG + _S_check_for_free_blocks(); +#endif + + const size_t __num_bitmaps = (_S_block_size + / size_t(__detail::bits_per_block)); + const size_t __size_to_allocate = sizeof(size_t) + + _S_block_size * sizeof(_Alloc_block) + + __num_bitmaps * sizeof(size_t); + + size_t* __temp = + reinterpret_cast<size_t*>(this->_M_get(__size_to_allocate)); + *__temp = 0; + ++__temp; + + // The Header information goes at the Beginning of the Block. + _Block_pair __bp = + std::make_pair(reinterpret_cast<_Alloc_block*> + (__temp + __num_bitmaps), + reinterpret_cast<_Alloc_block*> + (__temp + __num_bitmaps) + + _S_block_size - 1); + + // Fill the Vector with this information. + _S_mem_blocks.push_back(__bp); + + for (size_t __i = 0; __i < __num_bitmaps; ++__i) + __temp[__i] = ~static_cast<size_t>(0); // 1 Indicates all Free. + + _S_block_size *= 2; + } + + static _BPVector _S_mem_blocks; + static size_t _S_block_size; + static __detail::_Bitmap_counter<_Alloc_block*> _S_last_request; + static typename _BPVector::size_type _S_last_dealloc_index; +#if defined __GTHREADS + static __mutex_type _S_mut; +#endif + + public: + + /** @brief Allocates memory for a single object of size + * sizeof(_Tp). + * + * @throw std::bad_alloc. If memory can not be allocated. + * + * Complexity: Worst case complexity is O(N), but that + * is hardly ever hit. If and when this particular case is + * encountered, the next few cases are guaranteed to have a + * worst case complexity of O(1)! That's why this function + * performs very well on average. You can consider this + * function to have a complexity referred to commonly as: + * Amortized Constant time. + */ + pointer + _M_allocate_single_object() throw(std::bad_alloc) + { +#if defined __GTHREADS + __scoped_lock __bit_lock(_S_mut); +#endif + + // The algorithm is something like this: The last_request + // variable points to the last accessed Bit Map. When such a + // condition occurs, we try to find a free block in the + // current bitmap, or succeeding bitmaps until the last bitmap + // is reached. If no free block turns up, we resort to First + // Fit method. + + // WARNING: Do not re-order the condition in the while + // statement below, because it relies on C++'s short-circuit + // evaluation. The return from _S_last_request->_M_get() will + // NOT be dereference able if _S_last_request->_M_finished() + // returns true. This would inevitably lead to a NULL pointer + // dereference if tinkered with. + while (_S_last_request._M_finished() == false + && (*(_S_last_request._M_get()) == 0)) + _S_last_request.operator++(); + + if (__builtin_expect(_S_last_request._M_finished() == true, false)) + { + // Fall Back to First Fit algorithm. + typedef typename __detail::_Ffit_finder<_Alloc_block*> _FFF; + _FFF __fff; + _BPiter __bpi = _S_find(__detail::_Functor_Ref<_FFF>(__fff)); + + if (__bpi != _S_mem_blocks.end()) + { + // Search was successful. Ok, now mark the first bit from + // the right as 0, meaning Allocated. This bit is obtained + // by calling _M_get() on __fff. + size_t __nz_bit = _Bit_scan_forward(*__fff._M_get()); + __detail::__bit_allocate(__fff._M_get(), __nz_bit); + + _S_last_request._M_reset(__bpi - _S_mem_blocks.begin()); + + // Now, get the address of the bit we marked as allocated. + pointer __ret = reinterpret_cast<pointer> + (__bpi->first + __fff._M_offset() + __nz_bit); + size_t* __puse_count = + reinterpret_cast<size_t*> + (__bpi->first) - (__detail::__num_bitmaps(*__bpi) + 1); + + ++(*__puse_count); + return __ret; + } + else + { + // Search was unsuccessful. We Add more memory to the + // pool by calling _S_refill_pool(). + _S_refill_pool(); + + // _M_Reset the _S_last_request structure to the first + // free block's bit map. + _S_last_request._M_reset(_S_mem_blocks.size() - 1); + + // Now, mark that bit as allocated. + } + } + + // _S_last_request holds a pointer to a valid bit map, that + // points to a free block in memory. + size_t __nz_bit = _Bit_scan_forward(*_S_last_request._M_get()); + __detail::__bit_allocate(_S_last_request._M_get(), __nz_bit); + + pointer __ret = reinterpret_cast<pointer> + (_S_last_request._M_base() + _S_last_request._M_offset() + __nz_bit); + + size_t* __puse_count = reinterpret_cast<size_t*> + (_S_mem_blocks[_S_last_request._M_where()].first) + - (__detail:: + __num_bitmaps(_S_mem_blocks[_S_last_request._M_where()]) + 1); + + ++(*__puse_count); + return __ret; + } + + /** @brief Deallocates memory that belongs to a single object of + * size sizeof(_Tp). + * + * Complexity: O(lg(N)), but the worst case is not hit + * often! This is because containers usually deallocate memory + * close to each other and this case is handled in O(1) time by + * the deallocate function. + */ + void + _M_deallocate_single_object(pointer __p) throw() + { +#if defined __GTHREADS + __scoped_lock __bit_lock(_S_mut); +#endif + _Alloc_block* __real_p = reinterpret_cast<_Alloc_block*>(__p); + + typedef typename _BPVector::iterator _Iterator; + typedef typename _BPVector::difference_type _Difference_type; + + _Difference_type __diff; + long __displacement; + + _GLIBCXX_DEBUG_ASSERT(_S_last_dealloc_index >= 0); + + __detail::_Inclusive_between<_Alloc_block*> __ibt(__real_p); + if (__ibt(_S_mem_blocks[_S_last_dealloc_index])) + { + _GLIBCXX_DEBUG_ASSERT(_S_last_dealloc_index + <= _S_mem_blocks.size() - 1); + + // Initial Assumption was correct! + __diff = _S_last_dealloc_index; + __displacement = __real_p - _S_mem_blocks[__diff].first; + } + else + { + _Iterator _iter = _S_find(__ibt); + + _GLIBCXX_DEBUG_ASSERT(_iter != _S_mem_blocks.end()); + + __diff = _iter - _S_mem_blocks.begin(); + __displacement = __real_p - _S_mem_blocks[__diff].first; + _S_last_dealloc_index = __diff; + } + + // Get the position of the iterator that has been found. + const size_t __rotate = (__displacement + % size_t(__detail::bits_per_block)); + size_t* __bitmapC = + reinterpret_cast<size_t*> + (_S_mem_blocks[__diff].first) - 1; + __bitmapC -= (__displacement / size_t(__detail::bits_per_block)); + + __detail::__bit_free(__bitmapC, __rotate); + size_t* __puse_count = reinterpret_cast<size_t*> + (_S_mem_blocks[__diff].first) + - (__detail::__num_bitmaps(_S_mem_blocks[__diff]) + 1); + + _GLIBCXX_DEBUG_ASSERT(*__puse_count != 0); + + --(*__puse_count); + + if (__builtin_expect(*__puse_count == 0, false)) + { + _S_block_size /= 2; + + // We can safely remove this block. + // _Block_pair __bp = _S_mem_blocks[__diff]; + this->_M_insert(__puse_count); + _S_mem_blocks.erase(_S_mem_blocks.begin() + __diff); + + // Reset the _S_last_request variable to reflect the + // erased block. We do this to protect future requests + // after the last block has been removed from a particular + // memory Chunk, which in turn has been returned to the + // free list, and hence had been erased from the vector, + // so the size of the vector gets reduced by 1. + if ((_Difference_type)_S_last_request._M_where() >= __diff--) + _S_last_request._M_reset(__diff); + + // If the Index into the vector of the region of memory + // that might hold the next address that will be passed to + // deallocated may have been invalidated due to the above + // erase procedure being called on the vector, hence we + // try to restore this invariant too. + if (_S_last_dealloc_index >= _S_mem_blocks.size()) + { + _S_last_dealloc_index =(__diff != -1 ? __diff : 0); + _GLIBCXX_DEBUG_ASSERT(_S_last_dealloc_index >= 0); + } + } + } + + public: + bitmap_allocator() _GLIBCXX_USE_NOEXCEPT + { } + + bitmap_allocator(const bitmap_allocator&) _GLIBCXX_USE_NOEXCEPT + { } + + template<typename _Tp1> + bitmap_allocator(const bitmap_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT + { } + + ~bitmap_allocator() _GLIBCXX_USE_NOEXCEPT + { } + + pointer + allocate(size_type __n) + { + if (__n > this->max_size()) + std::__throw_bad_alloc(); + + if (__builtin_expect(__n == 1, true)) + return this->_M_allocate_single_object(); + else + { + const size_type __b = __n * sizeof(value_type); + return reinterpret_cast<pointer>(::operator new(__b)); + } + } + + pointer + allocate(size_type __n, typename bitmap_allocator<void>::const_pointer) + { return allocate(__n); } + + void + deallocate(pointer __p, size_type __n) throw() + { + if (__builtin_expect(__p != 0, true)) + { + if (__builtin_expect(__n == 1, true)) + this->_M_deallocate_single_object(__p); + else + ::operator delete(__p); + } + } + + pointer + address(reference __r) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__r); } + + const_pointer + address(const_reference __r) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__r); } + + size_type + max_size() const _GLIBCXX_USE_NOEXCEPT + { return size_type(-1) / sizeof(value_type); } + +#if __cplusplus >= 201103L + template<typename _Up, typename... _Args> + void + construct(_Up* __p, _Args&&... __args) + { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } + + template<typename _Up> + void + destroy(_Up* __p) + { __p->~_Up(); } +#else + void + construct(pointer __p, const_reference __data) + { ::new((void *)__p) value_type(__data); } + + void + destroy(pointer __p) + { __p->~value_type(); } +#endif + }; + + template<typename _Tp1, typename _Tp2> + bool + operator==(const bitmap_allocator<_Tp1>&, + const bitmap_allocator<_Tp2>&) throw() + { return true; } + + template<typename _Tp1, typename _Tp2> + bool + operator!=(const bitmap_allocator<_Tp1>&, + const bitmap_allocator<_Tp2>&) throw() + { return false; } + + // Static member definitions. + template<typename _Tp> + typename bitmap_allocator<_Tp>::_BPVector + bitmap_allocator<_Tp>::_S_mem_blocks; + + template<typename _Tp> + size_t bitmap_allocator<_Tp>::_S_block_size = + 2 * size_t(__detail::bits_per_block); + + template<typename _Tp> + typename bitmap_allocator<_Tp>::_BPVector::size_type + bitmap_allocator<_Tp>::_S_last_dealloc_index = 0; + + template<typename _Tp> + __detail::_Bitmap_counter + <typename bitmap_allocator<_Tp>::_Alloc_block*> + bitmap_allocator<_Tp>::_S_last_request(_S_mem_blocks); + +#if defined __GTHREADS + template<typename _Tp> + typename bitmap_allocator<_Tp>::__mutex_type + bitmap_allocator<_Tp>::_S_mut; +#endif + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace __gnu_cxx + +#endif + diff --git a/gcc-4.9/libstdc++-v3/include/ext/cast.h b/gcc-4.9/libstdc++-v3/include/ext/cast.h new file mode 100644 index 0000000..655ca06 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/cast.h @@ -0,0 +1,121 @@ +// <cast.h> -*- C++ -*- + +// Copyright (C) 2008-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/cast.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{ext/pointer.h} + */ + +#ifndef _GLIBCXX_CAST_H +#define _GLIBCXX_CAST_H 1 + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * These functions are here to allow containers to support non standard + * pointer types. For normal pointers, these resolve to the use of the + * standard cast operation. For other types the functions will perform + * the appropriate cast to/from the custom pointer class so long as that + * class meets the following conditions: + * 1) has a typedef element_type which names tehe type it points to. + * 2) has a get() const method which returns element_type*. + * 3) has a constructor which can take one element_type* argument. + */ + + /** + * This type supports the semantics of the pointer cast operators (below.) + */ + template<typename _ToType> + struct _Caster + { typedef typename _ToType::element_type* type; }; + + template<typename _ToType> + struct _Caster<_ToType*> + { typedef _ToType* type; }; + + /** + * Casting operations for cases where _FromType is not a standard pointer. + * _ToType can be a standard or non-standard pointer. Given that _FromType + * is not a pointer, it must have a get() method that returns the standard + * pointer equivalent of the address it points to, and must have an + * element_type typedef which names the type it points to. + */ + template<typename _ToType, typename _FromType> + inline _ToType + __static_pointer_cast(const _FromType& __arg) + { return _ToType(static_cast<typename _Caster<_ToType>:: + type>(__arg.get())); } + + template<typename _ToType, typename _FromType> + inline _ToType + __dynamic_pointer_cast(const _FromType& __arg) + { return _ToType(dynamic_cast<typename _Caster<_ToType>:: + type>(__arg.get())); } + + template<typename _ToType, typename _FromType> + inline _ToType + __const_pointer_cast(const _FromType& __arg) + { return _ToType(const_cast<typename _Caster<_ToType>:: + type>(__arg.get())); } + + template<typename _ToType, typename _FromType> + inline _ToType + __reinterpret_pointer_cast(const _FromType& __arg) + { return _ToType(reinterpret_cast<typename _Caster<_ToType>:: + type>(__arg.get())); } + + /** + * Casting operations for cases where _FromType is a standard pointer. + * _ToType can be a standard or non-standard pointer. + */ + template<typename _ToType, typename _FromType> + inline _ToType + __static_pointer_cast(_FromType* __arg) + { return _ToType(static_cast<typename _Caster<_ToType>:: + type>(__arg)); } + + template<typename _ToType, typename _FromType> + inline _ToType + __dynamic_pointer_cast(_FromType* __arg) + { return _ToType(dynamic_cast<typename _Caster<_ToType>:: + type>(__arg)); } + + template<typename _ToType, typename _FromType> + inline _ToType + __const_pointer_cast(_FromType* __arg) + { return _ToType(const_cast<typename _Caster<_ToType>:: + type>(__arg)); } + + template<typename _ToType, typename _FromType> + inline _ToType + __reinterpret_pointer_cast(_FromType* __arg) + { return _ToType(reinterpret_cast<typename _Caster<_ToType>:: + type>(__arg)); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif // _GLIBCXX_CAST_H diff --git a/gcc-4.9/libstdc++-v3/include/ext/cmath b/gcc-4.9/libstdc++-v3/include/ext/cmath new file mode 100644 index 0000000..91434d3 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/cmath @@ -0,0 +1,152 @@ +// Math extensions -*- C++ -*- + +// Copyright (C) 2013-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/cmath + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _EXT_CMATH +#define _EXT_CMATH 1 + +#pragma GCC system_header + +#if __cplusplus < 201103L +# include <bits/c++0x_warning.h> +#else + +#include <cmath> +#include <type_traits> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // A class for math constants. + template<typename _RealType> + struct __math_constants + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + // Constant @f$ \pi @f$. + static constexpr _RealType __pi = 3.1415926535897932384626433832795029L; + // Constant @f$ \pi / 2 @f$. + static constexpr _RealType __pi_half = 1.5707963267948966192313216916397514L; + // Constant @f$ \pi / 3 @f$. + static constexpr _RealType __pi_third = 1.0471975511965977461542144610931676L; + // Constant @f$ \pi / 4 @f$. + static constexpr _RealType __pi_quarter = 0.7853981633974483096156608458198757L; + // Constant @f$ \sqrt(\pi / 2) @f$. + static constexpr _RealType __root_pi_div_2 = 1.2533141373155002512078826424055226L; + // Constant @f$ 1 / \pi @f$. + static constexpr _RealType __one_div_pi = 0.3183098861837906715377675267450287L; + // Constant @f$ 2 / \pi @f$. + static constexpr _RealType __two_div_pi = 0.6366197723675813430755350534900574L; + // Constant @f$ 2 / \sqrt(\pi) @f$. + static constexpr _RealType __two_div_root_pi = 1.1283791670955125738961589031215452L; + + // Constant Euler's number @f$ e @f$. + static constexpr _RealType __e = 2.7182818284590452353602874713526625L; + // Constant @f$ 1 / e @f$. + static constexpr _RealType __one_div_e = 0.36787944117144232159552377016146087L; + // Constant @f$ \log_2(e) @f$. + static constexpr _RealType __log2_e = 1.4426950408889634073599246810018921L; + // Constant @f$ \log_10(e) @f$. + static constexpr _RealType __log10_e = 0.4342944819032518276511289189166051L; + // Constant @f$ \ln(2) @f$. + static constexpr _RealType __ln_2 = 0.6931471805599453094172321214581766L; + // Constant @f$ \ln(3) @f$. + static constexpr _RealType __ln_3 = 1.0986122886681096913952452369225257L; + // Constant @f$ \ln(10) @f$. + static constexpr _RealType __ln_10 = 2.3025850929940456840179914546843642L; + + // Constant Euler-Mascheroni @f$ \gamma_E @f$. + static constexpr _RealType __gamma_e = 0.5772156649015328606065120900824024L; + // Constant Golden Ratio @f$ \phi @f$. + static constexpr _RealType __phi = 1.6180339887498948482045868343656381L; + + // Constant @f$ \sqrt(2) @f$. + static constexpr _RealType __root_2 = 1.4142135623730950488016887242096981L; + // Constant @f$ \sqrt(3) @f$. + static constexpr _RealType __root_3 = 1.7320508075688772935274463415058724L; + // Constant @f$ \sqrt(5) @f$. + static constexpr _RealType __root_5 = 2.2360679774997896964091736687312762L; + // Constant @f$ \sqrt(7) @f$. + static constexpr _RealType __root_7 = 2.6457513110645905905016157536392604L; + // Constant @f$ 1 / \sqrt(2) @f$. + static constexpr _RealType __one_div_root_2 = 0.7071067811865475244008443621048490L; + }; + + // And the template definitions for the constants. + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__pi; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__pi_half; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__pi_third; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__pi_quarter; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__root_pi_div_2; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__one_div_pi; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__two_div_pi; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__two_div_root_pi; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__e; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__one_div_e; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__log2_e; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__log10_e; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__ln_2; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__ln_3; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__ln_10; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__gamma_e; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__phi; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__root_2; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__root_3; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__root_5; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__root_7; + template<typename _RealType> + constexpr _RealType __math_constants<_RealType>::__one_div_root_2; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace __gnu_cxx + +#endif // C++11 + +#endif // _EXT_CMATH diff --git a/gcc-4.9/libstdc++-v3/include/ext/codecvt_specializations.h b/gcc-4.9/libstdc++-v3/include/ext/codecvt_specializations.h new file mode 100644 index 0000000..9a4c6e0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/codecvt_specializations.h @@ -0,0 +1,512 @@ +// Locale support (codecvt) -*- C++ -*- + +// Copyright (C) 2000-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// +// ISO C++ 14882: 22.2.1.5 Template class codecvt +// + +// Written by Benjamin Kosnik <bkoz@redhat.com> + +/** @file ext/codecvt_specializations.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _EXT_CODECVT_SPECIALIZATIONS_H +#define _EXT_CODECVT_SPECIALIZATIONS_H 1 + +#include <bits/c++config.h> +#include <locale> +#include <iconv.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /// Extension to use iconv for dealing with character encodings. + // This includes conversions and comparisons between various character + // sets. This object encapsulates data that may need to be shared between + // char_traits, codecvt and ctype. + class encoding_state + { + public: + // Types: + // NB: A conversion descriptor subsumes and enhances the + // functionality of a simple state type such as mbstate_t. + typedef iconv_t descriptor_type; + + protected: + // Name of internal character set encoding. + std::string _M_int_enc; + + // Name of external character set encoding. + std::string _M_ext_enc; + + // Conversion descriptor between external encoding to internal encoding. + descriptor_type _M_in_desc; + + // Conversion descriptor between internal encoding to external encoding. + descriptor_type _M_out_desc; + + // The byte-order marker for the external encoding, if necessary. + int _M_ext_bom; + + // The byte-order marker for the internal encoding, if necessary. + int _M_int_bom; + + // Number of external bytes needed to construct one complete + // character in the internal encoding. + // NB: -1 indicates variable, or stateful, encodings. + int _M_bytes; + + public: + explicit + encoding_state() + : _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0), _M_bytes(0) + { } + + explicit + encoding_state(const char* __int, const char* __ext, + int __ibom = 0, int __ebom = 0, int __bytes = 1) + : _M_int_enc(__int), _M_ext_enc(__ext), _M_in_desc(0), _M_out_desc(0), + _M_ext_bom(__ebom), _M_int_bom(__ibom), _M_bytes(__bytes) + { init(); } + + // 21.1.2 traits typedefs + // p4 + // typedef STATE_T state_type + // requires: state_type shall meet the requirements of + // CopyConstructible types (20.1.3) + // NB: This does not preserve the actual state of the conversion + // descriptor member, but it does duplicate the encoding + // information. + encoding_state(const encoding_state& __obj) : _M_in_desc(0), _M_out_desc(0) + { construct(__obj); } + + // Need assignment operator as well. + encoding_state& + operator=(const encoding_state& __obj) + { + construct(__obj); + return *this; + } + + ~encoding_state() + { destroy(); } + + bool + good() const throw() + { + const descriptor_type __err = (iconv_t)(-1); + bool __test = _M_in_desc && _M_in_desc != __err; + __test &= _M_out_desc && _M_out_desc != __err; + return __test; + } + + int + character_ratio() const + { return _M_bytes; } + + const std::string + internal_encoding() const + { return _M_int_enc; } + + int + internal_bom() const + { return _M_int_bom; } + + const std::string + external_encoding() const + { return _M_ext_enc; } + + int + external_bom() const + { return _M_ext_bom; } + + const descriptor_type& + in_descriptor() const + { return _M_in_desc; } + + const descriptor_type& + out_descriptor() const + { return _M_out_desc; } + + protected: + void + init() + { + const descriptor_type __err = (iconv_t)(-1); + const bool __have_encodings = _M_int_enc.size() && _M_ext_enc.size(); + if (!_M_in_desc && __have_encodings) + { + _M_in_desc = iconv_open(_M_int_enc.c_str(), _M_ext_enc.c_str()); + if (_M_in_desc == __err) + std::__throw_runtime_error(__N("encoding_state::_M_init " + "creating iconv input descriptor failed")); + } + if (!_M_out_desc && __have_encodings) + { + _M_out_desc = iconv_open(_M_ext_enc.c_str(), _M_int_enc.c_str()); + if (_M_out_desc == __err) + std::__throw_runtime_error(__N("encoding_state::_M_init " + "creating iconv output descriptor failed")); + } + } + + void + construct(const encoding_state& __obj) + { + destroy(); + _M_int_enc = __obj._M_int_enc; + _M_ext_enc = __obj._M_ext_enc; + _M_ext_bom = __obj._M_ext_bom; + _M_int_bom = __obj._M_int_bom; + _M_bytes = __obj._M_bytes; + init(); + } + + void + destroy() throw() + { + const descriptor_type __err = (iconv_t)(-1); + if (_M_in_desc && _M_in_desc != __err) + { + iconv_close(_M_in_desc); + _M_in_desc = 0; + } + if (_M_out_desc && _M_out_desc != __err) + { + iconv_close(_M_out_desc); + _M_out_desc = 0; + } + } + }; + + /// encoding_char_traits + // Custom traits type with encoding_state for the state type, and the + // associated fpos<encoding_state> for the position type, all other + // bits equivalent to the required char_traits instantiations. + template<typename _CharT> + struct encoding_char_traits : public std::char_traits<_CharT> + { + typedef encoding_state state_type; + typedef typename std::fpos<state_type> pos_type; + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using __gnu_cxx::encoding_state; + + /// codecvt<InternT, _ExternT, encoding_state> specialization. + // This partial specialization takes advantage of iconv to provide + // code conversions between a large number of character encodings. + template<typename _InternT, typename _ExternT> + class codecvt<_InternT, _ExternT, encoding_state> + : public __codecvt_abstract_base<_InternT, _ExternT, encoding_state> + { + public: + // Types: + typedef codecvt_base::result result; + typedef _InternT intern_type; + typedef _ExternT extern_type; + typedef __gnu_cxx::encoding_state state_type; + typedef state_type::descriptor_type descriptor_type; + + // Data Members: + static locale::id id; + + explicit + codecvt(size_t __refs = 0) + : __codecvt_abstract_base<intern_type, extern_type, state_type>(__refs) + { } + + explicit + codecvt(state_type& __enc, size_t __refs = 0) + : __codecvt_abstract_base<intern_type, extern_type, state_type>(__refs) + { } + + protected: + virtual + ~codecvt() { } + + virtual result + do_out(state_type& __state, const intern_type* __from, + const intern_type* __from_end, const intern_type*& __from_next, + extern_type* __to, extern_type* __to_end, + extern_type*& __to_next) const; + + virtual result + do_unshift(state_type& __state, extern_type* __to, + extern_type* __to_end, extern_type*& __to_next) const; + + virtual result + do_in(state_type& __state, const extern_type* __from, + const extern_type* __from_end, const extern_type*& __from_next, + intern_type* __to, intern_type* __to_end, + intern_type*& __to_next) const; + + virtual int + do_encoding() const throw(); + + virtual bool + do_always_noconv() const throw(); + + virtual int + do_length(state_type&, const extern_type* __from, + const extern_type* __end, size_t __max) const; + + virtual int + do_max_length() const throw(); + }; + + template<typename _InternT, typename _ExternT> + locale::id + codecvt<_InternT, _ExternT, encoding_state>::id; + + // This adaptor works around the signature problems of the second + // argument to iconv(): SUSv2 and others use 'const char**', but glibc 2.2 + // uses 'char**', which matches the POSIX 1003.1-2001 standard. + // Using this adaptor, g++ will do the work for us. + template<typename _Tp> + inline size_t + __iconv_adaptor(size_t(*__func)(iconv_t, _Tp, size_t*, char**, size_t*), + iconv_t __cd, char** __inbuf, size_t* __inbytes, + char** __outbuf, size_t* __outbytes) + { return __func(__cd, (_Tp)__inbuf, __inbytes, __outbuf, __outbytes); } + + template<typename _InternT, typename _ExternT> + codecvt_base::result + codecvt<_InternT, _ExternT, encoding_state>:: + do_out(state_type& __state, const intern_type* __from, + const intern_type* __from_end, const intern_type*& __from_next, + extern_type* __to, extern_type* __to_end, + extern_type*& __to_next) const + { + result __ret = codecvt_base::error; + if (__state.good()) + { + const descriptor_type& __desc = __state.out_descriptor(); + const size_t __fmultiple = sizeof(intern_type); + size_t __fbytes = __fmultiple * (__from_end - __from); + const size_t __tmultiple = sizeof(extern_type); + size_t __tbytes = __tmultiple * (__to_end - __to); + + // Argument list for iconv specifies a byte sequence. Thus, + // all to/from arrays must be brutally casted to char*. + char* __cto = reinterpret_cast<char*>(__to); + char* __cfrom; + size_t __conv; + + // Some encodings need a byte order marker as the first item + // in the byte stream, to designate endian-ness. The default + // value for the byte order marker is NULL, so if this is + // the case, it's not necessary and we can just go on our + // merry way. + int __int_bom = __state.internal_bom(); + if (__int_bom) + { + size_t __size = __from_end - __from; + intern_type* __cfixed = static_cast<intern_type*> + (__builtin_alloca(sizeof(intern_type) * (__size + 1))); + __cfixed[0] = static_cast<intern_type>(__int_bom); + char_traits<intern_type>::copy(__cfixed + 1, __from, __size); + __cfrom = reinterpret_cast<char*>(__cfixed); + __conv = __iconv_adaptor(iconv, __desc, &__cfrom, + &__fbytes, &__cto, &__tbytes); + } + else + { + intern_type* __cfixed = const_cast<intern_type*>(__from); + __cfrom = reinterpret_cast<char*>(__cfixed); + __conv = __iconv_adaptor(iconv, __desc, &__cfrom, &__fbytes, + &__cto, &__tbytes); + } + + if (__conv != size_t(-1)) + { + __from_next = reinterpret_cast<const intern_type*>(__cfrom); + __to_next = reinterpret_cast<extern_type*>(__cto); + __ret = codecvt_base::ok; + } + else + { + if (__fbytes < __fmultiple * (__from_end - __from)) + { + __from_next = reinterpret_cast<const intern_type*>(__cfrom); + __to_next = reinterpret_cast<extern_type*>(__cto); + __ret = codecvt_base::partial; + } + else + __ret = codecvt_base::error; + } + } + return __ret; + } + + template<typename _InternT, typename _ExternT> + codecvt_base::result + codecvt<_InternT, _ExternT, encoding_state>:: + do_unshift(state_type& __state, extern_type* __to, + extern_type* __to_end, extern_type*& __to_next) const + { + result __ret = codecvt_base::error; + if (__state.good()) + { + const descriptor_type& __desc = __state.in_descriptor(); + const size_t __tmultiple = sizeof(intern_type); + size_t __tlen = __tmultiple * (__to_end - __to); + + // Argument list for iconv specifies a byte sequence. Thus, + // all to/from arrays must be brutally casted to char*. + char* __cto = reinterpret_cast<char*>(__to); + size_t __conv = __iconv_adaptor(iconv,__desc, 0, 0, + &__cto, &__tlen); + + if (__conv != size_t(-1)) + { + __to_next = reinterpret_cast<extern_type*>(__cto); + if (__tlen == __tmultiple * (__to_end - __to)) + __ret = codecvt_base::noconv; + else if (__tlen == 0) + __ret = codecvt_base::ok; + else + __ret = codecvt_base::partial; + } + else + __ret = codecvt_base::error; + } + return __ret; + } + + template<typename _InternT, typename _ExternT> + codecvt_base::result + codecvt<_InternT, _ExternT, encoding_state>:: + do_in(state_type& __state, const extern_type* __from, + const extern_type* __from_end, const extern_type*& __from_next, + intern_type* __to, intern_type* __to_end, + intern_type*& __to_next) const + { + result __ret = codecvt_base::error; + if (__state.good()) + { + const descriptor_type& __desc = __state.in_descriptor(); + const size_t __fmultiple = sizeof(extern_type); + size_t __flen = __fmultiple * (__from_end - __from); + const size_t __tmultiple = sizeof(intern_type); + size_t __tlen = __tmultiple * (__to_end - __to); + + // Argument list for iconv specifies a byte sequence. Thus, + // all to/from arrays must be brutally casted to char*. + char* __cto = reinterpret_cast<char*>(__to); + char* __cfrom; + size_t __conv; + + // Some encodings need a byte order marker as the first item + // in the byte stream, to designate endian-ness. The default + // value for the byte order marker is NULL, so if this is + // the case, it's not necessary and we can just go on our + // merry way. + int __ext_bom = __state.external_bom(); + if (__ext_bom) + { + size_t __size = __from_end - __from; + extern_type* __cfixed = static_cast<extern_type*> + (__builtin_alloca(sizeof(extern_type) * (__size + 1))); + __cfixed[0] = static_cast<extern_type>(__ext_bom); + char_traits<extern_type>::copy(__cfixed + 1, __from, __size); + __cfrom = reinterpret_cast<char*>(__cfixed); + __conv = __iconv_adaptor(iconv, __desc, &__cfrom, + &__flen, &__cto, &__tlen); + } + else + { + extern_type* __cfixed = const_cast<extern_type*>(__from); + __cfrom = reinterpret_cast<char*>(__cfixed); + __conv = __iconv_adaptor(iconv, __desc, &__cfrom, + &__flen, &__cto, &__tlen); + } + + + if (__conv != size_t(-1)) + { + __from_next = reinterpret_cast<const extern_type*>(__cfrom); + __to_next = reinterpret_cast<intern_type*>(__cto); + __ret = codecvt_base::ok; + } + else + { + if (__flen < static_cast<size_t>(__from_end - __from)) + { + __from_next = reinterpret_cast<const extern_type*>(__cfrom); + __to_next = reinterpret_cast<intern_type*>(__cto); + __ret = codecvt_base::partial; + } + else + __ret = codecvt_base::error; + } + } + return __ret; + } + + template<typename _InternT, typename _ExternT> + int + codecvt<_InternT, _ExternT, encoding_state>:: + do_encoding() const throw() + { + int __ret = 0; + if (sizeof(_ExternT) <= sizeof(_InternT)) + __ret = sizeof(_InternT) / sizeof(_ExternT); + return __ret; + } + + template<typename _InternT, typename _ExternT> + bool + codecvt<_InternT, _ExternT, encoding_state>:: + do_always_noconv() const throw() + { return false; } + + template<typename _InternT, typename _ExternT> + int + codecvt<_InternT, _ExternT, encoding_state>:: + do_length(state_type&, const extern_type* __from, + const extern_type* __end, size_t __max) const + { return std::min(__max, static_cast<size_t>(__end - __from)); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 74. Garbled text for codecvt::do_max_length + template<typename _InternT, typename _ExternT> + int + codecvt<_InternT, _ExternT, encoding_state>:: + do_max_length() const throw() + { return 1; } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/concurrence.h b/gcc-4.9/libstdc++-v3/include/ext/concurrence.h new file mode 100644 index 0000000..1d39661 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/concurrence.h @@ -0,0 +1,318 @@ +// Support for concurrent programing -*- C++ -*- + +// Copyright (C) 2003-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/concurrence.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _CONCURRENCE_H +#define _CONCURRENCE_H 1 + +#pragma GCC system_header + +#include <exception> +#include <bits/gthr.h> +#include <bits/functexcept.h> +#include <bits/cpp_type_traits.h> +#include <ext/type_traits.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // Available locking policies: + // _S_single single-threaded code that doesn't need to be locked. + // _S_mutex multi-threaded code that requires additional support + // from gthr.h or abstraction layers in concurrence.h. + // _S_atomic multi-threaded code using atomic operations. + enum _Lock_policy { _S_single, _S_mutex, _S_atomic }; + + // Compile time constant that indicates prefered locking policy in + // the current configuration. + static const _Lock_policy __default_lock_policy = +#ifdef __GTHREADS +#if (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) \ + && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)) + _S_atomic; +#else + _S_mutex; +#endif +#else + _S_single; +#endif + + // NB: As this is used in libsupc++, need to only depend on + // exception. No stdexception classes, no use of std::string. + class __concurrence_lock_error : public std::exception + { + public: + virtual char const* + what() const throw() + { return "__gnu_cxx::__concurrence_lock_error"; } + }; + + class __concurrence_unlock_error : public std::exception + { + public: + virtual char const* + what() const throw() + { return "__gnu_cxx::__concurrence_unlock_error"; } + }; + + class __concurrence_broadcast_error : public std::exception + { + public: + virtual char const* + what() const throw() + { return "__gnu_cxx::__concurrence_broadcast_error"; } + }; + + class __concurrence_wait_error : public std::exception + { + public: + virtual char const* + what() const throw() + { return "__gnu_cxx::__concurrence_wait_error"; } + }; + + // Substitute for concurrence_error object in the case of -fno-exceptions. + inline void + __throw_concurrence_lock_error() + { _GLIBCXX_THROW_OR_ABORT(__concurrence_lock_error()); } + + inline void + __throw_concurrence_unlock_error() + { _GLIBCXX_THROW_OR_ABORT(__concurrence_unlock_error()); } + +#ifdef __GTHREAD_HAS_COND + inline void + __throw_concurrence_broadcast_error() + { _GLIBCXX_THROW_OR_ABORT(__concurrence_broadcast_error()); } + + inline void + __throw_concurrence_wait_error() + { _GLIBCXX_THROW_OR_ABORT(__concurrence_wait_error()); } +#endif + + class __mutex + { + private: +#if __GTHREADS && defined __GTHREAD_MUTEX_INIT + __gthread_mutex_t _M_mutex = __GTHREAD_MUTEX_INIT; +#else + __gthread_mutex_t _M_mutex; +#endif + + __mutex(const __mutex&); + __mutex& operator=(const __mutex&); + + public: + __mutex() + { +#if __GTHREADS && ! defined __GTHREAD_MUTEX_INIT + if (__gthread_active_p()) + __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex); +#endif + } + +#if __GTHREADS && ! defined __GTHREAD_MUTEX_INIT + ~__mutex() + { + if (__gthread_active_p()) + __gthread_mutex_destroy(&_M_mutex); + } +#endif + + void lock() + { +#if __GTHREADS + if (__gthread_active_p()) + { + if (__gthread_mutex_lock(&_M_mutex) != 0) + __throw_concurrence_lock_error(); + } +#endif + } + + void unlock() + { +#if __GTHREADS + if (__gthread_active_p()) + { + if (__gthread_mutex_unlock(&_M_mutex) != 0) + __throw_concurrence_unlock_error(); + } +#endif + } + + __gthread_mutex_t* gthread_mutex(void) + { return &_M_mutex; } + }; + + class __recursive_mutex + { + private: +#if __GTHREADS && defined __GTHREAD_RECURSIVE_MUTEX_INIT + __gthread_recursive_mutex_t _M_mutex = __GTHREAD_RECURSIVE_MUTEX_INIT; +#else + __gthread_recursive_mutex_t _M_mutex; +#endif + + __recursive_mutex(const __recursive_mutex&); + __recursive_mutex& operator=(const __recursive_mutex&); + + public: + __recursive_mutex() + { +#if __GTHREADS && ! defined __GTHREAD_RECURSIVE_MUTEX_INIT + if (__gthread_active_p()) + __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION(&_M_mutex); +#endif + } + +#if __GTHREADS && ! defined __GTHREAD_RECURSIVE_MUTEX_INIT + ~__recursive_mutex() + { + if (__gthread_active_p()) + __gthread_recursive_mutex_destroy(&_M_mutex); + } +#endif + + void lock() + { +#if __GTHREADS + if (__gthread_active_p()) + { + if (__gthread_recursive_mutex_lock(&_M_mutex) != 0) + __throw_concurrence_lock_error(); + } +#endif + } + + void unlock() + { +#if __GTHREADS + if (__gthread_active_p()) + { + if (__gthread_recursive_mutex_unlock(&_M_mutex) != 0) + __throw_concurrence_unlock_error(); + } +#endif + } + + __gthread_recursive_mutex_t* gthread_recursive_mutex(void) + { return &_M_mutex; } + }; + + /// Scoped lock idiom. + // Acquire the mutex here with a constructor call, then release with + // the destructor call in accordance with RAII style. + class __scoped_lock + { + public: + typedef __mutex __mutex_type; + + private: + __mutex_type& _M_device; + + __scoped_lock(const __scoped_lock&); + __scoped_lock& operator=(const __scoped_lock&); + + public: + explicit __scoped_lock(__mutex_type& __name) : _M_device(__name) + { _M_device.lock(); } + + ~__scoped_lock() throw() + { _M_device.unlock(); } + }; + +#ifdef __GTHREAD_HAS_COND + class __cond + { + private: +#if __GTHREADS && defined __GTHREAD_COND_INIT + __gthread_cond_t _M_cond = __GTHREAD_COND_INIT; +#else + __gthread_cond_t _M_cond; +#endif + + __cond(const __cond&); + __cond& operator=(const __cond&); + + public: + __cond() + { +#if __GTHREADS && ! defined __GTHREAD_COND_INIT + if (__gthread_active_p()) + __GTHREAD_COND_INIT_FUNCTION(&_M_cond); +#endif + } + +#if __GTHREADS && ! defined __GTHREAD_COND_INIT + ~__cond() + { + if (__gthread_active_p()) + __gthread_cond_destroy(&_M_cond); + } +#endif + + void broadcast() + { +#if __GTHREADS + if (__gthread_active_p()) + { + if (__gthread_cond_broadcast(&_M_cond) != 0) + __throw_concurrence_broadcast_error(); + } +#endif + } + + void wait(__mutex *mutex) + { +#if __GTHREADS + { + if (__gthread_cond_wait(&_M_cond, mutex->gthread_mutex()) != 0) + __throw_concurrence_wait_error(); + } +#endif + } + + void wait_recursive(__recursive_mutex *mutex) + { +#if __GTHREADS + { + if (__gthread_cond_wait_recursive(&_M_cond, + mutex->gthread_recursive_mutex()) + != 0) + __throw_concurrence_wait_error(); + } +#endif + } + }; +#endif + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/debug_allocator.h b/gcc-4.9/libstdc++-v3/include/ext/debug_allocator.h new file mode 100644 index 0000000..ffdfee6 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/debug_allocator.h @@ -0,0 +1,191 @@ +// Allocators -*- C++ -*- + +// Copyright (C) 2001-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * Copyright (c) 1996-1997 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/** @file ext/debug_allocator.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _DEBUG_ALLOCATOR_H +#define _DEBUG_ALLOCATOR_H 1 + +#include <stdexcept> +#include <bits/functexcept.h> +#include <ext/alloc_traits.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::size_t; + + /** + * @brief A meta-allocator with debugging bits. + * @ingroup allocators + * + * This is precisely the allocator defined in the C++03 Standard. + */ + template<typename _Alloc> + class debug_allocator + { + template<typename> friend class debug_allocator; + + typedef __alloc_traits<_Alloc> _Traits; + + public: + typedef typename _Traits::size_type size_type; + typedef typename _Traits::difference_type difference_type; + typedef typename _Traits::pointer pointer; + typedef typename _Traits::const_pointer const_pointer; + typedef typename _Traits::reference reference; + typedef typename _Traits::const_reference const_reference; + typedef typename _Traits::value_type value_type; + + template<typename _Up> + class rebind + { + typedef typename _Traits::template rebind<_Up>::other __other; + + public: + typedef debug_allocator<__other> other; + }; + + private: + // _M_extra is the number of objects that correspond to the + // extra space where debug information is stored. + size_type _M_extra; + + _Alloc _M_allocator; + + template<typename _Alloc2, + typename = typename _Alloc2::template rebind<value_type>::other> + struct __convertible + { }; + + template<typename _Alloc2> + struct __convertible<_Alloc2, _Alloc> + { + typedef void* __type; + }; + + size_type _S_extra() + { + const size_t __obj_size = sizeof(value_type); + return (sizeof(size_type) + __obj_size - 1) / __obj_size; + } + + public: + debug_allocator() : _M_extra(_S_extra()) { } + + template<typename _Alloc2> + debug_allocator(const debug_allocator<_Alloc2>& __a2, + typename __convertible<_Alloc2>::__type = 0) + : _M_allocator(__a2._M_allocator), _M_extra(_S_extra()) { } + + debug_allocator(const _Alloc& __a) + : _M_allocator(__a), _M_extra(_S_extra()) { } + + pointer + allocate(size_type __n) + { + pointer __res = _M_allocator.allocate(__n + _M_extra); + size_type* __ps = reinterpret_cast<size_type*>(__res); + *__ps = __n; + return __res + _M_extra; + } + + pointer + allocate(size_type __n, const void* __hint) + { + pointer __res = _M_allocator.allocate(__n + _M_extra, __hint); + size_type* __ps = reinterpret_cast<size_type*>(__res); + *__ps = __n; + return __res + _M_extra; + } + + void + deallocate(pointer __p, size_type __n) + { + using std::__throw_runtime_error; + if (__p) + { + pointer __real_p = __p - _M_extra; + if (*reinterpret_cast<size_type*>(__real_p) != __n) + __throw_runtime_error("debug_allocator::deallocate wrong size"); + _M_allocator.deallocate(__real_p, __n + _M_extra); + } + else + __throw_runtime_error("debug_allocator::deallocate null pointer"); + } + + void + construct(pointer __p, const value_type& __val) + { _Traits::construct(_M_allocator, __p, __val); } + +#if __cplusplus >= 201103L + template<typename _Tp, typename... _Args> + void + construct(_Tp* __p, _Args&&... __args) + { + _Traits::construct(_M_allocator, __p, + std::forward<_Args>(__args)...); + } +#endif + + template<typename _Tp> + void + destroy(_Tp* __p) + { _Traits::destroy(_M_allocator, __p); } + + size_type + max_size() const throw() + { return _Traits::max_size(_M_allocator) - _M_extra; } + + friend bool + operator==(const debug_allocator& __lhs, const debug_allocator& __rhs) + { return __lhs._M_allocator == __rhs._M_allocator; } + }; + + template<typename _Alloc> + inline bool + operator!=(const debug_allocator<_Alloc>& __lhs, + const debug_allocator<_Alloc>& __rhs) + { return !(__lhs == __rhs); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/enc_filebuf.h b/gcc-4.9/libstdc++-v3/include/ext/enc_filebuf.h new file mode 100644 index 0000000..2a181fc --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/enc_filebuf.h @@ -0,0 +1,65 @@ +// filebuf with encoding state type -*- C++ -*- + +// Copyright (C) 2002-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/enc_filebuf.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _EXT_ENC_FILEBUF_H +#define _EXT_ENC_FILEBUF_H 1 + +#include <fstream> +#include <locale> +#include <ext/codecvt_specializations.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /// class enc_filebuf. + template<typename _CharT> + class enc_filebuf + : public std::basic_filebuf<_CharT, encoding_char_traits<_CharT> > + { + public: + typedef encoding_char_traits<_CharT> traits_type; + typedef typename traits_type::state_type state_type; + typedef typename traits_type::pos_type pos_type; + + enc_filebuf(state_type& __state) + : std::basic_filebuf<_CharT, encoding_char_traits<_CharT> >() + { this->_M_state_beg = __state; } + + private: + // concept requirements: + // Set state type to something useful. + // Something more than copyconstructible is needed here, so + // require default and copy constructible + assignment operator. + __glibcxx_class_requires(state_type, _SGIAssignableConcept) + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/extptr_allocator.h b/gcc-4.9/libstdc++-v3/include/ext/extptr_allocator.h new file mode 100644 index 0000000..1b8bdc7 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/extptr_allocator.h @@ -0,0 +1,197 @@ +// <extptr_allocator.h> -*- C++ -*- + +// Copyright (C) 2008-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** + * @file ext/extptr_allocator.h + * This file is a GNU extension to the Standard C++ Library. + * + * @author Bob Walters + * + * An example allocator which uses an alternative pointer type from + * bits/pointer.h. Supports test cases which confirm container support + * for alternative pointers. + */ + +#ifndef _EXTPTR_ALLOCATOR_H +#define _EXTPTR_ALLOCATOR_H 1 + +#include <memory> +#include <ext/numeric_traits.h> +#include <ext/pointer.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * @brief An example allocator which uses a non-standard pointer type. + * @ingroup allocators + * + * This allocator specifies that containers use a 'relative pointer' as it's + * pointer type. (See ext/pointer.h) Memory allocation in this example + * is still performed using std::allocator. + */ + template<typename _Tp> + class _ExtPtr_allocator + { + public: + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + // Note the non-standard pointer types. + typedef _Pointer_adapter<_Relative_pointer_impl<_Tp> > pointer; + typedef _Pointer_adapter<_Relative_pointer_impl<const _Tp> > + const_pointer; + + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + + template<typename _Up> + struct rebind + { typedef _ExtPtr_allocator<_Up> other; }; + + _ExtPtr_allocator() _GLIBCXX_USE_NOEXCEPT + : _M_real_alloc() { } + + _ExtPtr_allocator(const _ExtPtr_allocator& __rarg) _GLIBCXX_USE_NOEXCEPT + : _M_real_alloc(__rarg._M_real_alloc) { } + + template<typename _Up> + _ExtPtr_allocator(const _ExtPtr_allocator<_Up>& __rarg) + _GLIBCXX_USE_NOEXCEPT + : _M_real_alloc(__rarg._M_getUnderlyingImp()) { } + + ~_ExtPtr_allocator() _GLIBCXX_USE_NOEXCEPT + { } + + pointer address(reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + const_pointer address(const_reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + pointer allocate(size_type __n, void* __hint = 0) + { return _M_real_alloc.allocate(__n,__hint); } + + void deallocate(pointer __p, size_type __n) + { _M_real_alloc.deallocate(__p.get(), __n); } + + size_type max_size() const _GLIBCXX_USE_NOEXCEPT + { return __numeric_traits<size_type>::__max / sizeof(_Tp); } + +#if __cplusplus >= 201103L + template<typename _Up, typename... _Args> + void + construct(_Up* __p, _Args&&... __args) + { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } + + template<typename... _Args> + void + construct(pointer __p, _Args&&... __args) + { construct(__p.get(), std::forward<_Args>(__args)...); } + + template<typename _Up> + void + destroy(_Up* __p) + { __p->~_Up(); } + + void destroy(pointer __p) + { destroy(__p.get()); } + +#else + + void construct(pointer __p, const _Tp& __val) + { ::new(__p.get()) _Tp(__val); } + + void destroy(pointer __p) + { __p->~_Tp(); } +#endif + + template<typename _Up> + inline bool + operator==(const _ExtPtr_allocator<_Up>& __rarg) + { return _M_real_alloc == __rarg._M_getUnderlyingImp(); } + + inline bool + operator==(const _ExtPtr_allocator& __rarg) + { return _M_real_alloc == __rarg._M_real_alloc; } + + template<typename _Up> + inline bool + operator!=(const _ExtPtr_allocator<_Up>& __rarg) + { return _M_real_alloc != __rarg._M_getUnderlyingImp(); } + + inline bool + operator!=(const _ExtPtr_allocator& __rarg) + { return _M_real_alloc != __rarg._M_real_alloc; } + + template<typename _Up> + inline friend void + swap(_ExtPtr_allocator<_Up>&, _ExtPtr_allocator<_Up>&); + + // A method specific to this implementation. + const std::allocator<_Tp>& + _M_getUnderlyingImp() const + { return _M_real_alloc; } + + private: + std::allocator<_Tp> _M_real_alloc; + }; + + // _ExtPtr_allocator<void> specialization. + template<> + class _ExtPtr_allocator<void> + { + public: + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef void value_type; + + // Note the non-standard pointer types + typedef _Pointer_adapter<_Relative_pointer_impl<void> > pointer; + typedef _Pointer_adapter<_Relative_pointer_impl<const void> > + const_pointer; + + template<typename _Up> + struct rebind + { typedef _ExtPtr_allocator<_Up> other; }; + + private: + std::allocator<void> _M_real_alloc; + }; + + template<typename _Tp> + inline void + swap(_ExtPtr_allocator<_Tp>& __larg, _ExtPtr_allocator<_Tp>& __rarg) + { + std::allocator<_Tp> __tmp( __rarg._M_real_alloc ); + __rarg._M_real_alloc = __larg._M_real_alloc; + __larg._M_real_alloc = __tmp; + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif /* _EXTPTR_ALLOCATOR_H */ diff --git a/gcc-4.9/libstdc++-v3/include/ext/functional b/gcc-4.9/libstdc++-v3/include/ext/functional new file mode 100644 index 0000000..ccdc85a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/functional @@ -0,0 +1,430 @@ +// Functional extensions -*- C++ -*- + +// Copyright (C) 2002-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * + * Copyright (c) 1994 + * Hewlett-Packard Company + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Hewlett-Packard Company makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * + * Copyright (c) 1996 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/** @file ext/functional + * This file is a GNU extension to the Standard C++ Library (possibly + * containing extensions from the HP/SGI STL subset). + */ + +#ifndef _EXT_FUNCTIONAL +#define _EXT_FUNCTIONAL 1 + +#pragma GCC system_header + +#include <functional> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::size_t; + using std::unary_function; + using std::binary_function; + using std::mem_fun1_t; + using std::const_mem_fun1_t; + using std::mem_fun1_ref_t; + using std::const_mem_fun1_ref_t; + + /** The @c identity_element functions are not part of the C++ + * standard; SGI provided them as an extension. Its argument is an + * operation, and its return value is the identity element for that + * operation. It is overloaded for addition and multiplication, + * and you can overload it for your own nefarious operations. + * + * @addtogroup SGIextensions + * @{ + */ + /// An \link SGIextensions SGI extension \endlink. + template <class _Tp> + inline _Tp + identity_element(std::plus<_Tp>) + { return _Tp(0); } + + /// An \link SGIextensions SGI extension \endlink. + template <class _Tp> + inline _Tp + identity_element(std::multiplies<_Tp>) + { return _Tp(1); } + /** @} */ + + /** As an extension to the binders, SGI provided composition functors and + * wrapper functions to aid in their creation. The @c unary_compose + * functor is constructed from two functions/functors, @c f and @c g. + * Calling @c operator() with a single argument @c x returns @c f(g(x)). + * The function @c compose1 takes the two functions and constructs a + * @c unary_compose variable for you. + * + * @c binary_compose is constructed from three functors, @c f, @c g1, + * and @c g2. Its @c operator() returns @c f(g1(x),g2(x)). The function + * compose2 takes f, g1, and g2, and constructs the @c binary_compose + * instance for you. For example, if @c f returns an int, then + * \code + * int answer = (compose2(f,g1,g2))(x); + * \endcode + * is equivalent to + * \code + * int temp1 = g1(x); + * int temp2 = g2(x); + * int answer = f(temp1,temp2); + * \endcode + * But the first form is more compact, and can be passed around as a + * functor to other algorithms. + * + * @addtogroup SGIextensions + * @{ + */ + /// An \link SGIextensions SGI extension \endlink. + template <class _Operation1, class _Operation2> + class unary_compose + : public unary_function<typename _Operation2::argument_type, + typename _Operation1::result_type> + { + protected: + _Operation1 _M_fn1; + _Operation2 _M_fn2; + + public: + unary_compose(const _Operation1& __x, const _Operation2& __y) + : _M_fn1(__x), _M_fn2(__y) {} + + typename _Operation1::result_type + operator()(const typename _Operation2::argument_type& __x) const + { return _M_fn1(_M_fn2(__x)); } + }; + + /// An \link SGIextensions SGI extension \endlink. + template <class _Operation1, class _Operation2> + inline unary_compose<_Operation1, _Operation2> + compose1(const _Operation1& __fn1, const _Operation2& __fn2) + { return unary_compose<_Operation1,_Operation2>(__fn1, __fn2); } + + /// An \link SGIextensions SGI extension \endlink. + template <class _Operation1, class _Operation2, class _Operation3> + class binary_compose + : public unary_function<typename _Operation2::argument_type, + typename _Operation1::result_type> + { + protected: + _Operation1 _M_fn1; + _Operation2 _M_fn2; + _Operation3 _M_fn3; + + public: + binary_compose(const _Operation1& __x, const _Operation2& __y, + const _Operation3& __z) + : _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { } + + typename _Operation1::result_type + operator()(const typename _Operation2::argument_type& __x) const + { return _M_fn1(_M_fn2(__x), _M_fn3(__x)); } + }; + + /// An \link SGIextensions SGI extension \endlink. + template <class _Operation1, class _Operation2, class _Operation3> + inline binary_compose<_Operation1, _Operation2, _Operation3> + compose2(const _Operation1& __fn1, const _Operation2& __fn2, + const _Operation3& __fn3) + { return binary_compose<_Operation1, _Operation2, _Operation3> + (__fn1, __fn2, __fn3); } + /** @} */ + + /** As an extension, SGI provided a functor called @c identity. When a + * functor is required but no operations are desired, this can be used as a + * pass-through. Its @c operator() returns its argument unchanged. + * + * @addtogroup SGIextensions + */ + template <class _Tp> + struct identity + : public std::_Identity<_Tp> {}; + + /** @c select1st and @c select2nd are extensions provided by SGI. Their + * @c operator()s + * take a @c std::pair as an argument, and return either the first member + * or the second member, respectively. They can be used (especially with + * the composition functors) to @a strip data from a sequence before + * performing the remainder of an algorithm. + * + * @addtogroup SGIextensions + * @{ + */ + /// An \link SGIextensions SGI extension \endlink. + template <class _Pair> + struct select1st + : public std::_Select1st<_Pair> {}; + + /// An \link SGIextensions SGI extension \endlink. + template <class _Pair> + struct select2nd + : public std::_Select2nd<_Pair> {}; + + /** @} */ + + // extension documented next + template <class _Arg1, class _Arg2> + struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> + { + _Arg1 + operator()(const _Arg1& __x, const _Arg2&) const + { return __x; } + }; + + template <class _Arg1, class _Arg2> + struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> + { + _Arg2 + operator()(const _Arg1&, const _Arg2& __y) const + { return __y; } + }; + + /** The @c operator() of the @c project1st functor takes two arbitrary + * arguments and returns the first one, while @c project2nd returns the + * second one. They are extensions provided by SGI. + * + * @addtogroup SGIextensions + * @{ + */ + + /// An \link SGIextensions SGI extension \endlink. + template <class _Arg1, class _Arg2> + struct project1st : public _Project1st<_Arg1, _Arg2> {}; + + /// An \link SGIextensions SGI extension \endlink. + template <class _Arg1, class _Arg2> + struct project2nd : public _Project2nd<_Arg1, _Arg2> {}; + /** @} */ + + // extension documented next + template <class _Result> + struct _Constant_void_fun + { + typedef _Result result_type; + result_type _M_val; + + _Constant_void_fun(const result_type& __v) : _M_val(__v) {} + + const result_type& + operator()() const + { return _M_val; } + }; + + template <class _Result, class _Argument> + struct _Constant_unary_fun + { + typedef _Argument argument_type; + typedef _Result result_type; + result_type _M_val; + + _Constant_unary_fun(const result_type& __v) : _M_val(__v) {} + + const result_type& + operator()(const _Argument&) const + { return _M_val; } + }; + + template <class _Result, class _Arg1, class _Arg2> + struct _Constant_binary_fun + { + typedef _Arg1 first_argument_type; + typedef _Arg2 second_argument_type; + typedef _Result result_type; + _Result _M_val; + + _Constant_binary_fun(const _Result& __v) : _M_val(__v) {} + + const result_type& + operator()(const _Arg1&, const _Arg2&) const + { return _M_val; } + }; + + /** These three functors are each constructed from a single arbitrary + * variable/value. Later, their @c operator()s completely ignore any + * arguments passed, and return the stored value. + * - @c constant_void_fun's @c operator() takes no arguments + * - @c constant_unary_fun's @c operator() takes one argument (ignored) + * - @c constant_binary_fun's @c operator() takes two arguments (ignored) + * + * The helper creator functions @c constant0, @c constant1, and + * @c constant2 each take a @a result argument and construct variables of + * the appropriate functor type. + * + * @addtogroup SGIextensions + * @{ + */ + /// An \link SGIextensions SGI extension \endlink. + template <class _Result> + struct constant_void_fun + : public _Constant_void_fun<_Result> + { + constant_void_fun(const _Result& __v) + : _Constant_void_fun<_Result>(__v) {} + }; + + /// An \link SGIextensions SGI extension \endlink. + template <class _Result, class _Argument = _Result> + struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument> + { + constant_unary_fun(const _Result& __v) + : _Constant_unary_fun<_Result, _Argument>(__v) {} + }; + + /// An \link SGIextensions SGI extension \endlink. + template <class _Result, class _Arg1 = _Result, class _Arg2 = _Arg1> + struct constant_binary_fun + : public _Constant_binary_fun<_Result, _Arg1, _Arg2> + { + constant_binary_fun(const _Result& __v) + : _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {} + }; + + /// An \link SGIextensions SGI extension \endlink. + template <class _Result> + inline constant_void_fun<_Result> + constant0(const _Result& __val) + { return constant_void_fun<_Result>(__val); } + + /// An \link SGIextensions SGI extension \endlink. + template <class _Result> + inline constant_unary_fun<_Result, _Result> + constant1(const _Result& __val) + { return constant_unary_fun<_Result, _Result>(__val); } + + /// An \link SGIextensions SGI extension \endlink. + template <class _Result> + inline constant_binary_fun<_Result,_Result,_Result> + constant2(const _Result& __val) + { return constant_binary_fun<_Result, _Result, _Result>(__val); } + /** @} */ + + /** The @c subtractive_rng class is documented on + * <a href="http://www.sgi.com/tech/stl/">SGI's site</a>. + * Note that this code assumes that @c int is 32 bits. + * + * @ingroup SGIextensions + */ + class subtractive_rng + : public unary_function<unsigned int, unsigned int> + { + private: + unsigned int _M_table[55]; + size_t _M_index1; + size_t _M_index2; + + public: + /// Returns a number less than the argument. + unsigned int + operator()(unsigned int __limit) + { + _M_index1 = (_M_index1 + 1) % 55; + _M_index2 = (_M_index2 + 1) % 55; + _M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2]; + return _M_table[_M_index1] % __limit; + } + + void + _M_initialize(unsigned int __seed) + { + unsigned int __k = 1; + _M_table[54] = __seed; + size_t __i; + for (__i = 0; __i < 54; __i++) + { + size_t __ii = (21 * (__i + 1) % 55) - 1; + _M_table[__ii] = __k; + __k = __seed - __k; + __seed = _M_table[__ii]; + } + for (int __loop = 0; __loop < 4; __loop++) + { + for (__i = 0; __i < 55; __i++) + _M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55]; + } + _M_index1 = 0; + _M_index2 = 31; + } + + /// Ctor allowing you to initialize the seed. + subtractive_rng(unsigned int __seed) + { _M_initialize(__seed); } + + /// Default ctor; initializes its state with some number you don't see. + subtractive_rng() + { _M_initialize(161803398u); } + }; + + // Mem_fun adaptor helper functions mem_fun1 and mem_fun1_ref, + // provided for backward compatibility, they are no longer part of + // the C++ standard. + + template <class _Ret, class _Tp, class _Arg> + inline mem_fun1_t<_Ret, _Tp, _Arg> + mem_fun1(_Ret (_Tp::*__f)(_Arg)) + { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); } + + template <class _Ret, class _Tp, class _Arg> + inline const_mem_fun1_t<_Ret, _Tp, _Arg> + mem_fun1(_Ret (_Tp::*__f)(_Arg) const) + { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); } + + template <class _Ret, class _Tp, class _Arg> + inline mem_fun1_ref_t<_Ret, _Tp, _Arg> + mem_fun1_ref(_Ret (_Tp::*__f)(_Arg)) + { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); } + + template <class _Ret, class _Tp, class _Arg> + inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg> + mem_fun1_ref(_Ret (_Tp::*__f)(_Arg) const) + { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif + diff --git a/gcc-4.9/libstdc++-v3/include/ext/iterator b/gcc-4.9/libstdc++-v3/include/ext/iterator new file mode 100644 index 0000000..c751e49 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/iterator @@ -0,0 +1,116 @@ +// HP/SGI iterator extensions -*- C++ -*- + +// Copyright (C) 2001-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * + * Copyright (c) 1994 + * Hewlett-Packard Company + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Hewlett-Packard Company makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * + * Copyright (c) 1996-1998 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/** @file ext/iterator + * This file is a GNU extension to the Standard C++ Library (possibly + * containing extensions from the HP/SGI STL subset). + */ + +#ifndef _EXT_ITERATOR +#define _EXT_ITERATOR 1 + +#pragma GCC system_header + +#include <bits/concept_check.h> +#include <iterator> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // There are two signatures for distance. In addition to the one + // taking two iterators and returning a result, there is another + // taking two iterators and a reference-to-result variable, and + // returning nothing. The latter seems to be an SGI extension. + // -- pedwards + template<typename _InputIterator, typename _Distance> + inline void + __distance(_InputIterator __first, _InputIterator __last, + _Distance& __n, std::input_iterator_tag) + { + // concept requirements + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) + while (__first != __last) + { + ++__first; + ++__n; + } + } + + template<typename _RandomAccessIterator, typename _Distance> + inline void + __distance(_RandomAccessIterator __first, _RandomAccessIterator __last, + _Distance& __n, std::random_access_iterator_tag) + { + // concept requirements + __glibcxx_function_requires(_RandomAccessIteratorConcept< + _RandomAccessIterator>) + __n += __last - __first; + } + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template<typename _InputIterator, typename _Distance> + inline void + distance(_InputIterator __first, _InputIterator __last, + _Distance& __n) + { + // concept requirements -- taken care of in __distance + __distance(__first, __last, __n, std::__iterator_category(__first)); + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif + diff --git a/gcc-4.9/libstdc++-v3/include/ext/malloc_allocator.h b/gcc-4.9/libstdc++-v3/include/ext/malloc_allocator.h new file mode 100644 index 0000000..83b65f1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/malloc_allocator.h @@ -0,0 +1,152 @@ +// Allocator that wraps "C" malloc -*- C++ -*- + +// Copyright (C) 2001-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/malloc_allocator.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _MALLOC_ALLOCATOR_H +#define _MALLOC_ALLOCATOR_H 1 + +#include <cstdlib> +#include <new> +#include <bits/functexcept.h> +#include <bits/move.h> +#if __cplusplus >= 201103L +#include <type_traits> +#endif + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::size_t; + using std::ptrdiff_t; + + /** + * @brief An allocator that uses malloc. + * @ingroup allocators + * + * This is precisely the allocator defined in the C++ Standard. + * - all allocation calls malloc + * - all deallocation calls free + */ + template<typename _Tp> + class malloc_allocator + { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + + template<typename _Tp1> + struct rebind + { typedef malloc_allocator<_Tp1> other; }; + +#if __cplusplus >= 201103L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2103. propagate_on_container_move_assignment + typedef std::true_type propagate_on_container_move_assignment; +#endif + + malloc_allocator() _GLIBCXX_USE_NOEXCEPT { } + + malloc_allocator(const malloc_allocator&) _GLIBCXX_USE_NOEXCEPT { } + + template<typename _Tp1> + malloc_allocator(const malloc_allocator<_Tp1>&) + _GLIBCXX_USE_NOEXCEPT { } + + ~malloc_allocator() _GLIBCXX_USE_NOEXCEPT { } + + pointer + address(reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + const_pointer + address(const_reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + // NB: __n is permitted to be 0. The C++ standard says nothing + // about what the return value is when __n == 0. + pointer + allocate(size_type __n, const void* = 0) + { + if (__n > this->max_size()) + std::__throw_bad_alloc(); + + pointer __ret = static_cast<_Tp*>(std::malloc(__n * sizeof(_Tp))); + if (!__ret) + std::__throw_bad_alloc(); + return __ret; + } + + // __p is not permitted to be a null pointer. + void + deallocate(pointer __p, size_type) + { std::free(static_cast<void*>(__p)); } + + size_type + max_size() const _GLIBCXX_USE_NOEXCEPT + { return size_t(-1) / sizeof(_Tp); } + +#if __cplusplus >= 201103L + template<typename _Up, typename... _Args> + void + construct(_Up* __p, _Args&&... __args) + { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } + + template<typename _Up> + void + destroy(_Up* __p) { __p->~_Up(); } +#else + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 402. wrong new expression in [some_] allocator::construct + void + construct(pointer __p, const _Tp& __val) + { ::new((void *)__p) value_type(__val); } + + void + destroy(pointer __p) { __p->~_Tp(); } +#endif + }; + + template<typename _Tp> + inline bool + operator==(const malloc_allocator<_Tp>&, const malloc_allocator<_Tp>&) + { return true; } + + template<typename _Tp> + inline bool + operator!=(const malloc_allocator<_Tp>&, const malloc_allocator<_Tp>&) + { return false; } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/memory b/gcc-4.9/libstdc++-v3/include/ext/memory new file mode 100644 index 0000000..d36a5b4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/memory @@ -0,0 +1,197 @@ +// Memory extensions -*- C++ -*- + +// Copyright (C) 2002-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * + * Copyright (c) 1994 + * Hewlett-Packard Company + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Hewlett-Packard Company makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * + * Copyright (c) 1996 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/** @file ext/memory + * This file is a GNU extension to the Standard C++ Library (possibly + * containing extensions from the HP/SGI STL subset). + */ + +#ifndef _EXT_MEMORY +#define _EXT_MEMORY 1 + +#pragma GCC system_header + +#include <memory> +#include <bits/stl_tempbuf.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::ptrdiff_t; + using std::pair; + using std::__iterator_category; + using std::_Temporary_buffer; + + template<typename _InputIter, typename _Size, typename _ForwardIter> + pair<_InputIter, _ForwardIter> + __uninitialized_copy_n(_InputIter __first, _Size __count, + _ForwardIter __result, std::input_iterator_tag) + { + _ForwardIter __cur = __result; + __try + { + for (; __count > 0 ; --__count, ++__first, ++__cur) + std::_Construct(&*__cur, *__first); + return pair<_InputIter, _ForwardIter>(__first, __cur); + } + __catch(...) + { + std::_Destroy(__result, __cur); + __throw_exception_again; + } + } + + template<typename _RandomAccessIter, typename _Size, typename _ForwardIter> + inline pair<_RandomAccessIter, _ForwardIter> + __uninitialized_copy_n(_RandomAccessIter __first, _Size __count, + _ForwardIter __result, + std::random_access_iterator_tag) + { + _RandomAccessIter __last = __first + __count; + return (pair<_RandomAccessIter, _ForwardIter> + (__last, std::uninitialized_copy(__first, __last, __result))); + } + + template<typename _InputIter, typename _Size, typename _ForwardIter> + inline pair<_InputIter, _ForwardIter> + __uninitialized_copy_n(_InputIter __first, _Size __count, + _ForwardIter __result) + { return __gnu_cxx::__uninitialized_copy_n(__first, __count, __result, + __iterator_category(__first)); } + + /** + * @brief Copies the range [first,last) into result. + * @param __first An input iterator. + * @param __count Length + * @param __result An output iterator. + * @return __result + (__first + __count) + * @ingroup SGIextensions + * + * Like copy(), but does not require an initialized output range. + */ + template<typename _InputIter, typename _Size, typename _ForwardIter> + inline pair<_InputIter, _ForwardIter> + uninitialized_copy_n(_InputIter __first, _Size __count, + _ForwardIter __result) + { return __gnu_cxx::__uninitialized_copy_n(__first, __count, __result, + __iterator_category(__first)); } + + + // An alternative version of uninitialized_copy_n that constructs + // and destroys objects with a user-provided allocator. + template<typename _InputIter, typename _Size, typename _ForwardIter, + typename _Allocator> + pair<_InputIter, _ForwardIter> + __uninitialized_copy_n_a(_InputIter __first, _Size __count, + _ForwardIter __result, + _Allocator __alloc) + { + _ForwardIter __cur = __result; + __try + { + for (; __count > 0 ; --__count, ++__first, ++__cur) + __alloc.construct(&*__cur, *__first); + return pair<_InputIter, _ForwardIter>(__first, __cur); + } + __catch(...) + { + std::_Destroy(__result, __cur, __alloc); + __throw_exception_again; + } + } + + template<typename _InputIter, typename _Size, typename _ForwardIter, + typename _Tp> + inline pair<_InputIter, _ForwardIter> + __uninitialized_copy_n_a(_InputIter __first, _Size __count, + _ForwardIter __result, + std::allocator<_Tp>) + { + return __gnu_cxx::uninitialized_copy_n(__first, __count, __result); + } + + /** + * This class provides similar behavior and semantics of the standard + * functions get_temporary_buffer() and return_temporary_buffer(), but + * encapsulated in a type vaguely resembling a standard container. + * + * By default, a temporary_buffer<Iter> stores space for objects of + * whatever type the Iter iterator points to. It is constructed from a + * typical [first,last) range, and provides the begin(), end(), size() + * functions, as well as requested_size(). For non-trivial types, copies + * of *first will be used to initialize the storage. + * + * @c malloc is used to obtain underlying storage. + * + * Like get_temporary_buffer(), not all the requested memory may be + * available. Ideally, the created buffer will be large enough to hold a + * copy of [first,last), but if size() is less than requested_size(), + * then this didn't happen. + * + * @ingroup SGIextensions + */ + template <class _ForwardIterator, class _Tp + = typename std::iterator_traits<_ForwardIterator>::value_type > + struct temporary_buffer : public _Temporary_buffer<_ForwardIterator, _Tp> + { + /// Requests storage large enough to hold a copy of [first,last). + temporary_buffer(_ForwardIterator __first, _ForwardIterator __last) + : _Temporary_buffer<_ForwardIterator, _Tp>(__first, __last) { } + + /// Destroys objects and frees storage. + ~temporary_buffer() { } + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif + diff --git a/gcc-4.9/libstdc++-v3/include/ext/mt_allocator.h b/gcc-4.9/libstdc++-v3/include/ext/mt_allocator.h new file mode 100644 index 0000000..0e6cfd9 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/mt_allocator.h @@ -0,0 +1,766 @@ +// MT-optimized allocator -*- C++ -*- + +// Copyright (C) 2003-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/mt_allocator.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _MT_ALLOCATOR_H +#define _MT_ALLOCATOR_H 1 + +#include <new> +#include <cstdlib> +#include <bits/functexcept.h> +#include <ext/atomicity.h> +#include <bits/move.h> +#if __cplusplus >= 201103L +#include <type_traits> +#endif + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::size_t; + using std::ptrdiff_t; + + typedef void (*__destroy_handler)(void*); + + /// Base class for pool object. + struct __pool_base + { + // Using short int as type for the binmap implies we are never + // caching blocks larger than 32768 with this allocator. + typedef unsigned short int _Binmap_type; + + // Variables used to configure the behavior of the allocator, + // assigned and explained in detail below. + struct _Tune + { + // Compile time constants for the default _Tune values. + enum { _S_align = 8 }; + enum { _S_max_bytes = 128 }; + enum { _S_min_bin = 8 }; + enum { _S_chunk_size = 4096 - 4 * sizeof(void*) }; + enum { _S_max_threads = 4096 }; + enum { _S_freelist_headroom = 10 }; + + // Alignment needed. + // NB: In any case must be >= sizeof(_Block_record), that + // is 4 on 32 bit machines and 8 on 64 bit machines. + size_t _M_align; + + // Allocation requests (after round-up to power of 2) below + // this value will be handled by the allocator. A raw new/ + // call will be used for requests larger than this value. + // NB: Must be much smaller than _M_chunk_size and in any + // case <= 32768. + size_t _M_max_bytes; + + // Size in bytes of the smallest bin. + // NB: Must be a power of 2 and >= _M_align (and of course + // much smaller than _M_max_bytes). + size_t _M_min_bin; + + // In order to avoid fragmenting and minimize the number of + // new() calls we always request new memory using this + // value. Based on previous discussions on the libstdc++ + // mailing list we have chosen the value below. + // See http://gcc.gnu.org/ml/libstdc++/2001-07/msg00077.html + // NB: At least one order of magnitude > _M_max_bytes. + size_t _M_chunk_size; + + // The maximum number of supported threads. For + // single-threaded operation, use one. Maximum values will + // vary depending on details of the underlying system. (For + // instance, Linux 2.4.18 reports 4070 in + // /proc/sys/kernel/threads-max, while Linux 2.6.6 reports + // 65534) + size_t _M_max_threads; + + // Each time a deallocation occurs in a threaded application + // we make sure that there are no more than + // _M_freelist_headroom % of used memory on the freelist. If + // the number of additional records is more than + // _M_freelist_headroom % of the freelist, we move these + // records back to the global pool. + size_t _M_freelist_headroom; + + // Set to true forces all allocations to use new(). + bool _M_force_new; + + explicit + _Tune() + : _M_align(_S_align), _M_max_bytes(_S_max_bytes), _M_min_bin(_S_min_bin), + _M_chunk_size(_S_chunk_size), _M_max_threads(_S_max_threads), + _M_freelist_headroom(_S_freelist_headroom), + _M_force_new(std::getenv("GLIBCXX_FORCE_NEW") ? true : false) + { } + + explicit + _Tune(size_t __align, size_t __maxb, size_t __minbin, size_t __chunk, + size_t __maxthreads, size_t __headroom, bool __force) + : _M_align(__align), _M_max_bytes(__maxb), _M_min_bin(__minbin), + _M_chunk_size(__chunk), _M_max_threads(__maxthreads), + _M_freelist_headroom(__headroom), _M_force_new(__force) + { } + }; + + struct _Block_address + { + void* _M_initial; + _Block_address* _M_next; + }; + + const _Tune& + _M_get_options() const + { return _M_options; } + + void + _M_set_options(_Tune __t) + { + if (!_M_init) + _M_options = __t; + } + + bool + _M_check_threshold(size_t __bytes) + { return __bytes > _M_options._M_max_bytes || _M_options._M_force_new; } + + size_t + _M_get_binmap(size_t __bytes) + { return _M_binmap[__bytes]; } + + size_t + _M_get_align() + { return _M_options._M_align; } + + explicit + __pool_base() + : _M_options(_Tune()), _M_binmap(0), _M_init(false) { } + + explicit + __pool_base(const _Tune& __options) + : _M_options(__options), _M_binmap(0), _M_init(false) { } + + private: + explicit + __pool_base(const __pool_base&); + + __pool_base& + operator=(const __pool_base&); + + protected: + // Configuration options. + _Tune _M_options; + + _Binmap_type* _M_binmap; + + // Configuration of the pool object via _M_options can happen + // after construction but before initialization. After + // initialization is complete, this variable is set to true. + bool _M_init; + }; + + + /** + * @brief Data describing the underlying memory pool, parameterized on + * threading support. + */ + template<bool _Thread> + class __pool; + + /// Specialization for single thread. + template<> + class __pool<false> : public __pool_base + { + public: + union _Block_record + { + // Points to the block_record of the next free block. + _Block_record* _M_next; + }; + + struct _Bin_record + { + // An "array" of pointers to the first free block. + _Block_record** _M_first; + + // A list of the initial addresses of all allocated blocks. + _Block_address* _M_address; + }; + + void + _M_initialize_once() + { + if (__builtin_expect(_M_init == false, false)) + _M_initialize(); + } + + void + _M_destroy() throw(); + + char* + _M_reserve_block(size_t __bytes, const size_t __thread_id); + + void + _M_reclaim_block(char* __p, size_t __bytes) throw (); + + size_t + _M_get_thread_id() { return 0; } + + const _Bin_record& + _M_get_bin(size_t __which) + { return _M_bin[__which]; } + + void + _M_adjust_freelist(const _Bin_record&, _Block_record*, size_t) + { } + + explicit __pool() + : _M_bin(0), _M_bin_size(1) { } + + explicit __pool(const __pool_base::_Tune& __tune) + : __pool_base(__tune), _M_bin(0), _M_bin_size(1) { } + + private: + // An "array" of bin_records each of which represents a specific + // power of 2 size. Memory to this "array" is allocated in + // _M_initialize(). + _Bin_record* _M_bin; + + // Actual value calculated in _M_initialize(). + size_t _M_bin_size; + + void + _M_initialize(); + }; + +#ifdef __GTHREADS + /// Specialization for thread enabled, via gthreads.h. + template<> + class __pool<true> : public __pool_base + { + public: + // Each requesting thread is assigned an id ranging from 1 to + // _S_max_threads. Thread id 0 is used as a global memory pool. + // In order to get constant performance on the thread assignment + // routine, we keep a list of free ids. When a thread first + // requests memory we remove the first record in this list and + // stores the address in a __gthread_key. When initializing the + // __gthread_key we specify a destructor. When this destructor + // (i.e. the thread dies) is called, we return the thread id to + // the front of this list. + struct _Thread_record + { + // Points to next free thread id record. NULL if last record in list. + _Thread_record* _M_next; + + // Thread id ranging from 1 to _S_max_threads. + size_t _M_id; + }; + + union _Block_record + { + // Points to the block_record of the next free block. + _Block_record* _M_next; + + // The thread id of the thread which has requested this block. + size_t _M_thread_id; + }; + + struct _Bin_record + { + // An "array" of pointers to the first free block for each + // thread id. Memory to this "array" is allocated in + // _S_initialize() for _S_max_threads + global pool 0. + _Block_record** _M_first; + + // A list of the initial addresses of all allocated blocks. + _Block_address* _M_address; + + // An "array" of counters used to keep track of the amount of + // blocks that are on the freelist/used for each thread id. + // - Note that the second part of the allocated _M_used "array" + // actually hosts (atomic) counters of reclaimed blocks: in + // _M_reserve_block and in _M_reclaim_block those numbers are + // subtracted from the first ones to obtain the actual size + // of the "working set" of the given thread. + // - Memory to these "arrays" is allocated in _S_initialize() + // for _S_max_threads + global pool 0. + size_t* _M_free; + size_t* _M_used; + + // Each bin has its own mutex which is used to ensure data + // integrity while changing "ownership" on a block. The mutex + // is initialized in _S_initialize(). + __gthread_mutex_t* _M_mutex; + }; + + // XXX GLIBCXX_ABI Deprecated + void + _M_initialize(__destroy_handler); + + void + _M_initialize_once() + { + if (__builtin_expect(_M_init == false, false)) + _M_initialize(); + } + + void + _M_destroy() throw(); + + char* + _M_reserve_block(size_t __bytes, const size_t __thread_id); + + void + _M_reclaim_block(char* __p, size_t __bytes) throw (); + + const _Bin_record& + _M_get_bin(size_t __which) + { return _M_bin[__which]; } + + void + _M_adjust_freelist(const _Bin_record& __bin, _Block_record* __block, + size_t __thread_id) + { + if (__gthread_active_p()) + { + __block->_M_thread_id = __thread_id; + --__bin._M_free[__thread_id]; + ++__bin._M_used[__thread_id]; + } + } + + // XXX GLIBCXX_ABI Deprecated + _GLIBCXX_CONST void + _M_destroy_thread_key(void*) throw (); + + size_t + _M_get_thread_id(); + + explicit __pool() + : _M_bin(0), _M_bin_size(1), _M_thread_freelist(0) + { } + + explicit __pool(const __pool_base::_Tune& __tune) + : __pool_base(__tune), _M_bin(0), _M_bin_size(1), + _M_thread_freelist(0) + { } + + private: + // An "array" of bin_records each of which represents a specific + // power of 2 size. Memory to this "array" is allocated in + // _M_initialize(). + _Bin_record* _M_bin; + + // Actual value calculated in _M_initialize(). + size_t _M_bin_size; + + _Thread_record* _M_thread_freelist; + void* _M_thread_freelist_initial; + + void + _M_initialize(); + }; +#endif + + template<template <bool> class _PoolTp, bool _Thread> + struct __common_pool + { + typedef _PoolTp<_Thread> pool_type; + + static pool_type& + _S_get_pool() + { + static pool_type _S_pool; + return _S_pool; + } + }; + + template<template <bool> class _PoolTp, bool _Thread> + struct __common_pool_base; + + template<template <bool> class _PoolTp> + struct __common_pool_base<_PoolTp, false> + : public __common_pool<_PoolTp, false> + { + using __common_pool<_PoolTp, false>::_S_get_pool; + + static void + _S_initialize_once() + { + static bool __init; + if (__builtin_expect(__init == false, false)) + { + _S_get_pool()._M_initialize_once(); + __init = true; + } + } + }; + +#ifdef __GTHREADS + template<template <bool> class _PoolTp> + struct __common_pool_base<_PoolTp, true> + : public __common_pool<_PoolTp, true> + { + using __common_pool<_PoolTp, true>::_S_get_pool; + + static void + _S_initialize() + { _S_get_pool()._M_initialize_once(); } + + static void + _S_initialize_once() + { + static bool __init; + if (__builtin_expect(__init == false, false)) + { + if (__gthread_active_p()) + { + // On some platforms, __gthread_once_t is an aggregate. + static __gthread_once_t __once = __GTHREAD_ONCE_INIT; + __gthread_once(&__once, _S_initialize); + } + + // Double check initialization. May be necessary on some + // systems for proper construction when not compiling with + // thread flags. + _S_get_pool()._M_initialize_once(); + __init = true; + } + } + }; +#endif + + /// Policy for shared __pool objects. + template<template <bool> class _PoolTp, bool _Thread> + struct __common_pool_policy : public __common_pool_base<_PoolTp, _Thread> + { + template<typename _Tp1, template <bool> class _PoolTp1 = _PoolTp, + bool _Thread1 = _Thread> + struct _M_rebind + { typedef __common_pool_policy<_PoolTp1, _Thread1> other; }; + + using __common_pool_base<_PoolTp, _Thread>::_S_get_pool; + using __common_pool_base<_PoolTp, _Thread>::_S_initialize_once; + }; + + + template<typename _Tp, template <bool> class _PoolTp, bool _Thread> + struct __per_type_pool + { + typedef _Tp value_type; + typedef _PoolTp<_Thread> pool_type; + + static pool_type& + _S_get_pool() + { + // Sane defaults for the _PoolTp. + typedef typename pool_type::_Block_record _Block_record; + const static size_t __a = (__alignof__(_Tp) >= sizeof(_Block_record) + ? __alignof__(_Tp) : sizeof(_Block_record)); + + typedef typename __pool_base::_Tune _Tune; + static _Tune _S_tune(__a, sizeof(_Tp) * 64, + sizeof(_Tp) * 2 >= __a ? sizeof(_Tp) * 2 : __a, + sizeof(_Tp) * size_t(_Tune::_S_chunk_size), + _Tune::_S_max_threads, + _Tune::_S_freelist_headroom, + std::getenv("GLIBCXX_FORCE_NEW") ? true : false); + static pool_type _S_pool(_S_tune); + return _S_pool; + } + }; + + template<typename _Tp, template <bool> class _PoolTp, bool _Thread> + struct __per_type_pool_base; + + template<typename _Tp, template <bool> class _PoolTp> + struct __per_type_pool_base<_Tp, _PoolTp, false> + : public __per_type_pool<_Tp, _PoolTp, false> + { + using __per_type_pool<_Tp, _PoolTp, false>::_S_get_pool; + + static void + _S_initialize_once() + { + static bool __init; + if (__builtin_expect(__init == false, false)) + { + _S_get_pool()._M_initialize_once(); + __init = true; + } + } + }; + + #ifdef __GTHREADS + template<typename _Tp, template <bool> class _PoolTp> + struct __per_type_pool_base<_Tp, _PoolTp, true> + : public __per_type_pool<_Tp, _PoolTp, true> + { + using __per_type_pool<_Tp, _PoolTp, true>::_S_get_pool; + + static void + _S_initialize() + { _S_get_pool()._M_initialize_once(); } + + static void + _S_initialize_once() + { + static bool __init; + if (__builtin_expect(__init == false, false)) + { + if (__gthread_active_p()) + { + // On some platforms, __gthread_once_t is an aggregate. + static __gthread_once_t __once = __GTHREAD_ONCE_INIT; + __gthread_once(&__once, _S_initialize); + } + + // Double check initialization. May be necessary on some + // systems for proper construction when not compiling with + // thread flags. + _S_get_pool()._M_initialize_once(); + __init = true; + } + } + }; +#endif + + /// Policy for individual __pool objects. + template<typename _Tp, template <bool> class _PoolTp, bool _Thread> + struct __per_type_pool_policy + : public __per_type_pool_base<_Tp, _PoolTp, _Thread> + { + template<typename _Tp1, template <bool> class _PoolTp1 = _PoolTp, + bool _Thread1 = _Thread> + struct _M_rebind + { typedef __per_type_pool_policy<_Tp1, _PoolTp1, _Thread1> other; }; + + using __per_type_pool_base<_Tp, _PoolTp, _Thread>::_S_get_pool; + using __per_type_pool_base<_Tp, _PoolTp, _Thread>::_S_initialize_once; + }; + + + /// Base class for _Tp dependent member functions. + template<typename _Tp> + class __mt_alloc_base + { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + +#if __cplusplus >= 201103L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2103. propagate_on_container_move_assignment + typedef std::true_type propagate_on_container_move_assignment; +#endif + + pointer + address(reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + const_pointer + address(const_reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + size_type + max_size() const _GLIBCXX_USE_NOEXCEPT + { return size_t(-1) / sizeof(_Tp); } + +#if __cplusplus >= 201103L + template<typename _Up, typename... _Args> + void + construct(_Up* __p, _Args&&... __args) + { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } + + template<typename _Up> + void + destroy(_Up* __p) { __p->~_Up(); } +#else + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 402. wrong new expression in [some_] allocator::construct + void + construct(pointer __p, const _Tp& __val) + { ::new((void *)__p) _Tp(__val); } + + void + destroy(pointer __p) { __p->~_Tp(); } +#endif + }; + +#ifdef __GTHREADS +#define __thread_default true +#else +#define __thread_default false +#endif + + /** + * @brief This is a fixed size (power of 2) allocator which - when + * compiled with thread support - will maintain one freelist per + * size per thread plus a @a global one. Steps are taken to limit + * the per thread freelist sizes (by returning excess back to + * the @a global list). + * @ingroup allocators + * + * Further details: + * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt12ch32.html + */ + template<typename _Tp, + typename _Poolp = __common_pool_policy<__pool, __thread_default> > + class __mt_alloc : public __mt_alloc_base<_Tp> + { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + typedef _Poolp __policy_type; + typedef typename _Poolp::pool_type __pool_type; + + template<typename _Tp1, typename _Poolp1 = _Poolp> + struct rebind + { + typedef typename _Poolp1::template _M_rebind<_Tp1>::other pol_type; + typedef __mt_alloc<_Tp1, pol_type> other; + }; + + __mt_alloc() _GLIBCXX_USE_NOEXCEPT { } + + __mt_alloc(const __mt_alloc&) _GLIBCXX_USE_NOEXCEPT { } + + template<typename _Tp1, typename _Poolp1> + __mt_alloc(const __mt_alloc<_Tp1, _Poolp1>&) _GLIBCXX_USE_NOEXCEPT { } + + ~__mt_alloc() _GLIBCXX_USE_NOEXCEPT { } + + pointer + allocate(size_type __n, const void* = 0); + + void + deallocate(pointer __p, size_type __n); + + const __pool_base::_Tune + _M_get_options() + { + // Return a copy, not a reference, for external consumption. + return __policy_type::_S_get_pool()._M_get_options(); + } + + void + _M_set_options(__pool_base::_Tune __t) + { __policy_type::_S_get_pool()._M_set_options(__t); } + }; + + template<typename _Tp, typename _Poolp> + typename __mt_alloc<_Tp, _Poolp>::pointer + __mt_alloc<_Tp, _Poolp>:: + allocate(size_type __n, const void*) + { + if (__n > this->max_size()) + std::__throw_bad_alloc(); + + __policy_type::_S_initialize_once(); + + // Requests larger than _M_max_bytes are handled by operator + // new/delete directly. + __pool_type& __pool = __policy_type::_S_get_pool(); + const size_t __bytes = __n * sizeof(_Tp); + if (__pool._M_check_threshold(__bytes)) + { + void* __ret = ::operator new(__bytes); + return static_cast<_Tp*>(__ret); + } + + // Round up to power of 2 and figure out which bin to use. + const size_t __which = __pool._M_get_binmap(__bytes); + const size_t __thread_id = __pool._M_get_thread_id(); + + // Find out if we have blocks on our freelist. If so, go ahead + // and use them directly without having to lock anything. + char* __c; + typedef typename __pool_type::_Bin_record _Bin_record; + const _Bin_record& __bin = __pool._M_get_bin(__which); + if (__bin._M_first[__thread_id]) + { + // Already reserved. + typedef typename __pool_type::_Block_record _Block_record; + _Block_record* __block = __bin._M_first[__thread_id]; + __bin._M_first[__thread_id] = __block->_M_next; + + __pool._M_adjust_freelist(__bin, __block, __thread_id); + __c = reinterpret_cast<char*>(__block) + __pool._M_get_align(); + } + else + { + // Null, reserve. + __c = __pool._M_reserve_block(__bytes, __thread_id); + } + return static_cast<_Tp*>(static_cast<void*>(__c)); + } + + template<typename _Tp, typename _Poolp> + void + __mt_alloc<_Tp, _Poolp>:: + deallocate(pointer __p, size_type __n) + { + if (__builtin_expect(__p != 0, true)) + { + // Requests larger than _M_max_bytes are handled by + // operators new/delete directly. + __pool_type& __pool = __policy_type::_S_get_pool(); + const size_t __bytes = __n * sizeof(_Tp); + if (__pool._M_check_threshold(__bytes)) + ::operator delete(__p); + else + __pool._M_reclaim_block(reinterpret_cast<char*>(__p), __bytes); + } + } + + template<typename _Tp, typename _Poolp> + inline bool + operator==(const __mt_alloc<_Tp, _Poolp>&, const __mt_alloc<_Tp, _Poolp>&) + { return true; } + + template<typename _Tp, typename _Poolp> + inline bool + operator!=(const __mt_alloc<_Tp, _Poolp>&, const __mt_alloc<_Tp, _Poolp>&) + { return false; } + +#undef __thread_default + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/new_allocator.h b/gcc-4.9/libstdc++-v3/include/ext/new_allocator.h new file mode 100644 index 0000000..996a219 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/new_allocator.h @@ -0,0 +1,150 @@ +// Allocator that wraps operator new -*- C++ -*- + +// Copyright (C) 2001-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/new_allocator.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _NEW_ALLOCATOR_H +#define _NEW_ALLOCATOR_H 1 + +#include <bits/c++config.h> +#include <new> +#include <bits/functexcept.h> +#include <bits/move.h> +#if __cplusplus >= 201103L +#include <type_traits> +#endif + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::size_t; + using std::ptrdiff_t; + + /** + * @brief An allocator that uses global new, as per [20.4]. + * @ingroup allocators + * + * This is precisely the allocator defined in the C++ Standard. + * - all allocation calls operator new + * - all deallocation calls operator delete + * + * @tparam _Tp Type of allocated object. + */ + template<typename _Tp> + class new_allocator + { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + + template<typename _Tp1> + struct rebind + { typedef new_allocator<_Tp1> other; }; + +#if __cplusplus >= 201103L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2103. propagate_on_container_move_assignment + typedef std::true_type propagate_on_container_move_assignment; +#endif + + new_allocator() _GLIBCXX_USE_NOEXCEPT { } + + new_allocator(const new_allocator&) _GLIBCXX_USE_NOEXCEPT { } + + template<typename _Tp1> + new_allocator(const new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { } + + ~new_allocator() _GLIBCXX_USE_NOEXCEPT { } + + pointer + address(reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + const_pointer + address(const_reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + // NB: __n is permitted to be 0. The C++ standard says nothing + // about what the return value is when __n == 0. + pointer + allocate(size_type __n, const void* = 0) + { + if (__n > this->max_size()) + std::__throw_bad_alloc(); + + return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); + } + + // __p is not permitted to be a null pointer. + void + deallocate(pointer __p, size_type) + { ::operator delete(__p); } + + size_type + max_size() const _GLIBCXX_USE_NOEXCEPT + { return size_t(-1) / sizeof(_Tp); } + +#if __cplusplus >= 201103L + template<typename _Up, typename... _Args> + void + construct(_Up* __p, _Args&&... __args) + { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } + + template<typename _Up> + void + destroy(_Up* __p) { __p->~_Up(); } +#else + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 402. wrong new expression in [some_] allocator::construct + void + construct(pointer __p, const _Tp& __val) + { ::new((void *)__p) _Tp(__val); } + + void + destroy(pointer __p) { __p->~_Tp(); } +#endif + }; + + template<typename _Tp> + inline bool + operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&) + { return true; } + + template<typename _Tp> + inline bool + operator!=(const new_allocator<_Tp>&, const new_allocator<_Tp>&) + { return false; } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/numeric b/gcc-4.9/libstdc++-v3/include/ext/numeric new file mode 100644 index 0000000..d957420 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/numeric @@ -0,0 +1,152 @@ +// Numeric extensions -*- C++ -*- + +// Copyright (C) 2002-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * + * Copyright (c) 1994 + * Hewlett-Packard Company + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Hewlett-Packard Company makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * + * Copyright (c) 1996 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/** @file ext/numeric + * This file is a GNU extension to the Standard C++ Library (possibly + * containing extensions from the HP/SGI STL subset). + */ + +#ifndef _EXT_NUMERIC +#define _EXT_NUMERIC 1 + +#pragma GCC system_header + +#include <bits/concept_check.h> +#include <numeric> + +#include <ext/functional> // For identity_element + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // Returns __x ** __n, where __n >= 0. _Note that "multiplication" + // is required to be associative, but not necessarily commutative. + template<typename _Tp, typename _Integer, typename _MonoidOperation> + _Tp + __power(_Tp __x, _Integer __n, _MonoidOperation __monoid_op) + { + if (__n == 0) + return identity_element(__monoid_op); + else + { + while ((__n & 1) == 0) + { + __n >>= 1; + __x = __monoid_op(__x, __x); + } + + _Tp __result = __x; + __n >>= 1; + while (__n != 0) + { + __x = __monoid_op(__x, __x); + if ((__n & 1) != 0) + __result = __monoid_op(__result, __x); + __n >>= 1; + } + return __result; + } + } + + template<typename _Tp, typename _Integer> + inline _Tp + __power(_Tp __x, _Integer __n) + { return __power(__x, __n, std::multiplies<_Tp>()); } + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + // Alias for the internal name __power. Note that power is an extension, + // not part of the C++ standard. + template<typename _Tp, typename _Integer, typename _MonoidOperation> + inline _Tp + power(_Tp __x, _Integer __n, _MonoidOperation __monoid_op) + { return __power(__x, __n, __monoid_op); } + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template<typename _Tp, typename _Integer> + inline _Tp + power(_Tp __x, _Integer __n) + { return __power(__x, __n); } + +#if __cplusplus >= 201103L + using std::iota; +#else + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + // iota is not part of the C++ standard. It is an extension. + template<typename _ForwardIter, typename _Tp> + void + iota(_ForwardIter __first, _ForwardIter __last, _Tp __value) + { + // concept requirements + __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>) + __glibcxx_function_requires(_ConvertibleConcept<_Tp, + typename std::iterator_traits<_ForwardIter>::value_type>) + + while (__first != __last) + *__first++ = __value++; + } +#endif // C++11 + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/numeric_traits.h b/gcc-4.9/libstdc++-v3/include/ext/numeric_traits.h new file mode 100644 index 0000000..72941a5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/numeric_traits.h @@ -0,0 +1,138 @@ +// -*- C++ -*- + +// Copyright (C) 2007-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/numeric_traits.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _EXT_NUMERIC_TRAITS +#define _EXT_NUMERIC_TRAITS 1 + +#pragma GCC system_header + +#include <bits/cpp_type_traits.h> +#include <ext/type_traits.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // Compile time constants for builtin types. + // Sadly std::numeric_limits member functions cannot be used for this. +#define __glibcxx_signed(_Tp) ((_Tp)(-1) < 0) +#define __glibcxx_digits(_Tp) \ + (sizeof(_Tp) * __CHAR_BIT__ - __glibcxx_signed(_Tp)) + +#define __glibcxx_min(_Tp) \ + (__glibcxx_signed(_Tp) ? (_Tp)1 << __glibcxx_digits(_Tp) : (_Tp)0) + +#define __glibcxx_max(_Tp) \ + (__glibcxx_signed(_Tp) ? \ + (((((_Tp)1 << (__glibcxx_digits(_Tp) - 1)) - 1) << 1) + 1) : ~(_Tp)0) + + template<typename _Value> + struct __numeric_traits_integer + { + // Only integers for initialization of member constant. + static const _Value __min = __glibcxx_min(_Value); + static const _Value __max = __glibcxx_max(_Value); + + // NB: these two also available in std::numeric_limits as compile + // time constants, but <limits> is big and we avoid including it. + static const bool __is_signed = __glibcxx_signed(_Value); + static const int __digits = __glibcxx_digits(_Value); + }; + + template<typename _Value> + const _Value __numeric_traits_integer<_Value>::__min; + + template<typename _Value> + const _Value __numeric_traits_integer<_Value>::__max; + + template<typename _Value> + const bool __numeric_traits_integer<_Value>::__is_signed; + + template<typename _Value> + const int __numeric_traits_integer<_Value>::__digits; + +#undef __glibcxx_signed +#undef __glibcxx_digits +#undef __glibcxx_min +#undef __glibcxx_max + +#define __glibcxx_floating(_Tp, _Fval, _Dval, _LDval) \ + (std::__are_same<_Tp, float>::__value ? _Fval \ + : std::__are_same<_Tp, double>::__value ? _Dval : _LDval) + +#define __glibcxx_max_digits10(_Tp) \ + (2 + __glibcxx_floating(_Tp, __FLT_MANT_DIG__, __DBL_MANT_DIG__, \ + __LDBL_MANT_DIG__) * 643L / 2136) + +#define __glibcxx_digits10(_Tp) \ + __glibcxx_floating(_Tp, __FLT_DIG__, __DBL_DIG__, __LDBL_DIG__) + +#define __glibcxx_max_exponent10(_Tp) \ + __glibcxx_floating(_Tp, __FLT_MAX_10_EXP__, __DBL_MAX_10_EXP__, \ + __LDBL_MAX_10_EXP__) + + template<typename _Value> + struct __numeric_traits_floating + { + // Only floating point types. See N1822. + static const int __max_digits10 = __glibcxx_max_digits10(_Value); + + // See above comment... + static const bool __is_signed = true; + static const int __digits10 = __glibcxx_digits10(_Value); + static const int __max_exponent10 = __glibcxx_max_exponent10(_Value); + }; + + template<typename _Value> + const int __numeric_traits_floating<_Value>::__max_digits10; + + template<typename _Value> + const bool __numeric_traits_floating<_Value>::__is_signed; + + template<typename _Value> + const int __numeric_traits_floating<_Value>::__digits10; + + template<typename _Value> + const int __numeric_traits_floating<_Value>::__max_exponent10; + + template<typename _Value> + struct __numeric_traits + : public __conditional_type<std::__is_integer<_Value>::__value, + __numeric_traits_integer<_Value>, + __numeric_traits_floating<_Value> >::__type + { }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#undef __glibcxx_floating +#undef __glibcxx_max_digits10 +#undef __glibcxx_digits10 +#undef __glibcxx_max_exponent10 + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/assoc_container.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/assoc_container.hpp new file mode 100644 index 0000000..dae2e41 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/assoc_container.hpp @@ -0,0 +1,861 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file assoc_container.hpp + * Contains associative containers. + */ + +#ifndef PB_DS_ASSOC_CNTNR_HPP +#define PB_DS_ASSOC_CNTNR_HPP + +#include <bits/c++config.h> +#include <ext/typelist.h> +#include <ext/pb_ds/tag_and_trait.hpp> +#include <ext/pb_ds/detail/standard_policies.hpp> +#include <ext/pb_ds/detail/container_base_dispatch.hpp> +#include <ext/pb_ds/detail/branch_policy/traits.hpp> + +namespace __gnu_pbds +{ + /** + * @defgroup containers-pbds Containers + * @ingroup pbds + * @{ + */ + + /** + * @defgroup hash-based Hash-Based + * @ingroup containers-pbds + * @{ + */ +#define PB_DS_HASH_BASE \ + detail::container_base_dispatch<Key, Mapped, _Alloc, Tag, \ + typename __gnu_cxx::typelist::append< \ + typename __gnu_cxx::typelist::create4<Hash_Fn, Eq_Fn, Resize_Policy, \ + detail::integral_constant<int, Store_Hash> >::type, Policy_Tl>::type>::type + + /** + * @defgroup hash-detail Base and Policy Classes + * @ingroup hash-based + */ + + /** + * A hashed container abstraction. + * + * @tparam Key Key type. + * @tparam Mapped Map type. + * @tparam Hash_Fn Hashing functor. + * @tparam Eq_Fn Equal functor. + * @tparam Resize_Policy Resizes hash. + * @tparam Store_Hash Indicates whether the hash value + * will be stored along with each key. + * @tparam Tag Instantiating data structure type, + * see container_tag. + * @tparam Policy_TL Policy typelist. + * @tparam _Alloc Allocator type. + * + * Base is dispatched at compile time via Tag, from the following + * choices: cc_hash_tag, gp_hash_tag, and descendants of basic_hash_tag. + * + * Base choices are: detail::cc_ht_map, detail::gp_ht_map + */ + template<typename Key, + typename Mapped, + typename Hash_Fn, + typename Eq_Fn, + typename Resize_Policy, + bool Store_Hash, + typename Tag, + typename Policy_Tl, + typename _Alloc> + class basic_hash_table : public PB_DS_HASH_BASE + { + private: + typedef typename PB_DS_HASH_BASE base_type; + + public: + virtual + ~basic_hash_table() { } + + protected: + basic_hash_table() { } + + basic_hash_table(const basic_hash_table& other) + : base_type((const base_type&)other) { } + + template<typename T0> + basic_hash_table(T0 t0) : base_type(t0) { } + + template<typename T0, typename T1> + basic_hash_table(T0 t0, T1 t1) : base_type(t0, t1) { } + + template<typename T0, typename T1, typename T2> + basic_hash_table(T0 t0, T1 t1, T2 t2) : base_type(t0, t1, t2) { } + + template<typename T0, typename T1, typename T2, typename T3> + basic_hash_table(T0 t0, T1 t1, T2 t2, T3 t3) + : base_type(t0, t1, t2, t3) { } + + template<typename T0, typename T1, typename T2, typename T3, typename T4> + basic_hash_table(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) + : base_type(t0, t1, t2, t3, t4) { } + + template<typename T0, typename T1, typename T2, typename T3, typename T4, + typename T5> + basic_hash_table(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) + : base_type(t0, t1, t2, t3, t4, t5) { } + + template<typename T0, typename T1, typename T2, typename T3, typename T4, + typename T5, typename T6> + basic_hash_table(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) + : base_type(t0, t1, t2, t3, t4, t5, t6) { } + + template<typename T0, typename T1, typename T2, typename T3, typename T4, + typename T5, typename T6, typename T7> + basic_hash_table(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) + : base_type(t0, t1, t2, t3, t4, t5, t6, t7) { } + + template<typename T0, typename T1, typename T2, typename T3, typename T4, + typename T5, typename T6, typename T7, typename T8> + basic_hash_table(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, + T7 t7, T8 t8) + : base_type(t0, t1, t2, t3, t4, t5, t6, t7, t8) + { } + + private: + basic_hash_table& + operator=(const base_type&); + }; + +#undef PB_DS_HASH_BASE + + +#define PB_DS_CC_HASH_BASE \ + basic_hash_table<Key, Mapped, Hash_Fn, Eq_Fn, Resize_Policy, Store_Hash, \ + cc_hash_tag, \ + typename __gnu_cxx::typelist::create1<Comb_Hash_Fn>::type, _Alloc> + + + /** + * A collision-chaining hash-based associative container. + * + * @tparam Key Key type. + * @tparam Mapped Map type. + * @tparam Hash_Fn Hashing functor. + * @tparam Eq_Fn Equal functor. + * @tparam Comb_Hash_Fn Combining hash functor. + * If Hash_Fn is not null_type, then this + * is the ranged-hash functor; otherwise, + * this is the range-hashing functor. + * XXX(See Design::Hash-Based Containers::Hash Policies.) + * @tparam Resize_Policy Resizes hash. + * @tparam Store_Hash Indicates whether the hash value + * will be stored along with each key. + * If Hash_Fn is null_type, then the + * container will not compile if this + * value is true + * @tparam _Alloc Allocator type. + * + * Base tag choices are: cc_hash_tag. + * + * Base is basic_hash_table. + */ + template<typename Key, + typename Mapped, + typename Hash_Fn = typename detail::default_hash_fn<Key>::type, + typename Eq_Fn = typename detail::default_eq_fn<Key>::type, + typename Comb_Hash_Fn = detail::default_comb_hash_fn::type, + typename Resize_Policy = typename detail::default_resize_policy<Comb_Hash_Fn>::type, + bool Store_Hash = detail::default_store_hash, + typename _Alloc = std::allocator<char> > + class cc_hash_table : public PB_DS_CC_HASH_BASE + { + private: + typedef PB_DS_CC_HASH_BASE base_type; + + public: + typedef cc_hash_tag container_category; + typedef Hash_Fn hash_fn; + typedef Eq_Fn eq_fn; + typedef Resize_Policy resize_policy; + typedef Comb_Hash_Fn comb_hash_fn; + + /// Default constructor. + cc_hash_table() { } + + /// Constructor taking some policy objects. r_hash_fn will be + /// copied by the Hash_Fn object of the container object. + cc_hash_table(const hash_fn& h) + : base_type(h) { } + + /// Constructor taking some policy objects. r_hash_fn will be + /// copied by the hash_fn object of the container object, and + /// r_eq_fn will be copied by the eq_fn object of the container + /// object. + cc_hash_table(const hash_fn& h, const eq_fn& e) + : base_type(h, e) { } + + /// Constructor taking some policy objects. r_hash_fn will be + /// copied by the hash_fn object of the container object, r_eq_fn + /// will be copied by the eq_fn object of the container object, + /// and r_comb_hash_fn will be copied by the comb_hash_fn object + /// of the container object. + cc_hash_table(const hash_fn& h, const eq_fn& e, const comb_hash_fn& ch) + : base_type(h, e, ch) { } + + /// Constructor taking some policy objects. r_hash_fn will be + /// copied by the hash_fn object of the container object, r_eq_fn + /// will be copied by the eq_fn object of the container object, + /// r_comb_hash_fn will be copied by the comb_hash_fn object of + /// the container object, and r_resize_policy will be copied by + /// the resize_policy object of the container object. + cc_hash_table(const hash_fn& h, const eq_fn& e, const comb_hash_fn& ch, + const resize_policy& rp) + : base_type(h, e, ch, rp) { } + + /// Constructor taking __iterators to a range of value_types. The + /// value_types between first_it and last_it will be inserted into + /// the container object. + template<typename It> + cc_hash_table(It first, It last) + { base_type::copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects. The value_types between first_it and + /// last_it will be inserted into the container object. + template<typename It> + cc_hash_table(It first, It last, const hash_fn& h) + : base_type(h) + { this->copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects The value_types between first_it and + /// last_it will be inserted into the container object. r_hash_fn + /// will be copied by the hash_fn object of the container object, + /// and r_eq_fn will be copied by the eq_fn object of the + /// container object. + template<typename It> + cc_hash_table(It first, It last, const hash_fn& h, const eq_fn& e) + : base_type(h, e) + { this->copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects The value_types between first_it and + /// last_it will be inserted into the container object. r_hash_fn + /// will be copied by the hash_fn object of the container object, + /// r_eq_fn will be copied by the eq_fn object of the container + /// object, and r_comb_hash_fn will be copied by the comb_hash_fn + /// object of the container object. + template<typename It> + cc_hash_table(It first, It last, const hash_fn& h, const eq_fn& e, + const comb_hash_fn& ch) + : base_type(h, e, ch) + { this->copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects The value_types between first_it and + /// last_it will be inserted into the container object. r_hash_fn + /// will be copied by the hash_fn object of the container object, + /// r_eq_fn will be copied by the eq_fn object of the container + /// object, r_comb_hash_fn will be copied by the comb_hash_fn + /// object of the container object, and r_resize_policy will be + /// copied by the resize_policy object of the container object. + template<typename It> + cc_hash_table(It first, It last, const hash_fn& h, const eq_fn& e, + const comb_hash_fn& ch, const resize_policy& rp) + : base_type(h, e, ch, rp) + { this->copy_from_range(first, last); } + + cc_hash_table(const cc_hash_table& other) + : base_type((const base_type&)other) + { } + + virtual + ~cc_hash_table() { } + + cc_hash_table& + operator=(const cc_hash_table& other) + { + if (this != &other) + { + cc_hash_table tmp(other); + swap(tmp); + } + return *this; + } + + void + swap(cc_hash_table& other) + { base_type::swap(other); } + }; + +#undef PB_DS_CC_HASH_BASE + + +#define PB_DS_GP_HASH_BASE \ + basic_hash_table<Key, Mapped, Hash_Fn, Eq_Fn, Resize_Policy, Store_Hash, \ + gp_hash_tag, \ + typename __gnu_cxx::typelist::create2<Comb_Probe_Fn, Probe_Fn>::type, _Alloc> + + + /** + * A general-probing hash-based associative container. + * + * @tparam Key Key type. + * @tparam Mapped Map type. + * @tparam Hash_Fn Hashing functor. + * @tparam Eq_Fn Equal functor. + * @tparam Comb_Probe_Fn Combining probe functor. + * If Hash_Fn is not null_type, then this + * is the ranged-probe functor; otherwise, + * this is the range-hashing functor. + * XXX See Design::Hash-Based Containers::Hash Policies. + * @tparam Probe_Fn Probe functor. + * @tparam Resize_Policy Resizes hash. + * @tparam Store_Hash Indicates whether the hash value + * will be stored along with each key. + * If Hash_Fn is null_type, then the + * container will not compile if this + * value is true + * @tparam _Alloc Allocator type. + * + * Base tag choices are: gp_hash_tag. + * + * Base is basic_hash_table. + */ + template<typename Key, + typename Mapped, + typename Hash_Fn = typename detail::default_hash_fn<Key>::type, + typename Eq_Fn = typename detail::default_eq_fn<Key>::type, + typename Comb_Probe_Fn = detail::default_comb_hash_fn::type, + typename Probe_Fn = typename detail::default_probe_fn<Comb_Probe_Fn>::type, + typename Resize_Policy = typename detail::default_resize_policy<Comb_Probe_Fn>::type, + bool Store_Hash = detail::default_store_hash, + typename _Alloc = std::allocator<char> > + class gp_hash_table : public PB_DS_GP_HASH_BASE + { + private: + typedef PB_DS_GP_HASH_BASE base_type; + + public: + typedef gp_hash_tag container_category; + typedef Hash_Fn hash_fn; + typedef Eq_Fn eq_fn; + typedef Comb_Probe_Fn comb_probe_fn; + typedef Probe_Fn probe_fn; + typedef Resize_Policy resize_policy; + + /// Default constructor. + gp_hash_table() { } + + /// Constructor taking some policy objects. r_hash_fn will be + /// copied by the hash_fn object of the container object. + gp_hash_table(const hash_fn& h) + : base_type(h) { } + + /// Constructor taking some policy objects. r_hash_fn will be + /// copied by the hash_fn object of the container object, and + /// r_eq_fn will be copied by the eq_fn object of the container + /// object. + gp_hash_table(const hash_fn& h, const eq_fn& e) + : base_type(h, e) { } + + /// Constructor taking some policy objects. r_hash_fn will be + /// copied by the hash_fn object of the container object, r_eq_fn + /// will be copied by the eq_fn object of the container object, + /// and r_comb_probe_fn will be copied by the comb_probe_fn object + /// of the container object. + gp_hash_table(const hash_fn& h, const eq_fn& e, const comb_probe_fn& cp) + : base_type(h, e, cp) { } + + /// Constructor taking some policy objects. r_hash_fn will be + /// copied by the hash_fn object of the container object, r_eq_fn + /// will be copied by the eq_fn object of the container object, + /// r_comb_probe_fn will be copied by the comb_probe_fn object of + /// the container object, and r_probe_fn will be copied by the + /// probe_fn object of the container object. + gp_hash_table(const hash_fn& h, const eq_fn& e, const comb_probe_fn& cp, + const probe_fn& p) + : base_type(h, e, cp, p) { } + + /// Constructor taking some policy objects. r_hash_fn will be + /// copied by the hash_fn object of the container object, r_eq_fn + /// will be copied by the eq_fn object of the container object, + /// r_comb_probe_fn will be copied by the comb_probe_fn object of + /// the container object, r_probe_fn will be copied by the + /// probe_fn object of the container object, and r_resize_policy + /// will be copied by the Resize_Policy object of the container + /// object. + gp_hash_table(const hash_fn& h, const eq_fn& e, const comb_probe_fn& cp, + const probe_fn& p, const resize_policy& rp) + : base_type(h, e, cp, p, rp) { } + + /// Constructor taking __iterators to a range of value_types. The + /// value_types between first_it and last_it will be inserted into + /// the container object. + template<typename It> + gp_hash_table(It first, It last) + { base_type::copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects. The value_types between first_it and + /// last_it will be inserted into the container object. r_hash_fn + /// will be copied by the hash_fn object of the container object. + template<typename It> + gp_hash_table(It first, It last, const hash_fn& h) + : base_type(h) + { base_type::copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects. The value_types between first_it and + /// last_it will be inserted into the container object. r_hash_fn + /// will be copied by the hash_fn object of the container object, + /// and r_eq_fn will be copied by the eq_fn object of the + /// container object. + template<typename It> + gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e) + : base_type(h, e) + { base_type::copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects. The value_types between first_it and + /// last_it will be inserted into the container object. r_hash_fn + /// will be copied by the hash_fn object of the container object, + /// r_eq_fn will be copied by the eq_fn object of the container + /// object, and r_comb_probe_fn will be copied by the + /// comb_probe_fn object of the container object. + template<typename It> + gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e, + const comb_probe_fn& cp) + : base_type(h, e, cp) + { base_type::copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects. The value_types between first_it and + /// last_it will be inserted into the container object. r_hash_fn + /// will be copied by the hash_fn object of the container object, + /// r_eq_fn will be copied by the eq_fn object of the container + /// object, r_comb_probe_fn will be copied by the comb_probe_fn + /// object of the container object, and r_probe_fn will be copied + /// by the probe_fn object of the container object. + template<typename It> + gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e, + const comb_probe_fn& cp, const probe_fn& p) + : base_type(h, e, cp, p) + { base_type::copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects. The value_types between first_it and + /// last_it will be inserted into the container object. r_hash_fn + /// will be copied by the hash_fn object of the container object, + /// r_eq_fn will be copied by the eq_fn object of the container + /// object, r_comb_probe_fn will be copied by the comb_probe_fn + /// object of the container object, r_probe_fn will be copied by + /// the probe_fn object of the container object, and + /// r_resize_policy will be copied by the resize_policy object of + /// the container object. + template<typename It> + gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e, + const comb_probe_fn& cp, const probe_fn& p, + const resize_policy& rp) + : base_type(h, e, cp, p, rp) + { base_type::copy_from_range(first, last); } + + gp_hash_table(const gp_hash_table& other) + : base_type((const base_type&)other) + { } + + virtual + ~gp_hash_table() { } + + gp_hash_table& + operator=(const gp_hash_table& other) + { + if (this != &other) + { + gp_hash_table tmp(other); + swap(tmp); + } + return *this; + } + + void + swap(gp_hash_table& other) + { base_type::swap(other); } + }; + //@} hash-based +#undef PB_DS_GP_HASH_BASE + + + /** + * @defgroup branch-based Branch-Based + * @ingroup containers-pbds + * @{ + */ +#define PB_DS_BRANCH_BASE \ + detail::container_base_dispatch<Key, Mapped, _Alloc, Tag, Policy_Tl>::type + + /** + * @defgroup branch-detail Base and Policy Classes + * @ingroup branch-based + */ + + /** + * A branched, tree-like (tree, trie) container abstraction. + * + * @tparam Key Key type. + * @tparam Mapped Map type. + * @tparam Tag Instantiating data structure type, + * see container_tag. + * @tparam Node_Update Updates nodes, restores invariants. + * @tparam Policy_TL Policy typelist. + * @tparam _Alloc Allocator type. + * + * Base is dispatched at compile time via Tag, from the following + * choices: tree_tag, trie_tag, and their descendants. + * + * Base choices are: detail::ov_tree_map, detail::rb_tree_map, + * detail::splay_tree_map, and detail::pat_trie_map. + */ + template<typename Key, typename Mapped, typename Tag, + typename Node_Update, typename Policy_Tl, typename _Alloc> + class basic_branch : public PB_DS_BRANCH_BASE + { + private: + typedef typename PB_DS_BRANCH_BASE base_type; + + public: + typedef Node_Update node_update; + + virtual + ~basic_branch() { } + + protected: + basic_branch() { } + + basic_branch(const basic_branch& other) + : base_type((const base_type&)other) { } + + template<typename T0> + basic_branch(T0 t0) : base_type(t0) { } + + template<typename T0, typename T1> + basic_branch(T0 t0, T1 t1) : base_type(t0, t1) { } + + template<typename T0, typename T1, typename T2> + basic_branch(T0 t0, T1 t1, T2 t2) : base_type(t0, t1, t2) { } + + template<typename T0, typename T1, typename T2, typename T3> + basic_branch(T0 t0, T1 t1, T2 t2, T3 t3) + : base_type(t0, t1, t2, t3) { } + + template<typename T0, typename T1, typename T2, typename T3, typename T4> + basic_branch(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) + : base_type(t0, t1, t2, t3, t4) { } + + template<typename T0, typename T1, typename T2, typename T3, typename T4, + typename T5> + basic_branch(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) + : base_type(t0, t1, t2, t3, t4, t5) { } + + template<typename T0, typename T1, typename T2, typename T3, typename T4, + typename T5, typename T6> + basic_branch(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) + : base_type(t0, t1, t2, t3, t4, t5, t6) { } + }; +#undef PB_DS_BRANCH_BASE + + +#define PB_DS_TREE_NODE_AND_IT_TRAITS \ + detail::tree_traits<Key, Mapped,Cmp_Fn,Node_Update,Tag,_Alloc> + +#define PB_DS_TREE_BASE \ + basic_branch<Key,Mapped, Tag, \ + typename PB_DS_TREE_NODE_AND_IT_TRAITS::node_update, \ + typename __gnu_cxx::typelist::create2<Cmp_Fn, \ + PB_DS_TREE_NODE_AND_IT_TRAITS>::type, _Alloc> + + + /** + * A tree-based container. + * + * @tparam Key Key type. + * @tparam Mapped Map type. + * @tparam Cmp_Fn Comparison functor. + * @tparam Tag Instantiating data structure type, + * see container_tag. + * @tparam Node_Update Updates tree internal-nodes, + * restores invariants when invalidated. + * XXX See design::tree-based-containers::node invariants. + * @tparam _Alloc Allocator type. + * + * Base tag choices are: ov_tree_tag, rb_tree_tag, splay_tree_tag. + * + * Base is basic_branch. + */ + template<typename Key, typename Mapped, typename Cmp_Fn = std::less<Key>, + typename Tag = rb_tree_tag, + template<typename Node_CItr, typename Node_Itr, + typename Cmp_Fn_, typename _Alloc_> + class Node_Update = null_node_update, + typename _Alloc = std::allocator<char> > + class tree : public PB_DS_TREE_BASE + { + private: + typedef PB_DS_TREE_BASE base_type; + + public: + /// Comparison functor type. + typedef Cmp_Fn cmp_fn; + + tree() { } + + /// Constructor taking some policy objects. r_cmp_fn will be + /// copied by the Cmp_Fn object of the container object. + tree(const cmp_fn& c) + : base_type(c) { } + + /// Constructor taking __iterators to a range of value_types. The + /// value_types between first_it and last_it will be inserted into + /// the container object. + template<typename It> + tree(It first, It last) + { base_type::copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects The value_types between first_it and + /// last_it will be inserted into the container object. r_cmp_fn + /// will be copied by the cmp_fn object of the container object. + template<typename It> + tree(It first, It last, const cmp_fn& c) + : base_type(c) + { base_type::copy_from_range(first, last); } + + tree(const tree& other) + : base_type((const base_type&)other) { } + + virtual + ~tree() { } + + tree& + operator=(const tree& other) + { + if (this != &other) + { + tree tmp(other); + swap(tmp); + } + return *this; + } + + void + swap(tree& other) + { base_type::swap(other); } + }; + +#undef PB_DS_TREE_BASE +#undef PB_DS_TREE_NODE_AND_IT_TRAITS + + +#define PB_DS_TRIE_NODE_AND_IT_TRAITS \ + detail::trie_traits<Key,Mapped,_ATraits,Node_Update,Tag,_Alloc> + +#define PB_DS_TRIE_BASE \ + basic_branch<Key,Mapped,Tag, \ + typename PB_DS_TRIE_NODE_AND_IT_TRAITS::node_update, \ + typename __gnu_cxx::typelist::create2<_ATraits, \ + PB_DS_TRIE_NODE_AND_IT_TRAITS >::type, _Alloc> + + + /** + * A trie-based container. + * + * @tparam Key Key type. + * @tparam Mapped Map type. + * @tparam _ATraits Element access traits. + * @tparam Tag Instantiating data structure type, + * see container_tag. + * @tparam Node_Update Updates trie internal-nodes, + * restores invariants when invalidated. + * XXX See design::tree-based-containers::node invariants. + * @tparam _Alloc Allocator type. + * + * Base tag choice is pat_trie_tag. + * + * Base is basic_branch. + */ + template<typename Key, + typename Mapped, + typename _ATraits = \ + typename detail::default_trie_access_traits<Key>::type, + typename Tag = pat_trie_tag, + template<typename Node_CItr, + typename Node_Itr, + typename _ATraits_, + typename _Alloc_> + class Node_Update = null_node_update, + typename _Alloc = std::allocator<char> > + class trie : public PB_DS_TRIE_BASE + { + private: + typedef PB_DS_TRIE_BASE base_type; + + public: + /// Element access traits type. + typedef _ATraits access_traits; + + trie() { } + + /// Constructor taking some policy objects. r_access_traits will + /// be copied by the _ATraits object of the container object. + trie(const access_traits& t) + : base_type(t) { } + + /// Constructor taking __iterators to a range of value_types. The + /// value_types between first_it and last_it will be inserted into + /// the container object. + template<typename It> + trie(It first, It last) + { base_type::copy_from_range(first, last); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects. The value_types between first_it and + /// last_it will be inserted into the container object. + template<typename It> + trie(It first, It last, const access_traits& t) + : base_type(t) + { base_type::copy_from_range(first, last); } + + trie(const trie& other) + : base_type((const base_type&)other) { } + + virtual + ~trie() { } + + trie& + operator=(const trie& other) + { + if (this != &other) + { + trie tmp(other); + swap(tmp); + } + return *this; + } + + void + swap(trie& other) + { base_type::swap(other); } + }; + //@} branch-based +#undef PB_DS_TRIE_BASE +#undef PB_DS_TRIE_NODE_AND_IT_TRAITS + + + /** + * @defgroup list-based List-Based + * @ingroup containers-pbds + * @{ + */ +#define PB_DS_LU_BASE \ + detail::container_base_dispatch<Key, Mapped, _Alloc, list_update_tag, \ + typename __gnu_cxx::typelist::create2<Eq_Fn, Update_Policy>::type>::type + + + /** + * A list-update based associative container. + * + * @tparam Key Key type. + * @tparam Mapped Map type. + * @tparam Eq_Fn Equal functor. + * @tparam Update_Policy Update policy, determines when an element + * will be moved to the front of the list. + * @tparam _Alloc Allocator type. + * + * Base is detail::lu_map. + */ + template<typename Key, + typename Mapped, + class Eq_Fn = typename detail::default_eq_fn<Key>::type, + class Update_Policy = detail::default_update_policy::type, + class _Alloc = std::allocator<char> > + class list_update : public PB_DS_LU_BASE + { + private: + typedef typename PB_DS_LU_BASE base_type; + + public: + typedef list_update_tag container_category; + typedef Eq_Fn eq_fn; + typedef Update_Policy update_policy; + + list_update() { } + + /// Constructor taking __iterators to a range of value_types. The + /// value_types between first_it and last_it will be inserted into + /// the container object. + template<typename It> + list_update(It first, It last) + { base_type::copy_from_range(first, last); } + + list_update(const list_update& other) + : base_type((const base_type&)other) { } + + virtual + ~list_update() { } + + list_update& + operator=(const list_update& other) + { + if (this !=& other) + { + list_update tmp(other); + swap(tmp); + } + return *this; + } + + void + swap(list_update& other) + { base_type::swap(other); } + }; + //@} list-based +#undef PB_DS_LU_BASE + + // @} group containers-pbds +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/bin_search_tree_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/bin_search_tree_.hpp new file mode 100644 index 0000000..da1e269 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/bin_search_tree_.hpp @@ -0,0 +1,428 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/bin_search_tree_.hpp + * Contains an implementation class for binary search tree. + */ + +#include <ext/pb_ds/exception.hpp> +#include <ext/pb_ds/tree_policy.hpp> +#include <ext/pb_ds/detail/eq_fn/eq_by_less.hpp> +#include <ext/pb_ds/detail/types_traits.hpp> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/tree_trace_base.hpp> +#ifdef _GLIBCXX_DEBUG +#include <ext/pb_ds/detail/debug_map_base.hpp> +#endif +#include <utility> +#include <functional> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#ifdef PB_DS_DATA_TRUE_INDICATOR +#define PB_DS_BIN_TREE_NAME bin_search_tree_map +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR +#define PB_DS_BIN_TREE_NAME bin_search_tree_set +#endif + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Mapped, typename Cmp_Fn, \ + typename Node_And_It_Traits, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + PB_DS_BIN_TREE_NAME<Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc> + +#define PB_DS_BIN_TREE_TRAITS_BASE \ + types_traits<Key, Mapped, _Alloc, false> + +#ifdef _GLIBCXX_DEBUG +#define PB_DS_DEBUG_MAP_BASE_C_DEC \ + debug_map_base<Key, eq_by_less<Key, Cmp_Fn>, \ + typename _Alloc::template rebind<Key>::other::const_reference> +#endif + +#ifdef PB_DS_TREE_TRACE +#define PB_DS_TREE_TRACE_BASE_C_DEC \ + tree_trace_base<typename Node_And_It_Traits::node_const_iterator, \ + typename Node_And_It_Traits::node_iterator, \ + Cmp_Fn, true, _Alloc> +#endif + + + /* + * @brief Binary search tree (BST). + * + * This implementation uses an idea from the SGI STL (using a @a + * header node which is needed for efficient iteration). + */ + template<typename Key, typename Mapped, typename Cmp_Fn, + typename Node_And_It_Traits, typename _Alloc> + class PB_DS_BIN_TREE_NAME : +#ifdef _GLIBCXX_DEBUG + public PB_DS_DEBUG_MAP_BASE_C_DEC, +#endif +#ifdef PB_DS_TREE_TRACE + public PB_DS_TREE_TRACE_BASE_C_DEC, +#endif + public Cmp_Fn, + public PB_DS_BIN_TREE_TRAITS_BASE, + public Node_And_It_Traits::node_update + { + typedef Node_And_It_Traits traits_type; + + protected: + typedef PB_DS_BIN_TREE_TRAITS_BASE traits_base; + + typedef + typename _Alloc::template rebind<typename traits_type::node>::other + node_allocator; + + typedef typename node_allocator::value_type node; + typedef typename node_allocator::pointer node_pointer; + + typedef typename traits_type::null_node_update_pointer + null_node_update_pointer; + + private: + typedef cond_dealtor<node, _Alloc> cond_dealtor_t; + +#ifdef _GLIBCXX_DEBUG + typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base; +#endif + + public: + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef typename traits_base::key_type key_type; + typedef typename traits_base::key_pointer key_pointer; + typedef typename traits_base::key_const_pointer key_const_pointer; + typedef typename traits_base::key_reference key_reference; + typedef typename traits_base::key_const_reference key_const_reference; + +#ifdef PB_DS_DATA_TRUE_INDICATOR + typedef typename traits_base::mapped_type mapped_type; + typedef typename traits_base::mapped_pointer mapped_pointer; + typedef typename traits_base::mapped_const_pointer mapped_const_pointer; + typedef typename traits_base::mapped_reference mapped_reference; + typedef typename traits_base::mapped_const_reference mapped_const_reference; +#endif + + typedef typename traits_base::value_type value_type; + typedef typename traits_base::pointer pointer; + typedef typename traits_base::const_pointer const_pointer; + typedef typename traits_base::reference reference; + typedef typename traits_base::const_reference const_reference; + typedef typename traits_type::point_const_iterator point_const_iterator; + + typedef point_const_iterator const_iterator; + typedef typename traits_type::point_iterator point_iterator; + typedef point_iterator iterator; + + typedef typename traits_type::const_reverse_iterator const_reverse_iterator; + + typedef typename traits_type::reverse_iterator reverse_iterator; + typedef typename traits_type::node_const_iterator node_const_iterator; + typedef typename traits_type::node_iterator node_iterator; + typedef typename traits_type::node_update node_update; + + typedef Cmp_Fn cmp_fn; + typedef _Alloc allocator_type; + + PB_DS_BIN_TREE_NAME(); + + PB_DS_BIN_TREE_NAME(const Cmp_Fn&); + + PB_DS_BIN_TREE_NAME(const Cmp_Fn&, const node_update&); + + PB_DS_BIN_TREE_NAME(const PB_DS_CLASS_C_DEC&); + + void + swap(PB_DS_CLASS_C_DEC&); + + ~PB_DS_BIN_TREE_NAME(); + + inline bool + empty() const; + + inline size_type + size() const; + + inline size_type + max_size() const; + + Cmp_Fn& + get_cmp_fn(); + + const Cmp_Fn& + get_cmp_fn() const; + + inline point_iterator + lower_bound(key_const_reference); + + inline point_const_iterator + lower_bound(key_const_reference) const; + + inline point_iterator + upper_bound(key_const_reference); + + inline point_const_iterator + upper_bound(key_const_reference) const; + + inline point_iterator + find(key_const_reference); + + inline point_const_iterator + find(key_const_reference) const; + + inline iterator + begin(); + + inline const_iterator + begin() const; + + inline iterator + end(); + + inline const_iterator + end() const; + + inline reverse_iterator + rbegin(); + + inline const_reverse_iterator + rbegin() const; + + inline reverse_iterator + rend(); + + inline const_reverse_iterator + rend() const; + + /// Returns a const node_iterator corresponding to the node at the + /// root of the tree. + inline node_const_iterator + node_begin() const; + + /// Returns a node_iterator corresponding to the node at the + /// root of the tree. + inline node_iterator + node_begin(); + + /// Returns a const node_iterator corresponding to a node just + /// after a leaf of the tree. + inline node_const_iterator + node_end() const; + + /// Returns a node_iterator corresponding to a node just + /// after a leaf of the tree. + inline node_iterator + node_end(); + + void + clear(); + + protected: + void + value_swap(PB_DS_CLASS_C_DEC&); + + void + initialize_min_max(); + + inline iterator + insert_imp_empty(const_reference); + + inline iterator + insert_leaf_new(const_reference, node_pointer, bool); + + inline node_pointer + get_new_node_for_leaf_insert(const_reference, false_type); + + inline node_pointer + get_new_node_for_leaf_insert(const_reference, true_type); + + inline void + actual_erase_node(node_pointer); + + inline std::pair<node_pointer, bool> + erase(node_pointer); + + inline void + update_min_max_for_erased_node(node_pointer); + + static void + clear_imp(node_pointer); + + inline std::pair<point_iterator, bool> + insert_leaf(const_reference); + + inline void + rotate_left(node_pointer); + + inline void + rotate_right(node_pointer); + + inline void + rotate_parent(node_pointer); + + inline void + apply_update(node_pointer, null_node_update_pointer); + + template<typename Node_Update_> + inline void + apply_update(node_pointer, Node_Update_*); + + inline void + update_to_top(node_pointer, null_node_update_pointer); + + template<typename Node_Update_> + inline void + update_to_top(node_pointer, Node_Update_*); + + bool + join_prep(PB_DS_CLASS_C_DEC&); + + void + join_finish(PB_DS_CLASS_C_DEC&); + + bool + split_prep(key_const_reference, PB_DS_CLASS_C_DEC&); + + void + split_finish(PB_DS_CLASS_C_DEC&); + + size_type + recursive_count(node_pointer) const; + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; + + void + structure_only_assert_valid(const char*, int) const; + + void + assert_node_consistent(const node_pointer, const char*, int) const; +#endif + + private: +#ifdef _GLIBCXX_DEBUG + void + assert_iterators(const char*, int) const; + + void + assert_consistent_with_debug_base(const char*, int) const; + + void + assert_node_consistent_with_left(const node_pointer, + const char*, int) const; + + void + assert_node_consistent_with_right(const node_pointer, + const char*, int) const; + + void + assert_consistent_with_debug_base(const node_pointer, + const char*, int) const; + + void + assert_min(const char*, int) const; + + void + assert_min_imp(const node_pointer, const char*, int) const; + + void + assert_max(const char*, int) const; + + void + assert_max_imp(const node_pointer, const char*, int) const; + + void + assert_size(const char*, int) const; + + typedef std::pair<const_pointer, const_pointer> node_consistent_t; + + node_consistent_t + assert_node_consistent_(const node_pointer, const char*, int) const; +#endif + + void + initialize(); + + node_pointer + recursive_copy_node(const node_pointer); + + protected: + node_pointer m_p_head; + size_type m_size; + static node_allocator s_node_allocator; + }; + +#define PB_DS_STRUCT_ONLY_ASSERT_VALID(X) \ + _GLIBCXX_DEBUG_ONLY(X.structure_only_assert_valid(__FILE__, __LINE__);) + +#define PB_DS_ASSERT_NODE_CONSISTENT(_Node) \ + _GLIBCXX_DEBUG_ONLY(assert_node_consistent(_Node, __FILE__, __LINE__);) + +#include <ext/pb_ds/detail/bin_search_tree_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/iterators_fn_imps.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/info_fn_imps.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/split_join_fn_imps.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/rotate_fn_imps.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/policy_access_fn_imps.hpp> + +#undef PB_DS_ASSERT_NODE_CONSISTENT +#undef PB_DS_STRUCT_ONLY_ASSERT_VALID +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_BIN_TREE_NAME +#undef PB_DS_BIN_TREE_TRAITS_BASE +#undef PB_DS_DEBUG_MAP_BASE_C_DEC + +#ifdef PB_DS_TREE_TRACE +#undef PB_DS_TREE_TRACE_BASE_C_DEC +#endif + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..27c2a46 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,218 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/constructors_destructor_fn_imps.hpp + * Contains an implementation class for bin_search_tree_. + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_allocator +PB_DS_CLASS_C_DEC::s_node_allocator; + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_BIN_TREE_NAME() : m_p_head(s_node_allocator.allocate(1)), m_size(0) +{ + initialize(); + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_BIN_TREE_NAME(const Cmp_Fn& r_cmp_fn) : + Cmp_Fn(r_cmp_fn), m_p_head(s_node_allocator.allocate(1)), m_size(0) +{ + initialize(); + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_BIN_TREE_NAME(const Cmp_Fn& r_cmp_fn, const node_update& r_node_update) : + Cmp_Fn(r_cmp_fn), + node_update(r_node_update), + m_p_head(s_node_allocator.allocate(1)), + m_size(0) +{ + initialize(); + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_BIN_TREE_NAME(const PB_DS_CLASS_C_DEC& other) : +#ifdef _GLIBCXX_DEBUG + debug_base(other), +#endif +#ifdef PB_DS_TREE_TRACE + PB_DS_TREE_TRACE_BASE_C_DEC(other), +#endif + Cmp_Fn(other), + node_update(other), + m_p_head(s_node_allocator.allocate(1)), + m_size(0) +{ + initialize(); + m_size = other.m_size; + PB_DS_STRUCT_ONLY_ASSERT_VALID(other) + + __try + { + m_p_head->m_p_parent = recursive_copy_node(other.m_p_head->m_p_parent); + if (m_p_head->m_p_parent != 0) + m_p_head->m_p_parent->m_p_parent = m_p_head; + m_size = other.m_size; + initialize_min_max(); + } + __catch(...) + { + _GLIBCXX_DEBUG_ONLY(debug_base::clear();) + s_node_allocator.deallocate(m_p_head, 1); + __throw_exception_again; + } + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + PB_DS_STRUCT_ONLY_ASSERT_VALID(other) + value_swap(other); + std::swap((Cmp_Fn& )(*this), (Cmp_Fn& )other); + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + PB_DS_STRUCT_ONLY_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +value_swap(PB_DS_CLASS_C_DEC& other) +{ + _GLIBCXX_DEBUG_ONLY(debug_base::swap(other);) + std::swap(m_p_head, other.m_p_head); + std::swap(m_size, other.m_size); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~PB_DS_BIN_TREE_NAME() +{ + clear(); + s_node_allocator.deallocate(m_p_head, 1); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +initialize() +{ + m_p_head->m_p_parent = 0; + m_p_head->m_p_left = m_p_head; + m_p_head->m_p_right = m_p_head; + m_size = 0; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +recursive_copy_node(const node_pointer p_nd) +{ + if (p_nd == 0) + return (0); + + node_pointer p_ret = s_node_allocator.allocate(1); + __try + { + new (p_ret) node(*p_nd); + } + __catch(...) + { + s_node_allocator.deallocate(p_ret, 1); + __throw_exception_again; + } + + p_ret->m_p_left = p_ret->m_p_right = 0; + + __try + { + p_ret->m_p_left = recursive_copy_node(p_nd->m_p_left); + p_ret->m_p_right = recursive_copy_node(p_nd->m_p_right); + } + __catch(...) + { + clear_imp(p_ret); + __throw_exception_again; + } + + if (p_ret->m_p_left != 0) + p_ret->m_p_left->m_p_parent = p_ret; + + if (p_ret->m_p_right != 0) + p_ret->m_p_right->m_p_parent = p_ret; + + PB_DS_ASSERT_NODE_CONSISTENT(p_ret) + return p_ret; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +initialize_min_max() +{ + if (m_p_head->m_p_parent == 0) + { + m_p_head->m_p_left = m_p_head->m_p_right = m_p_head; + return; + } + + { + node_pointer p_min = m_p_head->m_p_parent; + while (p_min->m_p_left != 0) + p_min = p_min->m_p_left; + m_p_head->m_p_left = p_min; + } + + { + node_pointer p_max = m_p_head->m_p_parent; + while (p_max->m_p_right != 0) + p_max = p_max->m_p_right; + m_p_head->m_p_right = p_max; + } +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/debug_fn_imps.hpp new file mode 100644 index 0000000..cd6fd6f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/debug_fn_imps.hpp @@ -0,0 +1,277 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/debug_fn_imps.hpp + * Contains an implementation class for bin_search_tree_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + structure_only_assert_valid(__file, __line); + assert_consistent_with_debug_base(__file, __line); + assert_size(__file, __line); + assert_iterators(__file, __line); + if (m_p_head->m_p_parent == 0) + { + PB_DS_DEBUG_VERIFY(m_size == 0); + } + else + { + PB_DS_DEBUG_VERIFY(m_size > 0); + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +structure_only_assert_valid(const char* __file, int __line) const +{ + PB_DS_DEBUG_VERIFY(m_p_head != 0); + if (m_p_head->m_p_parent == 0) + { + PB_DS_DEBUG_VERIFY(m_p_head->m_p_left == m_p_head); + PB_DS_DEBUG_VERIFY(m_p_head->m_p_right == m_p_head); + } + else + { + PB_DS_DEBUG_VERIFY(m_p_head->m_p_parent->m_p_parent == m_p_head); + PB_DS_DEBUG_VERIFY(m_p_head->m_p_left != m_p_head); + PB_DS_DEBUG_VERIFY(m_p_head->m_p_right != m_p_head); + } + + if (m_p_head->m_p_parent != 0) + assert_node_consistent(m_p_head->m_p_parent, __file, __line); + assert_min(__file, __line); + assert_max(__file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_node_consistent(const node_pointer p_nd, + const char* __file, int __line) const +{ + assert_node_consistent_(p_nd, __file, __line); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_consistent_t +PB_DS_CLASS_C_DEC:: +assert_node_consistent_(const node_pointer p_nd, + const char* __file, int __line) const +{ + if (p_nd == 0) + return (std::make_pair((const_pointer)0,(const_pointer)0)); + + assert_node_consistent_with_left(p_nd, __file, __line); + assert_node_consistent_with_right(p_nd, __file, __line); + + const std::pair<const_pointer, const_pointer> + l_range = assert_node_consistent_(p_nd->m_p_left, __file, __line); + + if (l_range.second != 0) + PB_DS_DEBUG_VERIFY(Cmp_Fn::operator()(PB_DS_V2F(*l_range.second), + PB_DS_V2F(p_nd->m_value))); + + const std::pair<const_pointer, const_pointer> + r_range = assert_node_consistent_(p_nd->m_p_right, __file, __line); + + if (r_range.first != 0) + PB_DS_DEBUG_VERIFY(Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), + PB_DS_V2F(*r_range.first))); + + return std::make_pair((l_range.first != 0) ? l_range.first : &p_nd->m_value, + (r_range.second != 0)? r_range.second : &p_nd->m_value); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_node_consistent_with_left(const node_pointer p_nd, + const char* __file, int __line) const +{ + if (p_nd->m_p_left == 0) + return; + PB_DS_DEBUG_VERIFY(p_nd->m_p_left->m_p_parent == p_nd); + PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), + PB_DS_V2F(p_nd->m_p_left->m_value))); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_node_consistent_with_right(const node_pointer p_nd, + const char* __file, int __line) const +{ + if (p_nd->m_p_right == 0) + return; + PB_DS_DEBUG_VERIFY(p_nd->m_p_right->m_p_parent == p_nd); + PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_p_right->m_value), + PB_DS_V2F(p_nd->m_value))); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_min(const char* __file, int __line) const +{ + assert_min_imp(m_p_head->m_p_parent, __file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_min_imp(const node_pointer p_nd, const char* __file, int __line) const +{ + if (p_nd == 0) + { + PB_DS_DEBUG_VERIFY(m_p_head->m_p_left == m_p_head); + return; + } + + if (p_nd->m_p_left == 0) + { + PB_DS_DEBUG_VERIFY(p_nd == m_p_head->m_p_left); + return; + } + assert_min_imp(p_nd->m_p_left, __file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_max(const char* __file, int __line) const +{ + assert_max_imp(m_p_head->m_p_parent, __file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_max_imp(const node_pointer p_nd, + const char* __file, int __line) const +{ + if (p_nd == 0) + { + PB_DS_DEBUG_VERIFY(m_p_head->m_p_right == m_p_head); + return; + } + + if (p_nd->m_p_right == 0) + { + PB_DS_DEBUG_VERIFY(p_nd == m_p_head->m_p_right); + return; + } + + assert_max_imp(p_nd->m_p_right, __file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_iterators(const char* __file, int __line) const +{ + size_type iterated_num = 0; + const_iterator prev_it = end(); + for (const_iterator it = begin(); it != end(); ++it) + { + ++iterated_num; + PB_DS_DEBUG_VERIFY(lower_bound(PB_DS_V2F(*it)).m_p_nd == it.m_p_nd); + const_iterator upper_bound_it = upper_bound(PB_DS_V2F(*it)); + --upper_bound_it; + PB_DS_DEBUG_VERIFY(upper_bound_it.m_p_nd == it.m_p_nd); + + if (prev_it != end()) + PB_DS_DEBUG_VERIFY(Cmp_Fn::operator()(PB_DS_V2F(*prev_it), + PB_DS_V2F(*it))); + prev_it = it; + } + + PB_DS_DEBUG_VERIFY(iterated_num == m_size); + size_type reverse_iterated_num = 0; + const_reverse_iterator reverse_prev_it = rend(); + for (const_reverse_iterator reverse_it = rbegin(); reverse_it != rend(); + ++reverse_it) + { + ++reverse_iterated_num; + PB_DS_DEBUG_VERIFY(lower_bound( + PB_DS_V2F(*reverse_it)).m_p_nd == reverse_it.m_p_nd); + + const_iterator upper_bound_it = upper_bound(PB_DS_V2F(*reverse_it)); + --upper_bound_it; + PB_DS_DEBUG_VERIFY(upper_bound_it.m_p_nd == reverse_it.m_p_nd); + if (reverse_prev_it != rend()) + PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(PB_DS_V2F(*reverse_prev_it), + PB_DS_V2F(*reverse_it))); + reverse_prev_it = reverse_it; + } + PB_DS_DEBUG_VERIFY(reverse_iterated_num == m_size); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_consistent_with_debug_base(const char* __file, int __line) const +{ + debug_base::check_size(m_size, __file, __line); + assert_consistent_with_debug_base(m_p_head->m_p_parent, __file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_consistent_with_debug_base(const node_pointer p_nd, + const char* __file, int __line) const +{ + if (p_nd == 0) + return; + debug_base::check_key_exists(PB_DS_V2F(p_nd->m_value), __file, __line); + assert_consistent_with_debug_base(p_nd->m_p_left, __file, __line); + assert_consistent_with_debug_base(p_nd->m_p_right, __file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_size(const char* __file, int __line) const +{ PB_DS_DEBUG_VERIFY(recursive_count(m_p_head->m_p_parent) == m_size); } + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/erase_fn_imps.hpp new file mode 100644 index 0000000..919b248 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/erase_fn_imps.hpp @@ -0,0 +1,103 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/erase_fn_imps.hpp + * Contains an implementation class for bin_search_tree_. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +actual_erase_node(node_pointer p_z) +{ + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + --m_size; + _GLIBCXX_DEBUG_ONLY(debug_base::erase_existing(PB_DS_V2F(p_z->m_value));) + p_z->~node(); + s_node_allocator.deallocate(p_z, 1); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +update_min_max_for_erased_node(node_pointer p_z) +{ + if (m_size == 1) + { + m_p_head->m_p_left = m_p_head->m_p_right = m_p_head; + return; + } + + if (m_p_head->m_p_left == p_z) + { + iterator it(p_z); + ++it; + m_p_head->m_p_left = it.m_p_nd; + } + else if (m_p_head->m_p_right == p_z) + { + iterator it(p_z); + --it; + m_p_head->m_p_right = it.m_p_nd; + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + clear_imp(m_p_head->m_p_parent); + m_size = 0; + initialize(); + _GLIBCXX_DEBUG_ONLY(debug_base::clear();) + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear_imp(node_pointer p_nd) +{ + if (p_nd == 0) + return; + + clear_imp(p_nd->m_p_left); + clear_imp(p_nd->m_p_right); + p_nd->~node(); + s_node_allocator.deallocate(p_nd, 1); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/find_fn_imps.hpp new file mode 100644 index 0000000..2b8d539 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/find_fn_imps.hpp @@ -0,0 +1,171 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/find_fn_imps.hpp + * Contains an implementation class for bin_search_tree_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +lower_bound(key_const_reference r_key) const +{ + node_pointer p_pot = m_p_head; + node_pointer p_nd = m_p_head->m_p_parent; + + while (p_nd != 0) + if (Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) + p_nd = p_nd->m_p_right; + else + { + p_pot = p_nd; + p_nd = p_nd->m_p_left; + } + return iterator(p_pot); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +lower_bound(key_const_reference r_key) +{ + node_pointer p_pot = m_p_head; + node_pointer p_nd = m_p_head->m_p_parent; + + while (p_nd != 0) + if (Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) + p_nd = p_nd->m_p_right; + else + { + p_pot = p_nd; + p_nd = p_nd->m_p_left; + } + return iterator(p_pot); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +upper_bound(key_const_reference r_key) const +{ + node_pointer p_pot = m_p_head; + node_pointer p_nd = m_p_head->m_p_parent; + + while (p_nd != 0) + if (Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value))) + { + p_pot = p_nd; + p_nd = p_nd->m_p_left; + } + else + p_nd = p_nd->m_p_right; + return const_iterator(p_pot); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +upper_bound(key_const_reference r_key) +{ + node_pointer p_pot = m_p_head; + node_pointer p_nd = m_p_head->m_p_parent; + + while (p_nd != 0) + if (Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value))) + { + p_pot = p_nd; + p_nd = p_nd->m_p_left; + } + else + p_nd = p_nd->m_p_right; + return point_iterator(p_pot); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +find(key_const_reference r_key) +{ + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + node_pointer p_pot = m_p_head; + node_pointer p_nd = m_p_head->m_p_parent; + + while (p_nd != 0) + if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) + { + p_pot = p_nd; + p_nd = p_nd->m_p_left; + } + else + p_nd = p_nd->m_p_right; + + node_pointer ret = p_pot; + if (p_pot != m_p_head) + { + const bool __cmp = Cmp_Fn::operator()(r_key, PB_DS_V2F(p_pot->m_value)); + if (__cmp) + ret = m_p_head; + } + return point_iterator(ret); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +find(key_const_reference r_key) const +{ + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + node_pointer p_pot = m_p_head; + node_pointer p_nd = m_p_head->m_p_parent; + + while (p_nd != 0) + if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) + { + p_pot = p_nd; + p_nd = p_nd->m_p_left; + } + else + p_nd = p_nd->m_p_right; + + node_pointer ret = p_pot; + if (p_pot != m_p_head) + { + const bool __cmp = Cmp_Fn::operator()(r_key, PB_DS_V2F(p_pot->m_value)); + if (__cmp) + ret = m_p_head; + } + return point_const_iterator(ret); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/info_fn_imps.hpp new file mode 100644 index 0000000..a3e4fff --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/info_fn_imps.hpp @@ -0,0 +1,64 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/info_fn_imps.hpp + * Contains an implementation class for bin_search_tree_. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +empty() const +{ + return (m_size == 0); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size() const +{ + return (m_size); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +max_size() const +{ + return (s_node_allocator.max_size()); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/insert_fn_imps.hpp new file mode 100644 index 0000000..409cfee --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/insert_fn_imps.hpp @@ -0,0 +1,180 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/insert_fn_imps.hpp + * Contains an implementation class for bin_search_tree_. + */ + +PB_DS_CLASS_T_DEC +inline std::pair<typename PB_DS_CLASS_C_DEC::point_iterator, bool> +PB_DS_CLASS_C_DEC:: +insert_leaf(const_reference r_value) +{ + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + + if (m_size == 0) + return std::make_pair(insert_imp_empty(r_value), + true); + + node_pointer p_nd = m_p_head->m_p_parent; + node_pointer p_pot = m_p_head; + + while (p_nd != 0) + if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), + PB_DS_V2F(r_value))) + { + p_pot = p_nd; + + p_nd = p_nd->m_p_left; + } + else + p_nd = p_nd->m_p_right; + + if (p_pot == m_p_head) + return std::make_pair(insert_leaf_new(r_value, m_p_head->m_p_right, false), + true); + + if (!Cmp_Fn::operator()(PB_DS_V2F(r_value), + PB_DS_V2F(p_pot->m_value))) + { + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + PB_DS_CHECK_KEY_EXISTS(PB_DS_V2F(r_value)) + return std::make_pair(p_pot, false); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(PB_DS_V2F(r_value)) + + p_nd = p_pot->m_p_left; + if (p_nd == 0) + return std::make_pair(insert_leaf_new(r_value, p_pot, true), + true); + + while (p_nd->m_p_right != 0) + p_nd = p_nd->m_p_right; + + return std::make_pair(insert_leaf_new(r_value, p_nd, false), + true); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +insert_leaf_new(const_reference r_value, node_pointer p_nd, bool left_nd) +{ + node_pointer p_new_nd = + get_new_node_for_leaf_insert(r_value, + traits_base::m_no_throw_copies_indicator); + + if (left_nd) + { + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_left == 0); + _GLIBCXX_DEBUG_ASSERT(Cmp_Fn::operator()(PB_DS_V2F(r_value), + PB_DS_V2F(p_nd->m_value))); + + p_nd->m_p_left = p_new_nd; + if (m_p_head->m_p_left == p_nd) + m_p_head->m_p_left = p_new_nd; + } + else + { + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_right == 0); + _GLIBCXX_DEBUG_ASSERT(Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), + PB_DS_V2F(r_value))); + + p_nd->m_p_right = p_new_nd; + if (m_p_head->m_p_right == p_nd) + m_p_head->m_p_right = p_new_nd; + } + + p_new_nd->m_p_parent = p_nd; + p_new_nd->m_p_left = p_new_nd->m_p_right = 0; + PB_DS_ASSERT_NODE_CONSISTENT(p_nd) + + update_to_top(p_new_nd, (node_update* )this); + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_value));) + return iterator(p_new_nd); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +insert_imp_empty(const_reference r_value) +{ + node_pointer p_new_node = + get_new_node_for_leaf_insert(r_value, traits_base::m_no_throw_copies_indicator); + + m_p_head->m_p_left = m_p_head->m_p_right = + m_p_head->m_p_parent = p_new_node; + + p_new_node->m_p_parent = m_p_head; + p_new_node->m_p_left = p_new_node->m_p_right = 0; + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_value));) + + update_to_top(m_p_head->m_p_parent, (node_update*)this); + return iterator(p_new_node); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +get_new_node_for_leaf_insert(const_reference r_val, false_type) +{ + node_pointer p_new_nd = s_node_allocator.allocate(1); + cond_dealtor_t cond(p_new_nd); + + new (const_cast<void* >(static_cast<const void* >(&p_new_nd->m_value))) + typename node::value_type(r_val); + + cond.set_no_action(); + p_new_nd->m_p_left = p_new_nd->m_p_right = 0; + ++m_size; + return p_new_nd; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +get_new_node_for_leaf_insert(const_reference r_val, true_type) +{ + node_pointer p_new_nd = s_node_allocator.allocate(1); + + new (const_cast<void* >(static_cast<const void* >(&p_new_nd->m_value))) + typename node::value_type(r_val); + + p_new_nd->m_p_left = p_new_nd->m_p_right = 0; + ++m_size; + return p_new_nd; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/iterators_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/iterators_fn_imps.hpp new file mode 100644 index 0000000..806ffcf --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/iterators_fn_imps.hpp @@ -0,0 +1,136 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/iterators_fn_imps.hpp + * Contains an implementation class for bin_search_tree_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +begin() +{ + return (iterator(m_p_head->m_p_left)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin() const +{ + return (const_iterator(m_p_head->m_p_left)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +end() +{ + return (iterator(m_p_head)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end() const +{ + return (const_iterator(m_p_head)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reverse_iterator +PB_DS_CLASS_C_DEC:: +rbegin() const +{ + return (const_reverse_iterator(m_p_head->m_p_right)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::reverse_iterator +PB_DS_CLASS_C_DEC:: +rbegin() +{ + return (reverse_iterator(m_p_head->m_p_right)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::reverse_iterator +PB_DS_CLASS_C_DEC:: +rend() +{ + return (reverse_iterator(m_p_head)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reverse_iterator +PB_DS_CLASS_C_DEC:: +rend() const +{ + return (const_reverse_iterator(m_p_head)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_const_iterator +PB_DS_CLASS_C_DEC:: +node_begin() const +{ + return (node_const_iterator(m_p_head->m_p_parent)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_iterator +PB_DS_CLASS_C_DEC:: +node_begin() +{ + return (node_iterator(m_p_head->m_p_parent)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_const_iterator +PB_DS_CLASS_C_DEC:: +node_end() const +{ + return (node_const_iterator(0)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_iterator +PB_DS_CLASS_C_DEC:: +node_end() +{ + return (node_iterator(0)); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/node_iterators.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/node_iterators.hpp new file mode 100644 index 0000000..77c826f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/node_iterators.hpp @@ -0,0 +1,189 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/node_iterators.hpp + * Contains an implementation class for bin_search_tree_. + */ + +#ifndef PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP +#define PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP + +#include <ext/pb_ds/tag_and_trait.hpp> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC \ + bin_search_tree_const_node_it_<Node, Const_Iterator, Iterator, _Alloc> + + /// Const node iterator. + template<typename Node, + class Const_Iterator, + class Iterator, + typename _Alloc> + class bin_search_tree_const_node_it_ + { + private: + typedef + typename _Alloc::template rebind< + Node>::other::pointer + node_pointer; + + public: + /// Category. + typedef trivial_iterator_tag iterator_category; + + /// Difference type. + typedef trivial_iterator_difference_type difference_type; + + /// Iterator's value type. + typedef Const_Iterator value_type; + + /// Iterator's reference type. + typedef Const_Iterator reference; + + /// Iterator's __const reference type. + typedef Const_Iterator const_reference; + + /// Metadata type. + typedef typename Node::metadata_type metadata_type; + + /// Const metadata reference type. + typedef + typename _Alloc::template rebind<metadata_type>::other::const_reference + metadata_const_reference; + + + bin_search_tree_const_node_it_(const node_pointer p_nd = 0) + : m_p_nd(const_cast<node_pointer>(p_nd)) + { } + + /// Access. + const_reference + operator*() const + { return Const_Iterator(m_p_nd); } + + /// Metadata access. + metadata_const_reference + get_metadata() const + { return m_p_nd->get_metadata(); } + + /// Returns the __const node iterator associated with the left node. + PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC + get_l_child() const + { return PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(m_p_nd->m_p_left); } + + /// Returns the __const node iterator associated with the right node. + PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC + get_r_child() const + { return PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(m_p_nd->m_p_right); } + + /// Compares to a different iterator object. + bool + operator==(const PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC& other) const + { return m_p_nd == other.m_p_nd; } + + /// Compares (negatively) to a different iterator object. + bool + operator!=(const PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC& other) const + { return m_p_nd != other.m_p_nd; } + + node_pointer m_p_nd; + }; + +#define PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC \ + bin_search_tree_node_it_<Node, Const_Iterator, Iterator, _Alloc> + + /// Node iterator. + template<typename Node, + class Const_Iterator, + class Iterator, + typename _Alloc> + class bin_search_tree_node_it_ + : public PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC + { + private: + typedef + typename _Alloc::template rebind< + Node>::other::pointer + node_pointer; + + public: + /// Iterator's value type. + typedef Iterator value_type; + + /// Iterator's reference type. + typedef Iterator reference; + + /// Iterator's __const reference type. + typedef Iterator const_reference; + + inline + bin_search_tree_node_it_(const node_pointer p_nd = 0) + : PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(const_cast<node_pointer>(p_nd)) + { } + + /// Access. + Iterator + operator*() const + { return Iterator(PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd); } + + /// Returns the node iterator associated with the left node. + PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC + get_l_child() const + { + return PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC( + PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd->m_p_left); + } + + /// Returns the node iterator associated with the right node. + PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC + get_r_child() const + { + return PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC( + PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd->m_p_right); + } + + }; + +#undef PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC +#undef PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC + + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/point_iterators.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/point_iterators.hpp new file mode 100644 index 0000000..9bc5caa --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/point_iterators.hpp @@ -0,0 +1,367 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/point_iterators.hpp + * Contains an implementation class for bin_search_tree_. + */ + +#ifndef PB_DS_BIN_SEARCH_TREE_FIND_ITERATORS_HPP +#define PB_DS_BIN_SEARCH_TREE_FIND_ITERATORS_HPP + +#include <ext/pb_ds/tag_and_trait.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { + +#define PB_DS_TREE_CONST_IT_C_DEC \ + bin_search_tree_const_it_< \ + Node_Pointer, \ + Value_Type, \ + Pointer, \ + Const_Pointer, \ + Reference, \ + Const_Reference, \ + Is_Forward_Iterator, \ + _Alloc> + +#define PB_DS_TREE_CONST_ODIR_IT_C_DEC \ + bin_search_tree_const_it_< \ + Node_Pointer, \ + Value_Type, \ + Pointer, \ + Const_Pointer, \ + Reference, \ + Const_Reference, \ + !Is_Forward_Iterator, \ + _Alloc> + +#define PB_DS_TREE_IT_C_DEC \ + bin_search_tree_it_< \ + Node_Pointer, \ + Value_Type, \ + Pointer, \ + Const_Pointer, \ + Reference, \ + Const_Reference, \ + Is_Forward_Iterator, \ + _Alloc> + +#define PB_DS_TREE_ODIR_IT_C_DEC \ + bin_search_tree_it_< \ + Node_Pointer, \ + Value_Type, \ + Pointer, \ + Const_Pointer, \ + Reference, \ + Const_Reference, \ + !Is_Forward_Iterator, \ + _Alloc> + + /// Const iterator. + template<typename Node_Pointer, + typename Value_Type, + typename Pointer, + typename Const_Pointer, + typename Reference, + typename Const_Reference, + bool Is_Forward_Iterator, + typename _Alloc> + class bin_search_tree_const_it_ + { + public: + typedef std::bidirectional_iterator_tag iterator_category; + typedef typename _Alloc::difference_type difference_type; + typedef Value_Type value_type; + typedef Pointer pointer; + typedef Const_Pointer const_pointer; + typedef Reference reference; + typedef Const_Reference const_reference; + + inline + bin_search_tree_const_it_(const Node_Pointer p_nd = 0) + : m_p_nd(const_cast<Node_Pointer>(p_nd)) + { } + + inline + bin_search_tree_const_it_(const PB_DS_TREE_CONST_ODIR_IT_C_DEC& other) + : m_p_nd(other.m_p_nd) + { } + + inline + PB_DS_TREE_CONST_IT_C_DEC& + operator=(const PB_DS_TREE_CONST_IT_C_DEC& other) + { + m_p_nd = other.m_p_nd; + return *this; + } + + inline + PB_DS_TREE_CONST_IT_C_DEC& + operator=(const PB_DS_TREE_CONST_ODIR_IT_C_DEC& other) + { + m_p_nd = other.m_p_nd; + return *this; + } + + inline const_pointer + operator->() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_nd != 0); + return &m_p_nd->m_value; + } + + inline const_reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_nd != 0); + return m_p_nd->m_value; + } + + inline bool + operator==(const PB_DS_TREE_CONST_IT_C_DEC & other) const + { return m_p_nd == other.m_p_nd; } + + inline bool + operator==(const PB_DS_TREE_CONST_ODIR_IT_C_DEC & other) const + { return m_p_nd == other.m_p_nd; } + + inline bool + operator!=(const PB_DS_TREE_CONST_IT_C_DEC& other) const + { return m_p_nd != other.m_p_nd; } + + inline bool + operator!=(const PB_DS_TREE_CONST_ODIR_IT_C_DEC& other) const + { return m_p_nd != other.m_p_nd; } + + inline PB_DS_TREE_CONST_IT_C_DEC& + operator++() + { + _GLIBCXX_DEBUG_ASSERT(m_p_nd != 0); + inc(integral_constant<int,Is_Forward_Iterator>()); + return *this; + } + + inline PB_DS_TREE_CONST_IT_C_DEC + operator++(int) + { + PB_DS_TREE_CONST_IT_C_DEC ret_it(m_p_nd); + operator++(); + return ret_it; + } + + inline PB_DS_TREE_CONST_IT_C_DEC& + operator--() + { + dec(integral_constant<int,Is_Forward_Iterator>()); + return *this; + } + + inline PB_DS_TREE_CONST_IT_C_DEC + operator--(int) + { + PB_DS_TREE_CONST_IT_C_DEC ret_it(m_p_nd); + operator--(); + return ret_it; + } + + protected: + inline void + inc(false_type) + { dec(true_type()); } + + void + inc(true_type) + { + if (m_p_nd->special()&& + m_p_nd->m_p_parent->m_p_parent == m_p_nd) + { + m_p_nd = m_p_nd->m_p_left; + return; + } + + if (m_p_nd->m_p_right != 0) + { + m_p_nd = m_p_nd->m_p_right; + while (m_p_nd->m_p_left != 0) + m_p_nd = m_p_nd->m_p_left; + return; + } + + Node_Pointer p_y = m_p_nd->m_p_parent; + while (m_p_nd == p_y->m_p_right) + { + m_p_nd = p_y; + p_y = p_y->m_p_parent; + } + + if (m_p_nd->m_p_right != p_y) + m_p_nd = p_y; + } + + inline void + dec(false_type) + { inc(true_type()); } + + void + dec(true_type) + { + if (m_p_nd->special() && m_p_nd->m_p_parent->m_p_parent == m_p_nd) + { + m_p_nd = m_p_nd->m_p_right; + return; + } + + if (m_p_nd->m_p_left != 0) + { + Node_Pointer p_y = m_p_nd->m_p_left; + while (p_y->m_p_right != 0) + p_y = p_y->m_p_right; + m_p_nd = p_y; + return; + } + + Node_Pointer p_y = m_p_nd->m_p_parent; + while (m_p_nd == p_y->m_p_left) + { + m_p_nd = p_y; + p_y = p_y->m_p_parent; + } + if (m_p_nd->m_p_left != p_y) + m_p_nd = p_y; + } + + public: + Node_Pointer m_p_nd; + }; + + /// Iterator. + template<typename Node_Pointer, + typename Value_Type, + typename Pointer, + typename Const_Pointer, + typename Reference, + typename Const_Reference, + bool Is_Forward_Iterator, + typename _Alloc> + class bin_search_tree_it_ : public PB_DS_TREE_CONST_IT_C_DEC + { + public: + inline + bin_search_tree_it_(const Node_Pointer p_nd = 0) + : PB_DS_TREE_CONST_IT_C_DEC((Node_Pointer)p_nd) + { } + + inline + bin_search_tree_it_(const PB_DS_TREE_ODIR_IT_C_DEC& other) + : PB_DS_TREE_CONST_IT_C_DEC(other.m_p_nd) + { } + + inline + PB_DS_TREE_IT_C_DEC& + operator=(const PB_DS_TREE_IT_C_DEC& other) + { + base_it_type::m_p_nd = other.m_p_nd; + return *this; + } + + inline + PB_DS_TREE_IT_C_DEC& + operator=(const PB_DS_TREE_ODIR_IT_C_DEC& other) + { + base_it_type::m_p_nd = other.m_p_nd; + return *this; + } + + inline typename PB_DS_TREE_CONST_IT_C_DEC::pointer + operator->() const + { + _GLIBCXX_DEBUG_ASSERT(base_it_type::m_p_nd != 0); + return &base_it_type::m_p_nd->m_value; + } + + inline typename PB_DS_TREE_CONST_IT_C_DEC::reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(base_it_type::m_p_nd != 0); + return base_it_type::m_p_nd->m_value; + } + + inline PB_DS_TREE_IT_C_DEC& + operator++() + { + PB_DS_TREE_CONST_IT_C_DEC:: operator++(); + return *this; + } + + inline PB_DS_TREE_IT_C_DEC + operator++(int) + { + PB_DS_TREE_IT_C_DEC ret_it(base_it_type::m_p_nd); + operator++(); + return ret_it; + } + + inline PB_DS_TREE_IT_C_DEC& + operator--() + { + PB_DS_TREE_CONST_IT_C_DEC:: operator--(); + return *this; + } + + inline PB_DS_TREE_IT_C_DEC + operator--(int) + { + PB_DS_TREE_IT_C_DEC ret_it(base_it_type::m_p_nd); + operator--(); + return ret_it; + } + + protected: + typedef PB_DS_TREE_CONST_IT_C_DEC base_it_type; + }; + +#undef PB_DS_TREE_CONST_IT_C_DEC +#undef PB_DS_TREE_CONST_ODIR_IT_C_DEC +#undef PB_DS_TREE_IT_C_DEC +#undef PB_DS_TREE_ODIR_IT_C_DEC + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/policy_access_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/policy_access_fn_imps.hpp new file mode 100644 index 0000000..e47b313 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/policy_access_fn_imps.hpp @@ -0,0 +1,52 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/policy_access_fn_imps.hpp + * Contains an implementation class for bin_search_tree_. + */ + +PB_DS_CLASS_T_DEC +Cmp_Fn& +PB_DS_CLASS_C_DEC:: +get_cmp_fn() +{ return (*this); } + +PB_DS_CLASS_T_DEC +const Cmp_Fn& +PB_DS_CLASS_C_DEC:: +get_cmp_fn() const +{ return (*this); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/r_erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/r_erase_fn_imps.hpp new file mode 100644 index 0000000..8bd0c7d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/r_erase_fn_imps.hpp @@ -0,0 +1,103 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/r_erase_fn_imps.hpp + * Contains an implementation class for bin_search_tree_. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +actual_erase_node(node_pointer p_z) +{ + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + --m_size; + _GLIBCXX_DEBUG_ONLY(erase_existing(PB_DS_V2F(p_z->m_value));) + p_z->~node(); + s_node_allocator.deallocate(p_z, 1); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +update_min_max_for_erased_node(node_pointer p_z) +{ + if (m_size == 1) + { + m_p_head->m_p_left = m_p_head->m_p_right = m_p_head; + return; + } + + if (m_p_head->m_p_left == p_z) + { + iterator it(p_z); + ++it; + m_p_head->m_p_left = it.m_p_nd; + } + else if (m_p_head->m_p_right == p_z) + { + iterator it(p_z); + --it; + m_p_head->m_p_right = it.m_p_nd; + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + clear_imp(m_p_head->m_p_parent); + m_size = 0; + initialize(); + _GLIBCXX_DEBUG_ONLY(debug_base::clear();) + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear_imp(node_pointer p_nd) +{ + if (p_nd == 0) + return; + + clear_imp(p_nd->m_p_left); + clear_imp(p_nd->m_p_right); + p_nd->~Node(); + s_node_allocator.deallocate(p_nd, 1); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/rotate_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/rotate_fn_imps.hpp new file mode 100644 index 0000000..355f484 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/rotate_fn_imps.hpp @@ -0,0 +1,155 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/rotate_fn_imps.hpp + * Contains imps for rotating nodes. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +rotate_left(node_pointer p_x) +{ + node_pointer p_y = p_x->m_p_right; + + p_x->m_p_right = p_y->m_p_left; + + if (p_y->m_p_left != 0) + p_y->m_p_left->m_p_parent = p_x; + + p_y->m_p_parent = p_x->m_p_parent; + + if (p_x == m_p_head->m_p_parent) + m_p_head->m_p_parent = p_y; + else if (p_x == p_x->m_p_parent->m_p_left) + p_x->m_p_parent->m_p_left = p_y; + else + p_x->m_p_parent->m_p_right = p_y; + + p_y->m_p_left = p_x; + p_x->m_p_parent = p_y; + + PB_DS_ASSERT_NODE_CONSISTENT(p_x) + PB_DS_ASSERT_NODE_CONSISTENT(p_y) + + apply_update(p_x, (node_update* )this); + apply_update(p_x->m_p_parent, (node_update* )this); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +rotate_right(node_pointer p_x) +{ + node_pointer p_y = p_x->m_p_left; + + p_x->m_p_left = p_y->m_p_right; + + if (p_y->m_p_right != 0) + p_y->m_p_right->m_p_parent = p_x; + + p_y->m_p_parent = p_x->m_p_parent; + + if (p_x == m_p_head->m_p_parent) + m_p_head->m_p_parent = p_y; + else if (p_x == p_x->m_p_parent->m_p_right) + p_x->m_p_parent->m_p_right = p_y; + else + p_x->m_p_parent->m_p_left = p_y; + + p_y->m_p_right = p_x; + p_x->m_p_parent = p_y; + + PB_DS_ASSERT_NODE_CONSISTENT(p_x) + PB_DS_ASSERT_NODE_CONSISTENT(p_y) + + apply_update(p_x, (node_update* )this); + apply_update(p_x->m_p_parent, (node_update* )this); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +rotate_parent(node_pointer p_nd) +{ + node_pointer p_parent = p_nd->m_p_parent; + + if (p_nd == p_parent->m_p_left) + rotate_right(p_parent); + else + rotate_left(p_parent); + + _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_parent = p_nd); + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_left == p_parent || + p_nd->m_p_right == p_parent); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +apply_update(node_pointer /*p_nd*/, null_node_update_pointer /*p_update*/) +{ } + +PB_DS_CLASS_T_DEC +template<typename Node_Update_> +inline void +PB_DS_CLASS_C_DEC:: +apply_update(node_pointer p_nd, Node_Update_* /*p_update*/) +{ + node_update::operator()(node_iterator(p_nd), + node_const_iterator(static_cast<node_pointer>(0))); +} + +PB_DS_CLASS_T_DEC +template<typename Node_Update_> +inline void +PB_DS_CLASS_C_DEC:: +update_to_top(node_pointer p_nd, Node_Update_* p_update) +{ + while (p_nd != m_p_head) + { + apply_update(p_nd, p_update); + + p_nd = p_nd->m_p_parent; + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +update_to_top(node_pointer /*p_nd*/, null_node_update_pointer /*p_update*/) +{ } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/split_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/split_join_fn_imps.hpp new file mode 100644 index 0000000..f4f5aac --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/split_join_fn_imps.hpp @@ -0,0 +1,150 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/split_join_fn_imps.hpp + * Contains an implementation class for bin_search_tree_. + */ + +PB_DS_CLASS_T_DEC +bool +PB_DS_CLASS_C_DEC:: +join_prep(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + if (other.m_size == 0) + return false; + + if (m_size == 0) + { + value_swap(other); + return false; + } + + const bool greater = + Cmp_Fn::operator()(PB_DS_V2F(m_p_head->m_p_right->m_value), + PB_DS_V2F(other.m_p_head->m_p_left->m_value)); + + const bool lesser = + Cmp_Fn::operator()(PB_DS_V2F(other.m_p_head->m_p_right->m_value), + PB_DS_V2F(m_p_head->m_p_left->m_value)); + + if (!greater && !lesser) + __throw_join_error(); + + if (lesser) + value_swap(other); + + m_size += other.m_size; + _GLIBCXX_DEBUG_ONLY(debug_base::join(other);) + return true; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +join_finish(PB_DS_CLASS_C_DEC& other) +{ + initialize_min_max(); + other.initialize(); +} + +PB_DS_CLASS_T_DEC +bool +PB_DS_CLASS_C_DEC:: +split_prep(key_const_reference r_key, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + other.clear(); + + if (m_size == 0) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return false; + } + + if (Cmp_Fn::operator()(r_key, PB_DS_V2F(m_p_head->m_p_left->m_value))) + { + value_swap(other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return false; + } + + if (!Cmp_Fn::operator()(r_key, PB_DS_V2F(m_p_head->m_p_right->m_value))) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return false; + } + + if (m_size == 1) + { + value_swap(other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return false; + } + + _GLIBCXX_DEBUG_ONLY(debug_base::split(r_key,(Cmp_Fn& )(*this), other);) + return true; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +split_finish(PB_DS_CLASS_C_DEC& other) +{ + other.initialize_min_max(); + other.m_size = std::distance(other.begin(), other.end()); + m_size -= other.m_size; + initialize_min_max(); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +recursive_count(node_pointer p) const +{ + if (p == 0) + return 0; + return 1 + recursive_count(p->m_p_left) + recursive_count(p->m_p_right); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/traits.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/traits.hpp new file mode 100644 index 0000000..d97b432 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/traits.hpp @@ -0,0 +1,241 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file bin_search_tree_/traits.hpp + * Contains an implementation for bin_search_tree_. + */ + +#ifndef PB_DS_BIN_SEARCH_TREE_NODE_AND_IT_TRAITS_HPP +#define PB_DS_BIN_SEARCH_TREE_NODE_AND_IT_TRAITS_HPP + +#include <ext/pb_ds/detail/bin_search_tree_/point_iterators.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/node_iterators.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /// Binary search tree traits, primary template + /// @ingroup traits + template<typename Key, + typename Mapped, + class Cmp_Fn, + template<typename Node_CItr, + class Node_Itr, + class Cmp_Fn, + typename _Alloc> + class Node_Update, + class Node, + typename _Alloc> + struct bin_search_tree_traits + { + private: + typedef types_traits<Key, Mapped, _Alloc, false> type_traits; + + public: + typedef Node node; + + typedef + bin_search_tree_const_it_< + typename _Alloc::template rebind< + node>::other::pointer, + typename type_traits::value_type, + typename type_traits::pointer, + typename type_traits::const_pointer, + typename type_traits::reference, + typename type_traits::const_reference, + true, + _Alloc> + point_const_iterator; + + typedef + bin_search_tree_it_< + typename _Alloc::template rebind< + node>::other::pointer, + typename type_traits::value_type, + typename type_traits::pointer, + typename type_traits::const_pointer, + typename type_traits::reference, + typename type_traits::const_reference, + true, + _Alloc> + point_iterator; + + typedef + bin_search_tree_const_it_< + typename _Alloc::template rebind< + node>::other::pointer, + typename type_traits::value_type, + typename type_traits::pointer, + typename type_traits::const_pointer, + typename type_traits::reference, + typename type_traits::const_reference, + false, + _Alloc> + const_reverse_iterator; + + typedef + bin_search_tree_it_< + typename _Alloc::template rebind< + node>::other::pointer, + typename type_traits::value_type, + typename type_traits::pointer, + typename type_traits::const_pointer, + typename type_traits::reference, + typename type_traits::const_reference, + false, + _Alloc> + reverse_iterator; + + /// This is an iterator to an iterator: it iterates over nodes, + /// and de-referencing it returns one of the tree's iterators. + typedef + bin_search_tree_const_node_it_< + Node, + point_const_iterator, + point_iterator, + _Alloc> + node_const_iterator; + + typedef + bin_search_tree_node_it_< + Node, + point_const_iterator, + point_iterator, + _Alloc> + node_iterator; + + typedef + Node_Update< + node_const_iterator, + node_iterator, + Cmp_Fn, + _Alloc> + node_update; + + typedef + __gnu_pbds::null_node_update< + node_const_iterator, + node_iterator, + Cmp_Fn, + _Alloc>* + null_node_update_pointer; + }; + + /// Specialization. + /// @ingroup traits + template<typename Key, + class Cmp_Fn, + template<typename Node_CItr, + class Node_Itr, + class Cmp_Fn, + typename _Alloc> + class Node_Update, + class Node, + typename _Alloc> + struct bin_search_tree_traits< + Key, + null_type, + Cmp_Fn, + Node_Update, + Node, + _Alloc> + { + private: + typedef types_traits<Key, null_type, _Alloc, false> type_traits; + + public: + typedef Node node; + + typedef + bin_search_tree_const_it_< + typename _Alloc::template rebind< + node>::other::pointer, + typename type_traits::value_type, + typename type_traits::pointer, + typename type_traits::const_pointer, + typename type_traits::reference, + typename type_traits::const_reference, + true, + _Alloc> + point_const_iterator; + + typedef point_const_iterator point_iterator; + + typedef + bin_search_tree_const_it_< + typename _Alloc::template rebind< + node>::other::pointer, + typename type_traits::value_type, + typename type_traits::pointer, + typename type_traits::const_pointer, + typename type_traits::reference, + typename type_traits::const_reference, + false, + _Alloc> + const_reverse_iterator; + + typedef const_reverse_iterator reverse_iterator; + + /// This is an iterator to an iterator: it iterates over nodes, + /// and de-referencing it returns one of the tree's iterators. + typedef + bin_search_tree_const_node_it_< + Node, + point_const_iterator, + point_iterator, + _Alloc> + node_const_iterator; + + typedef node_const_iterator node_iterator; + + typedef + Node_Update<node_const_iterator, node_iterator, Cmp_Fn, _Alloc> + node_update; + + typedef + __gnu_pbds::null_node_update< + node_const_iterator, + node_iterator, + Cmp_Fn, + _Alloc>* + null_node_update_pointer; + }; + + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_BIN_SEARCH_TREE_NODE_AND_IT_TRAITS_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/binary_heap_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/binary_heap_.hpp new file mode 100644 index 0000000..2d6842d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/binary_heap_.hpp @@ -0,0 +1,352 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/binary_heap_.hpp + * Contains an implementation class for a binary heap. + */ + +#ifndef PB_DS_BINARY_HEAP_HPP +#define PB_DS_BINARY_HEAP_HPP + +#include <queue> +#include <algorithm> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/binary_heap_/entry_cmp.hpp> +#include <ext/pb_ds/detail/binary_heap_/entry_pred.hpp> +#include <ext/pb_ds/detail/binary_heap_/resize_policy.hpp> +#include <ext/pb_ds/detail/binary_heap_/point_const_iterator.hpp> +#include <ext/pb_ds/detail/binary_heap_/const_iterator.hpp> +#ifdef PB_DS_BINARY_HEAP_TRACE_ +#include <iostream> +#endif +#include <ext/pb_ds/detail/type_utils.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + binary_heap<Value_Type, Cmp_Fn, _Alloc> + +#define PB_DS_ENTRY_CMP_DEC \ + entry_cmp<Value_Type, Cmp_Fn, _Alloc, is_simple<Value_Type>::value>::type + +#define PB_DS_RESIZE_POLICY_DEC \ + __gnu_pbds::detail::resize_policy<typename _Alloc::size_type> + + /** + * Binary heaps composed of resize and compare policies. + * + * @ingroup heap-detail + * + * Based on CLRS. + */ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + class binary_heap + : public PB_DS_ENTRY_CMP_DEC, public PB_DS_RESIZE_POLICY_DEC + { + public: + typedef Value_Type value_type; + typedef Cmp_Fn cmp_fn; + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef typename PB_DS_ENTRY_CMP_DEC entry_cmp; + typedef PB_DS_RESIZE_POLICY_DEC resize_policy; + typedef cond_dealtor<value_type, _Alloc> cond_dealtor_t; + + private: + enum + { + simple_value = is_simple<value_type>::value + }; + + typedef integral_constant<int, simple_value> no_throw_copies_t; + + typedef typename _Alloc::template rebind<value_type> __rebind_v; + typedef typename __rebind_v::other value_allocator; + + public: + typedef typename value_allocator::pointer pointer; + typedef typename value_allocator::const_pointer const_pointer; + typedef typename value_allocator::reference reference; + typedef typename value_allocator::const_reference const_reference; + + typedef typename __conditional_type<simple_value, + value_type, pointer>::__type + entry; + + typedef typename _Alloc::template rebind<entry>::other + entry_allocator; + + typedef typename entry_allocator::pointer entry_pointer; + + typedef binary_heap_point_const_iterator_<value_type, entry, + simple_value, _Alloc> + point_const_iterator; + + typedef point_const_iterator point_iterator; + + typedef binary_heap_const_iterator_<value_type, entry, + simple_value, _Alloc> + const_iterator; + + typedef const_iterator iterator; + + + binary_heap(); + + binary_heap(const cmp_fn&); + + binary_heap(const binary_heap&); + + void + swap(binary_heap&); + + ~binary_heap(); + + inline bool + empty() const; + + inline size_type + size() const; + + inline size_type + max_size() const; + + Cmp_Fn& + get_cmp_fn(); + + const Cmp_Fn& + get_cmp_fn() const; + + inline point_iterator + push(const_reference); + + void + modify(point_iterator, const_reference); + + inline const_reference + top() const; + + inline void + pop(); + + inline void + erase(point_iterator); + + template<typename Pred> + size_type + erase_if(Pred); + + inline void + erase_at(entry_pointer, size_type, false_type); + + inline void + erase_at(entry_pointer, size_type, true_type); + + inline iterator + begin(); + + inline const_iterator + begin() const; + + inline iterator + end(); + + inline const_iterator + end() const; + + void + clear(); + + template<typename Pred> + void + split(Pred, binary_heap&); + + void + join(binary_heap&); + +#ifdef PB_DS_BINARY_HEAP_TRACE_ + void + trace() const; +#endif + + protected: + template<typename It> + void + copy_from_range(It, It); + + private: + void + value_swap(binary_heap&); + + inline void + insert_value(const_reference, false_type); + + inline void + insert_value(value_type, true_type); + + inline void + resize_for_insert_if_needed(); + + inline void + swap_value_imp(entry_pointer, value_type, true_type); + + inline void + swap_value_imp(entry_pointer, const_reference, false_type); + + void + fix(entry_pointer); + + inline const_reference + top_imp(true_type) const; + + inline const_reference + top_imp(false_type) const; + + inline static size_type + left_child(size_type); + + inline static size_type + right_child(size_type); + + inline static size_type + parent(size_type); + + inline void + resize_for_erase_if_needed(); + + template<typename Pred> + size_type + partition(Pred); + + void + make_heap() + { + const entry_cmp& m_cmp = static_cast<entry_cmp&>(*this); + entry_pointer end = m_a_entries + m_size; + std::make_heap(m_a_entries, end, m_cmp); + _GLIBCXX_DEBUG_ASSERT(is_heap()); + } + + void + push_heap() + { + if (!is_heap()) + make_heap(); + else + { + const entry_cmp& m_cmp = static_cast<entry_cmp&>(*this); + entry_pointer end = m_a_entries + m_size; + std::push_heap(m_a_entries, end, m_cmp); + } + } + + void + pop_heap() + { + const entry_cmp& m_cmp = static_cast<entry_cmp&>(*this); + entry_pointer end = m_a_entries + m_size; + std::pop_heap(m_a_entries, end, m_cmp); + } + + bool + is_heap() + { + const entry_cmp& m_cmp = static_cast<entry_cmp&>(*this); + entry_pointer end = m_a_entries + m_size; + bool p = std::__is_heap(m_a_entries, end, m_cmp); + return p; + } + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; +#endif + +#ifdef PB_DS_BINARY_HEAP_TRACE_ + void + trace_entry(const entry&, false_type) const; + + void + trace_entry(const entry&, true_type) const; +#endif + + static entry_allocator s_entry_allocator; + static value_allocator s_value_allocator; + static no_throw_copies_t s_no_throw_copies_ind; + + size_type m_size; + size_type m_actual_size; + entry_pointer m_a_entries; + }; + +#define PB_DS_ASSERT_VALID(X) \ + _GLIBCXX_DEBUG_ONLY(X.assert_valid(__FILE__, __LINE__);) + +#define PB_DS_DEBUG_VERIFY(_Cond) \ + _GLIBCXX_DEBUG_VERIFY_AT(_Cond, \ + _M_message(#_Cond" assertion from %1;:%2;") \ + ._M_string(__FILE__)._M_integer(__LINE__) \ + ,__file,__line) + +#include <ext/pb_ds/detail/binary_heap_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/binary_heap_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/binary_heap_/iterators_fn_imps.hpp> +#include <ext/pb_ds/detail/binary_heap_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/binary_heap_/trace_fn_imps.hpp> +#include <ext/pb_ds/detail/binary_heap_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/binary_heap_/info_fn_imps.hpp> +#include <ext/pb_ds/detail/binary_heap_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/binary_heap_/split_join_fn_imps.hpp> +#include <ext/pb_ds/detail/binary_heap_/policy_access_fn_imps.hpp> + +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_ENTRY_CMP_DEC +#undef PB_DS_RESIZE_POLICY_DEC + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/const_iterator.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/const_iterator.hpp new file mode 100644 index 0000000..0f41db0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/const_iterator.hpp @@ -0,0 +1,139 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/const_iterator.hpp + * Contains an iterator class returned by the table's const find and insert + * methods. + */ + +#ifndef PB_DS_BINARY_HEAP_CONST_ITERATOR_HPP +#define PB_DS_BINARY_HEAP_CONST_ITERATOR_HPP + +#include <ext/pb_ds/detail/binary_heap_/point_const_iterator.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_BIN_HEAP_CIT_BASE \ + binary_heap_point_const_iterator_<Value_Type, Entry, Simple, _Alloc> + + /// Const point-type iterator. + template<typename Value_Type, + typename Entry, + bool Simple, + typename _Alloc> + class binary_heap_const_iterator_ : public PB_DS_BIN_HEAP_CIT_BASE + { + private: + typedef PB_DS_BIN_HEAP_CIT_BASE base_type; + typedef typename base_type::entry_pointer entry_pointer; + + public: + /// Category. + typedef std::forward_iterator_tag iterator_category; + + /// Difference type. + typedef typename _Alloc::difference_type difference_type; + + /// Iterator's value type. + typedef typename base_type::value_type value_type; + + /// Iterator's pointer type. + typedef typename base_type::pointer pointer; + + /// Iterator's const pointer type. + typedef typename base_type::const_pointer const_pointer; + + /// Iterator's reference type. + typedef typename base_type::reference reference; + + /// Iterator's const reference type. + typedef typename base_type::const_reference const_reference; + + inline + binary_heap_const_iterator_(entry_pointer p_e) : base_type(p_e) + { } + + /// Default constructor. + inline + binary_heap_const_iterator_() + { } + + /// Copy constructor. + inline + binary_heap_const_iterator_(const binary_heap_const_iterator_& other) + : base_type(other) + { } + + /// Compares content to a different iterator object. + inline bool + operator==(const binary_heap_const_iterator_& other) const + { return base_type::m_p_e == other.m_p_e; } + + /// Compares content (negatively) to a different iterator object. + inline bool + operator!=(const binary_heap_const_iterator_& other) const + { return base_type::m_p_e != other.m_p_e; } + + inline binary_heap_const_iterator_& + operator++() + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_p_e != 0); + inc(); + return *this; + } + + inline binary_heap_const_iterator_ + operator++(int) + { + binary_heap_const_iterator_ ret_it(base_type::m_p_e); + operator++(); + return ret_it; + } + + private: + void + inc() + { ++base_type::m_p_e; } + }; + +#undef PB_DS_BIN_HEAP_CIT_BASE + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..b3aef0e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,139 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/constructors_destructor_fn_imps.hpp + * Contains an implementation class for binary_heap_. + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::entry_allocator +PB_DS_CLASS_C_DEC::s_entry_allocator; + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::value_allocator +PB_DS_CLASS_C_DEC::s_value_allocator; + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::no_throw_copies_t +PB_DS_CLASS_C_DEC::s_no_throw_copies_ind; + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + { + insert_value(*first_it, s_no_throw_copies_ind); + ++first_it; + } + make_heap(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +binary_heap() +: m_size(0), m_actual_size(resize_policy::min_size), + m_a_entries(s_entry_allocator.allocate(m_actual_size)) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +binary_heap(const Cmp_Fn& r_cmp_fn) +: entry_cmp(r_cmp_fn), m_size(0), m_actual_size(resize_policy::min_size), + m_a_entries(s_entry_allocator.allocate(m_actual_size)) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +binary_heap(const PB_DS_CLASS_C_DEC& other) +: entry_cmp(other), resize_policy(other), m_size(0), + m_actual_size(other.m_actual_size), + m_a_entries(s_entry_allocator.allocate(m_actual_size)) +{ + PB_DS_ASSERT_VALID(other) + _GLIBCXX_DEBUG_ASSERT(m_a_entries != other.m_a_entries); + + __try + { + copy_from_range(other.begin(), other.end()); + } + __catch(...) + { + for (size_type i = 0; i < m_size; ++i) + erase_at(m_a_entries, i, s_no_throw_copies_ind); + + s_entry_allocator.deallocate(m_a_entries, m_actual_size); + __throw_exception_again; + } + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + _GLIBCXX_DEBUG_ASSERT(m_a_entries != other.m_a_entries); + value_swap(other); + std::swap((entry_cmp&)(*this), (entry_cmp&)other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +value_swap(PB_DS_CLASS_C_DEC& other) +{ + std::swap(m_a_entries, other.m_a_entries); + std::swap(m_size, other.m_size); + std::swap(m_actual_size, other.m_actual_size); + static_cast<resize_policy*>(this)->swap(other); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~binary_heap() +{ + for (size_type i = 0; i < m_size; ++i) + erase_at(m_a_entries, i, s_no_throw_copies_ind); + s_entry_allocator.deallocate(m_a_entries, m_actual_size); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/debug_fn_imps.hpp new file mode 100644 index 0000000..b9c645c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/debug_fn_imps.hpp @@ -0,0 +1,72 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/debug_fn_imps.hpp + * Contains an implementation class for a binary_heap. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ +#ifdef PB_DS_REGRESSION + s_entry_allocator.check_allocated(m_a_entries, m_actual_size); +#endif + + resize_policy::assert_valid(__file, __line); + PB_DS_DEBUG_VERIFY(m_size <= m_actual_size); + for (size_type i = 0; i < m_size; ++i) + { +#ifdef PB_DS_REGRESSION + s_value_allocator.check_allocated(m_a_entries[i], 1); +#endif + + if (left_child(i) < m_size) + PB_DS_DEBUG_VERIFY(!entry_cmp::operator()(m_a_entries[i], m_a_entries[left_child(i)])); + + PB_DS_DEBUG_VERIFY(parent(left_child(i)) == i); + + if (right_child(i) < m_size) + PB_DS_DEBUG_VERIFY(!entry_cmp::operator()(m_a_entries[i], m_a_entries[right_child(i)])); + + PB_DS_DEBUG_VERIFY(parent(right_child(i)) == i); + } +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/entry_cmp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/entry_cmp.hpp new file mode 100644 index 0000000..3908206 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/entry_cmp.hpp @@ -0,0 +1,85 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/entry_cmp.hpp + * Contains an implementation class for a binary_heap. + */ + +#ifndef PB_DS_BINARY_HEAP_ENTRY_CMP_HPP +#define PB_DS_BINARY_HEAP_ENTRY_CMP_HPP + +namespace __gnu_pbds +{ + namespace detail + { + /// Entry compare, primary template. + template<typename _VTp, typename Cmp_Fn, typename _Alloc, bool No_Throw> + struct entry_cmp; + + /// Specialization, true. + template<typename _VTp, typename Cmp_Fn, typename _Alloc> + struct entry_cmp<_VTp, Cmp_Fn, _Alloc, true> + { + /// Compare. + typedef Cmp_Fn type; + }; + + /// Specialization, false. + template<typename _VTp, typename Cmp_Fn, typename _Alloc> + struct entry_cmp<_VTp, Cmp_Fn, _Alloc, false> + { + private: + typedef typename _Alloc::template rebind<_VTp> __rebind_v; + + public: + typedef typename __rebind_v::other::const_pointer entry; + + /// Compare plus entry. + struct type : public Cmp_Fn + { + type() { } + + type(const Cmp_Fn& other) : Cmp_Fn(other) { } + + bool + operator()(entry lhs, entry rhs) const + { return Cmp_Fn::operator()(*lhs, *rhs); } + }; + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_BINARY_HEAP_ENTRY_CMP_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/entry_pred.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/entry_pred.hpp new file mode 100644 index 0000000..660c18a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/entry_pred.hpp @@ -0,0 +1,85 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/entry_pred.hpp + * Contains an implementation class for a binary_heap. + */ + +#ifndef PB_DS_BINARY_HEAP_ENTRY_PRED_HPP +#define PB_DS_BINARY_HEAP_ENTRY_PRED_HPP + +namespace __gnu_pbds +{ + namespace detail + { + /// Entry predicate primary class template. + template<typename _VTp, typename Pred, typename _Alloc, bool No_Throw> + struct entry_pred; + + /// Specialization, true. + template<typename _VTp, typename Pred, typename _Alloc> + struct entry_pred<_VTp, Pred, _Alloc, true> + { + typedef Pred type; + }; + + /// Specialization, false. + template<typename _VTp, typename Pred, typename _Alloc> + struct entry_pred<_VTp, Pred, _Alloc, false> + { + private: + typedef typename _Alloc::template rebind<_VTp> __rebind_v; + + public: + typedef typename __rebind_v::other::const_pointer entry; + + struct type : public Pred + { + inline + type() { } + + inline + type(const Pred& other) : Pred(other) { } + + inline bool + operator()(entry p_v) const + { return Pred::operator()(*p_v); } + }; + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_BINARY_HEAP_ENTRY_PRED_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/erase_fn_imps.hpp new file mode 100644 index 0000000..3fcf6c8 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/erase_fn_imps.hpp @@ -0,0 +1,208 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/erase_fn_imps.hpp + * Contains an implementation class for a binary_heap. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + for (size_type i = 0; i < m_size; ++i) + erase_at(m_a_entries, i, s_no_throw_copies_ind); + + __try + { + const size_type new_size = resize_policy::get_new_size_for_arbitrary(0); + entry_pointer new_entries = s_entry_allocator.allocate(new_size); + resize_policy::notify_arbitrary(new_size); + s_entry_allocator.deallocate(m_a_entries, m_actual_size); + m_actual_size = new_size; + m_a_entries = new_entries; + } + __catch(...) + { } + + m_size = 0; + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase_at(entry_pointer a_entries, size_type i, false_type) +{ + a_entries[i]->~value_type(); + s_value_allocator.deallocate(a_entries[i], 1); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase_at(entry_pointer, size_type, true_type) +{ } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +pop() +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!empty()); + + pop_heap(); + erase_at(m_a_entries, m_size - 1, s_no_throw_copies_ind); + resize_for_erase_if_needed(); + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + --m_size; + + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + PB_DS_ASSERT_VALID((*this)) + + typedef typename entry_pred<value_type, Pred, _Alloc, simple_value>::type + pred_t; + + const size_type left = partition(pred_t(pred)); + _GLIBCXX_DEBUG_ASSERT(m_size >= left); + const size_type ersd = m_size - left; + for (size_type i = left; i < m_size; ++i) + erase_at(m_a_entries, i, s_no_throw_copies_ind); + + __try + { + const size_type new_size = + resize_policy::get_new_size_for_arbitrary(left); + + entry_pointer new_entries = s_entry_allocator.allocate(new_size); + std::copy(m_a_entries, m_a_entries + left, new_entries); + s_entry_allocator.deallocate(m_a_entries, m_actual_size); + m_actual_size = new_size; + resize_policy::notify_arbitrary(m_actual_size); + } + __catch(...) + { }; + + m_size = left; + make_heap(); + PB_DS_ASSERT_VALID((*this)) + return ersd; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +erase(point_iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!empty()); + + const size_type fix_pos = it.m_p_e - m_a_entries; + std::swap(*it.m_p_e, m_a_entries[m_size - 1]); + erase_at(m_a_entries, m_size - 1, s_no_throw_copies_ind); + resize_for_erase_if_needed(); + + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + --m_size; + _GLIBCXX_DEBUG_ASSERT(fix_pos <= m_size); + + if (fix_pos != m_size) + fix(m_a_entries + fix_pos); + + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +resize_for_erase_if_needed() +{ + if (!resize_policy::resize_needed_for_shrink(m_size)) + return; + + __try + { + const size_type new_size = resize_policy::get_new_size_for_shrink(); + entry_pointer new_entries = s_entry_allocator.allocate(new_size); + resize_policy::notify_shrink_resize(); + + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + std::copy(m_a_entries, m_a_entries + m_size - 1, new_entries); + s_entry_allocator.deallocate(m_a_entries, m_actual_size); + m_actual_size = new_size; + m_a_entries = new_entries; + } + __catch(...) + { } +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +partition(Pred pred) +{ + size_type left = 0; + size_type right = m_size - 1; + + while (right + 1 != left) + { + _GLIBCXX_DEBUG_ASSERT(left <= m_size); + + if (!pred(m_a_entries[left])) + ++left; + else if (pred(m_a_entries[right])) + --right; + else + { + _GLIBCXX_DEBUG_ASSERT(left < right); + std::swap(m_a_entries[left], m_a_entries[right]); + ++left; + --right; + } + } + + return left; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/find_fn_imps.hpp new file mode 100644 index 0000000..3f61fe3 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/find_fn_imps.hpp @@ -0,0 +1,79 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/find_fn_imps.hpp + * Contains an implementation class for a binary_heap. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reference +PB_DS_CLASS_C_DEC:: +top() const +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!empty()); + return top_imp(s_no_throw_copies_ind); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reference +PB_DS_CLASS_C_DEC:: +top_imp(true_type) const +{ return *m_a_entries; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reference +PB_DS_CLASS_C_DEC:: +top_imp(false_type) const +{ return **m_a_entries; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +left_child(size_type i) +{ return i * 2 + 1; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +right_child(size_type i) +{ return i * 2 + 2; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +parent(size_type i) +{ return (i - 1) / 2; } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/info_fn_imps.hpp new file mode 100644 index 0000000..2f6584f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/info_fn_imps.hpp @@ -0,0 +1,58 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/info_fn_imps.hpp + * Contains an implementation class for a binary_heap. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +empty() const +{ return m_size == 0; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size() const +{ return m_size; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +max_size() const +{ return s_entry_allocator.max_size(); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/insert_fn_imps.hpp new file mode 100644 index 0000000..8ade3a9 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/insert_fn_imps.hpp @@ -0,0 +1,174 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/insert_fn_imps.hpp + * Contains an implementation class for a binary_heap. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +push(const_reference r_val) +{ + PB_DS_ASSERT_VALID((*this)) + insert_value(r_val, s_no_throw_copies_ind); + push_heap(); + PB_DS_ASSERT_VALID((*this)) + return point_iterator(m_a_entries); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +insert_value(value_type val, true_type) +{ + resize_for_insert_if_needed(); + m_a_entries[m_size++] = val; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +insert_value(const_reference r_val, false_type) +{ + resize_for_insert_if_needed(); + pointer p_new = s_value_allocator.allocate(1); + cond_dealtor_t cond(p_new); + new (p_new) value_type(r_val); + cond.set_no_action(); + m_a_entries[m_size++] = p_new; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +resize_for_insert_if_needed() +{ + if (!resize_policy::resize_needed_for_grow(m_size)) + { + _GLIBCXX_DEBUG_ASSERT(m_size < m_actual_size); + return; + } + + const size_type new_size = resize_policy::get_new_size_for_grow(); + entry_pointer new_entries = s_entry_allocator.allocate(new_size); + resize_policy::notify_grow_resize(); + + std::copy(m_a_entries, m_a_entries + m_size, new_entries); + s_entry_allocator.deallocate(m_a_entries, m_actual_size); + m_actual_size = new_size; + m_a_entries = new_entries; + make_heap(); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +modify(point_iterator it, const_reference r_new_val) +{ + PB_DS_ASSERT_VALID((*this)) + swap_value_imp(it.m_p_e, r_new_val, s_no_throw_copies_ind); + fix(it.m_p_e); + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(is_heap()); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +fix(entry_pointer p_e) +{ + size_type i = p_e - m_a_entries; + if (i > 0 && entry_cmp::operator()(m_a_entries[parent(i)], m_a_entries[i])) + { + size_type parent_i = parent(i); + while (i > 0 + && entry_cmp::operator()(m_a_entries[parent_i], m_a_entries[i])) + { + std::swap(m_a_entries[i], m_a_entries[parent_i]); + i = parent_i; + parent_i = parent(i); + } + + PB_DS_ASSERT_VALID((*this)) + return; + } + + while (i < m_size) + { + const size_type lchild_i = left_child(i); + const size_type rchild_i = right_child(i); + _GLIBCXX_DEBUG_ASSERT(rchild_i > lchild_i); + + const bool smaller_than_lchild = lchild_i < m_size && + entry_cmp::operator()(m_a_entries[i], m_a_entries[lchild_i]); + + const bool smaller_than_rchild = rchild_i < m_size && + entry_cmp::operator()(m_a_entries[i], m_a_entries[rchild_i]); + + const bool swap_with_rchild = smaller_than_rchild && (!smaller_than_lchild || entry_cmp::operator()(m_a_entries[lchild_i], m_a_entries[rchild_i])); + + const bool swap_with_lchild = !swap_with_rchild && smaller_than_lchild; + + if (swap_with_lchild) + { + std::swap(m_a_entries[i], m_a_entries[lchild_i]); + i = lchild_i; + } + else if (swap_with_rchild) + { + std::swap(m_a_entries[i], m_a_entries[rchild_i]); + i = rchild_i; + } + else + i = m_size; + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +swap_value_imp(entry_pointer p_e, value_type new_val, true_type) +{ *p_e = new_val; } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +swap_value_imp(entry_pointer p_e, const_reference r_new_val, false_type) +{ + value_type tmp(r_new_val); + (*p_e)->swap(tmp); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/iterators_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/iterators_fn_imps.hpp new file mode 100644 index 0000000..35dd014 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/iterators_fn_imps.hpp @@ -0,0 +1,64 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/iterators_fn_imps.hpp + * Contains an implementation class for a binary_heap. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +begin() +{ return iterator(m_a_entries); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin() const +{ return const_iterator(m_a_entries); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +end() +{ return iterator(m_a_entries + m_size); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end() const +{ return const_iterator(m_a_entries + m_size); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/point_const_iterator.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/point_const_iterator.hpp new file mode 100644 index 0000000..f16a001 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/point_const_iterator.hpp @@ -0,0 +1,144 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/point_const_iterator.hpp + * Contains an iterator class returned by the table's const find and insert + * methods. + */ + +#ifndef PB_DS_BINARY_HEAP_CONST_FIND_ITERATOR_HPP +#define PB_DS_BINARY_HEAP_CONST_FIND_ITERATOR_HPP + +#include <ext/pb_ds/tag_and_trait.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { + /// Const point-type iterator. + template<typename Value_Type, typename Entry, bool Simple, + typename _Alloc> + class binary_heap_point_const_iterator_ + { + protected: + typedef typename _Alloc::template rebind<Entry>::other::pointer entry_pointer; + + public: + /// Category. + typedef trivial_iterator_tag iterator_category; + + /// Difference type. + typedef trivial_iterator_difference_type difference_type; + + /// Iterator's value type. + typedef Value_Type value_type; + + /// Iterator's pointer type. + typedef typename _Alloc::template rebind<value_type>::other::pointer + pointer; + + /// Iterator's const pointer type. + typedef + typename _Alloc::template rebind<value_type>::other::const_pointer + const_pointer; + + /// Iterator's reference type. + typedef + typename _Alloc::template rebind<value_type>::other::reference + reference; + + /// Iterator's const reference type. + typedef + typename _Alloc::template rebind<value_type>::other::const_reference + const_reference; + + inline + binary_heap_point_const_iterator_(entry_pointer p_e) : m_p_e(p_e) + { } + + /// Default constructor. + inline + binary_heap_point_const_iterator_() : m_p_e(0) { } + + /// Copy constructor. + inline + binary_heap_point_const_iterator_(const binary_heap_point_const_iterator_& other) + : m_p_e(other.m_p_e) + { } + + /// Access. + inline const_pointer + operator->() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_e != 0); + return to_ptr(integral_constant<int, Simple>()); + } + + /// Access. + inline const_reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_e != 0); + return *to_ptr(integral_constant<int, Simple>()); + } + + /// Compares content to a different iterator object. + inline bool + operator==(const binary_heap_point_const_iterator_& other) const + { return m_p_e == other.m_p_e; } + + /// Compares content (negatively) to a different iterator object. + inline bool + operator!=(const binary_heap_point_const_iterator_& other) const + { return m_p_e != other.m_p_e; } + + private: + inline const_pointer + to_ptr(true_type) const + { return m_p_e; } + + inline const_pointer + to_ptr(false_type) const + { return *m_p_e; } + + public: + entry_pointer m_p_e; + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/policy_access_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/policy_access_fn_imps.hpp new file mode 100644 index 0000000..805d6af --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/policy_access_fn_imps.hpp @@ -0,0 +1,56 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/policy_access_fn_imps.hpp + * Contains an implementation class for a binary_heap. + */ + +PB_DS_CLASS_T_DEC +Cmp_Fn& +PB_DS_CLASS_C_DEC:: +get_cmp_fn() +{ + return (*this); +} + +PB_DS_CLASS_T_DEC +const Cmp_Fn& +PB_DS_CLASS_C_DEC:: +get_cmp_fn() const +{ + return (*this); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/resize_policy.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/resize_policy.hpp new file mode 100644 index 0000000..f5b7ccb --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/resize_policy.hpp @@ -0,0 +1,240 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/resize_policy.hpp + * Contains an implementation class for a binary_heap. + */ + +#ifndef PB_DS_BINARY_HEAP_RESIZE_POLICY_HPP +#define PB_DS_BINARY_HEAP_RESIZE_POLICY_HPP + +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { + /// Resize policy for binary heap. + template<typename _Tp> + class resize_policy + { + private: + enum + { + ratio = 8, + factor = 2 + }; + + /// Next shrink size. + _Tp m_shrink_size; + + /// Next grow size. + _Tp m_grow_size; + + public: + typedef _Tp size_type; + + static const _Tp min_size = 16; + + resize_policy() : m_shrink_size(0), m_grow_size(min_size) + { PB_DS_ASSERT_VALID((*this)) } + + resize_policy(const resize_policy& other) + : m_shrink_size(other.m_shrink_size), m_grow_size(other.m_grow_size) + { PB_DS_ASSERT_VALID((*this)) } + + inline void + swap(resize_policy<_Tp>&); + + inline bool + resize_needed_for_grow(size_type) const; + + inline bool + resize_needed_for_shrink(size_type) const; + + inline bool + grow_needed(size_type) const; + + inline bool + shrink_needed(size_type) const; + + inline size_type + get_new_size_for_grow() const; + + inline size_type + get_new_size_for_shrink() const; + + inline size_type + get_new_size_for_arbitrary(size_type) const; + + inline void + notify_grow_resize(); + + inline void + notify_shrink_resize(); + + void + notify_arbitrary(size_type); + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; +#endif + +#ifdef PB_DS_BINARY_HEAP_TRACE_ + void + trace() const; +#endif + }; + + template<typename _Tp> + const _Tp resize_policy<_Tp>::min_size; + + template<typename _Tp> + inline void + resize_policy<_Tp>:: + swap(resize_policy<_Tp>& other) + { + std::swap(m_shrink_size, other.m_shrink_size); + std::swap(m_grow_size, other.m_grow_size); + } + + template<typename _Tp> + inline bool + resize_policy<_Tp>:: + resize_needed_for_grow(size_type size) const + { + _GLIBCXX_DEBUG_ASSERT(size <= m_grow_size); + return size == m_grow_size; + } + + template<typename _Tp> + inline bool + resize_policy<_Tp>:: + resize_needed_for_shrink(size_type size) const + { + _GLIBCXX_DEBUG_ASSERT(size <= m_grow_size); + return size == m_shrink_size; + } + + template<typename _Tp> + inline typename resize_policy<_Tp>::size_type + resize_policy<_Tp>:: + get_new_size_for_grow() const + { return m_grow_size * factor; } + + template<typename _Tp> + inline typename resize_policy<_Tp>::size_type + resize_policy<_Tp>:: + get_new_size_for_shrink() const + { + const size_type half_size = m_grow_size / factor; + return std::max(min_size, half_size); + } + + template<typename _Tp> + inline typename resize_policy<_Tp>::size_type + resize_policy<_Tp>:: + get_new_size_for_arbitrary(size_type size) const + { + size_type ret = min_size; + while (ret < size) + ret *= factor; + return ret; + } + + template<typename _Tp> + inline void + resize_policy<_Tp>:: + notify_grow_resize() + { + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(m_grow_size >= min_size); + m_grow_size *= factor; + m_shrink_size = m_grow_size / ratio; + PB_DS_ASSERT_VALID((*this)) + } + + template<typename _Tp> + inline void + resize_policy<_Tp>:: + notify_shrink_resize() + { + PB_DS_ASSERT_VALID((*this)) + m_shrink_size /= factor; + if (m_shrink_size == 1) + m_shrink_size = 0; + m_grow_size = std::max(m_grow_size / factor, min_size); + PB_DS_ASSERT_VALID((*this)) + } + + template<typename _Tp> + inline void + resize_policy<_Tp>:: + notify_arbitrary(size_type actual_size) + { + m_grow_size = actual_size; + m_shrink_size = m_grow_size / ratio; + PB_DS_ASSERT_VALID((*this)) + } + +#ifdef _GLIBCXX_DEBUG + template<typename _Tp> + void + resize_policy<_Tp>:: + assert_valid(const char* __file, int __line) const + { + PB_DS_DEBUG_VERIFY(m_shrink_size == 0 + || m_shrink_size * ratio == m_grow_size); + PB_DS_DEBUG_VERIFY(m_grow_size >= min_size); + } +#endif + +#ifdef PB_DS_BINARY_HEAP_TRACE_ + template<typename _Tp> + void + resize_policy<_Tp>:: + trace() const + { + std::cerr << "shrink = " << m_shrink_size + << " grow = " << m_grow_size << std::endl; + } +#endif + +} // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/split_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/split_join_fn_imps.hpp new file mode 100644 index 0000000..322ac08 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/split_join_fn_imps.hpp @@ -0,0 +1,160 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/split_join_fn_imps.hpp + * Contains an implementation class for a binary_heap. + */ + +PB_DS_CLASS_T_DEC +template<typename Pred> +void +PB_DS_CLASS_C_DEC:: +split(Pred pred, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + + typedef + typename entry_pred<value_type, Pred, _Alloc, simple_value>::type + pred_t; + + const size_type left = partition(pred_t(pred)); + _GLIBCXX_DEBUG_ASSERT(m_size >= left); + + const size_type ersd = m_size - left; + _GLIBCXX_DEBUG_ASSERT(m_size >= ersd); + + const size_type new_size = resize_policy::get_new_size_for_arbitrary(left); + const size_type other_actual_size = other.get_new_size_for_arbitrary(ersd); + + entry_pointer a_entries = 0; + entry_pointer a_other_entries = 0; + + __try + { + a_entries = s_entry_allocator.allocate(new_size); + a_other_entries = s_entry_allocator.allocate(other_actual_size); + } + __catch(...) + { + if (a_entries != 0) + s_entry_allocator.deallocate(a_entries, new_size); + + if (a_other_entries != 0) + s_entry_allocator.deallocate(a_other_entries, other_actual_size); + + __throw_exception_again; + }; + + for (size_type i = 0; i < other.m_size; ++i) + erase_at(other.m_a_entries, i, s_no_throw_copies_ind); + + _GLIBCXX_DEBUG_ASSERT(new_size >= left); + std::copy(m_a_entries, m_a_entries + left, a_entries); + std::copy(m_a_entries + left, m_a_entries + m_size, a_other_entries); + + s_entry_allocator.deallocate(m_a_entries, m_actual_size); + s_entry_allocator.deallocate(other.m_a_entries, other.m_actual_size); + + m_actual_size = new_size; + other.m_actual_size = other_actual_size; + + m_size = left; + other.m_size = ersd; + + m_a_entries = a_entries; + other.m_a_entries = a_other_entries; + + make_heap(); + other.make_heap(); + + resize_policy::notify_arbitrary(m_actual_size); + other.notify_arbitrary(other.m_actual_size); + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +join(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + const size_type len = m_size + other.m_size; + const size_type new_size = resize_policy::get_new_size_for_arbitrary(len); + + entry_pointer a_entries = 0; + entry_pointer a_other_entries = 0; + + __try + { + a_entries = s_entry_allocator.allocate(new_size); + a_other_entries = s_entry_allocator.allocate(resize_policy::min_size); + } + __catch(...) + { + if (a_entries != 0) + s_entry_allocator.deallocate(a_entries, new_size); + + if (a_other_entries != 0) + s_entry_allocator.deallocate(a_other_entries, resize_policy::min_size); + + __throw_exception_again; + } + + std::copy(m_a_entries, m_a_entries + m_size, a_entries); + std::copy(other.m_a_entries, other.m_a_entries + other.m_size, + a_entries + m_size); + + s_entry_allocator.deallocate(m_a_entries, m_actual_size); + m_a_entries = a_entries; + m_size = len; + m_actual_size = new_size; + resize_policy::notify_arbitrary(new_size); + make_heap(); + + s_entry_allocator.deallocate(other.m_a_entries, other.m_actual_size); + other.m_a_entries = a_other_entries; + other.m_size = 0; + other.m_actual_size = resize_policy::min_size; + other.notify_arbitrary(resize_policy::min_size); + other.make_heap(); + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/trace_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/trace_fn_imps.hpp new file mode 100644 index 0000000..5176a69 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/trace_fn_imps.hpp @@ -0,0 +1,78 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binary_heap_/trace_fn_imps.hpp + * Contains an implementation class for a binary_heap. + */ + +#ifdef PB_DS_BINARY_HEAP_TRACE_ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace() const +{ + std::cerr << this << std::endl; + + std::cerr << m_a_entries << std::endl; + + for (size_type i = 0; i < m_size; ++i) + trace_entry(m_a_entries[i], s_no_throw_copies_ind); + + std::cerr << std::endl; + + std::cerr << "size = " << m_size << " " << "actual_size = " << m_actual_size << std::endl; + + resize_policy::trace(); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace_entry(const entry& r_e, false_type) const +{ + std::cout << r_e << " " <<* r_e << std::endl; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace_entry(const entry& r_e, true_type) const +{ + std::cout << r_e << std::endl; +} + +#endif // #ifdef PB_DS_BINARY_HEAP_TRACE_ diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_/binomial_heap_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_/binomial_heap_.hpp new file mode 100644 index 0000000..ee078a8 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_/binomial_heap_.hpp @@ -0,0 +1,112 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binomial_heap_.hpp + * Contains an implementation class for a binomial heap. + */ + +/* + * Binomial heap. + * Vuillemin J is the mastah. + * Modified from CLRS. + */ + +#include <debug/debug.h> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/binomial_heap_base_/binomial_heap_base_.hpp> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + binomial_heap<Value_Type, Cmp_Fn, _Alloc> + + /** + * Binomial heap. + * + * @ingroup heap-detail + */ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + class binomial_heap + : public binomial_heap_base<Value_Type, Cmp_Fn, _Alloc> + { + private: + typedef binomial_heap_base<Value_Type, Cmp_Fn, _Alloc> base_type; + typedef typename base_type::node_pointer node_pointer; + typedef typename base_type::node_const_pointer node_const_pointer; + + public: + typedef Value_Type value_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef typename base_type::pointer pointer; + typedef typename base_type::const_pointer const_pointer; + typedef typename base_type::reference reference; + typedef typename base_type::const_reference const_reference; + typedef typename base_type::point_const_iterator point_const_iterator; + typedef typename base_type::point_iterator point_iterator; + typedef typename base_type::const_iterator const_iterator; + typedef typename base_type::iterator iterator; + typedef typename base_type::cmp_fn cmp_fn; + typedef typename base_type::allocator_type allocator_type; + + binomial_heap(); + + binomial_heap(const Cmp_Fn&); + + binomial_heap(const binomial_heap&); + + ~binomial_heap(); + + protected: +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; +#endif + }; + +#include <ext/pb_ds/detail/binomial_heap_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/binomial_heap_/debug_fn_imps.hpp> + +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..cd8dbca --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,60 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file detail/binomial_heap_/constructors_destructor_fn_imps.hpp + * Contains an implementation for binomial_heap_. + */ + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +binomial_heap() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +binomial_heap(const Cmp_Fn& r_cmp_fn) +: base_type(r_cmp_fn) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +binomial_heap(const PB_DS_CLASS_C_DEC& other) +: base_type(other) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~binomial_heap() { } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_/debug_fn_imps.hpp new file mode 100644 index 0000000..f03ec00 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_/debug_fn_imps.hpp @@ -0,0 +1,49 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file detail/binomial_heap_/debug_fn_imps.hpp + * Contains an implementation for binomial_heap_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ base_type::assert_valid(true, __file, __line); } + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/binomial_heap_base_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/binomial_heap_base_.hpp new file mode 100644 index 0000000..eb916bc --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/binomial_heap_base_.hpp @@ -0,0 +1,211 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binomial_heap_base_/binomial_heap_base_.hpp + * Contains an implementation class for a base of binomial heaps. + */ + +#ifndef PB_DS_BINOMIAL_HEAP_BASE_HPP +#define PB_DS_BINOMIAL_HEAP_BASE_HPP + +/* + * Binomial heap base. + * Vuillemin J is the mastah. + * Modified from CLRS. + */ + +#include <debug/debug.h> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + binomial_heap_base<Value_Type, Cmp_Fn, _Alloc> + +#ifdef _GLIBCXX_DEBUG +#define PB_DS_B_HEAP_BASE \ + left_child_next_sibling_heap<Value_Type, Cmp_Fn, \ + typename _Alloc::size_type, _Alloc, false> +#else +#define PB_DS_B_HEAP_BASE \ + left_child_next_sibling_heap<Value_Type, Cmp_Fn, \ + typename _Alloc::size_type, _Alloc> +#endif + + /// Base class for binomial heap. + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + class binomial_heap_base + : public PB_DS_B_HEAP_BASE + { + private: + typedef typename _Alloc::template rebind<Value_Type>::other __rebind_v; + typedef PB_DS_B_HEAP_BASE base_type; + + protected: + typedef typename base_type::node node; + typedef typename base_type::node_pointer node_pointer; + typedef typename base_type::node_const_pointer node_const_pointer; + + public: + typedef Value_Type value_type; + typedef Cmp_Fn cmp_fn; + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + + typedef typename __rebind_v::pointer pointer; + typedef typename __rebind_v::const_pointer const_pointer; + typedef typename __rebind_v::reference reference; + typedef typename __rebind_v::const_reference const_reference; + + typedef typename base_type::point_const_iterator point_const_iterator; + typedef typename base_type::point_iterator point_iterator; + typedef typename base_type::const_iterator const_iterator; + typedef typename base_type::iterator iterator; + + public: + + inline point_iterator + push(const_reference); + + void + modify(point_iterator, const_reference); + + inline const_reference + top() const; + + void + pop(); + + void + erase(point_iterator); + + inline void + clear(); + + template<typename Pred> + size_type + erase_if(Pred); + + template<typename Pred> + void + split(Pred, PB_DS_CLASS_C_DEC&); + + void + join(PB_DS_CLASS_C_DEC&); + + protected: + + binomial_heap_base(); + + binomial_heap_base(const Cmp_Fn&); + + binomial_heap_base(const PB_DS_CLASS_C_DEC&); + + void + swap(PB_DS_CLASS_C_DEC&); + + ~binomial_heap_base(); + + template<typename It> + void + copy_from_range(It, It); + + inline void + find_max(); + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(bool, const char*, int) const; + + void + assert_max(const char*, int) const; +#endif + + private: + + inline node_pointer + fix(node_pointer) const; + + inline void + insert_node(node_pointer); + + inline void + remove_parentless_node(node_pointer); + + inline node_pointer + join(node_pointer, node_pointer) const; + +#ifdef _GLIBCXX_DEBUG + void + assert_node_consistent(node_const_pointer, bool, bool, + const char*, int) const; +#endif + + protected: + node_pointer m_p_max; + }; + +#define PB_DS_ASSERT_VALID_COND(X, _StrictlyBinomial) \ + _GLIBCXX_DEBUG_ONLY(X.assert_valid(_StrictlyBinomial,__FILE__, __LINE__);) + +#define PB_DS_ASSERT_BASE_NODE_CONSISTENT(_Node, _Bool) \ + _GLIBCXX_DEBUG_ONLY(base_type::assert_node_consistent(_Node, _Bool, \ + __FILE__, __LINE__);) + +#include <ext/pb_ds/detail/binomial_heap_base_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/binomial_heap_base_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/binomial_heap_base_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/binomial_heap_base_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/binomial_heap_base_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/binomial_heap_base_/split_join_fn_imps.hpp> + +#undef PB_DS_ASSERT_BASE_NODE_CONSISTENT +#undef PB_DS_ASSERT_VALID_COND +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_B_HEAP_BASE + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..144b1f7 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,85 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binomial_heap_base_/constructors_destructor_fn_imps.hpp + * Contains an implementation class for a base of binomial heaps. + */ + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + push(*(first_it++)); + PB_DS_ASSERT_VALID_COND((*this),false) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +binomial_heap_base() : m_p_max(0) +{ + PB_DS_ASSERT_VALID_COND((*this),false) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +binomial_heap_base(const Cmp_Fn& r_cmp_fn) +: base_type(r_cmp_fn), m_p_max(0) +{ PB_DS_ASSERT_VALID_COND((*this),false) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +binomial_heap_base(const PB_DS_CLASS_C_DEC& other) +: base_type(other), m_p_max(0) +{ PB_DS_ASSERT_VALID_COND((*this),false) } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID_COND((*this),false) + base_type::swap(other); + std::swap(m_p_max, other.m_p_max); + PB_DS_ASSERT_VALID_COND((*this),false) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~binomial_heap_base() +{ } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/debug_fn_imps.hpp new file mode 100644 index 0000000..6944b2f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/debug_fn_imps.hpp @@ -0,0 +1,100 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binomial_heap_base_/debug_fn_imps.hpp + * Contains an implementation class for a base of binomial heaps. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(bool strictly_binomial, const char* __file, int __line) const +{ + base_type::assert_valid(__file, __line); + assert_node_consistent(base_type::m_p_root, strictly_binomial, true, + __file, __line); + assert_max(__file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_max(const char* __file, int __line) const +{ + if (m_p_max == 0) + return; + PB_DS_DEBUG_VERIFY(base_type::parent(m_p_max) == 0); + for (const_iterator it = base_type::begin(); it != base_type::end(); ++it) + PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(m_p_max->m_value, + it.m_p_nd->m_value)); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_node_consistent(node_const_pointer p_nd, bool strictly_binomial, + bool increasing, const char* __file, int __line) const +{ + PB_DS_DEBUG_VERIFY(increasing || strictly_binomial); + base_type::assert_node_consistent(p_nd, false, __file, __line); + if (p_nd == 0) + return; + PB_DS_DEBUG_VERIFY(p_nd->m_metadata == base_type::degree(p_nd)); + PB_DS_DEBUG_VERIFY(base_type::size_under_node(p_nd) == + static_cast<size_type>(1 << p_nd->m_metadata)); + assert_node_consistent(p_nd->m_p_next_sibling, strictly_binomial, increasing, + __file, __line); + assert_node_consistent(p_nd->m_p_l_child, true, false, __file, __line); + if (p_nd->m_p_next_sibling != 0) + { + if (increasing) + { + if (strictly_binomial) + PB_DS_DEBUG_VERIFY(p_nd->m_metadata + < p_nd->m_p_next_sibling->m_metadata); + else + PB_DS_DEBUG_VERIFY(p_nd->m_metadata + <= p_nd->m_p_next_sibling->m_metadata); + } + else + PB_DS_DEBUG_VERIFY(p_nd->m_metadata + > p_nd->m_p_next_sibling->m_metadata); + } +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/erase_fn_imps.hpp new file mode 100644 index 0000000..f922823 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/erase_fn_imps.hpp @@ -0,0 +1,161 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binomial_heap_base_/erase_fn_imps.hpp + * Contains an implementation class for a base of binomial heaps. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +pop() +{ + PB_DS_ASSERT_VALID_COND((*this),true) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + + if (m_p_max == 0) + find_max(); + + _GLIBCXX_DEBUG_ASSERT(m_p_max != 0); + node_pointer p_nd = m_p_max; + remove_parentless_node(m_p_max); + base_type::actual_erase_node(p_nd); + m_p_max = 0; + PB_DS_ASSERT_VALID_COND((*this),true) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +remove_parentless_node(node_pointer p_nd) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + _GLIBCXX_DEBUG_ASSERT(base_type::parent(p_nd) == 0); + + node_pointer p_cur_root = p_nd == base_type::m_p_root? + p_nd->m_p_next_sibling : base_type::m_p_root; + + if (p_cur_root != 0) + p_cur_root->m_p_prev_or_parent = 0; + + if (p_nd->m_p_prev_or_parent != 0) + p_nd->m_p_prev_or_parent->m_p_next_sibling = p_nd->m_p_next_sibling; + + if (p_nd->m_p_next_sibling != 0) + p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd->m_p_prev_or_parent; + + node_pointer p_child = p_nd->m_p_l_child; + if (p_child != 0) + { + p_child->m_p_prev_or_parent = 0; + while (p_child->m_p_next_sibling != 0) + p_child = p_child->m_p_next_sibling; + } + + m_p_max = 0; + base_type::m_p_root = join(p_cur_root, p_child); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +clear() +{ + base_type::clear(); + m_p_max = 0; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase(point_iterator it) +{ + PB_DS_ASSERT_VALID_COND((*this),true) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + + base_type::bubble_to_top(it.m_p_nd); + remove_parentless_node(it.m_p_nd); + base_type::actual_erase_node(it.m_p_nd); + m_p_max = 0; + PB_DS_ASSERT_VALID_COND((*this),true) +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + PB_DS_ASSERT_VALID_COND((*this),true) + + if (base_type::empty()) + { + PB_DS_ASSERT_VALID_COND((*this),true) + return 0; + } + + base_type::to_linked_list(); + node_pointer p_out = base_type::prune(pred); + size_type ersd = 0; + while (p_out != 0) + { + ++ersd; + node_pointer p_next = p_out->m_p_next_sibling; + base_type::actual_erase_node(p_out); + p_out = p_next; + } + + node_pointer p_cur = base_type::m_p_root; + base_type::m_p_root = 0; + while (p_cur != 0) + { + node_pointer p_next = p_cur->m_p_next_sibling; + p_cur->m_p_l_child = p_cur->m_p_prev_or_parent = 0; + p_cur->m_metadata = 0; + p_cur->m_p_next_sibling = base_type::m_p_root; + + if (base_type::m_p_root != 0) + base_type::m_p_root->m_p_prev_or_parent = p_cur; + + base_type::m_p_root = p_cur; + base_type::m_p_root = fix(base_type::m_p_root); + p_cur = p_next; + } + + m_p_max = 0; + PB_DS_ASSERT_VALID_COND((*this),true) + return ersd; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/find_fn_imps.hpp new file mode 100644 index 0000000..ba8f0e2 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/find_fn_imps.hpp @@ -0,0 +1,70 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binomial_heap_base_/find_fn_imps.hpp + * Contains an implementation class for a base of binomial heaps. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reference +PB_DS_CLASS_C_DEC:: +top() const +{ + PB_DS_ASSERT_VALID_COND((*this),false) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + + if (m_p_max == 0) + const_cast<PB_DS_CLASS_C_DEC* >(this)->find_max(); + + _GLIBCXX_DEBUG_ASSERT(m_p_max != 0); + return m_p_max->m_value; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +find_max() +{ + node_pointer p_cur = base_type::m_p_root; + m_p_max = p_cur; + while (p_cur != 0) + { + if (Cmp_Fn::operator()(m_p_max->m_value, p_cur->m_value)) + m_p_max = p_cur; + p_cur = p_cur->m_p_next_sibling; + } +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/insert_fn_imps.hpp new file mode 100644 index 0000000..7f7df13 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/insert_fn_imps.hpp @@ -0,0 +1,178 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binomial_heap_base_/insert_fn_imps.hpp + * Contains an implementation class for a base of binomial heaps. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +push(const_reference r_val) +{ + PB_DS_ASSERT_VALID_COND((*this),true) + node_pointer p_nd = base_type::get_new_node_for_insert(r_val); + insert_node(p_nd); + m_p_max = 0; + PB_DS_ASSERT_VALID_COND((*this),true) + return point_iterator(p_nd); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +insert_node(node_pointer p_nd) +{ + if (base_type::m_p_root == 0) + { + p_nd->m_p_next_sibling = 0; + p_nd->m_p_prev_or_parent = 0; + p_nd->m_p_l_child = 0; + p_nd->m_metadata = 0; + base_type::m_p_root = p_nd; + return; + } + + if (base_type::m_p_root->m_metadata > 0) + { + p_nd->m_p_prev_or_parent = p_nd->m_p_l_child = 0; + p_nd->m_p_next_sibling = base_type::m_p_root; + base_type::m_p_root->m_p_prev_or_parent = p_nd; + base_type::m_p_root = p_nd; + p_nd->m_metadata = 0; + return; + } + + if (Cmp_Fn::operator()(base_type::m_p_root->m_value, p_nd->m_value)) + { + p_nd->m_p_next_sibling = base_type::m_p_root->m_p_next_sibling; + p_nd->m_p_prev_or_parent = 0; + p_nd->m_metadata = 1; + p_nd->m_p_l_child = base_type::m_p_root; + base_type::m_p_root->m_p_prev_or_parent = p_nd; + base_type::m_p_root->m_p_next_sibling = 0; + base_type::m_p_root = p_nd; + } + else + { + p_nd->m_p_next_sibling = 0; + p_nd->m_p_l_child = 0; + p_nd->m_p_prev_or_parent = base_type::m_p_root; + p_nd->m_metadata = 0; + _GLIBCXX_DEBUG_ASSERT(base_type::m_p_root->m_p_l_child == 0); + base_type::m_p_root->m_p_l_child = p_nd; + base_type::m_p_root->m_metadata = 1; + } + + base_type::m_p_root = fix(base_type::m_p_root); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +fix(node_pointer p_nd) const +{ + while (p_nd->m_p_next_sibling != 0 && + p_nd->m_metadata == p_nd->m_p_next_sibling->m_metadata) + { + node_pointer p_next = p_nd->m_p_next_sibling; + if (Cmp_Fn::operator()(p_nd->m_value, p_next->m_value)) + { + p_next->m_p_prev_or_parent = p_nd->m_p_prev_or_parent; + + if (p_nd->m_p_prev_or_parent != 0) + p_nd->m_p_prev_or_parent->m_p_next_sibling = p_next; + + base_type::make_child_of(p_nd, p_next); + ++p_next->m_metadata; + p_nd = p_next; + } + else + { + p_nd->m_p_next_sibling = p_next->m_p_next_sibling; + + if (p_nd->m_p_next_sibling != 0) + p_next->m_p_next_sibling = 0; + + base_type::make_child_of(p_next, p_nd); + ++p_nd->m_metadata; + } + } + + if (p_nd->m_p_next_sibling != 0) + p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd; + + return p_nd; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +modify(point_iterator it, const_reference r_new_val) +{ + PB_DS_ASSERT_VALID_COND((*this),true) + node_pointer p_nd = it.m_p_nd; + + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_nd, false) + + const bool bubble_up = Cmp_Fn::operator()(p_nd->m_value, r_new_val); + p_nd->m_value = r_new_val; + + if (bubble_up) + { + node_pointer p_parent = base_type::parent(p_nd); + while (p_parent != 0 && + Cmp_Fn::operator()(p_parent->m_value, p_nd->m_value)) + { + base_type::swap_with_parent(p_nd, p_parent); + p_parent = base_type::parent(p_nd); + } + + if (p_nd->m_p_prev_or_parent == 0) + base_type::m_p_root = p_nd; + + m_p_max = 0; + PB_DS_ASSERT_VALID_COND((*this),true) + return; + } + + base_type::bubble_to_top(p_nd); + remove_parentless_node(p_nd); + insert_node(p_nd); + m_p_max = 0; + PB_DS_ASSERT_VALID_COND((*this),true) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/split_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/split_join_fn_imps.hpp new file mode 100644 index 0000000..664e8c1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/binomial_heap_base_/split_join_fn_imps.hpp @@ -0,0 +1,197 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file binomial_heap_base_/split_join_fn_imps.hpp + * Contains an implementation class for a base of binomial heaps. + */ + +PB_DS_CLASS_T_DEC +template<typename Pred> +void +PB_DS_CLASS_C_DEC:: +split(Pred pred, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID_COND((*this),true) + PB_DS_ASSERT_VALID_COND(other,true) + + other.clear(); + if (base_type::empty()) + { + PB_DS_ASSERT_VALID_COND((*this),true) + PB_DS_ASSERT_VALID_COND(other,true) + return; + } + + base_type::to_linked_list(); + node_pointer p_out = base_type::prune(pred); + while (p_out != 0) + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_size > 0); + --base_type::m_size; + ++other.m_size; + + node_pointer p_next = p_out->m_p_next_sibling; + p_out->m_p_l_child = p_out->m_p_prev_or_parent = 0; + p_out->m_metadata = 0; + + p_out->m_p_next_sibling = other.m_p_root; + if (other.m_p_root != 0) + other.m_p_root->m_p_prev_or_parent = p_out; + + other.m_p_root = p_out; + other.m_p_root = other.fix(other.m_p_root); + p_out = p_next; + } + + PB_DS_ASSERT_VALID_COND(other,true) + node_pointer p_cur = base_type::m_p_root; + base_type::m_p_root = 0; + + while (p_cur != 0) + { + node_pointer p_next = p_cur->m_p_next_sibling; + p_cur->m_p_l_child = p_cur->m_p_prev_or_parent = 0; + p_cur->m_metadata = 0; + p_cur->m_p_next_sibling = base_type::m_p_root; + + if (base_type::m_p_root != 0) + base_type::m_p_root->m_p_prev_or_parent = p_cur; + + base_type::m_p_root = p_cur; + base_type::m_p_root = fix(base_type::m_p_root); + p_cur = p_next; + } + + m_p_max = 0; + PB_DS_ASSERT_VALID_COND((*this),true) + PB_DS_ASSERT_VALID_COND(other,true) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +join(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID_COND((*this),true) + PB_DS_ASSERT_VALID_COND(other,true) + + node_pointer p_other = other.m_p_root; + if (p_other != 0) + do + { + node_pointer p_next = p_other->m_p_next_sibling; + std::swap(p_other->m_p_next_sibling, p_other->m_p_prev_or_parent); + p_other = p_next; + } + while (p_other != 0); + + base_type::m_p_root = join(base_type::m_p_root, other.m_p_root); + base_type::m_size += other.m_size; + m_p_max = 0; + + other.m_p_root = 0; + other.m_size = 0; + other.m_p_max = 0; + + PB_DS_ASSERT_VALID_COND((*this),true) + PB_DS_ASSERT_VALID_COND(other,true) +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +join(node_pointer p_lhs, node_pointer p_rhs) const +{ + node_pointer p_ret = 0; + node_pointer p_cur = 0; + + while (p_lhs != 0 || p_rhs != 0) + { + if (p_rhs == 0) + { + if (p_cur == 0) + p_ret = p_cur = p_lhs; + else + { + p_cur->m_p_next_sibling = p_lhs; + p_lhs->m_p_prev_or_parent = p_cur; + } + p_cur = p_lhs = 0; + } + else if (p_lhs == 0 || p_rhs->m_metadata < p_lhs->m_metadata) + { + if (p_cur == 0) + { + p_ret = p_cur = p_rhs; + p_rhs = p_rhs->m_p_prev_or_parent; + } + else + { + p_cur->m_p_next_sibling = p_rhs; + p_rhs = p_rhs->m_p_prev_or_parent; + p_cur->m_p_next_sibling->m_p_prev_or_parent = p_cur; + p_cur = p_cur->m_p_next_sibling; + } + } + else if (p_lhs->m_metadata < p_rhs->m_metadata) + { + if (p_cur == 0) + p_ret = p_cur = p_lhs; + else + { + p_cur->m_p_next_sibling = p_lhs; + p_lhs->m_p_prev_or_parent = p_cur; + p_cur = p_cur->m_p_next_sibling; + } + p_lhs = p_cur->m_p_next_sibling; + } + else + { + node_pointer p_next_rhs = p_rhs->m_p_prev_or_parent; + p_rhs->m_p_next_sibling = p_lhs; + p_lhs = fix(p_rhs); + p_rhs = p_next_rhs; + } + } + + if (p_cur != 0) + p_cur->m_p_next_sibling = 0; + + if (p_ret != 0) + p_ret->m_p_prev_or_parent = 0; + + return p_ret; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/branch_policy/branch_policy.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/branch_policy/branch_policy.hpp new file mode 100644 index 0000000..b198f94 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/branch_policy/branch_policy.hpp @@ -0,0 +1,119 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file branch_policy/branch_policy.hpp + * Contains a base class for branch policies. + */ + +#ifndef PB_DS_BRANCH_POLICY_BASE_HPP +#define PB_DS_BRANCH_POLICY_BASE_HPP + +#include <ext/pb_ds/tag_and_trait.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /// Primary template, base class for branch structure policies. + template<typename Node_CItr, typename Node_Itr, typename _Alloc> + struct branch_policy + { + protected: + typedef typename Node_Itr::value_type it_type; + typedef typename std::iterator_traits<it_type>::value_type value_type; + typedef typename value_type::first_type key_type; + + typedef typename remove_const<value_type>::type rcvalue_type; + typedef typename remove_const<key_type>::type rckey_type; + + typedef typename _Alloc::template rebind<rcvalue_type>::other rebind_v; + typedef typename _Alloc::template rebind<rckey_type>::other rebind_k; + + typedef typename rebind_v::reference reference; + typedef typename rebind_v::const_reference const_reference; + typedef typename rebind_v::const_pointer const_pointer; + + typedef typename rebind_k::const_reference key_const_reference; + + static inline key_const_reference + extract_key(const_reference r_val) + { return r_val.first; } + + virtual it_type + end() = 0; + + it_type + end_iterator() const + { return const_cast<branch_policy*>(this)->end(); } + + virtual + ~branch_policy() { } + }; + + /// Specialization for const iterators. + template<typename Node_CItr, typename _Alloc> + struct branch_policy<Node_CItr, Node_CItr, _Alloc> + { + protected: + typedef typename Node_CItr::value_type it_type; + typedef typename std::iterator_traits<it_type>::value_type value_type; + typedef typename remove_const<value_type>::type rcvalue_type; + typedef typename _Alloc::template rebind<rcvalue_type>::other rebind_v; + typedef typename rebind_v::reference reference; + typedef typename rebind_v::const_reference const_reference; + typedef typename rebind_v::const_pointer const_pointer; + + typedef value_type key_type; + typedef typename rebind_v::const_reference key_const_reference; + + static inline key_const_reference + extract_key(const_reference r_val) + { return r_val; } + + virtual it_type + end() const = 0; + + it_type + end_iterator() const + { return end(); } + + virtual + ~branch_policy() { } + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_BRANCH_POLICY_BASE_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/branch_policy/null_node_metadata.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/branch_policy/null_node_metadata.hpp new file mode 100644 index 0000000..e92585d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/branch_policy/null_node_metadata.hpp @@ -0,0 +1,66 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file branch_policy/null_node_metadata.hpp + * Contains an implementation class for tree-like classes. + */ + +#ifndef PB_DS_0_NODE_METADATA_HPP +#define PB_DS_0_NODE_METADATA_HPP + +#include <ext/pb_ds/detail/types_traits.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /// Constant node iterator. + template<typename Key, typename Data, typename _Alloc> + struct dumnode_const_iterator + { + private: + typedef types_traits<Key, Data, _Alloc, false> __traits_type; + typedef typename __traits_type::pointer const_iterator; + + public: + typedef const_iterator value_type; + typedef const_iterator const_reference; + typedef const_reference reference; + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/branch_policy/traits.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/branch_policy/traits.hpp new file mode 100644 index 0000000..be1c49a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/branch_policy/traits.hpp @@ -0,0 +1,95 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file branch_policy/traits.hpp + * Contains an implementation class for tree-like classes. + */ + +#ifndef PB_DS_NODE_AND_IT_TRAITS_HPP +#define PB_DS_NODE_AND_IT_TRAITS_HPP + +#include <ext/pb_ds/detail/types_traits.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/traits.hpp> +#include <ext/pb_ds/detail/tree_policy/node_metadata_selector.hpp> +#include <ext/pb_ds/detail/trie_policy/node_metadata_selector.hpp> + +#define PB_DS_DEBUG_VERIFY(_Cond) \ + _GLIBCXX_DEBUG_VERIFY_AT(_Cond, \ + _M_message(#_Cond" assertion from %1;:%2;") \ + ._M_string(__FILE__)._M_integer(__LINE__) \ + ,__file,__line) + +namespace __gnu_pbds +{ + namespace detail + { + /// Tree traits class, primary template. + template<typename Key, + typename Data, + typename Cmp_Fn, + template<typename Node_CItr, + typename Node_Itr, + typename Cmp_Fn_, + typename _Alloc> + class Node_Update, + typename Tag, + typename _Alloc> + struct tree_traits; + + /// Trie traits class, primary template. + template<typename Key, + typename Data, + typename _ATraits, + template<typename Node_CItr, + typename Node_Itr, + typename _ATraits_, + typename _Alloc> + class Node_Update, + typename Tag, + typename _Alloc> + struct trie_traits; + + } // namespace detail +} // namespace __gnu_pbds + +#include <ext/pb_ds/detail/rb_tree_map_/traits.hpp> +#include <ext/pb_ds/detail/splay_tree_/traits.hpp> +#include <ext/pb_ds/detail/ov_tree_map_/traits.hpp> +#include <ext/pb_ds/detail/pat_trie_/traits.hpp> + +#undef PB_DS_DEBUG_VERIFY + +#endif // #ifndef PB_DS_NODE_AND_IT_TRAITS_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp new file mode 100644 index 0000000..d2cda4b --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp @@ -0,0 +1,679 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/cc_ht_map_.hpp + * Contains an implementation class for cc_ht_map_. + */ + +#include <utility> +#include <iterator> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/tag_and_trait.hpp> +#include <ext/pb_ds/detail/hash_fn/ranged_hash_fn.hpp> +#include <ext/pb_ds/detail/types_traits.hpp> +#include <ext/pb_ds/exception.hpp> +#include <ext/pb_ds/detail/eq_fn/hash_eq_fn.hpp> +#ifdef _GLIBCXX_DEBUG +#include <ext/pb_ds/detail/debug_map_base.hpp> +#endif +#ifdef PB_DS_HT_MAP_TRACE_ +#include <iostream> +#endif +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#ifdef PB_DS_DATA_TRUE_INDICATOR +#define PB_DS_CC_HASH_NAME cc_ht_map +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR +#define PB_DS_CC_HASH_NAME cc_ht_set +#endif + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Mapped, typename Hash_Fn, \ + typename Eq_Fn, typename _Alloc, bool Store_Hash, \ + typename Comb_Hash_Fn, typename Resize_Policy> + +#define PB_DS_CLASS_C_DEC \ + PB_DS_CC_HASH_NAME<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, \ + Store_Hash, Comb_Hash_Fn, Resize_Policy> + +#define PB_DS_HASH_EQ_FN_C_DEC \ + hash_eq_fn<Key, Eq_Fn, _Alloc, Store_Hash> + +#define PB_DS_RANGED_HASH_FN_C_DEC \ + ranged_hash_fn<Key, Hash_Fn, _Alloc, Comb_Hash_Fn, Store_Hash> + +#define PB_DS_CC_HASH_TRAITS_BASE \ + types_traits<Key, Mapped, _Alloc, Store_Hash> + +#ifdef _GLIBCXX_DEBUG +#define PB_DS_DEBUG_MAP_BASE_C_DEC \ + debug_map_base<Key, Eq_Fn, \ + typename _Alloc::template rebind<Key>::other::const_reference> +#endif + + + /** + * A collision-chaining hash-based container. + * + * + * @ingroup hash-detail + * + * @tparam Key Key type. + * + * @tparam Mapped Map type. + * + * @tparam Hash_Fn Hashing functor. + * Default is __gnu_cxx::hash. + * + * @tparam Eq_Fn Equal functor. + * Default std::equal_to<Key> + * + * @tparam _Alloc Allocator type. + * + * @tparam Store_Hash If key type stores extra metadata. + * Defaults to false. + * + * @tparam Comb_Hash_Fn Combining hash functor. + * If Hash_Fn is not null_type, then this + * is the ranged-hash functor; otherwise, + * this is the range-hashing functor. + * XXX(See Design::Hash-Based Containers::Hash Policies.) + * Default direct_mask_range_hashing. + * + * @tparam Resize_Policy Resizes hash. + * Defaults to hash_standard_resize_policy, + * using hash_exponential_size_policy and + * hash_load_check_resize_trigger. + * + * + * Bases are: detail::hash_eq_fn, Resize_Policy, detail::ranged_hash_fn, + * detail::types_traits. (Optional: detail::debug_map_base.) + */ + template<typename Key, + typename Mapped, + typename Hash_Fn, + typename Eq_Fn, + typename _Alloc, + bool Store_Hash, + typename Comb_Hash_Fn, + typename Resize_Policy > + class PB_DS_CC_HASH_NAME: +#ifdef _GLIBCXX_DEBUG + protected PB_DS_DEBUG_MAP_BASE_C_DEC, +#endif + public PB_DS_HASH_EQ_FN_C_DEC, + public Resize_Policy, + public PB_DS_RANGED_HASH_FN_C_DEC, + public PB_DS_CC_HASH_TRAITS_BASE + { + private: + typedef PB_DS_CC_HASH_TRAITS_BASE traits_base; + typedef typename traits_base::comp_hash comp_hash; + typedef typename traits_base::value_type value_type_; + typedef typename traits_base::pointer pointer_; + typedef typename traits_base::const_pointer const_pointer_; + typedef typename traits_base::reference reference_; + typedef typename traits_base::const_reference const_reference_; + + struct entry : public traits_base::stored_data_type + { + typename _Alloc::template rebind<entry>::other::pointer m_p_next; + }; + + typedef cond_dealtor<entry, _Alloc> cond_dealtor_t; + + typedef typename _Alloc::template rebind<entry>::other entry_allocator; + typedef typename entry_allocator::pointer entry_pointer; + typedef typename entry_allocator::const_pointer const_entry_pointer; + typedef typename entry_allocator::reference entry_reference; + typedef typename entry_allocator::const_reference const_entry_reference; + + typedef typename _Alloc::template rebind<entry_pointer>::other entry_pointer_allocator; + typedef typename entry_pointer_allocator::pointer entry_pointer_array; + + typedef PB_DS_RANGED_HASH_FN_C_DEC ranged_hash_fn_base; + typedef PB_DS_HASH_EQ_FN_C_DEC hash_eq_fn_base; + typedef Resize_Policy resize_base; + +#ifdef _GLIBCXX_DEBUG + typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base; +#endif + +#define PB_DS_GEN_POS std::pair<entry_pointer, typename _Alloc::size_type> + +#include <ext/pb_ds/detail/unordered_iterator/point_const_iterator.hpp> +#include <ext/pb_ds/detail/unordered_iterator/point_iterator.hpp> +#include <ext/pb_ds/detail/unordered_iterator/const_iterator.hpp> +#include <ext/pb_ds/detail/unordered_iterator/iterator.hpp> + +#undef PB_DS_GEN_POS + + public: + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef Hash_Fn hash_fn; + typedef Eq_Fn eq_fn; + typedef Comb_Hash_Fn comb_hash_fn; + typedef Resize_Policy resize_policy; + + /// Value stores hash, true or false. + enum + { + store_hash = Store_Hash + }; + + typedef typename traits_base::key_type key_type; + typedef typename traits_base::key_pointer key_pointer; + typedef typename traits_base::key_const_pointer key_const_pointer; + typedef typename traits_base::key_reference key_reference; + typedef typename traits_base::key_const_reference key_const_reference; + typedef typename traits_base::mapped_type mapped_type; + typedef typename traits_base::mapped_pointer mapped_pointer; + typedef typename traits_base::mapped_const_pointer mapped_const_pointer; + typedef typename traits_base::mapped_reference mapped_reference; + typedef typename traits_base::mapped_const_reference mapped_const_reference; + typedef typename traits_base::value_type value_type; + typedef typename traits_base::pointer pointer; + typedef typename traits_base::const_pointer const_pointer; + typedef typename traits_base::reference reference; + typedef typename traits_base::const_reference const_reference; + +#ifdef PB_DS_DATA_TRUE_INDICATOR + typedef point_iterator_ point_iterator; +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR + typedef point_const_iterator_ point_iterator; +#endif + + typedef point_const_iterator_ point_const_iterator; + +#ifdef PB_DS_DATA_TRUE_INDICATOR + typedef iterator_ iterator; +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR + typedef const_iterator_ iterator; +#endif + + typedef const_iterator_ const_iterator; + + PB_DS_CC_HASH_NAME(); + + PB_DS_CC_HASH_NAME(const Hash_Fn&); + + PB_DS_CC_HASH_NAME(const Hash_Fn&, const Eq_Fn&); + + PB_DS_CC_HASH_NAME(const Hash_Fn&, const Eq_Fn&, const Comb_Hash_Fn&); + + PB_DS_CC_HASH_NAME(const Hash_Fn&, const Eq_Fn&, const Comb_Hash_Fn&, + const Resize_Policy&); + + PB_DS_CC_HASH_NAME(const PB_DS_CLASS_C_DEC&); + + virtual + ~PB_DS_CC_HASH_NAME(); + + void + swap(PB_DS_CLASS_C_DEC&); + + template<typename It> + void + copy_from_range(It, It); + + void + initialize(); + + inline size_type + size() const; + + inline size_type + max_size() const; + + /// True if size() == 0. + inline bool + empty() const; + + /// Return current hash_fn. + Hash_Fn& + get_hash_fn(); + + /// Return current const hash_fn. + const Hash_Fn& + get_hash_fn() const; + + /// Return current eq_fn. + Eq_Fn& + get_eq_fn(); + + /// Return current const eq_fn. + const Eq_Fn& + get_eq_fn() const; + + /// Return current comb_hash_fn. + Comb_Hash_Fn& + get_comb_hash_fn(); + + /// Return current const comb_hash_fn. + const Comb_Hash_Fn& + get_comb_hash_fn() const; + + /// Return current resize_policy. + Resize_Policy& + get_resize_policy(); + + /// Return current const resize_policy. + const Resize_Policy& + get_resize_policy() const; + + inline std::pair<point_iterator, bool> + insert(const_reference r_val) + { return insert_imp(r_val, traits_base::m_store_extra_indicator); } + + inline mapped_reference + operator[](key_const_reference r_key) + { +#ifdef PB_DS_DATA_TRUE_INDICATOR + return (subscript_imp(r_key, traits_base::m_store_extra_indicator)); +#else + insert(r_key); + return traits_base::s_null_type; +#endif + } + + inline point_iterator + find(key_const_reference); + + inline point_const_iterator + find(key_const_reference) const; + + inline point_iterator + find_end(); + + inline point_const_iterator + find_end() const; + + inline bool + erase(key_const_reference); + + template<typename Pred> + inline size_type + erase_if(Pred); + + void + clear(); + + inline iterator + begin(); + + inline const_iterator + begin() const; + + inline iterator + end(); + + inline const_iterator + end() const; + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; +#endif + +#ifdef PB_DS_HT_MAP_TRACE_ + void + trace() const; +#endif + + private: + void + deallocate_all(); + + inline bool + do_resize_if_needed(); + + inline void + do_resize_if_needed_no_throw(); + + void + resize_imp(size_type); + + void + do_resize(size_type); + + void + resize_imp_no_exceptions(size_type, entry_pointer_array, size_type); + + inline entry_pointer + resize_imp_no_exceptions_reassign_pointer(entry_pointer, + entry_pointer_array, + false_type); + + inline entry_pointer + resize_imp_no_exceptions_reassign_pointer(entry_pointer, + entry_pointer_array, + true_type); + + void + deallocate_links_in_list(entry_pointer); + + inline entry_pointer + get_entry(const_reference, false_type); + + inline entry_pointer + get_entry(const_reference, true_type); + + inline void + rels_entry(entry_pointer); + +#ifdef PB_DS_DATA_TRUE_INDICATOR + inline mapped_reference + subscript_imp(key_const_reference r_key, false_type) + { + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + const size_type pos = ranged_hash_fn_base::operator()(r_key); + entry_pointer p_e = m_entries[pos]; + resize_base::notify_insert_search_start(); + + while (p_e != 0 + && !hash_eq_fn_base::operator()(p_e->m_value.first, r_key)) + { + resize_base::notify_insert_search_collision(); + p_e = p_e->m_p_next; + } + + resize_base::notify_insert_search_end(); + if (p_e != 0) + { + PB_DS_CHECK_KEY_EXISTS(r_key) + return (p_e->m_value.second); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return insert_new_imp(value_type(r_key, mapped_type()), pos)->second; + } + + inline mapped_reference + subscript_imp(key_const_reference r_key, true_type) + { + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + comp_hash pos_hash_pair = ranged_hash_fn_base::operator()(r_key); + entry_pointer p_e = m_entries[pos_hash_pair.first]; + resize_base::notify_insert_search_start(); + while (p_e != 0 && + !hash_eq_fn_base::operator()(p_e->m_value.first, p_e->m_hash, + r_key, pos_hash_pair.second)) + { + resize_base::notify_insert_search_collision(); + p_e = p_e->m_p_next; + } + + resize_base::notify_insert_search_end(); + if (p_e != 0) + { + PB_DS_CHECK_KEY_EXISTS(r_key) + return p_e->m_value.second; + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return insert_new_imp(value_type(r_key, mapped_type()), + pos_hash_pair)->second; + } +#endif + + inline std::pair<point_iterator, bool> + insert_imp(const_reference, false_type); + + inline std::pair<point_iterator, bool> + insert_imp(const_reference, true_type); + + inline pointer + insert_new_imp(const_reference r_val, size_type pos) + { + if (do_resize_if_needed()) + pos = ranged_hash_fn_base::operator()(PB_DS_V2F(r_val)); + + // Following lines might throw an exception. + entry_pointer p_e = get_entry(r_val, + traits_base::m_no_throw_copies_indicator); + + // At this point no exceptions can be thrown. + p_e->m_p_next = m_entries[pos]; + m_entries[pos] = p_e; + resize_base::notify_inserted(++m_num_used_e); + + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_val));) + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + return &p_e->m_value; + } + + inline pointer + insert_new_imp(const_reference r_val, comp_hash& r_pos_hash_pair) + { + // Following lines might throw an exception. + if (do_resize_if_needed()) + r_pos_hash_pair = ranged_hash_fn_base::operator()(PB_DS_V2F(r_val)); + + entry_pointer p_e = get_entry(r_val, + traits_base::m_no_throw_copies_indicator); + + // At this point no exceptions can be thrown. + p_e->m_hash = r_pos_hash_pair.second; + p_e->m_p_next = m_entries[r_pos_hash_pair.first]; + m_entries[r_pos_hash_pair.first] = p_e; + resize_base::notify_inserted(++m_num_used_e); + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_val));) + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + return &p_e->m_value; + } + + inline pointer + find_key_pointer(key_const_reference r_key, false_type) + { + entry_pointer p_e = m_entries[ranged_hash_fn_base::operator()(r_key)]; + resize_base::notify_find_search_start(); + while (p_e != 0 && + !hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), r_key)) + { + resize_base::notify_find_search_collision(); + p_e = p_e->m_p_next; + } + + resize_base::notify_find_search_end(); + +#ifdef _GLIBCXX_DEBUG + if (p_e == 0) + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + else + PB_DS_CHECK_KEY_EXISTS(r_key) +#endif + return &p_e->m_value; + } + + inline pointer + find_key_pointer(key_const_reference r_key, true_type) + { + comp_hash pos_hash_pair = ranged_hash_fn_base::operator()(r_key); + entry_pointer p_e = m_entries[pos_hash_pair.first]; + resize_base::notify_find_search_start(); + while (p_e != 0 && + !hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), + p_e->m_hash, + r_key, pos_hash_pair.second)) + { + resize_base::notify_find_search_collision(); + p_e = p_e->m_p_next; + } + + resize_base::notify_find_search_end(); + +#ifdef _GLIBCXX_DEBUG + if (p_e == 0) + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + else + PB_DS_CHECK_KEY_EXISTS(r_key) +#endif + return &p_e->m_value; + } + + inline bool + erase_in_pos_imp(key_const_reference, size_type); + + inline bool + erase_in_pos_imp(key_const_reference, const comp_hash&); + + inline void + erase_entry_pointer(entry_pointer&); + +#ifdef PB_DS_DATA_TRUE_INDICATOR + void + inc_it_state(pointer& r_p_value, + std::pair<entry_pointer, size_type>& r_pos) const + { + inc_it_state((mapped_const_pointer& )r_p_value, r_pos); + } +#endif + + void + inc_it_state(const_pointer& r_p_value, + std::pair<entry_pointer, size_type>& r_pos) const + { + _GLIBCXX_DEBUG_ASSERT(r_p_value != 0); + r_pos.first = r_pos.first->m_p_next; + if (r_pos.first != 0) + { + r_p_value = &r_pos.first->m_value; + return; + } + + for (++r_pos.second; r_pos.second < m_num_e; ++r_pos.second) + if (m_entries[r_pos.second] != 0) + { + r_pos.first = m_entries[r_pos.second]; + r_p_value = &r_pos.first->m_value; + return; + } + r_p_value = 0; + } + + void + get_start_it_state(pointer& r_p_value, + std::pair<entry_pointer, size_type>& r_pos) const + { + for (r_pos.second = 0; r_pos.second < m_num_e; ++r_pos.second) + if (m_entries[r_pos.second] != 0) + { + r_pos.first = m_entries[r_pos.second]; + r_p_value = &r_pos.first->m_value; + return; + } + r_p_value = 0; + } + +#ifdef _GLIBCXX_DEBUG + void + assert_entry_pointer_array_valid(const entry_pointer_array, + const char*, int) const; + + void + assert_entry_pointer_valid(const entry_pointer, true_type, + const char*, int) const; + + void + assert_entry_pointer_valid(const entry_pointer, false_type, + const char*, int) const; +#endif + +#ifdef PB_DS_HT_MAP_TRACE_ + void + trace_list(const_entry_pointer) const; +#endif + + private: +#ifdef PB_DS_DATA_TRUE_INDICATOR + friend class iterator_; +#endif + + friend class const_iterator_; + + static entry_allocator s_entry_allocator; + static entry_pointer_allocator s_entry_pointer_allocator; + static iterator s_end_it; + static const_iterator s_const_end_it; + static point_iterator s_find_end_it; + static point_const_iterator s_const_find_end_it; + + size_type m_num_e; + size_type m_num_used_e; + entry_pointer_array m_entries; + + enum + { + store_hash_ok = !Store_Hash + || !is_same<Hash_Fn, __gnu_pbds::null_type>::value + }; + + PB_DS_STATIC_ASSERT(sth, store_hash_ok); + }; + +#include <ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/entry_list_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/resize_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/size_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/policy_access_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/iterators_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/trace_fn_imps.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_HASH_EQ_FN_C_DEC +#undef PB_DS_RANGED_HASH_FN_C_DEC +#undef PB_DS_CC_HASH_TRAITS_BASE +#undef PB_DS_DEBUG_MAP_BASE_C_DEC +#undef PB_DS_CC_HASH_NAME + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cmp_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cmp_fn_imps.hpp new file mode 100644 index 0000000..dd2da87 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cmp_fn_imps.hpp @@ -0,0 +1,83 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/cmp_fn_imps.hpp + * Contains implementations of cc_ht_map_'s entire container comparison related + * functions. + */ + +PB_DS_CLASS_T_DEC +template<typename Other_HT_Map_Type> +bool +PB_DS_CLASS_C_DEC:: +operator==(const Other_HT_Map_Type& other) const +{ return cmp_with_other(other); } + +PB_DS_CLASS_T_DEC +template<typename Other_Map_Type> +bool +PB_DS_CLASS_C_DEC:: +cmp_with_other(const Other_Map_Type& other) const +{ + if (size() != other.size()) + return false; + + for (typename Other_Map_Type::const_iterator it = other.begin(); + it != other.end(); ++it) + { + key_const_reference r_key = key_const_reference(PB_DS_V2F(*it)); + + mapped_const_pointer p_mapped_value = + const_cast<PB_DS_CLASS_C_DEC& >(*this). + find_key_pointer(r_key, traits_base::m_store_extra_indicator); + + if (p_mapped_value == 0) + return false; + +#ifdef PB_DS_DATA_TRUE_INDICATOR + if (p_mapped_value->second != it->second) + return false; +#endif + } + return true; +} + +PB_DS_CLASS_T_DEC +template<typename Other_HT_Map_Type> +bool +PB_DS_CLASS_C_DEC:: +operator!=(const Other_HT_Map_Type& other) const +{ return !operator==(other); } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cond_key_dtor_entry_dealtor.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cond_key_dtor_entry_dealtor.hpp new file mode 100644 index 0000000..a38d423 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/cond_key_dtor_entry_dealtor.hpp @@ -0,0 +1,90 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/cond_key_dtor_entry_dealtor.hpp + * Contains a conditional key destructor, used for exception handling. + */ + +namespace __gnu_pbds +{ + namespace detail + { + /// Conditional dey destructor, cc_hash. + template<typename HT_Map> + class cond_dealtor + { + public: + typedef typename HT_Map::entry entry; + typedef typename HT_Map::entry_allocator entry_allocator; + typedef typename HT_Map::key_type key_type; + + cond_dealtor(entry_allocator* p_a, entry* p_e) + : m_p_a(p_a), m_p_e(p_e), m_key_destruct(false), + m_no_action_destructor(false) + { } + + inline + ~cond_dealtor(); + + void + set_key_destruct() + { m_key_destruct = true; } + + void + set_no_action_destructor() + { m_no_action_destructor = true; } + + protected: + entry_allocator* const m_p_a; + entry* const m_p_e; + + bool m_key_destruct; + bool m_no_action_destructor; + }; + + template<typename HT_Map> + inline + cond_dealtor<HT_Map>:: + ~cond_dealtor() + { + if (m_no_action_destructor) + return; + if (m_key_destruct) + m_p_e->m_value.first.~key_type(); + m_p_a->deallocate(m_p_e, 1); + } + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_fn_imps.hpp new file mode 100644 index 0000000..3b54c30 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_fn_imps.hpp @@ -0,0 +1,191 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/constructor_destructor_fn_imps.hpp + * Contains implementations of cc_ht_map_'s constructors, destructor, + * and related functions. + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::entry_allocator +PB_DS_CLASS_C_DEC::s_entry_allocator; + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::entry_pointer_allocator +PB_DS_CLASS_C_DEC::s_entry_pointer_allocator; + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + insert(*(first_it++)); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_CC_HASH_NAME() : + ranged_hash_fn_base(resize_base::get_nearest_larger_size(1)), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_pointer_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn) : + ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_pointer_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) : + PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), + ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_pointer_allocator.allocate(m_num_e)) +{ + std::fill(m_entries, m_entries + m_num_e, (entry_pointer)0); + Resize_Policy::notify_cleared(); + ranged_hash_fn_base::notify_resized(m_num_e); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, + const Comb_Hash_Fn& r_comb_hash_fn) : + PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), + ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), + r_hash_fn, r_comb_hash_fn), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_pointer_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, + const Comb_Hash_Fn& r_comb_hash_fn, + const Resize_Policy& r_resize_policy) : + PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn), + Resize_Policy(r_resize_policy), + ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), + r_hash_fn, r_comb_hash_fn), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_pointer_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_CC_HASH_NAME(const PB_DS_CLASS_C_DEC& other) : + PB_DS_HASH_EQ_FN_C_DEC(other), + resize_base(other), ranged_hash_fn_base(other), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_pointer_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) + __try + { + copy_from_range(other.begin(), other.end()); + } + __catch(...) + { + deallocate_all(); + __throw_exception_again; + } + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~PB_DS_CC_HASH_NAME() +{ deallocate_all(); } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + std::swap(m_entries, other.m_entries); + std::swap(m_num_e, other.m_num_e); + std::swap(m_num_used_e, other.m_num_used_e); + ranged_hash_fn_base::swap(other); + hash_eq_fn_base::swap(other); + resize_base::swap(other); + + _GLIBCXX_DEBUG_ONLY(debug_base::swap(other)); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +deallocate_all() +{ + clear(); + s_entry_pointer_allocator.deallocate(m_entries, m_num_e); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +initialize() +{ + std::fill(m_entries, m_entries + m_num_e, entry_pointer(0)); + Resize_Policy::notify_resized(m_num_e); + Resize_Policy::notify_cleared(); + ranged_hash_fn_base::notify_resized(m_num_e); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..90f7808 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_no_store_hash_fn_imps.hpp @@ -0,0 +1,55 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/constructor_destructor_no_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s constructors, destructor, + * and related functions. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +constructor_insert_new_imp(mapped_const_reference r_val, size_type pos, + false_type) +{ + // Following lines might throw an exception. + entry_pointer p = get_entry(r_val, traits_base::s_no_throw_copies_indicator); + + // At this point no exceptions can be thrown. + p->m_p_next = m_entries[pos]; + m_entries[pos] = p; + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(r_key);) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_store_hash_fn_imps.hpp new file mode 100644 index 0000000..db36fd1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_store_hash_fn_imps.hpp @@ -0,0 +1,56 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/constructor_destructor_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s constructors, destructor, + * and related functions. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +constructor_insert_new_imp(const_reference r_val, size_type pos, true_type) +{ + // Following lines might throw an exception. + entry_pointer p = get_entry(r_val, traits_base::s_no_throw_copies_indicator); + + // At this point no exceptions can be thrown. + p->m_p_next = m_entries[pos]; + p->m_hash = ranged_hash_fn_base::operator()((key_const_reference)(PB_DS_V2F(p->m_value))).second; + + m_entries[pos] = p; + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(r_key);) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/debug_fn_imps.hpp new file mode 100644 index 0000000..a86face --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/debug_fn_imps.hpp @@ -0,0 +1,76 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/debug_fn_imps.hpp + * Contains implementations of cc_ht_map_'s debug-mode functions. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + debug_base::check_size(m_num_used_e, __file, __line); + assert_entry_pointer_array_valid(m_entries, __file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_entry_pointer_array_valid(const entry_pointer_array a_p_entries, + const char* __file, int __line) const +{ + size_type iterated_num_used_e = 0; + for (size_type pos = 0; pos < m_num_e; ++pos) + { + entry_pointer p_e = a_p_entries[pos]; + while (p_e != 0) + { + ++iterated_num_used_e; + assert_entry_pointer_valid(p_e, traits_base::m_store_extra_indicator, + __file, __line); + p_e = p_e->m_p_next; + } + } + PB_DS_DEBUG_VERIFY(iterated_num_used_e == m_num_used_e); +} + +#include <ext/pb_ds/detail/cc_hash_table_map_/debug_store_hash_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/debug_no_store_hash_fn_imps.hpp> + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/debug_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/debug_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..d1c6905 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/debug_no_store_hash_fn_imps.hpp @@ -0,0 +1,50 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/debug_no_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s debug-mode functions. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_entry_pointer_valid(const entry_pointer p, false_type, + const char* __file, int __line) const +{ debug_base::check_key_exists(PB_DS_V2F(p->m_value), __file, __line); } + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/debug_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/debug_store_hash_fn_imps.hpp new file mode 100644 index 0000000..d686bbb --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/debug_store_hash_fn_imps.hpp @@ -0,0 +1,54 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/debug_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s debug-mode functions. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_entry_pointer_valid(const entry_pointer p_e, true_type, + const char* __file, int __line) const +{ + debug_base::check_key_exists(PB_DS_V2F(p_e->m_value), __file, __line); + comp_hash pos_hash_pair = ranged_hash_fn_base::operator()(PB_DS_V2F(p_e->m_value)); + PB_DS_DEBUG_VERIFY(p_e->m_hash == pos_hash_pair.second); +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/entry_list_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/entry_list_fn_imps.hpp new file mode 100644 index 0000000..be2086d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/entry_list_fn_imps.hpp @@ -0,0 +1,91 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/entry_list_fn_imps.hpp + * Contains implementations of cc_ht_map_'s entry-list related functions. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +deallocate_links_in_list(entry_pointer p_e) +{ + while (p_e != 0) + { + entry_pointer p_dealloc_e = p_e; + p_e = p_e->m_p_next; + s_entry_allocator.deallocate(p_dealloc_e, 1); + } +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::entry_pointer +PB_DS_CLASS_C_DEC:: +get_entry(const_reference r_val, true_type) +{ + // Following line might throw an exception. + entry_pointer p_e = s_entry_allocator.allocate(1); + + // Following lines* cannot* throw an exception. + new (&p_e->m_value) value_type(r_val); + return p_e; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::entry_pointer +PB_DS_CLASS_C_DEC:: +get_entry(const_reference r_val, false_type) +{ + // Following line might throw an exception. + entry_pointer p_e = s_entry_allocator.allocate(1); + cond_dealtor_t cond(p_e); + + // Following lines might throw an exception. + new (&p_e->m_value) value_type(r_val); + cond.set_no_action(); + return p_e; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +rels_entry(entry_pointer p_e) +{ + // The following lines cannot throw exceptions (unless if key-data dtors do). + p_e->m_value.~value_type(); + s_entry_allocator.deallocate(p_e, 1); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/erase_fn_imps.hpp new file mode 100644 index 0000000..e9d9ded --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/erase_fn_imps.hpp @@ -0,0 +1,103 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/erase_fn_imps.hpp + * Contains implementations of cc_ht_map_'s erase related functions. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +erase_entry_pointer(entry_pointer& r_p_e) +{ + _GLIBCXX_DEBUG_ONLY(debug_base::erase_existing(PB_DS_V2F(r_p_e->m_value))); + + entry_pointer p_e = r_p_e; + r_p_e = r_p_e->m_p_next; + rels_entry(p_e); + _GLIBCXX_DEBUG_ASSERT(m_num_used_e > 0); + resize_base::notify_erased(--m_num_used_e); +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + size_type num_ersd = 0; + for (size_type pos = 0; pos < m_num_e; ++pos) + { + while (m_entries[pos] != 0 && pred(m_entries[pos]->m_value)) + { + ++num_ersd; + entry_pointer p_next_e = m_entries[pos]->m_p_next; + erase_entry_pointer(m_entries[pos]); + m_entries[pos] = p_next_e; + } + + entry_pointer p_e = m_entries[pos]; + while (p_e != 0 && p_e->m_p_next != 0) + { + if (pred(p_e->m_p_next->m_value)) + { + ++num_ersd; + erase_entry_pointer(p_e->m_p_next); + } + else + p_e = p_e->m_p_next; + } + } + + do_resize_if_needed_no_throw(); + return num_ersd; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + for (size_type pos = 0; pos < m_num_e; ++pos) + while (m_entries[pos] != 0) + erase_entry_pointer(m_entries[pos]); + do_resize_if_needed_no_throw(); + resize_base::notify_cleared(); +} + +#include <ext/pb_ds/detail/cc_hash_table_map_/erase_no_store_hash_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/erase_store_hash_fn_imps.hpp> + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/erase_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/erase_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..e8a9749 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/erase_no_store_hash_fn_imps.hpp @@ -0,0 +1,100 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/erase_no_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s erase related functions, + * when the hash value is not stored. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +erase(key_const_reference r_key) +{ + PB_DS_ASSERT_VALID((*this)) + return erase_in_pos_imp(r_key, ranged_hash_fn_base::operator()(r_key)); +} + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +erase_in_pos_imp(key_const_reference r_key, size_type pos) +{ + PB_DS_ASSERT_VALID((*this)) + entry_pointer p_e = m_entries[pos]; + resize_base::notify_erase_search_start(); + if (p_e == 0) + { + resize_base::notify_erase_search_end(); + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + PB_DS_ASSERT_VALID((*this)) + return false; + } + + if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), r_key)) + { + resize_base::notify_erase_search_end(); + PB_DS_CHECK_KEY_EXISTS(r_key) + erase_entry_pointer(m_entries[pos]); + do_resize_if_needed_no_throw(); + PB_DS_ASSERT_VALID((*this)) + return true; + } + + while (true) + { + entry_pointer p_next_e = p_e->m_p_next; + if (p_next_e == 0) + { + resize_base::notify_erase_search_end(); + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + PB_DS_ASSERT_VALID((*this)) + return false; + } + + if (hash_eq_fn_base::operator()(PB_DS_V2F(p_next_e->m_value), r_key)) + { + resize_base::notify_erase_search_end(); + PB_DS_CHECK_KEY_EXISTS(r_key) + erase_entry_pointer(p_e->m_p_next); + do_resize_if_needed_no_throw(); + PB_DS_ASSERT_VALID((*this)) + return true; + } + resize_base::notify_erase_search_collision(); + p_e = p_next_e; + } +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/erase_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/erase_store_hash_fn_imps.hpp new file mode 100644 index 0000000..a1840e5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/erase_store_hash_fn_imps.hpp @@ -0,0 +1,94 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/erase_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s erase related functions, + * when the hash value is stored. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +erase_in_pos_imp(key_const_reference r_key, const comp_hash& r_pos_hash_pair) +{ + PB_DS_ASSERT_VALID((*this)) + entry_pointer p_e = m_entries[r_pos_hash_pair.first]; + resize_base::notify_erase_search_start(); + if (p_e == 0) + { + resize_base::notify_erase_search_end(); + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + PB_DS_ASSERT_VALID((*this)) + return false; + } + + if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), p_e->m_hash, + r_key, r_pos_hash_pair.second)) + { + resize_base::notify_erase_search_end(); + PB_DS_CHECK_KEY_EXISTS(r_key) + erase_entry_pointer(m_entries[r_pos_hash_pair.first]); + do_resize_if_needed_no_throw(); + PB_DS_ASSERT_VALID((*this)) + return true; + } + + while (true) + { + entry_pointer p_next_e = p_e->m_p_next; + if (p_next_e == 0) + { + resize_base::notify_erase_search_end(); + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + PB_DS_ASSERT_VALID((*this)) + return false; + } + + if (hash_eq_fn_base::operator()(PB_DS_V2F(p_next_e->m_value), + p_next_e->m_hash, r_key, + r_pos_hash_pair.second)) + { + resize_base::notify_erase_search_end(); + PB_DS_CHECK_KEY_EXISTS(r_key) + erase_entry_pointer(p_e->m_p_next); + do_resize_if_needed_no_throw(); + PB_DS_ASSERT_VALID((*this)) + return true; + } + resize_base::notify_erase_search_collision(); + p_e = p_next_e; + } +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/find_fn_imps.hpp new file mode 100644 index 0000000..fe8bc6a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/find_fn_imps.hpp @@ -0,0 +1,71 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/find_fn_imps.hpp + * Contains implementations of cc_ht_map_'s find related functions. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +find(key_const_reference r_key) +{ + PB_DS_ASSERT_VALID((*this)) + return find_key_pointer(r_key, traits_base::m_store_extra_indicator); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +find(key_const_reference r_key) const +{ + PB_DS_ASSERT_VALID((*this)) + return const_cast<PB_DS_CLASS_C_DEC& >(*this).find_key_pointer(r_key, + traits_base::m_store_extra_indicator); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +find_end() +{ return 0; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +find_end() const +{ return 0; } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/find_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/find_store_hash_fn_imps.hpp new file mode 100644 index 0000000..ce727a1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/find_store_hash_fn_imps.hpp @@ -0,0 +1,41 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/find_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s find related functions, + * when the hash value is stored. + */ + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/info_fn_imps.hpp new file mode 100644 index 0000000..a87f2b6 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/info_fn_imps.hpp @@ -0,0 +1,100 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/info_fn_imps.hpp + * Contains implementations of cc_ht_map_'s entire container info related + * functions. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size() const +{ return m_num_used_e; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +max_size() const +{ return m_entry_allocator.max_size(); } + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +empty() const +{ return (size() == 0); } + +PB_DS_CLASS_T_DEC +template<typename Other_HT_Map_Type> +bool +PB_DS_CLASS_C_DEC:: +operator==(const Other_HT_Map_Type& other) const +{ return cmp_with_other(other); } + +PB_DS_CLASS_T_DEC +template<typename Other_Map_Type> +bool +PB_DS_CLASS_C_DEC:: +cmp_with_other(const Other_Map_Type& other) const +{ + if (size() != other.size()) + return false; + + for (typename Other_Map_Type::const_iterator it = other.begin(); + it != other.end(); ++it) + { + key_const_reference r_key =(key_const_reference)PB_DS_V2F(*it); + mapped_const_pointer p_mapped_value = + const_cast<PB_DS_CLASS_C_DEC& >(*this). + find_key_pointer(r_key, traits_base::m_store_extra_indicator); + + if (p_mapped_value == 0) + return false; + +#ifdef PB_DS_DATA_TRUE_INDICATOR + if (p_mapped_value->second != it->second) + return false; +#endif + } + return true; +} + +PB_DS_CLASS_T_DEC +template<typename Other_HT_Map_Type> +bool +PB_DS_CLASS_C_DEC:: +operator!=(const Other_HT_Map_Type& other) const +{ return !operator==(other); } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/insert_fn_imps.hpp new file mode 100644 index 0000000..4553662 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/insert_fn_imps.hpp @@ -0,0 +1,43 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/insert_fn_imps.hpp + * Contains implementations of cc_ht_map_'s insert related functions. + */ + +#include <ext/pb_ds/detail/cc_hash_table_map_/insert_no_store_hash_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/insert_store_hash_fn_imps.hpp> + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/insert_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/insert_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..1257f48 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/insert_no_store_hash_fn_imps.hpp @@ -0,0 +1,70 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/insert_no_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s insert related functions, + * when the hash value is not stored. + */ + +PB_DS_CLASS_T_DEC +inline std::pair<typename PB_DS_CLASS_C_DEC::point_iterator, bool> +PB_DS_CLASS_C_DEC:: +insert_imp(const_reference r_val, false_type) +{ + PB_DS_ASSERT_VALID((*this)) + key_const_reference r_key = PB_DS_V2F(r_val); + const size_type pos = ranged_hash_fn_base::operator()(r_key); + entry_pointer p_e = m_entries[pos]; + resize_base::notify_insert_search_start(); + + while (p_e != 0 && !hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), + r_key)) + { + resize_base::notify_insert_search_collision(); + p_e = p_e->m_p_next; + } + + resize_base::notify_insert_search_end(); + if (p_e != 0) + { + PB_DS_CHECK_KEY_EXISTS(r_key) + return std::make_pair(&p_e->m_value, false); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return std::make_pair(insert_new_imp(r_val, pos), true); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/insert_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/insert_store_hash_fn_imps.hpp new file mode 100644 index 0000000..ef7d102 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/insert_store_hash_fn_imps.hpp @@ -0,0 +1,71 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/insert_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s insert related functions, + * when the hash value is stored. + */ + +PB_DS_CLASS_T_DEC +inline std::pair<typename PB_DS_CLASS_C_DEC::point_iterator, bool> +PB_DS_CLASS_C_DEC:: +insert_imp(const_reference r_val, true_type) +{ + PB_DS_ASSERT_VALID((*this)) + key_const_reference key = PB_DS_V2F(r_val); + comp_hash pos_hash_pair = ranged_hash_fn_base::operator()(key); + entry_pointer p_e = m_entries[pos_hash_pair.first]; + resize_base::notify_insert_search_start(); + + while (p_e != 0 && !hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), + p_e->m_hash, + key, pos_hash_pair.second)) + { + resize_base::notify_insert_search_collision(); + p_e = p_e->m_p_next; + } + + resize_base::notify_insert_search_end(); + if (p_e != 0) + { + PB_DS_CHECK_KEY_EXISTS(key) + return std::make_pair(&p_e->m_value, false); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(key) + return std::make_pair(insert_new_imp(r_val, pos_hash_pair), true); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/iterators_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/iterators_fn_imps.hpp new file mode 100644 index 0000000..821c6d5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/iterators_fn_imps.hpp @@ -0,0 +1,83 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/iterators_fn_imps.hpp + * Contains implementations of cc_ht_map_'s iterators related functions, e.g., + * begin(). + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC::s_end_it; + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC::s_const_end_it; + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +begin() +{ + pointer p_value; + std::pair<entry_pointer, size_type> pos; + get_start_it_state(p_value, pos); + return iterator(p_value, pos, this); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +end() +{ return s_end_it; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin() const +{ + pointer p_value; + std::pair<entry_pointer, size_type> pos; + get_start_it_state(p_value, pos); + return const_iterator(p_value, pos, this); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end() const +{ return s_const_end_it; } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/policy_access_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/policy_access_fn_imps.hpp new file mode 100644 index 0000000..7f547c3 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/policy_access_fn_imps.hpp @@ -0,0 +1,88 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/policy_access_fn_imps.hpp + * Contains implementations of cc_ht_map_'s policy access + * functions. + */ + +PB_DS_CLASS_T_DEC +Hash_Fn& +PB_DS_CLASS_C_DEC:: +get_hash_fn() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Hash_Fn& +PB_DS_CLASS_C_DEC:: +get_hash_fn() const +{ return *this; } + +PB_DS_CLASS_T_DEC +Eq_Fn& +PB_DS_CLASS_C_DEC:: +get_eq_fn() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Eq_Fn& +PB_DS_CLASS_C_DEC:: +get_eq_fn() const +{ return *this; } + +PB_DS_CLASS_T_DEC +Comb_Hash_Fn& +PB_DS_CLASS_C_DEC:: +get_comb_hash_fn() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Comb_Hash_Fn& +PB_DS_CLASS_C_DEC:: +get_comb_hash_fn() const +{ return *this; } + +PB_DS_CLASS_T_DEC +Resize_Policy& +PB_DS_CLASS_C_DEC:: +get_resize_policy() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Resize_Policy& +PB_DS_CLASS_C_DEC:: +get_resize_policy() const +{ return *this; } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/resize_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/resize_fn_imps.hpp new file mode 100644 index 0000000..c4889d3 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/resize_fn_imps.hpp @@ -0,0 +1,134 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/resize_fn_imps.hpp + * Contains implementations of cc_ht_map_'s resize related functions. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +do_resize_if_needed() +{ + if (!resize_base::is_resize_needed()) + return false; + resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); + return true; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +do_resize(size_type len) +{ resize_imp(resize_base::get_nearest_larger_size(len)); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +do_resize_if_needed_no_throw() +{ + if (!resize_base::is_resize_needed()) + return; + + __try + { + resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); + } + __catch(...) + { } + + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +resize_imp(size_type new_size) +{ + PB_DS_ASSERT_VALID((*this)) + if (new_size == m_num_e) + return; + + const size_type old_size = m_num_e; + entry_pointer_array a_p_entries_resized; + + // Following line might throw an exception. + ranged_hash_fn_base::notify_resized(new_size); + + __try + { + // Following line might throw an exception. + a_p_entries_resized = s_entry_pointer_allocator.allocate(new_size); + m_num_e = new_size; + } + __catch(...) + { + ranged_hash_fn_base::notify_resized(old_size); + __throw_exception_again; + } + + // At this point no exceptions can be thrown. + resize_imp_no_exceptions(new_size, a_p_entries_resized, old_size); + Resize_Policy::notify_resized(new_size); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +resize_imp_no_exceptions(size_type new_size, entry_pointer_array a_p_entries_resized, size_type old_size) +{ + std::fill(a_p_entries_resized, a_p_entries_resized + m_num_e, + entry_pointer(0)); + + for (size_type pos = 0; pos < old_size; ++pos) + { + entry_pointer p_e = m_entries[pos]; + while (p_e != 0) + p_e = resize_imp_no_exceptions_reassign_pointer(p_e, a_p_entries_resized, traits_base::m_store_extra_indicator); + } + + m_num_e = new_size; + _GLIBCXX_DEBUG_ONLY(assert_entry_pointer_array_valid(a_p_entries_resized, + __FILE__, __LINE__);) + s_entry_pointer_allocator.deallocate(m_entries, old_size); + m_entries = a_p_entries_resized; + PB_DS_ASSERT_VALID((*this)) +} + +#include <ext/pb_ds/detail/cc_hash_table_map_/resize_no_store_hash_fn_imps.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/resize_store_hash_fn_imps.hpp> + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/resize_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/resize_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..d316b2d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/resize_no_store_hash_fn_imps.hpp @@ -0,0 +1,54 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/resize_no_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s resize related functions, when the + * hash value is not stored. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::entry_pointer +PB_DS_CLASS_C_DEC:: +resize_imp_no_exceptions_reassign_pointer(entry_pointer p_e, entry_pointer_array a_p_entries_resized, false_type) +{ + const size_type hash_pos = + ranged_hash_fn_base::operator()(PB_DS_V2F(p_e->m_value)); + + entry_pointer const p_next_e = p_e->m_p_next; + p_e->m_p_next = a_p_entries_resized[hash_pos]; + a_p_entries_resized[hash_pos] = p_e; + return p_next_e; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/resize_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/resize_store_hash_fn_imps.hpp new file mode 100644 index 0000000..19d2c92 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/resize_store_hash_fn_imps.hpp @@ -0,0 +1,54 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/resize_store_hash_fn_imps.hpp + * Contains implementations of cc_ht_map_'s resize related functions, when the + * hash value is stored. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::entry_pointer +PB_DS_CLASS_C_DEC:: +resize_imp_no_exceptions_reassign_pointer(entry_pointer p_e, entry_pointer_array a_p_entries_resized, true_type) +{ + const comp_hash pos_hash_pair = + ranged_hash_fn_base::operator()(PB_DS_V2F(p_e->m_value), p_e->m_hash); + + entry_pointer const p_next_e = p_e->m_p_next; + p_e->m_p_next = a_p_entries_resized[pos_hash_pair.first]; + a_p_entries_resized[pos_hash_pair.first] = p_e; + return p_next_e; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/size_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/size_fn_imps.hpp new file mode 100644 index 0000000..ca0089e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/size_fn_imps.hpp @@ -0,0 +1,59 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/size_fn_imps.hpp + * Contains implementations of cc_ht_map_'s entire container size related + * functions. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size() const +{ return m_num_used_e; } + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +empty() const +{ return (size() == 0); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +max_size() const +{ return s_entry_allocator.max_size(); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/trace_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/trace_fn_imps.hpp new file mode 100644 index 0000000..bf53ed1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/trace_fn_imps.hpp @@ -0,0 +1,72 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_table_map_/trace_fn_imps.hpp + * Contains implementations of cc_ht_map_'s trace-mode functions. + */ + +#ifdef PB_DS_HT_MAP_TRACE_ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace() const +{ + std::cerr << static_cast<unsigned long>(m_num_e) << " " + << static_cast<unsigned long>(m_num_used_e) << std::endl; + + for (size_type i = 0; i < m_num_e; ++i) + { + std::cerr << static_cast<unsigned long>(i) << " "; + trace_list(m_entries[i]); + std::cerr << std::endl; + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace_list(const_entry_pointer p_l) const +{ + size_type iterated_num_used_e = 0; + while (p_l != 0) + { + std::cerr << PB_DS_V2F(p_l->m_value) << " "; + p_l = p_l->m_p_next; + } +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cond_dealtor.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cond_dealtor.hpp new file mode 100644 index 0000000..c776fe4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/cond_dealtor.hpp @@ -0,0 +1,84 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file detail/cond_dealtor.hpp + * Contains a conditional deallocator. + */ + +#ifndef PB_DS_COND_DEALTOR_HPP +#define PB_DS_COND_DEALTOR_HPP + +namespace __gnu_pbds +{ + namespace detail + { + /// Conditional deallocate constructor argument. + template<typename Entry, typename _Alloc> + class cond_dealtor + { + typedef typename _Alloc::template rebind<Entry> __rebind_e; + + public: + typedef typename __rebind_e::other entry_allocator; + typedef typename entry_allocator::pointer entry_pointer; + + cond_dealtor(entry_pointer p_e) + : m_p_e(p_e), m_no_action_destructor(false) { } + + ~cond_dealtor() + { + if (m_no_action_destructor) + return; + s_alloc.deallocate(m_p_e, 1); + } + + void + set_no_action() + { m_no_action_destructor = true; } + + private: + entry_pointer m_p_e; + bool m_no_action_destructor; + static entry_allocator s_alloc; + }; + + template<typename Entry, class _Alloc> + typename cond_dealtor<Entry, _Alloc>::entry_allocator + cond_dealtor<Entry, _Alloc>::s_alloc; + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_COND_DEALTOR_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/container_base_dispatch.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/container_base_dispatch.hpp new file mode 100644 index 0000000..764a1de --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/container_base_dispatch.hpp @@ -0,0 +1,352 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file container_base_dispatch.hpp + * Contains associative container dispatching. + */ + +#ifndef PB_DS_ASSOC_CNTNR_BASE_DS_DISPATCHER_HPP +#define PB_DS_ASSOC_CNTNR_BASE_DS_DISPATCHER_HPP + +#include <ext/typelist.h> + +#define PB_DS_ASSERT_VALID(X) \ + _GLIBCXX_DEBUG_ONLY(X.assert_valid(__FILE__, __LINE__);) + +#define PB_DS_DEBUG_VERIFY(_Cond) \ + _GLIBCXX_DEBUG_VERIFY_AT(_Cond, \ + _M_message(#_Cond" assertion from %1;:%2;") \ + ._M_string(__FILE__)._M_integer(__LINE__) \ + ,__file,__line) + +#define PB_DS_CHECK_KEY_EXISTS(_Key) \ + _GLIBCXX_DEBUG_ONLY(debug_base::check_key_exists(_Key, __FILE__, __LINE__);) + +#define PB_DS_CHECK_KEY_DOES_NOT_EXIST(_Key) \ + _GLIBCXX_DEBUG_ONLY(debug_base::check_key_does_not_exist(_Key, \ + __FILE__, __LINE__);) + +#define PB_DS_DATA_TRUE_INDICATOR +#define PB_DS_V2F(X) (X).first +#define PB_DS_V2S(X) (X).second +#define PB_DS_EP2VP(X)& ((X)->m_value) +#include <ext/pb_ds/detail/list_update_map_/lu_map_.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/bin_search_tree_.hpp> +#include <ext/pb_ds/detail/rb_tree_map_/rb_tree_.hpp> +#include <ext/pb_ds/detail/splay_tree_/splay_tree_.hpp> +#include <ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp> +#include <ext/pb_ds/detail/pat_trie_/pat_trie_.hpp> +#undef PB_DS_DATA_TRUE_INDICATOR +#undef PB_DS_V2F +#undef PB_DS_V2S +#undef PB_DS_EP2VP + +#define PB_DS_DATA_FALSE_INDICATOR +#define PB_DS_V2F(X) (X) +#define PB_DS_V2S(X) Mapped_Data() +#define PB_DS_EP2VP(X)& ((X)->m_value.first) +#include <ext/pb_ds/detail/list_update_map_/lu_map_.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/bin_search_tree_.hpp> +#include <ext/pb_ds/detail/rb_tree_map_/rb_tree_.hpp> +#include <ext/pb_ds/detail/splay_tree_/splay_tree_.hpp> +#include <ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp> +#include <ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp> +#include <ext/pb_ds/detail/pat_trie_/pat_trie_.hpp> +#undef PB_DS_DATA_FALSE_INDICATOR +#undef PB_DS_V2F +#undef PB_DS_V2S +#undef PB_DS_EP2VP + +#undef PB_DS_CHECK_KEY_DOES_NOT_EXIST +#undef PB_DS_CHECK_KEY_EXISTS +#undef PB_DS_DEBUG_VERIFY +#undef PB_DS_ASSERT_VALID + +namespace __gnu_pbds +{ +namespace detail +{ + /// Specialization for list-update map. + template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, Mapped, _Alloc, list_update_tag, + Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + + public: + /// Dispatched type. + typedef lu_map<Key, Mapped, at0t, _Alloc, at1t> type; + }; + + /// Specialization for list-update set. + template<typename Key, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, null_type, _Alloc, list_update_tag, + Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + + public: + /// Dispatched type. + typedef lu_set<Key, null_type, at0t, _Alloc, at1t> type; + }; + + /// Specialization for PATRICIA trie map. + template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, Mapped, _Alloc, pat_trie_tag, Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + + public: + typedef pat_trie_map<Key, Mapped, at1t, _Alloc> type; + }; + + /// Specialization for PATRICIA trie set. + template<typename Key, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, null_type, _Alloc, pat_trie_tag, + Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + + public: + /// Dispatched type. + typedef pat_trie_set<Key, null_type, at1t, _Alloc> type; + }; + + /// Specialization for R-B tree map. + template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, Mapped, _Alloc, rb_tree_tag, Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + + public: + /// Dispatched type. + typedef rb_tree_map<Key, Mapped, at0t, at1t, _Alloc> type; + }; + + /// Specialization for R-B tree set. + template<typename Key, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, null_type, _Alloc, rb_tree_tag, + Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + + public: + typedef rb_tree_set<Key, null_type, at0t, at1t, _Alloc> type; + }; + + /// Specialization splay tree map. + template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, Mapped, _Alloc, splay_tree_tag, + Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + + public: + /// Dispatched type. + typedef splay_tree_map<Key, Mapped, at0t, at1t, _Alloc> type; + }; + + /// Specialization splay tree set. + template<typename Key, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, null_type, _Alloc, splay_tree_tag, + Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + + public: + /// Dispatched type. + typedef splay_tree_set<Key, null_type, at0t, at1t, _Alloc> type; + }; + + /// Specialization ordered-vector tree map. + template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, Mapped, _Alloc, ov_tree_tag, Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + + public: + /// Dispatched type. + typedef ov_tree_map<Key, Mapped, at0t, at1t, _Alloc> type; + }; + + /// Specialization ordered-vector tree set. + template<typename Key, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, null_type, _Alloc, ov_tree_tag, + Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + + public: + /// Dispatched type. + typedef ov_tree_set<Key, null_type, at0t, at1t, _Alloc> type; + }; + + /// Specialization colision-chaining hash map. + template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, Mapped, _Alloc, cc_hash_tag, Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 2> at2; + typedef typename at2::type at2t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 3> at3; + typedef typename at3::type at3t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 4> at4; + typedef typename at4::type at4t; + + public: + /// Dispatched type. + typedef cc_ht_map<Key, Mapped, at0t, at1t, _Alloc, + at3t::value, at4t, at2t> type; + }; + + /// Specialization colision-chaining hash set. + template<typename Key, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, null_type, _Alloc, cc_hash_tag, + Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 2> at2; + typedef typename at2::type at2t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 3> at3; + typedef typename at3::type at3t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 4> at4; + typedef typename at4::type at4t; + + public: + /// Dispatched type. + typedef cc_ht_set<Key, null_type, at0t, at1t, _Alloc, + at3t::value, at4t, at2t> type; + }; + + /// Specialization general-probe hash map. + template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, Mapped, _Alloc, gp_hash_tag, Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 2> at2; + typedef typename at2::type at2t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 3> at3; + typedef typename at3::type at3t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 4> at4; + typedef typename at4::type at4t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 5> at5; + typedef typename at5::type at5t; + + public: + /// Dispatched type. + typedef gp_ht_map<Key, Mapped, at0t, at1t, _Alloc, + at3t::value, at4t, at5t, at2t> type; + }; + + /// Specialization general-probe hash set. + template<typename Key, typename _Alloc, typename Policy_Tl> + struct container_base_dispatch<Key, null_type, _Alloc, gp_hash_tag, + Policy_Tl> + { + private: + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0> at0; + typedef typename at0::type at0t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1> at1; + typedef typename at1::type at1t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 2> at2; + typedef typename at2::type at2t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 3> at3; + typedef typename at3::type at3t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 4> at4; + typedef typename at4::type at4t; + typedef __gnu_cxx::typelist::at_index<Policy_Tl, 5> at5; + typedef typename at5::type at5t; + + public: + /// Dispatched type. + typedef gp_ht_set<Key, null_type, at0t, at1t, _Alloc, + at3t::value, at4t, at5t, at2t> type; + }; +} // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/debug_map_base.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/debug_map_base.hpp new file mode 100644 index 0000000..cb7324d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/debug_map_base.hpp @@ -0,0 +1,349 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file detail/debug_map_base.hpp + * Contains a debug-mode base for all maps. + */ + +#ifndef PB_DS_DEBUG_MAP_BASE_HPP +#define PB_DS_DEBUG_MAP_BASE_HPP + +#ifdef _GLIBCXX_DEBUG + +#include <list> +#include <utility> +#include <cstdlib> +#include <iostream> +#include <ext/throw_allocator.h> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { + // Need std::pair ostream extractor. + template<typename _CharT, typename _Traits, typename _Tp1, typename _Tp2> + inline std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __out, + const std::pair<_Tp1, _Tp2>& p) + { return (__out << '(' << p.first << ',' << p.second << ')'); } + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Eq_Fn, typename Const_Key_Reference> + +#define PB_DS_CLASS_C_DEC \ + debug_map_base<Key, Eq_Fn, Const_Key_Reference> + + /// Debug base class. + template<typename Key, typename Eq_Fn, typename Const_Key_Reference> + class debug_map_base + { + private: + typedef Const_Key_Reference key_const_reference; + typedef std::_GLIBCXX_STD_C::list<Key> key_repository; + typedef typename key_repository::size_type size_type; + typedef typename key_repository::iterator iterator; + typedef typename key_repository::const_iterator const_iterator; + + protected: + debug_map_base(); + + debug_map_base(const PB_DS_CLASS_C_DEC&); + + ~debug_map_base(); + + inline void + insert_new(key_const_reference); + + inline void + erase_existing(key_const_reference); + + void + clear(); + + inline void + check_key_exists(key_const_reference, const char*, int) const; + + inline void + check_key_does_not_exist(key_const_reference, const char*, int) const; + + inline void + check_size(size_type, const char*, int) const; + + void + swap(PB_DS_CLASS_C_DEC&); + + template<typename Cmp_Fn> + void + split(key_const_reference, Cmp_Fn, PB_DS_CLASS_C_DEC&); + + void + join(PB_DS_CLASS_C_DEC&, bool with_cleanup = true); + + private: + void + assert_valid(const char*, int) const; + + const_iterator + find(key_const_reference) const; + + iterator + find(key_const_reference); + + key_repository m_keys; + Eq_Fn m_eq; + }; + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + debug_map_base() + { PB_DS_ASSERT_VALID((*this)) } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + debug_map_base(const PB_DS_CLASS_C_DEC& other) + : m_keys(other.m_keys), m_eq(other.m_eq) + { PB_DS_ASSERT_VALID((*this)) } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ~debug_map_base() + { PB_DS_ASSERT_VALID((*this)) } + + PB_DS_CLASS_T_DEC + inline void + PB_DS_CLASS_C_DEC:: + insert_new(key_const_reference r_key) + { + PB_DS_ASSERT_VALID((*this)) + + if (find(r_key) != m_keys.end()) + { + std::cerr << "insert_new key already present " << r_key << std::endl; + std::abort(); + } + + __try + { + m_keys.push_back(r_key); + } + __catch(...) + { + std::cerr << "insert_new " << r_key << std::endl; + std::abort(); + } + + PB_DS_ASSERT_VALID((*this)) + } + + PB_DS_CLASS_T_DEC + inline void + PB_DS_CLASS_C_DEC:: + erase_existing(key_const_reference r_key) + { + PB_DS_ASSERT_VALID((*this)) + iterator it = find(r_key); + if (it == m_keys.end()) + { + std::cerr << "erase_existing" << r_key << std::endl; + std::abort(); + } + m_keys.erase(it); + PB_DS_ASSERT_VALID((*this)) + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + clear() + { + PB_DS_ASSERT_VALID((*this)) + m_keys.clear(); + PB_DS_ASSERT_VALID((*this)) + } + + PB_DS_CLASS_T_DEC + inline void + PB_DS_CLASS_C_DEC:: + check_key_exists(key_const_reference r_key, + const char* __file, int __line) const + { + assert_valid(__file, __line); + if (find(r_key) == m_keys.end()) + { + std::cerr << __file << ':' << __line << ": check_key_exists " + << r_key << std::endl; + std::abort(); + } + } + + PB_DS_CLASS_T_DEC + inline void + PB_DS_CLASS_C_DEC:: + check_key_does_not_exist(key_const_reference r_key, + const char* __file, int __line) const + { + assert_valid(__file, __line); + if (find(r_key) != m_keys.end()) + { + using std::cerr; + using std::endl; + cerr << __file << ':' << __line << ": check_key_does_not_exist " + << r_key << endl; + std::abort(); + } + } + + PB_DS_CLASS_T_DEC + inline void + PB_DS_CLASS_C_DEC:: + check_size(size_type size, const char* __file, int __line) const + { + assert_valid(__file, __line); + const size_type keys_size = m_keys.size(); + if (size != keys_size) + { + std::cerr << __file << ':' << __line << ": check_size " + << size << " != " << keys_size << std::endl; + std::abort(); + } + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + swap(PB_DS_CLASS_C_DEC& other) + { + PB_DS_ASSERT_VALID((*this)) + m_keys.swap(other.m_keys); + std::swap(m_eq, other.m_eq); + PB_DS_ASSERT_VALID((*this)) + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::const_iterator + PB_DS_CLASS_C_DEC:: + find(key_const_reference r_key) const + { + PB_DS_ASSERT_VALID((*this)) + typedef const_iterator iterator_type; + for (iterator_type it = m_keys.begin(); it != m_keys.end(); ++it) + if (m_eq(*it, r_key)) + return it; + return m_keys.end(); + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::iterator + PB_DS_CLASS_C_DEC:: + find(key_const_reference r_key) + { + PB_DS_ASSERT_VALID((*this)) + iterator it = m_keys.begin(); + while (it != m_keys.end()) + { + if (m_eq(*it, r_key)) + return it; + ++it; + } + return it; + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + assert_valid(const char* __file, int __line) const + { + const_iterator prime_it = m_keys.begin(); + while (prime_it != m_keys.end()) + { + const_iterator sec_it = prime_it; + ++sec_it; + while (sec_it != m_keys.end()) + { + PB_DS_DEBUG_VERIFY(!m_eq(*sec_it, *prime_it)); + PB_DS_DEBUG_VERIFY(!m_eq(*prime_it, *sec_it)); + ++sec_it; + } + ++prime_it; + } + } + + PB_DS_CLASS_T_DEC + template<typename Cmp_Fn> + void + PB_DS_CLASS_C_DEC:: + split(key_const_reference r_key, Cmp_Fn cmp_fn, PB_DS_CLASS_C_DEC& other) + { + other.clear(); + iterator it = m_keys.begin(); + while (it != m_keys.end()) + if (cmp_fn(r_key, *it)) + { + other.insert_new(*it); + it = m_keys.erase(it); + } + else + ++it; + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + join(PB_DS_CLASS_C_DEC& other, bool with_cleanup) + { + iterator it = other.m_keys.begin(); + while (it != other.m_keys.end()) + { + insert_new(*it); + if (with_cleanup) + it = other.m_keys.erase(it); + else + ++it; + } + _GLIBCXX_DEBUG_ASSERT(!with_cleanup || other.m_keys.empty()); + } + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +} // namespace detail +} // namespace __gnu_pbds + + +#endif + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/eq_fn/eq_by_less.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/eq_fn/eq_by_less.hpp new file mode 100644 index 0000000..5d54fa2 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/eq_fn/eq_by_less.hpp @@ -0,0 +1,69 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file eq_by_less.hpp + * Contains an equivalence function. + */ + +#ifndef PB_DS_EQ_BY_LESS_HPP +#define PB_DS_EQ_BY_LESS_HPP + +#include <utility> +#include <functional> +#include <vector> +#include <assert.h> +#include <ext/pb_ds/detail/types_traits.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /// Equivalence function. + template<typename Key, class Cmp_Fn> + struct eq_by_less : private Cmp_Fn + { + bool + operator()(const Key& r_lhs, const Key& r_rhs) const + { + const bool l = Cmp_Fn::operator()(r_lhs, r_rhs); + const bool g = Cmp_Fn::operator()(r_rhs, r_lhs); + return !(l || g); + } + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_EQ_BY_LESS_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/eq_fn/hash_eq_fn.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/eq_fn/hash_eq_fn.hpp new file mode 100644 index 0000000..7ba0098 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/eq_fn/hash_eq_fn.hpp @@ -0,0 +1,110 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file hash_eq_fn.hpp + * Contains 2 eqivalence functions, one employing a hash value, + * and one ignoring it. + */ + +#ifndef PB_DS_HASH_EQ_FN_HPP +#define PB_DS_HASH_EQ_FN_HPP + +#include <utility> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { + /// Primary template. + template<typename Key, typename Eq_Fn, typename _Alloc, bool Store_Hash> + struct hash_eq_fn; + + /// Specialization 1 - The client requests that hash values not be stored. + template<typename Key, typename Eq_Fn, typename _Alloc> + struct hash_eq_fn<Key, Eq_Fn, _Alloc, false> : public Eq_Fn + { + typedef Eq_Fn eq_fn_base; + typedef typename _Alloc::template rebind<Key>::other key_allocator; + typedef typename key_allocator::const_reference key_const_reference; + + hash_eq_fn() { } + + hash_eq_fn(const Eq_Fn& r_eq_fn) : Eq_Fn(r_eq_fn) { } + + bool + operator()(key_const_reference r_lhs_key, + key_const_reference r_rhs_key) const + { return eq_fn_base::operator()(r_lhs_key, r_rhs_key); } + + void + swap(const hash_eq_fn& other) + { std::swap((Eq_Fn&)(*this), (Eq_Fn&)other); } + }; + + + /// Specialization 2 - The client requests that hash values be stored. + template<typename Key, class Eq_Fn, class _Alloc> + struct hash_eq_fn<Key, Eq_Fn, _Alloc, true> : public Eq_Fn + { + typedef typename _Alloc::size_type size_type; + typedef Eq_Fn eq_fn_base; + typedef typename _Alloc::template rebind<Key>::other key_allocator; + typedef typename key_allocator::const_reference key_const_reference; + + hash_eq_fn() { } + + hash_eq_fn(const Eq_Fn& r_eq_fn) : Eq_Fn(r_eq_fn) { } + + bool + operator()(key_const_reference r_lhs_key, size_type lhs_hash, + key_const_reference r_rhs_key, size_type rhs_hash) const + { + _GLIBCXX_DEBUG_ASSERT(!eq_fn_base::operator()(r_lhs_key, r_rhs_key) + || lhs_hash == rhs_hash); + + return (lhs_hash == rhs_hash && + eq_fn_base::operator()(r_lhs_key, r_rhs_key)); + } + + void + swap(const hash_eq_fn& other) + { std::swap((Eq_Fn&)(*this), (Eq_Fn&)(other)); } + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_fn_imps.hpp new file mode 100644 index 0000000..1b957a5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_fn_imps.hpp @@ -0,0 +1,223 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/constructor_destructor_fn_imps.hpp + * Contains implementations of gp_ht_map_'s constructors, destructor, + * and related functions. + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::entry_allocator +PB_DS_CLASS_C_DEC::s_entry_allocator; + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + insert(*(first_it++)); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_GP_HASH_NAME() +: ranged_probe_fn_base(resize_base::get_nearest_larger_size(1)), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn) +: ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) +: hash_eq_fn_base(r_eq_fn), + ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, + const Comb_Probe_Fn& r_comb_hash_fn) +: hash_eq_fn_base(r_eq_fn), + ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), + r_hash_fn, r_comb_hash_fn), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, + const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober) +: hash_eq_fn_base(r_eq_fn), + ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), + r_hash_fn, comb_hash_fn, prober), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_GP_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, + const Comb_Probe_Fn& comb_hash_fn, const Probe_Fn& prober, + const Resize_Policy& r_resize_policy) +: hash_eq_fn_base(r_eq_fn), resize_base(r_resize_policy), + ranged_probe_fn_base(resize_base::get_nearest_larger_size(1), + r_hash_fn, comb_hash_fn, prober), + m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0), + m_entries(s_entry_allocator.allocate(m_num_e)) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_GP_HASH_NAME(const PB_DS_CLASS_C_DEC& other) : +#ifdef _GLIBCXX_DEBUG + debug_base(other), +#endif + hash_eq_fn_base(other), + resize_base(other), + ranged_probe_fn_base(other), + m_num_e(other.m_num_e), + m_num_used_e(other.m_num_used_e), + m_entries(s_entry_allocator.allocate(m_num_e)) +{ + for (size_type i = 0; i < m_num_e; ++i) + m_entries[i].m_stat = (entry_status)empty_entry_status; + + __try + { + for (size_type i = 0; i < m_num_e; ++i) + { + m_entries[i].m_stat = other.m_entries[i].m_stat; + if (m_entries[i].m_stat == valid_entry_status) + new (m_entries + i) entry(other.m_entries[i]); + } + } + __catch(...) + { + deallocate_all(); + __throw_exception_again; + } + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~PB_DS_GP_HASH_NAME() +{ deallocate_all(); } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + std::swap(m_num_e, other.m_num_e); + std::swap(m_num_used_e, other.m_num_used_e); + std::swap(m_entries, other.m_entries); + ranged_probe_fn_base::swap(other); + hash_eq_fn_base::swap(other); + resize_base::swap(other); + _GLIBCXX_DEBUG_ONLY(debug_base::swap(other)); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +deallocate_all() +{ + clear(); + erase_all_valid_entries(m_entries, m_num_e); + s_entry_allocator.deallocate(m_entries, m_num_e); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase_all_valid_entries(entry_array a_entries_resized, size_type len) +{ + for (size_type pos = 0; pos < len; ++pos) + { + entry_pointer p_e = &a_entries_resized[pos]; + if (p_e->m_stat == valid_entry_status) + p_e->m_value.~value_type(); + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +initialize() +{ + Resize_Policy::notify_resized(m_num_e); + Resize_Policy::notify_cleared(); + ranged_probe_fn_base::notify_resized(m_num_e); + for (size_type i = 0; i < m_num_e; ++i) + m_entries[i].m_stat = empty_entry_status; +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..af5a8c4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_no_store_hash_fn_imps.hpp @@ -0,0 +1,53 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/constructor_destructor_no_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s constructors, destructor, + * and related functions. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +constructor_insert_new_imp(mapped_const_reference r_val, size_type pos, + false_type) +{ + _GLIBCXX_DEBUG_ASSERT(m_entries[pos].m_stat != valid_entry_status)k; + entry* const p_e = m_entries + pos; + new (&p_e->m_value) mapped_value_type(r_val); + p_e->m_stat = valid_entry_status; + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(p_e->m_value.first);) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_store_hash_fn_imps.hpp new file mode 100644 index 0000000..7ce74f2 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_store_hash_fn_imps.hpp @@ -0,0 +1,54 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/constructor_destructor_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s constructors, destructor, + * and related functions. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +constructor_insert_new_imp(mapped_const_reference r_val, size_type pos, + true_type) +{ + _GLIBCXX_DEBUG_ASSERT(m_entries[pos].m_stat != valid_entry_status); + entry* const p_e = m_entries + pos; + new (&p_e->m_value) mapped_value_type(r_val); + p_e->m_hash = ranged_probe_fn_base::operator()(PB_DS_V2F(r_val)).second; + p_e->m_stat = valid_entry_status; + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(p_e->m_value.first);) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/debug_fn_imps.hpp new file mode 100644 index 0000000..6965ebf --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/debug_fn_imps.hpp @@ -0,0 +1,56 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/debug_fn_imps.hpp + * Contains implementations of gp_ht_map_'s debug-mode functions. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + debug_base::check_size(m_num_used_e, __file, __line); + assert_entry_array_valid(m_entries, traits_base::m_store_extra_indicator, + __file, __line); +} + +#include <ext/pb_ds/detail/gp_hash_table_map_/debug_no_store_hash_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/debug_store_hash_fn_imps.hpp> + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/debug_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/debug_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..1535d6c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/debug_no_store_hash_fn_imps.hpp @@ -0,0 +1,72 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/debug_no_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s debug-mode functions. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_entry_array_valid(const entry_array a_entries, false_type, + const char* __file, int __line) const +{ + size_type iterated_num_used_e = 0; + for (size_type pos = 0; pos < m_num_e; ++pos) + { + const_entry_pointer p_e = &a_entries[pos]; + switch(p_e->m_stat) + { + case empty_entry_status: + case erased_entry_status: + break; + case valid_entry_status: + { + key_const_reference r_key = PB_DS_V2F(p_e->m_value); + debug_base::check_key_exists(r_key, __file, __line); + ++iterated_num_used_e; + break; + } + default: + PB_DS_DEBUG_VERIFY(0); + }; + } + PB_DS_DEBUG_VERIFY(iterated_num_used_e == m_num_used_e); +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/debug_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/debug_store_hash_fn_imps.hpp new file mode 100644 index 0000000..cae4352 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/debug_store_hash_fn_imps.hpp @@ -0,0 +1,78 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/debug_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s debug-mode functions. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_entry_array_valid(const entry_array a_entries, true_type, + const char* __file, int __line) const +{ + size_type iterated_num_used_e = 0; + + for (size_type pos = 0; pos < m_num_e; ++pos) + { + const_entry_pointer p_e =& a_entries[pos]; + switch(p_e->m_stat) + { + case empty_entry_status: + case erased_entry_status: + break; + case valid_entry_status: + { + key_const_reference r_key = PB_DS_V2F(p_e->m_value); + debug_base::check_key_exists(r_key, __file, __line); + + const comp_hash pos_hash_pair = ranged_probe_fn_base::operator()(r_key); + + PB_DS_DEBUG_VERIFY(p_e->m_hash == pos_hash_pair.second); + ++iterated_num_used_e; + break; + } + default: + PB_DS_DEBUG_VERIFY(0); + }; + } + + PB_DS_DEBUG_VERIFY(iterated_num_used_e == m_num_used_e); +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/erase_fn_imps.hpp new file mode 100644 index 0000000..a4bc92e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/erase_fn_imps.hpp @@ -0,0 +1,100 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/erase_fn_imps.hpp + * Contains implementations of gp_ht_map_'s erase related functions. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +erase_entry(entry_pointer p_e) +{ + _GLIBCXX_DEBUG_ASSERT(p_e->m_stat = valid_entry_status); + _GLIBCXX_DEBUG_ONLY(debug_base::erase_existing(PB_DS_V2F(p_e->m_value));) + p_e->m_value.~value_type(); + p_e->m_stat = erased_entry_status; + _GLIBCXX_DEBUG_ASSERT(m_num_used_e > 0); + resize_base::notify_erased(--m_num_used_e); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + for (size_type pos = 0; pos < m_num_e; ++pos) + { + entry_pointer p_e = &m_entries[pos]; + if (p_e->m_stat == valid_entry_status) + erase_entry(p_e); + } + do_resize_if_needed_no_throw(); + resize_base::notify_cleared(); +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + PB_DS_ASSERT_VALID((*this)) + size_type num_ersd = 0; + for (size_type pos = 0; pos < m_num_e; ++pos) + { + entry_pointer p_e = &m_entries[pos]; + if (p_e->m_stat == valid_entry_status) + if (pred(p_e->m_value)) + { + ++num_ersd; + erase_entry(p_e); + } + } + + do_resize_if_needed_no_throw(); + PB_DS_ASSERT_VALID((*this)) + return num_ersd; +} + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +erase(key_const_reference r_key) +{ return erase_imp(r_key, traits_base::m_store_extra_indicator); } + +#include <ext/pb_ds/detail/gp_hash_table_map_/erase_no_store_hash_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/erase_store_hash_fn_imps.hpp> diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/erase_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/erase_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..a8555f7 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/erase_no_store_hash_fn_imps.hpp @@ -0,0 +1,84 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/erase_no_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s erase related functions, + * when the hash value is not stored. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +erase_imp(key_const_reference r_key, false_type) +{ + PB_DS_ASSERT_VALID((*this)) + size_type hash = ranged_probe_fn_base::operator()(r_key); + size_type i; + resize_base::notify_erase_search_start(); + + for (i = 0; i < m_num_e; ++i) + { + const size_type pos = ranged_probe_fn_base::operator()(r_key, hash, i); + entry* const p_e = m_entries + pos; + switch(p_e->m_stat) + { + case empty_entry_status: + { + resize_base::notify_erase_search_end(); + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return false; + } + break; + case valid_entry_status: + if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), r_key)) + { + resize_base::notify_erase_search_end(); + erase_entry(p_e); + do_resize_if_needed_no_throw(); + return true; + } + break; + case erased_entry_status: + break; + default: + _GLIBCXX_DEBUG_ASSERT(0); + }; + resize_base::notify_erase_search_collision(); + } + resize_base::notify_erase_search_end(); + return false; +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/erase_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/erase_store_hash_fn_imps.hpp new file mode 100644 index 0000000..f483e11 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/erase_store_hash_fn_imps.hpp @@ -0,0 +1,85 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/erase_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s erase related functions, + * when the hash value is stored. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +erase_imp(key_const_reference r_key, true_type) +{ + const comp_hash pos_hash_pair = ranged_probe_fn_base::operator()(r_key); + size_type i; + resize_base::notify_erase_search_start(); + for (i = 0; i < m_num_e; ++i) + { + const size_type pos = ranged_probe_fn_base::operator()(r_key, pos_hash_pair.second, i); + + entry* const p_e = m_entries + pos; + switch(p_e->m_stat) + { + case empty_entry_status: + { + resize_base::notify_erase_search_end(); + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return false; + } + break; + case valid_entry_status: + if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), p_e->m_hash, + r_key, pos_hash_pair.second)) + { + resize_base::notify_erase_search_end(); + erase_entry(p_e); + do_resize_if_needed_no_throw(); + return true; + } + break; + case erased_entry_status: + break; + default: + _GLIBCXX_DEBUG_ASSERT(0); + }; + + resize_base::notify_erase_search_collision(); + } + resize_base::notify_erase_search_end(); + return false; +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/find_fn_imps.hpp new file mode 100644 index 0000000..2ef1569 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/find_fn_imps.hpp @@ -0,0 +1,70 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/find_fn_imps.hpp + * Contains implementations of gp_ht_map_'s find related functions. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +find(key_const_reference r_key) +{ + PB_DS_ASSERT_VALID((*this)) + return find_key_pointer(r_key, traits_base::m_store_extra_indicator); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +find(key_const_reference r_key) const +{ + PB_DS_ASSERT_VALID((*this)) + return const_cast<PB_DS_CLASS_C_DEC&>(*this).find_key_pointer(r_key, traits_base::m_store_extra_indicator); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +find_end() +{ return 0; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +find_end() const +{ return 0; } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/find_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/find_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..485389c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/find_no_store_hash_fn_imps.hpp @@ -0,0 +1,46 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/find_no_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s find related functions, + * when the hash value is not stored. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::pointer +PB_DS_CLASS_C_DEC:: +find_key_pointer(key_const_reference r_key, false_type) + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/find_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/find_store_hash_fn_imps.hpp new file mode 100644 index 0000000..6f7e4c2 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/find_store_hash_fn_imps.hpp @@ -0,0 +1,40 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/find_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s insert related functions, + * when the hash value is stored. + */ diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp new file mode 100644 index 0000000..881d26e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp @@ -0,0 +1,713 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/gp_ht_map_.hpp + * Contains an implementation class for general probing hash. + */ + +#include <ext/pb_ds/tag_and_trait.hpp> +#include <ext/pb_ds/detail/hash_fn/ranged_probe_fn.hpp> +#include <ext/pb_ds/detail/types_traits.hpp> +#include <ext/pb_ds/exception.hpp> +#include <ext/pb_ds/detail/eq_fn/hash_eq_fn.hpp> +#include <utility> +#ifdef PB_DS_HT_MAP_TRACE_ +#include <iostream> +#endif +#ifdef _GLIBCXX_DEBUG +#include <ext/pb_ds/detail/debug_map_base.hpp> +#endif +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#ifdef PB_DS_DATA_TRUE_INDICATOR +#define PB_DS_GP_HASH_NAME gp_ht_map +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR +#define PB_DS_GP_HASH_NAME gp_ht_set +#endif + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Mapped, typename Hash_Fn, typename Eq_Fn, \ + typename _Alloc, bool Store_Hash, typename Comb_Probe_Fn, \ + typename Probe_Fn, typename Resize_Policy> + +#define PB_DS_CLASS_C_DEC \ + PB_DS_GP_HASH_NAME<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, \ + Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy> + +#define PB_DS_HASH_EQ_FN_C_DEC \ + hash_eq_fn<Key, Eq_Fn, _Alloc, Store_Hash> + +#define PB_DS_RANGED_PROBE_FN_C_DEC \ + ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, Probe_Fn, Store_Hash> + +#define PB_DS_GP_HASH_TRAITS_BASE \ + types_traits<Key, Mapped, _Alloc, Store_Hash> + +#ifdef _GLIBCXX_DEBUG +#define PB_DS_DEBUG_MAP_BASE_C_DEC \ + debug_map_base<Key, Eq_Fn, \ + typename _Alloc::template rebind<Key>::other::const_reference> +#endif + + + /** + * A general-probing hash-based container. + * + * + * @ingroup hash-detail + * + * @tparam Key Key type. + * + * @tparam Mapped Map type. + * + * @tparam Hash_Fn Hashing functor. + * Default is __gnu_cxx::hash. + * + * @tparam Eq_Fn Equal functor. + * Default std::equal_to<Key> + * + * @tparam _Alloc Allocator type. + * + * @tparam Store_Hash If key type stores extra metadata. + * Defaults to false. + * + * @tparam Comb_Probe_Fn Combining probe functor. + * If Hash_Fn is not null_type, then this + * is the ranged-probe functor; otherwise, + * this is the range-hashing functor. + * XXX See Design::Hash-Based Containers::Hash Policies. + * Default direct_mask_range_hashing. + * + * @tparam Probe_Fn Probe functor. + * Defaults to linear_probe_fn, + * also quadratic_probe_fn. + * + * @tparam Resize_Policy Resizes hash. + * Defaults to hash_standard_resize_policy, + * using hash_exponential_size_policy and + * hash_load_check_resize_trigger. + * + * + * Bases are: detail::hash_eq_fn, Resize_Policy, detail::ranged_probe_fn, + * detail::types_traits. (Optional: detail::debug_map_base.) + */ + template<typename Key, + typename Mapped, + typename Hash_Fn, + typename Eq_Fn, + typename _Alloc, + bool Store_Hash, + typename Comb_Probe_Fn, + typename Probe_Fn, + typename Resize_Policy> + class PB_DS_GP_HASH_NAME : +#ifdef _GLIBCXX_DEBUG + protected PB_DS_DEBUG_MAP_BASE_C_DEC, +#endif + public PB_DS_HASH_EQ_FN_C_DEC, + public Resize_Policy, + public PB_DS_RANGED_PROBE_FN_C_DEC, + public PB_DS_GP_HASH_TRAITS_BASE + { + private: + typedef PB_DS_GP_HASH_TRAITS_BASE traits_base; + typedef typename traits_base::value_type value_type_; + typedef typename traits_base::pointer pointer_; + typedef typename traits_base::const_pointer const_pointer_; + typedef typename traits_base::reference reference_; + typedef typename traits_base::const_reference const_reference_; + typedef typename traits_base::comp_hash comp_hash; + + enum entry_status + { + empty_entry_status, + valid_entry_status, + erased_entry_status + } __attribute__ ((packed)); + + struct entry : public traits_base::stored_data_type + { + entry_status m_stat; + }; + + typedef typename _Alloc::template rebind<entry>::other entry_allocator; + typedef typename entry_allocator::pointer entry_pointer; + typedef typename entry_allocator::const_pointer const_entry_pointer; + typedef typename entry_allocator::reference entry_reference; + typedef typename entry_allocator::const_reference const_entry_reference; + typedef typename entry_allocator::pointer entry_array; + + typedef PB_DS_RANGED_PROBE_FN_C_DEC ranged_probe_fn_base; + +#ifdef _GLIBCXX_DEBUG + typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base; +#endif + + typedef PB_DS_HASH_EQ_FN_C_DEC hash_eq_fn_base; + typedef Resize_Policy resize_base; + +#define PB_DS_GEN_POS typename _Alloc::size_type + +#include <ext/pb_ds/detail/unordered_iterator/point_const_iterator.hpp> +#include <ext/pb_ds/detail/unordered_iterator/point_iterator.hpp> +#include <ext/pb_ds/detail/unordered_iterator/const_iterator.hpp> +#include <ext/pb_ds/detail/unordered_iterator/iterator.hpp> + +#undef PB_DS_GEN_POS + + public: + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef Hash_Fn hash_fn; + typedef Eq_Fn eq_fn; + typedef Probe_Fn probe_fn; + typedef Comb_Probe_Fn comb_probe_fn; + typedef Resize_Policy resize_policy; + + /// Value stores hash, true or false. + enum + { + store_hash = Store_Hash + }; + + typedef typename traits_base::key_type key_type; + typedef typename traits_base::key_pointer key_pointer; + typedef typename traits_base::key_const_pointer key_const_pointer; + typedef typename traits_base::key_reference key_reference; + typedef typename traits_base::key_const_reference key_const_reference; + typedef typename traits_base::mapped_type mapped_type; + typedef typename traits_base::mapped_pointer mapped_pointer; + typedef typename traits_base::mapped_const_pointer mapped_const_pointer; + typedef typename traits_base::mapped_reference mapped_reference; + typedef typename traits_base::mapped_const_reference mapped_const_reference; + typedef typename traits_base::value_type value_type; + typedef typename traits_base::pointer pointer; + typedef typename traits_base::const_pointer const_pointer; + typedef typename traits_base::reference reference; + typedef typename traits_base::const_reference const_reference; + +#ifdef PB_DS_DATA_TRUE_INDICATOR + typedef point_iterator_ point_iterator; +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR + typedef point_const_iterator_ point_iterator; +#endif + + typedef point_const_iterator_ point_const_iterator; + +#ifdef PB_DS_DATA_TRUE_INDICATOR + typedef iterator_ iterator; +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR + typedef const_iterator_ iterator; +#endif + + typedef const_iterator_ const_iterator; + + PB_DS_GP_HASH_NAME(); + + PB_DS_GP_HASH_NAME(const PB_DS_CLASS_C_DEC&); + + PB_DS_GP_HASH_NAME(const Hash_Fn&); + + PB_DS_GP_HASH_NAME(const Hash_Fn&, const Eq_Fn&); + + PB_DS_GP_HASH_NAME(const Hash_Fn&, const Eq_Fn&, const Comb_Probe_Fn&); + + PB_DS_GP_HASH_NAME(const Hash_Fn&, const Eq_Fn&, const Comb_Probe_Fn&, + const Probe_Fn&); + + PB_DS_GP_HASH_NAME(const Hash_Fn&, const Eq_Fn&, const Comb_Probe_Fn&, + const Probe_Fn&, const Resize_Policy&); + + template<typename It> + void + copy_from_range(It, It); + + virtual + ~PB_DS_GP_HASH_NAME(); + + void + swap(PB_DS_CLASS_C_DEC&); + + inline size_type + size() const; + + inline size_type + max_size() const; + + /// True if size() == 0. + inline bool + empty() const; + + /// Return current hash_fn. + Hash_Fn& + get_hash_fn(); + + /// Return current const hash_fn. + const Hash_Fn& + get_hash_fn() const; + + /// Return current eq_fn. + Eq_Fn& + get_eq_fn(); + + /// Return current const eq_fn. + const Eq_Fn& + get_eq_fn() const; + + /// Return current probe_fn. + Probe_Fn& + get_probe_fn(); + + /// Return current const probe_fn. + const Probe_Fn& + get_probe_fn() const; + + /// Return current comb_probe_fn. + Comb_Probe_Fn& + get_comb_probe_fn(); + + /// Return current const comb_probe_fn. + const Comb_Probe_Fn& + get_comb_probe_fn() const; + + /// Return current resize_policy. + Resize_Policy& + get_resize_policy(); + + /// Return current const resize_policy. + const Resize_Policy& + get_resize_policy() const; + + inline std::pair<point_iterator, bool> + insert(const_reference r_val) + { + _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid(__FILE__, __LINE__);) + return insert_imp(r_val, traits_base::m_store_extra_indicator); + } + + inline mapped_reference + operator[](key_const_reference r_key) + { +#ifdef PB_DS_DATA_TRUE_INDICATOR + return subscript_imp(r_key, traits_base::m_store_extra_indicator); +#else + insert(r_key); + return traits_base::s_null_type; +#endif + } + + inline point_iterator + find(key_const_reference); + + inline point_const_iterator + find(key_const_reference) const; + + inline point_iterator + find_end(); + + inline point_const_iterator + find_end() const; + + inline bool + erase(key_const_reference); + + template<typename Pred> + inline size_type + erase_if(Pred); + + void + clear(); + + inline iterator + begin(); + + inline const_iterator + begin() const; + + inline iterator + end(); + + inline const_iterator + end() const; + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; +#endif + +#ifdef PB_DS_HT_MAP_TRACE_ + void + trace() const; +#endif + + private: +#ifdef PB_DS_DATA_TRUE_INDICATOR + friend class iterator_; +#endif + + friend class const_iterator_; + + void + deallocate_all(); + + void + initialize(); + + void + erase_all_valid_entries(entry_array, size_type); + + inline bool + do_resize_if_needed(); + + inline void + do_resize_if_needed_no_throw(); + + void + resize_imp(size_type); + + virtual void + do_resize(size_type); + + void + resize_imp(entry_array, size_type); + + inline void + resize_imp_reassign(entry_pointer, entry_array, false_type); + + inline void + resize_imp_reassign(entry_pointer, entry_array, true_type); + + inline size_type + find_ins_pos(key_const_reference, false_type); + + inline comp_hash + find_ins_pos(key_const_reference, true_type); + + inline std::pair<point_iterator, bool> + insert_imp(const_reference, false_type); + + inline std::pair<point_iterator, bool> + insert_imp(const_reference, true_type); + + inline pointer + insert_new_imp(const_reference r_val, size_type pos) + { + _GLIBCXX_DEBUG_ASSERT(m_entries[pos].m_stat != valid_entry_status); + + if (do_resize_if_needed()) + pos = find_ins_pos(PB_DS_V2F(r_val), + traits_base::m_store_extra_indicator); + + _GLIBCXX_DEBUG_ASSERT(m_entries[pos].m_stat != valid_entry_status); + entry* const p_e = m_entries + pos; + new (&p_e->m_value) value_type(r_val); + p_e->m_stat = valid_entry_status; + resize_base::notify_inserted(++m_num_used_e); + + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(p_e->m_value));) + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + return &p_e->m_value; + } + + inline pointer + insert_new_imp(const_reference r_val, comp_hash& r_pos_hash_pair) + { + _GLIBCXX_DEBUG_ASSERT(m_entries[r_pos_hash_pair.first].m_stat != + valid_entry_status); + + if (do_resize_if_needed()) + r_pos_hash_pair = find_ins_pos(PB_DS_V2F(r_val), + traits_base::m_store_extra_indicator); + + _GLIBCXX_DEBUG_ASSERT(m_entries[r_pos_hash_pair.first].m_stat != + valid_entry_status); + + entry* const p_e = m_entries + r_pos_hash_pair.first; + new (&p_e->m_value) value_type(r_val); + p_e->m_hash = r_pos_hash_pair.second; + p_e->m_stat = valid_entry_status; + + resize_base::notify_inserted(++m_num_used_e); + + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(p_e->m_value));) + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + return &p_e->m_value; + } + +#ifdef PB_DS_DATA_TRUE_INDICATOR + inline mapped_reference + subscript_imp(key_const_reference key, false_type) + { + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + + const size_type pos = find_ins_pos(key, + traits_base::m_store_extra_indicator); + + entry_pointer p_e = &m_entries[pos]; + if (p_e->m_stat != valid_entry_status) + return insert_new_imp(value_type(key, mapped_type()), pos)->second; + + PB_DS_CHECK_KEY_EXISTS(key) + return p_e->m_value.second; + } + + inline mapped_reference + subscript_imp(key_const_reference key, true_type) + { + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + + comp_hash pos_hash_pair = find_ins_pos(key, + traits_base::m_store_extra_indicator); + + if (m_entries[pos_hash_pair.first].m_stat != valid_entry_status) + return insert_new_imp(value_type(key, mapped_type()), + pos_hash_pair)->second; + + PB_DS_CHECK_KEY_EXISTS(key) + return (m_entries + pos_hash_pair.first)->m_value.second; + } +#endif + + inline pointer + find_key_pointer(key_const_reference key, false_type) + { + const size_type hash = ranged_probe_fn_base::operator()(key); + resize_base::notify_find_search_start(); + + // Loop until entry is found or until all possible entries accessed. + for (size_type i = 0; i < m_num_e; ++i) + { + const size_type pos = ranged_probe_fn_base::operator()(key, + hash, i); + + entry* const p_e = m_entries + pos; + switch (p_e->m_stat) + { + case empty_entry_status: + { + resize_base::notify_find_search_end(); + PB_DS_CHECK_KEY_DOES_NOT_EXIST(key) + return 0; + } + break; + case valid_entry_status: + if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), key)) + { + resize_base::notify_find_search_end(); + PB_DS_CHECK_KEY_EXISTS(key) + return pointer(&p_e->m_value); + } + break; + case erased_entry_status: + break; + default: + _GLIBCXX_DEBUG_ASSERT(0); + }; + + resize_base::notify_find_search_collision(); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(key) + resize_base::notify_find_search_end(); + return 0; + } + + inline pointer + find_key_pointer(key_const_reference key, true_type) + { + comp_hash pos_hash_pair = ranged_probe_fn_base::operator()(key); + resize_base::notify_find_search_start(); + + // Loop until entry is found or until all possible entries accessed. + for (size_type i = 0; i < m_num_e; ++i) + { + const size_type pos = + ranged_probe_fn_base::operator()(key, pos_hash_pair.second, i); + + entry* const p_e = m_entries + pos; + + switch(p_e->m_stat) + { + case empty_entry_status: + { + resize_base::notify_find_search_end(); + PB_DS_CHECK_KEY_DOES_NOT_EXIST(key) + return 0; + } + break; + case valid_entry_status: + if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), + p_e->m_hash, + key, pos_hash_pair.second)) + { + resize_base::notify_find_search_end(); + PB_DS_CHECK_KEY_EXISTS(key) + return pointer(&p_e->m_value); + } + break; + case erased_entry_status: + break; + default: + _GLIBCXX_DEBUG_ASSERT(0); + }; + + resize_base::notify_find_search_collision(); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(key) + resize_base::notify_find_search_end(); + return 0; + } + + inline bool + erase_imp(key_const_reference, true_type); + + inline bool + erase_imp(key_const_reference, false_type); + + inline void + erase_entry(entry_pointer); + +#ifdef PB_DS_DATA_TRUE_INDICATOR + void + inc_it_state(pointer& r_p_value, size_type& r_pos) const + { inc_it_state((mapped_const_pointer& )r_p_value, r_pos); } +#endif + + void + inc_it_state(const_pointer& r_p_value, size_type& r_pos) const + { + _GLIBCXX_DEBUG_ASSERT(r_p_value != 0); + for (++r_pos; r_pos < m_num_e; ++r_pos) + { + const_entry_pointer p_e =& m_entries[r_pos]; + if (p_e->m_stat == valid_entry_status) + { + r_p_value =& p_e->m_value; + return; + } + } + r_p_value = 0; + } + + void + get_start_it_state(const_pointer& r_p_value, size_type& r_pos) const + { + for (r_pos = 0; r_pos < m_num_e; ++r_pos) + { + const_entry_pointer p_e = &m_entries[r_pos]; + if (p_e->m_stat == valid_entry_status) + { + r_p_value = &p_e->m_value; + return; + } + } + r_p_value = 0; + } + + void + get_start_it_state(pointer& r_p_value, size_type& r_pos) + { + for (r_pos = 0; r_pos < m_num_e; ++r_pos) + { + entry_pointer p_e = &m_entries[r_pos]; + if (p_e->m_stat == valid_entry_status) + { + r_p_value = &p_e->m_value; + return; + } + } + r_p_value = 0; + } + +#ifdef _GLIBCXX_DEBUG + void + assert_entry_array_valid(const entry_array, false_type, + const char*, int) const; + + void + assert_entry_array_valid(const entry_array, true_type, + const char*, int) const; +#endif + + static entry_allocator s_entry_allocator; + static iterator s_end_it; + static const_iterator s_const_end_it; + + size_type m_num_e; + size_type m_num_used_e; + entry_pointer m_entries; + + enum + { + store_hash_ok = !Store_Hash + || !is_same<Hash_Fn, __gnu_pbds::null_type>::value + }; + + PB_DS_STATIC_ASSERT(sth, store_hash_ok); + }; + +#include <ext/pb_ds/detail/gp_hash_table_map_/constructor_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/info_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/policy_access_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/iterator_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/trace_fn_imps.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_HASH_EQ_FN_C_DEC +#undef PB_DS_RANGED_PROBE_FN_C_DEC +#undef PB_DS_GP_HASH_TRAITS_BASE +#undef PB_DS_DEBUG_MAP_BASE_C_DEC +#undef PB_DS_GP_HASH_NAME + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/info_fn_imps.hpp new file mode 100644 index 0000000..09d05bf --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/info_fn_imps.hpp @@ -0,0 +1,58 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/info_fn_imps.hpp + * Contains implementations of gp_ht_map_'s entire container info related + * functions. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size() const +{ return m_num_used_e; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +max_size() const +{ return s_entry_allocator.max_size(); } + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +empty() const +{ return (size() == 0); } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/insert_fn_imps.hpp new file mode 100644 index 0000000..c8ed2ec --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/insert_fn_imps.hpp @@ -0,0 +1,43 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/insert_fn_imps.hpp + * Contains implementations of gp_ht_map_'s insert related functions. + */ + +#include <ext/pb_ds/detail/gp_hash_table_map_/insert_no_store_hash_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/insert_store_hash_fn_imps.hpp> + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/insert_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/insert_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..57126d5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/insert_no_store_hash_fn_imps.hpp @@ -0,0 +1,111 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/insert_no_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s insert related functions, + * when the hash value is not stored. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +find_ins_pos(key_const_reference r_key, false_type) +{ + size_type hash = ranged_probe_fn_base::operator()(r_key); + size_type i; + + /* The insertion position is initted to a non-legal value to indicate + * that it has not been initted yet. + */ + size_type ins_pos = m_num_e; + resize_base::notify_insert_search_start(); + for (i = 0; i < m_num_e; ++i) + { + const size_type pos = ranged_probe_fn_base::operator()(r_key, hash, i); + _GLIBCXX_DEBUG_ASSERT(pos < m_num_e); + entry* const p_e = m_entries + pos; + switch(p_e->m_stat) + { + case empty_entry_status: + { + resize_base::notify_insert_search_end(); + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return (ins_pos == m_num_e) ? pos : ins_pos; + } + break; + case erased_entry_status: + if (ins_pos == m_num_e) + ins_pos = pos; + break; + case valid_entry_status: + if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), r_key)) + { + resize_base::notify_insert_search_end(); + PB_DS_CHECK_KEY_EXISTS(r_key) + return pos; + } + break; + default: + _GLIBCXX_DEBUG_ASSERT(0); + }; + + resize_base::notify_insert_search_collision(); + } + resize_base::notify_insert_search_end(); + if (ins_pos == m_num_e) + __throw_insert_error(); + return ins_pos; +} + +PB_DS_CLASS_T_DEC +inline std::pair<typename PB_DS_CLASS_C_DEC::point_iterator, bool> +PB_DS_CLASS_C_DEC:: +insert_imp(const_reference r_val, false_type) +{ + key_const_reference r_key = PB_DS_V2F(r_val); + const size_type pos = find_ins_pos(r_key, + traits_base::m_store_extra_indicator); + + if (m_entries[pos].m_stat == valid_entry_status) + { + PB_DS_CHECK_KEY_EXISTS(r_key) + return std::make_pair(&(m_entries + pos)->m_value, false); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return std::make_pair(insert_new_imp(r_val, pos), true); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/insert_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/insert_store_hash_fn_imps.hpp new file mode 100644 index 0000000..1c3122f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/insert_store_hash_fn_imps.hpp @@ -0,0 +1,118 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/insert_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s find related functions, + * when the hash value is stored. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::comp_hash +PB_DS_CLASS_C_DEC:: +find_ins_pos(key_const_reference r_key, true_type) +{ + PB_DS_ASSERT_VALID((*this)) + comp_hash pos_hash_pair = ranged_probe_fn_base::operator()(r_key); + + size_type i; + + /* The insertion position is initted to a non-legal value to indicate + * that it has not been initted yet. + */ + size_type ins_pos = m_num_e; + resize_base::notify_insert_search_start(); + for (i = 0; i < m_num_e; ++i) + { + const size_type pos = ranged_probe_fn_base::operator()(r_key, pos_hash_pair.second, i); + + entry* const p_e = m_entries + pos; + switch(p_e->m_stat) + { + case empty_entry_status: + { + resize_base::notify_insert_search_end(); + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + + return ((ins_pos == m_num_e) ? + std::make_pair(pos, pos_hash_pair.second) : + std::make_pair(ins_pos, pos_hash_pair.second)); + } + break; + case erased_entry_status: + if (ins_pos == m_num_e) + ins_pos = pos; + break; + case valid_entry_status: + if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), p_e->m_hash, + r_key, pos_hash_pair.second)) + { + resize_base::notify_insert_search_end(); + PB_DS_CHECK_KEY_EXISTS(r_key) + return std::make_pair(pos, pos_hash_pair.second); + } + break; + default: + _GLIBCXX_DEBUG_ASSERT(0); + }; + resize_base::notify_insert_search_collision(); + } + resize_base::notify_insert_search_end(); + if (ins_pos == m_num_e) + __throw_insert_error(); + return std::make_pair(ins_pos, pos_hash_pair.second); +} + +PB_DS_CLASS_T_DEC +inline std::pair<typename PB_DS_CLASS_C_DEC::point_iterator, bool> +PB_DS_CLASS_C_DEC:: +insert_imp(const_reference r_val, true_type) +{ + key_const_reference r_key = PB_DS_V2F(r_val); + comp_hash pos_hash_pair = find_ins_pos(r_key, + traits_base::m_store_extra_indicator); + + _GLIBCXX_DEBUG_ASSERT(pos_hash_pair.first < m_num_e); + entry_pointer p_e =& m_entries[pos_hash_pair.first]; + if (p_e->m_stat == valid_entry_status) + { + PB_DS_CHECK_KEY_EXISTS(r_key) + return std::make_pair(&p_e->m_value, false); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return std::make_pair(insert_new_imp(r_val, pos_hash_pair), true); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/iterator_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/iterator_fn_imps.hpp new file mode 100644 index 0000000..06089cf --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/iterator_fn_imps.hpp @@ -0,0 +1,83 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/iterator_fn_imps.hpp + * Contains implementations of gp_ht_map_'s iterators related functions, e.g., + * begin(). + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC::s_end_it; + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC::s_const_end_it; + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +begin() +{ + pointer_ p_value; + size_type pos; + get_start_it_state(p_value, pos); + return iterator(p_value, pos, this); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +end() +{ return s_end_it; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin() const +{ + const_pointer_ p_value; + size_type pos; + get_start_it_state(p_value, pos); + return const_iterator(p_value, pos, this); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end() const +{ return s_const_end_it; } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/policy_access_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/policy_access_fn_imps.hpp new file mode 100644 index 0000000..dfc3769 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/policy_access_fn_imps.hpp @@ -0,0 +1,100 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/policy_access_fn_imps.hpp + * Contains implementations of gp_ht_map_'s policy agpess + * functions. + */ + +PB_DS_CLASS_T_DEC +Hash_Fn& +PB_DS_CLASS_C_DEC:: +get_hash_fn() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Hash_Fn& +PB_DS_CLASS_C_DEC:: +get_hash_fn() const +{ return *this; } + +PB_DS_CLASS_T_DEC +Eq_Fn& +PB_DS_CLASS_C_DEC:: +get_eq_fn() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Eq_Fn& +PB_DS_CLASS_C_DEC:: +get_eq_fn() const +{ return *this; } + +PB_DS_CLASS_T_DEC +Probe_Fn& +PB_DS_CLASS_C_DEC:: +get_probe_fn() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Probe_Fn& +PB_DS_CLASS_C_DEC:: +get_probe_fn() const +{ return *this; } + +PB_DS_CLASS_T_DEC +Comb_Probe_Fn& +PB_DS_CLASS_C_DEC:: +get_comb_probe_fn() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Comb_Probe_Fn& +PB_DS_CLASS_C_DEC:: +get_comb_probe_fn() const +{ return *this; } + +PB_DS_CLASS_T_DEC +Resize_Policy& +PB_DS_CLASS_C_DEC:: +get_resize_policy() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Resize_Policy& +PB_DS_CLASS_C_DEC:: +get_resize_policy() const +{ return *this; } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp new file mode 100644 index 0000000..fc8e8ad --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp @@ -0,0 +1,139 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/resize_fn_imps.hpp + * Contains implementations of gp_ht_map_'s resize related functions. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +do_resize_if_needed() +{ + if (!resize_base::is_resize_needed()) + return false; + resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); + return true; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +do_resize(size_type n) +{ resize_imp(resize_base::get_nearest_larger_size(n)); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +do_resize_if_needed_no_throw() +{ + if (!resize_base::is_resize_needed()) + return; + + __try + { + resize_imp(resize_base::get_new_size(m_num_e, m_num_used_e)); + } + __catch(...) + { } + + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +resize_imp(size_type new_size) +{ +#ifdef PB_DS_REGRESSION + typename _Alloc::group_adjustor adjust(m_num_e); +#endif + + if (new_size == m_num_e) + return; + + PB_DS_ASSERT_VALID((*this)) + const size_type old_size = m_num_e; + entry_array a_entries_resized = 0; + + // Following line might throw an exception. + a_entries_resized = s_entry_allocator.allocate(new_size); + + ranged_probe_fn_base::notify_resized(new_size); + m_num_e = new_size; + + for (size_type i = 0; i < m_num_e; ++i) + a_entries_resized[i].m_stat = empty_entry_status; + + __try + { + resize_imp(a_entries_resized, old_size); + } + __catch(...) + { + erase_all_valid_entries(a_entries_resized, new_size); + m_num_e = old_size; + s_entry_allocator.deallocate(a_entries_resized, new_size); + ranged_probe_fn_base::notify_resized(old_size); + __throw_exception_again; + } + + // At this point no exceptions can be thrown. + _GLIBCXX_DEBUG_ONLY(assert_entry_array_valid(a_entries_resized, + traits_base::m_store_extra_indicator, + __FILE__, __LINE__);) + + Resize_Policy::notify_resized(new_size); + erase_all_valid_entries(m_entries, old_size); + s_entry_allocator.deallocate(m_entries, old_size); + m_entries = a_entries_resized; + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +resize_imp(entry_array a_entries_resized, size_type old_size) +{ + for (size_type pos = 0; pos < old_size; ++pos) + if (m_entries[pos].m_stat == valid_entry_status) + resize_imp_reassign(m_entries + pos, a_entries_resized, + traits_base::m_store_extra_indicator); +} + +#include <ext/pb_ds/detail/gp_hash_table_map_/resize_no_store_hash_fn_imps.hpp> +#include <ext/pb_ds/detail/gp_hash_table_map_/resize_store_hash_fn_imps.hpp> + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_no_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_no_store_hash_fn_imps.hpp new file mode 100644 index 0000000..46d4f92 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_no_store_hash_fn_imps.hpp @@ -0,0 +1,72 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/resize_no_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s resize related functions, when the + * hash value is not stored. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +resize_imp_reassign(entry_pointer p_e, entry_array a_entries_resized, + false_type) +{ + key_const_reference r_key = PB_DS_V2F(p_e->m_value); + size_type hash = ranged_probe_fn_base::operator()(r_key); + size_type i; + for (i = 0; i < m_num_e; ++i) + { + const size_type pos = ranged_probe_fn_base::operator()(r_key, hash, i); + entry_pointer p_new_e = a_entries_resized + pos; + switch(p_new_e->m_stat) + { + case empty_entry_status: + new (&p_new_e->m_value) value_type(p_e->m_value); + p_new_e->m_stat = valid_entry_status; + return; + case erased_entry_status: + _GLIBCXX_DEBUG_ASSERT(0); + break; + case valid_entry_status: + break; + default: + _GLIBCXX_DEBUG_ASSERT(0); + }; + } + __throw_insert_error(); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_store_hash_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_store_hash_fn_imps.hpp new file mode 100644 index 0000000..40b5e73 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_store_hash_fn_imps.hpp @@ -0,0 +1,74 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/resize_store_hash_fn_imps.hpp + * Contains implementations of gp_ht_map_'s resize related functions, when the + * hash value is stored. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +resize_imp_reassign(entry_pointer p_e, entry_array a_entries_resized, + true_type) +{ + key_const_reference r_key = PB_DS_V2F(p_e->m_value); + size_type hash = ranged_probe_fn_base::operator()(r_key, p_e->m_hash); + + size_type i; + for (i = 0; i < m_num_e; ++i) + { + const size_type pos = ranged_probe_fn_base::operator()(r_key, hash, i); + entry_pointer p_new_e = a_entries_resized + pos; + switch(p_new_e->m_stat) + { + case empty_entry_status: + new (&p_new_e->m_value) value_type(p_e->m_value); + p_new_e->m_hash = hash; + p_new_e->m_stat = valid_entry_status; + return; + case erased_entry_status: + _GLIBCXX_DEBUG_ASSERT(0); + break; + case valid_entry_status: + break; + default: + _GLIBCXX_DEBUG_ASSERT(0); + }; + } + __throw_insert_error(); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/trace_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/trace_fn_imps.hpp new file mode 100644 index 0000000..4d804ba --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/trace_fn_imps.hpp @@ -0,0 +1,74 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file gp_hash_table_map_/trace_fn_imps.hpp + * Contains implementations of gp_ht_map_'s trace-mode functions. + */ + +#ifdef PB_DS_HT_MAP_TRACE_ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace() const +{ + std::cerr << static_cast<unsigned long>(m_num_e) << " " << + static_cast<unsigned long>(m_num_used_e) << std::endl; + + for (size_type i = 0; i < m_num_e; ++i) + { + std::cerr << static_cast<unsigned long>(i) << " "; + + switch(m_entries[i].m_stat) + { + case empty_entry_status: + std::cerr << "<empty>"; + break; + case erased_entry_status: + std::cerr << "<erased>"; + break; + case valid_entry_status: + std::cerr << PB_DS_V2F(m_entries[i].m_value); + break; + default: + _GLIBCXX_DEBUG_ASSERT(0); + }; + + std::cerr << std::endl; + } +} + +#endif // #ifdef PB_DS_HT_MAP_TRACE_ diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/direct_mask_range_hashing_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/direct_mask_range_hashing_imp.hpp new file mode 100644 index 0000000..9e3f313 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/direct_mask_range_hashing_imp.hpp @@ -0,0 +1,58 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file direct_mask_range_hashing_imp.hpp + * Contains a range-hashing policy implementation + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ mask_based_base::swap(other); } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +notify_resized(size_type size) +{ mask_based_base::notify_resized(size); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +operator()(size_type hash) const +{ return mask_based_base::range_hash(hash); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/direct_mod_range_hashing_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/direct_mod_range_hashing_imp.hpp new file mode 100644 index 0000000..c38ecec --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/direct_mod_range_hashing_imp.hpp @@ -0,0 +1,58 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file direct_mod_range_hashing_imp.hpp + * Contains a range-hashing policy implementation + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ mod_based_base::swap(other); } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +notify_resized(size_type n) +{ mod_based_base::notify_resized(n); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +operator()(size_type hash) const +{ return mod_based_base::range_hash(hash); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/linear_probe_fn_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/linear_probe_fn_imp.hpp new file mode 100644 index 0000000..5055d6a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/linear_probe_fn_imp.hpp @@ -0,0 +1,53 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file linear_probe_fn_imp.hpp + * Contains a probe policy implementation + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +operator()(size_type i) const +{ + return (i); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/mask_based_range_hashing.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/mask_based_range_hashing.hpp new file mode 100644 index 0000000..b92a3eb --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/mask_based_range_hashing.hpp @@ -0,0 +1,101 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file mask_based_range_hashing.hpp + * Contains a range hashing policy base. + */ + +#ifndef PB_DS_MASK_BASED_RANGE_HASHING_HPP +#define PB_DS_MASK_BASED_RANGE_HASHING_HPP + +namespace __gnu_pbds +{ + namespace detail + { + /// Range hashing policy. + template<typename Size_Type> + class mask_based_range_hashing + { + protected: + typedef Size_Type size_type; + + void + swap(mask_based_range_hashing& other) + { std::swap(m_mask, other.m_mask); } + + void + notify_resized(size_type size); + + inline size_type + range_hash(size_type hash) const + { return size_type(hash & m_mask); } + + private: + size_type m_mask; + const static size_type s_num_bits_in_size_type; + const static size_type s_highest_bit_1; + }; + + template<typename Size_Type> + const typename mask_based_range_hashing<Size_Type>::size_type + mask_based_range_hashing<Size_Type>::s_num_bits_in_size_type = + sizeof(typename mask_based_range_hashing<Size_Type>::size_type) << 3; + + template<typename Size_Type> + const typename mask_based_range_hashing<Size_Type>::size_type mask_based_range_hashing<Size_Type>::s_highest_bit_1 = static_cast<typename mask_based_range_hashing<Size_Type>::size_type>(1) << (s_num_bits_in_size_type - 1); + + + template<typename Size_Type> + void + mask_based_range_hashing<Size_Type>:: + notify_resized(size_type size) + { + size_type i = 0; + while (size ^ s_highest_bit_1) + { + size <<= 1; + ++i; + } + + m_mask = 1; + i += 2; + while (i++ < s_num_bits_in_size_type) + m_mask = (m_mask << 1) ^ 1; + } + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/mod_based_range_hashing.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/mod_based_range_hashing.hpp new file mode 100644 index 0000000..d1b3dda --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/mod_based_range_hashing.hpp @@ -0,0 +1,74 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file mod_based_range_hashing.hpp + * Contains a range hashing policy base. + */ + +#ifndef PB_DS_MOD_BASED_RANGE_HASHING_HPP +#define PB_DS_MOD_BASED_RANGE_HASHING_HPP + +namespace __gnu_pbds +{ + namespace detail + { + /// Mod based range hashing. + template<typename Size_Type> + class mod_based_range_hashing + { + protected: + typedef Size_Type size_type; + + void + swap(mod_based_range_hashing& other) + { std::swap(m_size, other.m_size); } + + void + notify_resized(size_type s) + { m_size = s; } + + inline size_type + range_hash(size_type s) const + { return s % m_size; } + + private: + size_type m_size; + }; + } // namespace detail + +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_MOD_BASED_RANGE_HASHING_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/probe_fn_base.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/probe_fn_base.hpp new file mode 100644 index 0000000..3cd06e1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/probe_fn_base.hpp @@ -0,0 +1,60 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file probe_fn_base.hpp + * Contains a probe policy base. + */ + +#ifndef PB_DS_PROBE_FN_BASE_HPP +#define PB_DS_PROBE_FN_BASE_HPP + +#include <functional> + +namespace __gnu_pbds +{ + namespace detail + { + /// Probe functor base. + template<typename _Alloc> + class probe_fn_base + { + protected: + ~probe_fn_base() { } + }; +} // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/quadratic_probe_fn_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/quadratic_probe_fn_imp.hpp new file mode 100644 index 0000000..4b31646 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/quadratic_probe_fn_imp.hpp @@ -0,0 +1,53 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file quadratic_probe_fn_imp.hpp + * Contains a probe policy implementation + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +operator()(size_type i) const +{ + return (i* i); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/ranged_hash_fn.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/ranged_hash_fn.hpp new file mode 100644 index 0000000..0a3cabe --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/ranged_hash_fn.hpp @@ -0,0 +1,359 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ranged_hash_fn.hpp + * Contains a unified ranged hash functor, allowing the hash tables + * to deal with a single class for ranged hashing. + */ + +#ifndef PB_DS_RANGED_HASH_FN_HPP +#define PB_DS_RANGED_HASH_FN_HPP + +#include <utility> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { + /// Primary template. + template<typename Key, typename Hash_Fn, typename _Alloc, + typename Comb_Hash_Fn, bool Store_Hash> + class ranged_hash_fn; + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Hash_Fn, typename _Alloc, \ + typename Comb_Hash_Fn> + +#define PB_DS_CLASS_C_DEC \ + ranged_hash_fn<Key, Hash_Fn, _Alloc, Comb_Hash_Fn, false> + + /** + * Specialization 1 + * The client supplies a hash function and a ranged hash function, + * and requests that hash values not be stored. + **/ + template<typename Key, typename Hash_Fn, typename _Alloc, + typename Comb_Hash_Fn> + class ranged_hash_fn< Key, Hash_Fn, _Alloc, Comb_Hash_Fn, false> + : public Hash_Fn, public Comb_Hash_Fn + { + protected: + typedef typename _Alloc::size_type size_type; + typedef Hash_Fn hash_fn_base; + typedef Comb_Hash_Fn comb_hash_fn_base; + typedef typename _Alloc::template rebind< Key>::other key_allocator; + typedef typename key_allocator::const_reference key_const_reference; + + ranged_hash_fn(size_type); + + ranged_hash_fn(size_type, const Hash_Fn&); + + ranged_hash_fn(size_type, const Hash_Fn&, const Comb_Hash_Fn&); + + void + swap(PB_DS_CLASS_C_DEC&); + + void + notify_resized(size_type); + + inline size_type + operator()(key_const_reference) const; + }; + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size) + { Comb_Hash_Fn::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn) + : Hash_Fn(r_hash_fn) + { Comb_Hash_Fn::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn, + const Comb_Hash_Fn& r_comb_hash_fn) + : Hash_Fn(r_hash_fn), Comb_Hash_Fn(r_comb_hash_fn) + { comb_hash_fn_base::notify_resized(size); } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + swap(PB_DS_CLASS_C_DEC& other) + { + comb_hash_fn_base::swap(other); + std::swap((Hash_Fn& )(*this), (Hash_Fn& )other); + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + notify_resized(size_type size) + { comb_hash_fn_base::notify_resized(size); } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::size_type + PB_DS_CLASS_C_DEC:: + operator()(key_const_reference r_key) const + { return (comb_hash_fn_base::operator()(hash_fn_base::operator()(r_key)));} + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Hash_Fn, typename _Alloc, \ + typename Comb_Hash_Fn> + +#define PB_DS_CLASS_C_DEC \ + ranged_hash_fn<Key,Hash_Fn, _Alloc, Comb_Hash_Fn, true> + + /** + * Specialization 2 + * The client supplies a hash function and a ranged hash function, + * and requests that hash values be stored. + **/ + template<typename Key, typename Hash_Fn, typename _Alloc, + typename Comb_Hash_Fn> + class ranged_hash_fn<Key, Hash_Fn, _Alloc, Comb_Hash_Fn, true> + : public Hash_Fn, public Comb_Hash_Fn + { + protected: + typedef typename _Alloc::size_type size_type; + typedef std::pair<size_type, size_type> comp_hash; + typedef Hash_Fn hash_fn_base; + typedef Comb_Hash_Fn comb_hash_fn_base; + typedef typename _Alloc::template rebind<Key>::other key_allocator; + typedef typename key_allocator::const_reference key_const_reference; + + ranged_hash_fn(size_type); + + ranged_hash_fn(size_type, const Hash_Fn&); + + ranged_hash_fn(size_type, const Hash_Fn&, const Comb_Hash_Fn&); + + void + swap(PB_DS_CLASS_C_DEC&); + + void + notify_resized(size_type); + + inline comp_hash + operator()(key_const_reference) const; + + inline comp_hash + operator()(key_const_reference, size_type) const; + }; + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size) + { Comb_Hash_Fn::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn) : + Hash_Fn(r_hash_fn) + { Comb_Hash_Fn::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn, + const Comb_Hash_Fn& r_comb_hash_fn) + : Hash_Fn(r_hash_fn), Comb_Hash_Fn(r_comb_hash_fn) + { comb_hash_fn_base::notify_resized(size); } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + swap(PB_DS_CLASS_C_DEC& other) + { + comb_hash_fn_base::swap(other); + std::swap((Hash_Fn& )(*this), (Hash_Fn& )other); + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + notify_resized(size_type size) + { comb_hash_fn_base::notify_resized(size); } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::comp_hash + PB_DS_CLASS_C_DEC:: + operator()(key_const_reference r_key) const + { + const size_type hash = hash_fn_base::operator()(r_key); + return std::make_pair(comb_hash_fn_base::operator()(hash), hash); + } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::comp_hash + PB_DS_CLASS_C_DEC:: + operator() +#ifdef _GLIBCXX_DEBUG + (key_const_reference r_key, size_type hash) const +#else + (key_const_reference /*r_key*/, size_type hash) const +#endif + { + _GLIBCXX_DEBUG_ASSERT(hash == hash_fn_base::operator()(r_key)); + return std::make_pair(comb_hash_fn_base::operator()(hash), hash); + } + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename _Alloc, typename Comb_Hash_Fn> + +#define PB_DS_CLASS_C_DEC \ + ranged_hash_fn<Key, null_type, _Alloc, Comb_Hash_Fn, false> + + /** + * Specialization 3 + * The client does not supply a hash function (by specifying + * null_type as the Hash_Fn parameter), and requests that hash + * values not be stored. + **/ + template<typename Key, typename _Alloc, typename Comb_Hash_Fn> + class ranged_hash_fn<Key, null_type, _Alloc, Comb_Hash_Fn, false> + : public Comb_Hash_Fn + { + protected: + typedef typename _Alloc::size_type size_type; + typedef Comb_Hash_Fn comb_hash_fn_base; + + ranged_hash_fn(size_type); + + ranged_hash_fn(size_type, const Comb_Hash_Fn&); + + ranged_hash_fn(size_type, const null_type&, const Comb_Hash_Fn&); + + void + swap(PB_DS_CLASS_C_DEC&); + }; + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size) + { Comb_Hash_Fn::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size, const Comb_Hash_Fn& r_comb_hash_fn) : + Comb_Hash_Fn(r_comb_hash_fn) + { } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size, const null_type& r_null_type, + const Comb_Hash_Fn& r_comb_hash_fn) + : Comb_Hash_Fn(r_comb_hash_fn) + { } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + swap(PB_DS_CLASS_C_DEC& other) + { comb_hash_fn_base::swap(other); } + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename _Alloc, typename Comb_Hash_Fn> + +#define PB_DS_CLASS_C_DEC \ + ranged_hash_fn<Key, null_type, _Alloc, Comb_Hash_Fn, true> + + /** + * Specialization 4 + * The client does not supply a hash function (by specifying + * null_type as the Hash_Fn parameter), and requests that hash + * values be stored. + **/ + template<typename Key, typename _Alloc, typename Comb_Hash_Fn> + class ranged_hash_fn<Key, null_type, _Alloc, Comb_Hash_Fn, true> + : public Comb_Hash_Fn + { + protected: + typedef typename _Alloc::size_type size_type; + typedef Comb_Hash_Fn comb_hash_fn_base; + + ranged_hash_fn(size_type); + + ranged_hash_fn(size_type, const Comb_Hash_Fn&); + + ranged_hash_fn(size_type, const null_type&, const Comb_Hash_Fn&); + + void + swap(PB_DS_CLASS_C_DEC&); + }; + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size) + { Comb_Hash_Fn::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size, const Comb_Hash_Fn& r_comb_hash_fn) + : Comb_Hash_Fn(r_comb_hash_fn) + { } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_hash_fn(size_type size, const null_type& r_null_type, + const Comb_Hash_Fn& r_comb_hash_fn) + : Comb_Hash_Fn(r_comb_hash_fn) + { } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + swap(PB_DS_CLASS_C_DEC& other) + { comb_hash_fn_base::swap(other); } + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/ranged_probe_fn.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/ranged_probe_fn.hpp new file mode 100644 index 0000000..d950d92 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/ranged_probe_fn.hpp @@ -0,0 +1,327 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ranged_probe_fn.hpp + * Contains a unified ranged probe functor, allowing the probe tables to deal with + * a single class for ranged probeing. + */ + +#ifndef PB_DS_RANGED_PROBE_FN_HPP +#define PB_DS_RANGED_PROBE_FN_HPP + +#include <utility> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { + /// Primary template. + template<typename Key, typename Hash_Fn, typename _Alloc, + typename Comb_Probe_Fn, typename Probe_Fn, bool Store_Hash> + class ranged_probe_fn; + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Hash_Fn, typename _Alloc, \ + typename Comb_Probe_Fn, typename Probe_Fn> + +#define PB_DS_CLASS_C_DEC \ + ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, Probe_Fn, false> + + /** + * Specialization 1 + * The client supplies a probe function and a ranged probe + * function, and requests that hash values not be stored. + **/ + template<typename Key, typename Hash_Fn, typename _Alloc, + typename Comb_Probe_Fn, typename Probe_Fn> + class ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, + Probe_Fn, false> + : public Hash_Fn, public Comb_Probe_Fn, public Probe_Fn + { + protected: + typedef typename _Alloc::size_type size_type; + typedef Comb_Probe_Fn comb_probe_fn_base; + typedef Hash_Fn hash_fn_base; + typedef Probe_Fn probe_fn_base; + typedef typename _Alloc::template rebind<Key>::other key_allocator; + typedef typename key_allocator::const_reference key_const_reference; + + ranged_probe_fn(size_type); + + ranged_probe_fn(size_type, const Hash_Fn&); + + ranged_probe_fn(size_type, const Hash_Fn&, const Comb_Probe_Fn&); + + ranged_probe_fn(size_type, const Hash_Fn&, const Comb_Probe_Fn&, + const Probe_Fn&); + + void + swap(PB_DS_CLASS_C_DEC&); + + void + notify_resized(size_type); + + inline size_type + operator()(key_const_reference) const; + + inline size_type + operator()(key_const_reference, size_type, size_type) const; + }; + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_probe_fn(size_type size) + { Comb_Probe_Fn::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn) + : Hash_Fn(r_hash_fn) + { Comb_Probe_Fn::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, + const Comb_Probe_Fn& r_comb_probe_fn) + : Hash_Fn(r_hash_fn), Comb_Probe_Fn(r_comb_probe_fn) + { comb_probe_fn_base::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, + const Comb_Probe_Fn& r_comb_probe_fn, + const Probe_Fn& r_probe_fn) + : Hash_Fn(r_hash_fn), Comb_Probe_Fn(r_comb_probe_fn), Probe_Fn(r_probe_fn) + { comb_probe_fn_base::notify_resized(size); } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + swap(PB_DS_CLASS_C_DEC& other) + { + comb_probe_fn_base::swap(other); + std::swap((Hash_Fn& )(*this), (Hash_Fn&)other); + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + notify_resized(size_type size) + { comb_probe_fn_base::notify_resized(size); } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::size_type + PB_DS_CLASS_C_DEC:: + operator()(key_const_reference r_key) const + { return comb_probe_fn_base::operator()(hash_fn_base::operator()(r_key)); } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::size_type + PB_DS_CLASS_C_DEC:: + operator()(key_const_reference, size_type hash, size_type i) const + { + return comb_probe_fn_base::operator()(hash + probe_fn_base::operator()(i)); + } + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Hash_Fn, typename _Alloc, \ + typename Comb_Probe_Fn, typename Probe_Fn> + +#define PB_DS_CLASS_C_DEC \ + ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, Probe_Fn, true> + + /** + * Specialization 2- The client supplies a probe function and a ranged + * probe function, and requests that hash values not be stored. + **/ + template<typename Key, typename Hash_Fn, typename _Alloc, + typename Comb_Probe_Fn, typename Probe_Fn> + class ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, + Probe_Fn, true> + : public Hash_Fn, public Comb_Probe_Fn, public Probe_Fn + { + protected: + typedef typename _Alloc::size_type size_type; + typedef std::pair<size_type, size_type> comp_hash; + typedef Comb_Probe_Fn comb_probe_fn_base; + typedef Hash_Fn hash_fn_base; + typedef Probe_Fn probe_fn_base; + typedef typename _Alloc::template rebind<Key>::other key_allocator; + typedef typename key_allocator::const_reference key_const_reference; + + ranged_probe_fn(size_type); + + ranged_probe_fn(size_type, const Hash_Fn&); + + ranged_probe_fn(size_type, const Hash_Fn&, + const Comb_Probe_Fn&); + + ranged_probe_fn(size_type, const Hash_Fn&, const Comb_Probe_Fn&, + const Probe_Fn&); + + void + swap(PB_DS_CLASS_C_DEC&); + + void + notify_resized(size_type); + + inline comp_hash + operator()(key_const_reference) const; + + inline size_type + operator()(key_const_reference, size_type, size_type) const; + + inline size_type + operator()(key_const_reference, size_type) const; + }; + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_probe_fn(size_type size) + { Comb_Probe_Fn::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn) + : Hash_Fn(r_hash_fn) + { Comb_Probe_Fn::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, + const Comb_Probe_Fn& r_comb_probe_fn) + : Hash_Fn(r_hash_fn), Comb_Probe_Fn(r_comb_probe_fn) + { comb_probe_fn_base::notify_resized(size); } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + ranged_probe_fn(size_type size, const Hash_Fn& r_hash_fn, + const Comb_Probe_Fn& r_comb_probe_fn, + const Probe_Fn& r_probe_fn) + : Hash_Fn(r_hash_fn), Comb_Probe_Fn(r_comb_probe_fn), Probe_Fn(r_probe_fn) + { comb_probe_fn_base::notify_resized(size); } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + swap(PB_DS_CLASS_C_DEC& other) + { + comb_probe_fn_base::swap(other); + std::swap((Hash_Fn& )(*this), (Hash_Fn& )other); + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + notify_resized(size_type size) + { comb_probe_fn_base::notify_resized(size); } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::comp_hash + PB_DS_CLASS_C_DEC:: + operator()(key_const_reference r_key) const + { + const size_type hash = hash_fn_base::operator()(r_key); + return std::make_pair(comb_probe_fn_base::operator()(hash), hash); + } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::size_type + PB_DS_CLASS_C_DEC:: + operator()(key_const_reference, size_type hash, size_type i) const + { + return comb_probe_fn_base::operator()(hash + probe_fn_base::operator()(i)); + } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::size_type + PB_DS_CLASS_C_DEC:: + operator() +#ifdef _GLIBCXX_DEBUG + (key_const_reference r_key, size_type hash) const +#else + (key_const_reference /*r_key*/, size_type hash) const +#endif + { + _GLIBCXX_DEBUG_ASSERT(hash == hash_fn_base::operator()(r_key)); + return hash; + } + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + + /** + * Specialization 3 and 4 + * The client does not supply a hash function or probe function, + * and requests that hash values not be stored. + **/ + template<typename Key, typename _Alloc, typename Comb_Probe_Fn> + class ranged_probe_fn<Key, null_type, _Alloc, Comb_Probe_Fn, + null_type, false> + : public Comb_Probe_Fn + { + protected: + typedef typename _Alloc::size_type size_type; + typedef Comb_Probe_Fn comb_probe_fn_base; + typedef typename _Alloc::template rebind<Key>::other key_allocator; + typedef typename key_allocator::const_reference key_const_reference; + + ranged_probe_fn(size_type size) + { Comb_Probe_Fn::notify_resized(size); } + + ranged_probe_fn(size_type, const Comb_Probe_Fn& r_comb_probe_fn) + : Comb_Probe_Fn(r_comb_probe_fn) + { } + + ranged_probe_fn(size_type, const null_type&, + const Comb_Probe_Fn& r_comb_probe_fn, + const null_type&) + : Comb_Probe_Fn(r_comb_probe_fn) + { } + + void + swap(ranged_probe_fn& other) + { comb_probe_fn_base::swap(other); } + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_probe_fn.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_probe_fn.hpp new file mode 100644 index 0000000..4b62bb0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_probe_fn.hpp @@ -0,0 +1,68 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file sample_probe_fn.hpp + * Contains a sample probe policy. + */ + +#ifndef PB_DS_SAMPLE_PROBE_FN_HPP +#define PB_DS_SAMPLE_PROBE_FN_HPP + +namespace __gnu_pbds +{ + /// A sample probe policy. + class sample_probe_fn + { + public: + typedef std::size_t size_type; + + /// Default constructor. + sample_probe_fn(); + + /// Copy constructor. + sample_probe_fn(const sample_probe_fn&); + + /// Swaps content. + inline void + swap(sample_probe_fn&); + + protected: + /// Returns the i-th offset from the hash value of some key r_key. + inline size_type + operator()(key_const_reference r_key, size_type i) const; + }; +} +#endif // #ifndef PB_DS_SAMPLE_PROBE_FN_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_range_hashing.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_range_hashing.hpp new file mode 100644 index 0000000..b38baf0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_range_hashing.hpp @@ -0,0 +1,74 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file sample_range_hashing.hpp + * Contains a range hashing policy. + */ + +#ifndef PB_DS_SAMPLE_RANGE_HASHING_HPP +#define PB_DS_SAMPLE_RANGE_HASHING_HPP + +namespace __gnu_pbds +{ + /// A sample range-hashing functor. + class sample_range_hashing + { + public: + /// Size type. + typedef std::size_t size_type; + + /// Default constructor. + sample_range_hashing(); + + /// Copy constructor. + sample_range_hashing(const sample_range_hashing& other); + + /// Swaps content. + inline void + swap(sample_range_hashing& other); + + protected: + /// Notifies the policy object that the container's size has + /// changed to argument's size. + void + notify_resized(size_type); + + /// Transforms the __hash value hash into a ranged-hash value. + inline size_type + operator()(size_type ) const; + }; +} +#endif // #ifndef PB_DS_SAMPLE_RANGE_HASHING_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_ranged_hash_fn.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_ranged_hash_fn.hpp new file mode 100644 index 0000000..4a51984 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_ranged_hash_fn.hpp @@ -0,0 +1,75 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file sample_ranged_hash_fn.hpp + * Contains a ranged hash policy. + */ + +#ifndef PB_DS_SAMPLE_RANGED_HASH_FN_HPP +#define PB_DS_SAMPLE_RANGED_HASH_FN_HPP + +namespace __gnu_pbds +{ + /// A sample ranged-hash functor. + class sample_ranged_hash_fn + { + public: + typedef std::size_t size_type; + + /// Default constructor. + sample_ranged_hash_fn(); + + /// Copy constructor. + sample_ranged_hash_fn(const sample_ranged_hash_fn&); + + /// Swaps content. + inline void + swap(sample_ranged_hash_fn&); + + protected: + + /// Notifies the policy object that the container's __size has + /// changed to size. + void + notify_resized(size_type); + + /// Transforms key_const_reference into a position within the table. + inline size_type + operator()(key_const_reference) const; + + }; +} +#endif // #ifndef PB_DS_SAMPLE_RANGED_HASH_FN_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_ranged_probe_fn.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_ranged_probe_fn.hpp new file mode 100644 index 0000000..4ec4100 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/hash_fn/sample_ranged_probe_fn.hpp @@ -0,0 +1,77 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file sample_ranged_probe_fn.hpp + * Contains a ranged probe policy. + */ + +#ifndef PB_DS_SAMPLE_RANGED_PROBE_FN_HPP +#define PB_DS_SAMPLE_RANGED_PROBE_FN_HPP + +namespace __gnu_pbds +{ + /// A sample ranged-probe functor. + class sample_ranged_probe_fn + { + public: + typedef std::size_t size_type; + + // Default constructor. + sample_ranged_probe_fn(); + + // Copy constructor. + sample_ranged_probe_fn(const sample_ranged_probe_fn&); + + // Swaps content. + inline void + swap(sample_ranged_probe_fn&); + + protected: + + // Notifies the policy object that the container's __size has + // changed to size. + void + notify_resized(size_type); + + // Transforms the const key reference r_key into the i-th position + // within the table. This method is called for each collision within + // the probe sequence. + inline size_type + operator()(key_const_reference, std::size_t, size_type) const; + + }; +} +#endif // #ifndef PB_DS_SAMPLE_RANGED_PROBE_FN_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/const_iterator.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/const_iterator.hpp new file mode 100644 index 0000000..477bcb9 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/const_iterator.hpp @@ -0,0 +1,159 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/const_iterator.hpp + * Contains an iterator class returned by the table's const find and insert + * methods. + */ + +#ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_ITERATOR_HPP +#define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_ITERATOR_HPP + +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_CLASS_C_DEC \ + left_child_next_sibling_heap_const_iterator_<Node, _Alloc> + +#define PB_DS_BASIC_HEAP_CIT_BASE \ + left_child_next_sibling_heap_node_point_const_iterator_<Node, _Alloc> + + /// Const point-type iterator. + template<typename Node, typename _Alloc> + class left_child_next_sibling_heap_const_iterator_ + : public PB_DS_BASIC_HEAP_CIT_BASE + { + private: + typedef PB_DS_BASIC_HEAP_CIT_BASE base_type; + typedef typename base_type::node_pointer node_pointer; + + public: + /// Category. + typedef std::forward_iterator_tag iterator_category; + + /// Difference type. + typedef typename _Alloc::difference_type difference_type; + + /// Iterator's value type. + typedef typename base_type::value_type value_type; + + /// Iterator's pointer type. + typedef typename base_type::pointer pointer; + + /// Iterator's const pointer type. + typedef typename base_type::const_pointer const_pointer; + + /// Iterator's reference type. + typedef typename base_type::reference reference; + + /// Iterator's const reference type. + typedef typename base_type::const_reference const_reference; + + inline + left_child_next_sibling_heap_const_iterator_(node_pointer p_nd) + : base_type(p_nd) + { } + + /// Default constructor. + inline + left_child_next_sibling_heap_const_iterator_() + { } + + /// Copy constructor. + inline + left_child_next_sibling_heap_const_iterator_(const PB_DS_CLASS_C_DEC& other) : base_type(other) + { } + + /// Compares content to a different iterator object. + bool + operator==(const PB_DS_CLASS_C_DEC& other) const + { return (base_type::m_p_nd == other.m_p_nd); } + + /// Compares content (negatively) to a different iterator object. + bool + operator!=(const PB_DS_CLASS_C_DEC& other) const + { return (base_type::m_p_nd != other.m_p_nd); } + + PB_DS_CLASS_C_DEC& + operator++() + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_p_nd != 0); + inc(); + return (*this); + } + + PB_DS_CLASS_C_DEC + operator++(int) + { + PB_DS_CLASS_C_DEC ret_it(base_type::m_p_nd); + operator++(); + return (ret_it); + } + + private: + void + inc() + { + if (base_type::m_p_nd->m_p_next_sibling != 0) + { + base_type::m_p_nd = base_type::m_p_nd->m_p_next_sibling; + while (base_type::m_p_nd->m_p_l_child != 0) + base_type::m_p_nd = base_type::m_p_nd->m_p_l_child; + return; + } + + while (true) + { + node_pointer p_next = base_type::m_p_nd; + base_type::m_p_nd = base_type::m_p_nd->m_p_prev_or_parent; + if (base_type::m_p_nd == 0 + || base_type::m_p_nd->m_p_l_child == p_next) + return; + } + } + }; + +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_BASIC_HEAP_CIT_BASE + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..3539f58 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,152 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_allocator +PB_DS_CLASS_C_DEC::s_node_allocator; + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::no_throw_copies_t +PB_DS_CLASS_C_DEC::s_no_throw_copies_ind; + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +left_child_next_sibling_heap() : + m_p_root(0), + m_size(0) +{ + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +left_child_next_sibling_heap(const Cmp_Fn& r_cmp_fn) : + Cmp_Fn(r_cmp_fn), + m_p_root(0), + m_size(0) +{ + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +left_child_next_sibling_heap(const PB_DS_CLASS_C_DEC& other) +: Cmp_Fn(other), m_p_root(0), m_size(0) +{ + m_size = other.m_size; + PB_DS_ASSERT_VALID(other) + m_p_root = recursive_copy_node(other.m_p_root); + m_size = other.m_size; + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + value_swap(other); + std::swap((Cmp_Fn& )(*this), (Cmp_Fn& )other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +value_swap(PB_DS_CLASS_C_DEC& other) +{ + std::swap(m_p_root, other.m_p_root); + std::swap(m_size, other.m_size); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~left_child_next_sibling_heap() +{ + clear(); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +recursive_copy_node(node_const_pointer p_nd) +{ + if (p_nd == 0) + return (0); + + node_pointer p_ret = s_node_allocator.allocate(1); + + __try + { + new (p_ret) node(*p_nd); + } + __catch(...) + { + s_node_allocator.deallocate(p_ret, 1); + __throw_exception_again; + } + + p_ret->m_p_l_child = p_ret->m_p_next_sibling = + p_ret->m_p_prev_or_parent = 0; + + __try + { + p_ret->m_p_l_child = recursive_copy_node(p_nd->m_p_l_child); + p_ret->m_p_next_sibling = recursive_copy_node(p_nd->m_p_next_sibling); + } + __catch(...) + { + clear_imp(p_ret); + __throw_exception_again; + } + + if (p_ret->m_p_l_child != 0) + p_ret->m_p_l_child->m_p_prev_or_parent = p_ret; + + if (p_ret->m_p_next_sibling != 0) + p_ret->m_p_next_sibling->m_p_prev_or_parent = + p_nd->m_p_next_sibling->m_p_prev_or_parent == p_nd ? p_ret : 0; + + return p_ret; +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp new file mode 100644 index 0000000..fda9f27 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp @@ -0,0 +1,137 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/debug_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + PB_DS_DEBUG_VERIFY(m_p_root == 0 || m_p_root->m_p_prev_or_parent == 0); + + if (m_p_root != 0) + assert_node_consistent(m_p_root, Single_Link_Roots, __file, __line); + assert_size(__file, __line); + assert_iterators(__file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_node_consistent(node_const_pointer p_nd, bool single_link, + const char* __file, int __line) const +{ + if (p_nd == 0) + return; + + assert_node_consistent(p_nd->m_p_l_child, false, __file, __line); + assert_node_consistent(p_nd->m_p_next_sibling, single_link, __file, __line); + + if (single_link) + PB_DS_DEBUG_VERIFY(p_nd->m_p_prev_or_parent == 0); + else if (p_nd->m_p_next_sibling != 0) + PB_DS_DEBUG_VERIFY(p_nd->m_p_next_sibling->m_p_prev_or_parent == p_nd); + + if (p_nd->m_p_l_child == 0) + return; + + node_const_pointer p_child = p_nd->m_p_l_child; + while (p_child != 0) + { + node_const_pointer p_next_child = p_child->m_p_next_sibling; + PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(p_nd->m_value, p_child->m_value)); + p_child = p_next_child; + } + PB_DS_DEBUG_VERIFY(p_nd->m_p_l_child->m_p_prev_or_parent == p_nd); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_iterators(const char* __file, int __line) const +{ + PB_DS_DEBUG_VERIFY(std::distance(begin(), end()) == size()); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_size(const char* __file, int __line) const +{ + PB_DS_DEBUG_VERIFY(size_from_node(m_p_root) == m_size); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size_under_node(node_const_pointer p_nd) +{ return 1 + size_from_node(p_nd->m_p_l_child); } + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size_from_node(node_const_pointer p_nd) +{ + size_type ret = 0; + while (p_nd != 0) + { + ret += 1 + size_from_node(p_nd->m_p_l_child); + p_nd = p_nd->m_p_next_sibling; + } + return ret; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +degree(node_const_pointer p_nd) +{ + size_type ret = 0; + node_const_pointer p_child = p_nd->m_p_l_child; + while (p_child != 0) + { + ++ret; + p_child = p_child->m_p_next_sibling; + } + return ret; +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp new file mode 100644 index 0000000..3106505 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp @@ -0,0 +1,150 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/erase_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + clear_imp(m_p_root); + _GLIBCXX_DEBUG_ASSERT(m_size == 0); + m_p_root = 0; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +actual_erase_node(node_pointer p_nd) +{ + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + --m_size; + p_nd->~node(); + s_node_allocator.deallocate(p_nd, 1); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear_imp(node_pointer p_nd) +{ + while (p_nd != 0) + { + clear_imp(p_nd->m_p_l_child); + node_pointer p_next = p_nd->m_p_next_sibling; + actual_erase_node(p_nd); + p_nd = p_next; + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +to_linked_list() +{ + PB_DS_ASSERT_VALID((*this)) + node_pointer p_cur = m_p_root; + while (p_cur != 0) + if (p_cur->m_p_l_child != 0) + { + node_pointer p_child_next = p_cur->m_p_l_child->m_p_next_sibling; + p_cur->m_p_l_child->m_p_next_sibling = p_cur->m_p_next_sibling; + p_cur->m_p_next_sibling = p_cur->m_p_l_child; + p_cur->m_p_l_child = p_child_next; + } + else + p_cur = p_cur->m_p_next_sibling; + +#ifdef _GLIBCXX_DEBUG + node_const_pointer p_counter = m_p_root; + size_type count = 0; + while (p_counter != 0) + { + ++count; + _GLIBCXX_DEBUG_ASSERT(p_counter->m_p_l_child == 0); + p_counter = p_counter->m_p_next_sibling; + } + _GLIBCXX_DEBUG_ASSERT(count == m_size); +#endif +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +prune(Pred pred) +{ + node_pointer p_cur = m_p_root; + m_p_root = 0; + node_pointer p_out = 0; + while (p_cur != 0) + { + node_pointer p_next = p_cur->m_p_next_sibling; + if (pred(p_cur->m_value)) + { + p_cur->m_p_next_sibling = p_out; + if (p_out != 0) + p_out->m_p_prev_or_parent = p_cur; + p_out = p_cur; + } + else + { + p_cur->m_p_next_sibling = m_p_root; + if (m_p_root != 0) + m_p_root->m_p_prev_or_parent = p_cur; + m_p_root = p_cur; + } + p_cur = p_next; + } + return p_out; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +bubble_to_top(node_pointer p_nd) +{ + node_pointer p_parent = parent(p_nd); + while (p_parent != 0) + { + swap_with_parent(p_nd, p_parent); + p_parent = parent(p_nd); + } +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp new file mode 100644 index 0000000..2a122f8 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp @@ -0,0 +1,64 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/info_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +empty() const +{ + return (m_size == 0); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size() const +{ + return (m_size); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +max_size() const +{ + return (s_node_allocator.max_size()); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp new file mode 100644 index 0000000..8f275c0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp @@ -0,0 +1,175 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/insert_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +get_new_node_for_insert(const_reference r_val) +{ + return get_new_node_for_insert(r_val, s_no_throw_copies_ind); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +get_new_node_for_insert(const_reference r_val, false_type) +{ + node_pointer p_new_nd = s_node_allocator.allocate(1); + + cond_dealtor_t cond(p_new_nd); + + new (const_cast<void* >( + static_cast<const void* >(&p_new_nd->m_value))) + typename node::value_type(r_val); + + cond.set_no_action(); + + ++m_size; + + return (p_new_nd); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +get_new_node_for_insert(const_reference r_val, true_type) +{ + node_pointer p_new_nd = s_node_allocator.allocate(1); + + new (const_cast<void* >( + static_cast<const void* >(&p_new_nd->m_value))) + typename node::value_type(r_val); + + ++m_size; + + return (p_new_nd); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +make_child_of(node_pointer p_nd, node_pointer p_new_parent) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + _GLIBCXX_DEBUG_ASSERT(p_new_parent != 0); + + p_nd->m_p_next_sibling = p_new_parent->m_p_l_child; + + if (p_new_parent->m_p_l_child != 0) + p_new_parent->m_p_l_child->m_p_prev_or_parent = p_nd; + + p_nd->m_p_prev_or_parent = p_new_parent; + + p_new_parent->m_p_l_child = p_nd; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +parent(node_pointer p_nd) +{ + while (true) + { + node_pointer p_pot = p_nd->m_p_prev_or_parent; + + if (p_pot == 0 || p_pot->m_p_l_child == p_nd) + return p_pot; + + p_nd = p_pot; + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +swap_with_parent(node_pointer p_nd, node_pointer p_parent) +{ + if (p_parent == m_p_root) + m_p_root = p_nd; + + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + _GLIBCXX_DEBUG_ASSERT(p_parent != 0); + _GLIBCXX_DEBUG_ASSERT(parent(p_nd) == p_parent); + + const bool nd_direct_child = p_parent->m_p_l_child == p_nd; + const bool parent_root = p_parent->m_p_prev_or_parent == 0; + const bool parent_direct_child = + !parent_root&& p_parent->m_p_prev_or_parent->m_p_l_child == p_parent; + + std::swap(p_parent->m_p_prev_or_parent, p_nd->m_p_prev_or_parent); + std::swap(p_parent->m_p_next_sibling, p_nd->m_p_next_sibling); + std::swap(p_parent->m_p_l_child, p_nd->m_p_l_child); + std::swap(p_parent->m_metadata, p_nd->m_metadata); + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_l_child != 0); + _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_prev_or_parent != 0); + + if (p_nd->m_p_next_sibling != 0) + p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd; + + if (p_parent->m_p_next_sibling != 0) + p_parent->m_p_next_sibling->m_p_prev_or_parent = p_parent; + + if (p_parent->m_p_l_child != 0) + p_parent->m_p_l_child->m_p_prev_or_parent = p_parent; + + if (parent_direct_child) + p_nd->m_p_prev_or_parent->m_p_l_child = p_nd; + else if (!parent_root) + p_nd->m_p_prev_or_parent->m_p_next_sibling = p_nd; + + if (!nd_direct_child) + { + p_nd->m_p_l_child->m_p_prev_or_parent = p_nd; + + p_parent->m_p_prev_or_parent->m_p_next_sibling = p_parent; + } + else + { + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_l_child == p_nd); + _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_prev_or_parent == p_parent); + + p_nd->m_p_l_child = p_parent; + p_parent->m_p_prev_or_parent = p_nd; + } + + _GLIBCXX_DEBUG_ASSERT(parent(p_parent) == p_nd); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp new file mode 100644 index 0000000..55d3eba --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp @@ -0,0 +1,88 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/iterators_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +begin() +{ + node_pointer p_nd = m_p_root; + + if (p_nd == 0) + return (iterator(0)); + + while (p_nd->m_p_l_child != 0) + p_nd = p_nd->m_p_l_child; + + return (iterator(p_nd)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin() const +{ + node_pointer p_nd = m_p_root; + + if (p_nd == 0) + return (const_iterator(0)); + + while (p_nd->m_p_l_child != 0) + p_nd = p_nd->m_p_l_child; + + return (const_iterator(p_nd)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +end() +{ + return (iterator(0)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end() const +{ + return (const_iterator(0)); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp new file mode 100644 index 0000000..7ced08f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp @@ -0,0 +1,286 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp + * Contains an implementation class for a basic heap. + */ + +#ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_HPP +#define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_HPP + +/* + * Based on CLRS. + */ + +#include <iterator> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/node.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/const_iterator.hpp> +#ifdef PB_DS_LC_NS_HEAP_TRACE_ +#include <iostream> +#endif +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#ifdef _GLIBCXX_DEBUG +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename Node_Metadata, \ + typename _Alloc, bool Single_Link_Roots> + +#define PB_DS_CLASS_C_DEC \ + left_child_next_sibling_heap<Value_Type, Cmp_Fn, Node_Metadata, \ + _Alloc, Single_Link_Roots> +#else +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename Node_Metadata, \ + typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + left_child_next_sibling_heap<Value_Type, Cmp_Fn, Node_Metadata, _Alloc> +#endif + + /// Base class for a basic heap. + template<typename Value_Type, + typename Cmp_Fn, + typename Node_Metadata, + typename _Alloc +#ifdef _GLIBCXX_DEBUG + ,bool Single_Link_Roots> +#else + > +#endif + class left_child_next_sibling_heap : public Cmp_Fn + { + protected: + typedef + typename _Alloc::template rebind< + left_child_next_sibling_heap_node_<Value_Type, Node_Metadata, + _Alloc> >::other + node_allocator; + + typedef typename node_allocator::value_type node; + typedef typename node_allocator::pointer node_pointer; + typedef typename node_allocator::const_pointer node_const_pointer; + typedef Node_Metadata node_metadata; + typedef std::pair< node_pointer, node_pointer> node_pointer_pair; + + private: + typedef cond_dealtor< node, _Alloc> cond_dealtor_t; + + enum + { + simple_value = is_simple<Value_Type>::value + }; + + typedef integral_constant<int, simple_value> no_throw_copies_t; + typedef typename _Alloc::template rebind<Value_Type> __rebind_v; + + public: + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef Value_Type value_type; + + typedef typename __rebind_v::other::pointer pointer; + typedef typename __rebind_v::other::const_pointer const_pointer; + typedef typename __rebind_v::other::reference reference; + typedef typename __rebind_v::other::const_reference const_reference; + + typedef left_child_next_sibling_heap_node_point_const_iterator_<node, _Alloc> + point_const_iterator; + + typedef point_const_iterator point_iterator; + + typedef left_child_next_sibling_heap_const_iterator_<node, _Alloc> + const_iterator; + + typedef const_iterator iterator; + typedef Cmp_Fn cmp_fn; + typedef _Alloc allocator_type; + + left_child_next_sibling_heap(); + left_child_next_sibling_heap(const Cmp_Fn&); + left_child_next_sibling_heap(const left_child_next_sibling_heap&); + + void + swap(PB_DS_CLASS_C_DEC&); + + ~left_child_next_sibling_heap(); + + inline bool + empty() const; + + inline size_type + size() const; + + inline size_type + max_size() const; + + Cmp_Fn& + get_cmp_fn(); + + const Cmp_Fn& + get_cmp_fn() const; + + inline iterator + begin(); + + inline const_iterator + begin() const; + + inline iterator + end(); + + inline const_iterator + end() const; + + void + clear(); + +#ifdef PB_DS_LC_NS_HEAP_TRACE_ + void + trace() const; +#endif + + protected: + inline node_pointer + get_new_node_for_insert(const_reference); + + inline static void + make_child_of(node_pointer, node_pointer); + + void + value_swap(left_child_next_sibling_heap&); + + inline static node_pointer + parent(node_pointer); + + inline void + swap_with_parent(node_pointer, node_pointer); + + void + bubble_to_top(node_pointer); + + inline void + actual_erase_node(node_pointer); + + void + clear_imp(node_pointer); + + void + to_linked_list(); + + template<typename Pred> + node_pointer + prune(Pred); + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; + + void + assert_node_consistent(node_const_pointer, bool, const char*, int) const; + + static size_type + size_under_node(node_const_pointer); + + static size_type + degree(node_const_pointer); +#endif + +#ifdef PB_DS_LC_NS_HEAP_TRACE_ + static void + trace_node(node_const_pointer, size_type); +#endif + + private: +#ifdef _GLIBCXX_DEBUG + void + assert_iterators(const char*, int) const; + + void + assert_size(const char*, int) const; + + static size_type + size_from_node(node_const_pointer); +#endif + + node_pointer + recursive_copy_node(node_const_pointer); + + inline node_pointer + get_new_node_for_insert(const_reference, false_type); + + inline node_pointer + get_new_node_for_insert(const_reference, true_type); + +#ifdef PB_DS_LC_NS_HEAP_TRACE_ + template<typename Metadata_> + static void + trace_node_metadata(node_const_pointer, type_to_type<Metadata_>); + + static void + trace_node_metadata(node_const_pointer, type_to_type<null_type>); +#endif + + static node_allocator s_node_allocator; + static no_throw_copies_t s_no_throw_copies_ind; + + protected: + node_pointer m_p_root; + size_type m_size; + }; + +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp> + +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/node.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/node.hpp new file mode 100644 index 0000000..27c70a8 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/node.hpp @@ -0,0 +1,90 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/node.hpp + * Contains an implementation struct for this type of heap's node. + */ + +#ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_NODE_HPP +#define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_NODE_HPP + +namespace __gnu_pbds +{ + namespace detail + { + /// Node. + template<typename _Value, typename _Metadata, typename _Alloc> + struct left_child_next_sibling_heap_node_ + { + private: + typedef left_child_next_sibling_heap_node_<_Value, _Metadata, _Alloc> this_type; + + public: + typedef _Value value_type; + typedef typename _Alloc::size_type size_type; + typedef _Metadata metadata_type; + + typedef typename _Alloc::template rebind<this_type>::other::pointer node_pointer; + + value_type m_value; + metadata_type m_metadata; + node_pointer m_p_l_child; + node_pointer m_p_next_sibling; + node_pointer m_p_prev_or_parent; + }; + + template<typename _Value, typename _Alloc> + struct left_child_next_sibling_heap_node_<_Value, null_type, _Alloc> + { + private: + typedef left_child_next_sibling_heap_node_<_Value, null_type, _Alloc> this_type; + + public: + typedef _Value value_type; + typedef typename _Alloc::size_type size_type; + + typedef typename _Alloc::template rebind<this_type>::other::pointer node_pointer; + + value_type m_value; + node_pointer m_p_l_child; + node_pointer m_p_next_sibling; + node_pointer m_p_prev_or_parent; + }; + + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_NODE_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp new file mode 100644 index 0000000..8aa9ef9 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp @@ -0,0 +1,149 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/point_const_iterator.hpp + * Contains an iterator class returned by the table's const find and insert + * methods. + */ + +#ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_FIND_ITERATOR_HPP +#define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_FIND_ITERATOR_HPP + +#include <ext/pb_ds/tag_and_trait.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { + +#define PB_DS_CLASS_T_DEC \ + template<typename Node, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + left_child_next_sibling_heap_node_point_const_iterator_<Node, _Alloc> + + /// Const point-type iterator. + template<typename Node, typename _Alloc> + class left_child_next_sibling_heap_node_point_const_iterator_ + { + protected: + typedef typename _Alloc::template rebind<Node>::other::pointer node_pointer; + + public: + /// Category. + typedef trivial_iterator_tag iterator_category; + + /// Difference type. + typedef trivial_iterator_difference_type difference_type; + + /// Iterator's value type. + typedef typename Node::value_type value_type; + + /// Iterator's pointer type. + typedef + typename _Alloc::template rebind< + value_type>::other::pointer + pointer; + + /// Iterator's const pointer type. + typedef + typename _Alloc::template rebind< + value_type>::other::const_pointer + const_pointer; + + /// Iterator's reference type. + typedef + typename _Alloc::template rebind< + value_type>::other::reference + reference; + + /// Iterator's const reference type. + typedef + typename _Alloc::template rebind< + value_type>::other::const_reference + const_reference; + + inline + left_child_next_sibling_heap_node_point_const_iterator_(node_pointer p_nd) : m_p_nd(p_nd) + { } + + /// Default constructor. + inline + left_child_next_sibling_heap_node_point_const_iterator_() : m_p_nd(0) + { } + + /// Copy constructor. + inline + left_child_next_sibling_heap_node_point_const_iterator_(const PB_DS_CLASS_C_DEC& other) : m_p_nd(other.m_p_nd) + { } + + /// Access. + const_pointer + operator->() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_nd != 0); + return &m_p_nd->m_value; + } + + /// Access. + const_reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_nd != 0); + return m_p_nd->m_value; + } + + /// Compares content to a different iterator object. + bool + operator==(const PB_DS_CLASS_C_DEC& other) const + { return m_p_nd == other.m_p_nd; } + + /// Compares content (negatively) to a different iterator object. + bool + operator!=(const PB_DS_CLASS_C_DEC& other) const + { return m_p_nd != other.m_p_nd; } + + node_pointer m_p_nd; + }; + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp new file mode 100644 index 0000000..3b296e7 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp @@ -0,0 +1,52 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/policy_access_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +Cmp_Fn& +PB_DS_CLASS_C_DEC:: +get_cmp_fn() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Cmp_Fn& +PB_DS_CLASS_C_DEC:: +get_cmp_fn() const +{ return *this; } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp new file mode 100644 index 0000000..bb47b56 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp @@ -0,0 +1,90 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file left_child_next_sibling_heap_/trace_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +#ifdef PB_DS_LC_NS_HEAP_TRACE_ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace() const +{ + std::cerr << std::endl; + trace_node(m_p_root, 0); + std::cerr << std::endl; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace_node(node_const_pointer p_nd, size_type level) +{ + while (p_nd != 0) + { + for (size_type i = 0; i < level; ++i) + std::cerr << ' '; + + std::cerr << p_nd << + " prev = " << p_nd->m_p_prev_or_parent << + " next " << p_nd->m_p_next_sibling << + " left = " << p_nd->m_p_l_child << " "; + + trace_node_metadata(p_nd, type_to_type<node_metadata>()); + std::cerr << p_nd->m_value << std::endl; + trace_node(p_nd->m_p_l_child, level + 1); + p_nd = p_nd->m_p_next_sibling; + } +} + +PB_DS_CLASS_T_DEC +template<typename Metadata_> +void +PB_DS_CLASS_C_DEC:: +trace_node_metadata(node_const_pointer p_nd, type_to_type<Metadata_>) +{ + std::cerr << "(" << p_nd->m_metadata << ") "; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace_node_metadata(node_const_pointer, type_to_type<null_type>) +{ } + +#endif // #ifdef PB_DS_LC_NS_HEAP_TRACE_ diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/constructor_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/constructor_destructor_fn_imps.hpp new file mode 100644 index 0000000..c734d4f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/constructor_destructor_fn_imps.hpp @@ -0,0 +1,136 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_map_/constructor_destructor_fn_imps.hpp + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::entry_allocator +PB_DS_CLASS_C_DEC::s_entry_allocator; + +PB_DS_CLASS_T_DEC +Eq_Fn PB_DS_CLASS_C_DEC::s_eq_fn; + +PB_DS_CLASS_T_DEC +null_type PB_DS_CLASS_C_DEC::s_null_type; + +PB_DS_CLASS_T_DEC +Update_Policy PB_DS_CLASS_C_DEC::s_update_policy; + +PB_DS_CLASS_T_DEC +type_to_type< + typename PB_DS_CLASS_C_DEC::update_metadata> PB_DS_CLASS_C_DEC::s_metadata_type_indicator; + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + insert(*(first_it++)); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_LU_NAME() : m_p_l(0) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +template<typename It> +PB_DS_CLASS_C_DEC:: +PB_DS_LU_NAME(It first_it, It last_it) : m_p_l(0) +{ + copy_from_range(first_it, last_it); + PB_DS_ASSERT_VALID((*this)); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_LU_NAME(const PB_DS_CLASS_C_DEC& other) : +m_p_l(0) +{ + __try + { + for (const_iterator it = other.begin(); it != other.end(); ++it) + { + entry_pointer p_l = allocate_new_entry(*it, + traits_base::m_no_throw_copies_indicator); + + p_l->m_p_next = m_p_l; + m_p_l = p_l; + } + } + __catch(...) + { + deallocate_all(); + __throw_exception_again; + } + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + _GLIBCXX_DEBUG_ONLY(debug_base::swap(other);) + std::swap(m_p_l, other.m_p_l); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +deallocate_all() +{ + entry_pointer p_l = m_p_l; + while (p_l != 0) + { + entry_pointer p_next_l = p_l->m_p_next; + actual_erase_entry(p_l); + p_l = p_next_l; + } + m_p_l = 0; +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~PB_DS_LU_NAME() +{ deallocate_all(); } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/debug_fn_imps.hpp new file mode 100644 index 0000000..5c99c08 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/debug_fn_imps.hpp @@ -0,0 +1,57 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_map_/debug_fn_imps.hpp + * Contains implementations of cc_ht_map_'s debug-mode functions. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + size_type calc_size = 0; + for (const_iterator it = begin(); it != end(); ++it) + { + debug_base::check_key_exists(PB_DS_V2F(*it), __file, __line); + ++calc_size; + } + debug_base::check_size(calc_size, __file, __line); +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/entry_metadata_base.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/entry_metadata_base.hpp new file mode 100644 index 0000000..29e404b --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/entry_metadata_base.hpp @@ -0,0 +1,60 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_map_/entry_metadata_base.hpp + * Contains an implementation for a list update map. + */ + +#ifndef PB_DS_LU_MAP_ENTRY_METADATA_BASE_HPP +#define PB_DS_LU_MAP_ENTRY_METADATA_BASE_HPP + +namespace __gnu_pbds +{ + namespace detail + { + template<typename Metadata> + struct lu_map_entry_metadata_base + { + Metadata m_update_metadata; + }; + + template<> + struct lu_map_entry_metadata_base<null_type> + { }; + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/erase_fn_imps.hpp new file mode 100644 index 0000000..bfe6004 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/erase_fn_imps.hpp @@ -0,0 +1,134 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_map_/erase_fn_imps.hpp + * Contains implementations of lu_map_. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +erase(key_const_reference r_key) +{ + PB_DS_ASSERT_VALID((*this)) + if (m_p_l == 0) + return false; + + if (s_eq_fn(r_key, PB_DS_V2F(m_p_l->m_value))) + { + entry_pointer p_next = m_p_l->m_p_next; + actual_erase_entry(m_p_l); + m_p_l = p_next; + return true; + } + + entry_pointer p_l = m_p_l; + while (p_l->m_p_next != 0) + if (s_eq_fn(r_key, PB_DS_V2F(p_l->m_p_next->m_value))) + { + erase_next(p_l); + return true; + } + else + p_l = p_l->m_p_next; + return false; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + deallocate_all(); +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + PB_DS_ASSERT_VALID((*this)) + size_type num_ersd = 0; + while (m_p_l != 0 && pred(m_p_l->m_value)) + { + entry_pointer p_next = m_p_l->m_p_next; + ++num_ersd; + actual_erase_entry(m_p_l); + m_p_l = p_next; + } + + if (m_p_l == 0) + return num_ersd; + + entry_pointer p_l = m_p_l; + while (p_l->m_p_next != 0) + { + if (pred(p_l->m_p_next->m_value)) + { + ++num_ersd; + erase_next(p_l); + } + else + p_l = p_l->m_p_next; + } + + PB_DS_ASSERT_VALID((*this)) + return num_ersd; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase_next(entry_pointer p_l) +{ + _GLIBCXX_DEBUG_ASSERT(p_l != 0); + _GLIBCXX_DEBUG_ASSERT(p_l->m_p_next != 0); + entry_pointer p_next_l = p_l->m_p_next->m_p_next; + actual_erase_entry(p_l->m_p_next); + p_l->m_p_next = p_next_l; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +actual_erase_entry(entry_pointer p_l) +{ + _GLIBCXX_DEBUG_ONLY(debug_base::erase_existing(PB_DS_V2F(p_l->m_value));) + p_l->~entry(); + s_entry_allocator.deallocate(p_l, 1); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/find_fn_imps.hpp new file mode 100644 index 0000000..36b84c8 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/find_fn_imps.hpp @@ -0,0 +1,90 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_map_/find_fn_imps.hpp + * Contains implementations of lu_map_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::entry_pointer +PB_DS_CLASS_C_DEC:: +find_imp(key_const_reference r_key) const +{ + if (m_p_l == 0) + return 0; + if (s_eq_fn(r_key, PB_DS_V2F(m_p_l->m_value))) + { + apply_update(m_p_l, s_metadata_type_indicator); + PB_DS_CHECK_KEY_EXISTS(r_key) + return m_p_l; + } + + entry_pointer p_l = m_p_l; + while (p_l->m_p_next != 0) + { + entry_pointer p_next = p_l->m_p_next; + if (s_eq_fn(r_key, PB_DS_V2F(p_next->m_value))) + { + if (apply_update(p_next, s_metadata_type_indicator)) + { + p_l->m_p_next = p_next->m_p_next; + p_next->m_p_next = m_p_l; + m_p_l = p_next; + return m_p_l; + } + return p_next; + } + else + p_l = p_next; + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return 0; +} + +PB_DS_CLASS_T_DEC +template<typename Metadata> +inline bool +PB_DS_CLASS_C_DEC:: +apply_update(entry_pointer p_l, type_to_type<Metadata>) +{ return s_update_policy(p_l->m_update_metadata); } + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +apply_update(entry_pointer, type_to_type<null_type>) +{ return s_update_policy(s_null_type); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/info_fn_imps.hpp new file mode 100644 index 0000000..c832214 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/info_fn_imps.hpp @@ -0,0 +1,57 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_map_/info_fn_imps.hpp + * Contains implementations of lu_map_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size() const +{ return std::distance(begin(), end()); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +max_size() const +{ return s_entry_allocator.max_size(); } + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +empty() const +{ return (m_p_l == 0); } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/insert_fn_imps.hpp new file mode 100644 index 0000000..a24e2c5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/insert_fn_imps.hpp @@ -0,0 +1,106 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_map_/insert_fn_imps.hpp + * Contains implementations of lu_map_. + */ + +PB_DS_CLASS_T_DEC +inline std::pair< + typename PB_DS_CLASS_C_DEC::point_iterator, + bool> +PB_DS_CLASS_C_DEC:: +insert(const_reference r_val) +{ + PB_DS_ASSERT_VALID((*this)) + entry_pointer p_l = find_imp(PB_DS_V2F(r_val)); + + if (p_l != 0) + { + PB_DS_CHECK_KEY_EXISTS(PB_DS_V2F(r_val)) + return std::make_pair(point_iterator(&p_l->m_value), false); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(PB_DS_V2F(r_val)) + + p_l = allocate_new_entry(r_val, traits_base::m_no_throw_copies_indicator); + p_l->m_p_next = m_p_l; + m_p_l = p_l; + PB_DS_ASSERT_VALID((*this)) + return std::make_pair(point_iterator(&p_l->m_value), true); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::entry_pointer +PB_DS_CLASS_C_DEC:: +allocate_new_entry(const_reference r_val, false_type) +{ + entry_pointer p_l = s_entry_allocator.allocate(1); + cond_dealtor_t cond(p_l); + new (const_cast<void* >(static_cast<const void* >(&p_l->m_value))) + value_type(r_val); + + cond.set_no_action(); + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_val));) + init_entry_metadata(p_l, s_metadata_type_indicator); + return p_l; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::entry_pointer +PB_DS_CLASS_C_DEC:: +allocate_new_entry(const_reference r_val, true_type) +{ + entry_pointer p_l = s_entry_allocator.allocate(1); + new (&p_l->m_value) value_type(r_val); + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_val));) + init_entry_metadata(p_l, s_metadata_type_indicator); + return p_l; +} + +PB_DS_CLASS_T_DEC +template<typename Metadata> +inline void +PB_DS_CLASS_C_DEC:: +init_entry_metadata(entry_pointer p_l, type_to_type<Metadata>) +{ new (&p_l->m_update_metadata) Metadata(s_update_policy()); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +init_entry_metadata(entry_pointer, type_to_type<null_type>) +{ } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/iterators_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/iterators_fn_imps.hpp new file mode 100644 index 0000000..325cce6 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/iterators_fn_imps.hpp @@ -0,0 +1,80 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_map_/iterators_fn_imps.hpp + * Contains implementations of lu_map_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +begin() +{ + if (m_p_l == 0) + { + _GLIBCXX_DEBUG_ASSERT(empty()); + return end(); + } + return iterator(&m_p_l->m_value, m_p_l, this); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin() const +{ + if (m_p_l == 0) + { + _GLIBCXX_DEBUG_ASSERT(empty()); + return end(); + } + return iterator(&m_p_l->m_value, m_p_l, const_cast<PB_DS_CLASS_C_DEC* >(this)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +end() +{ return iterator(0, 0, this); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end() const +{ + return const_iterator(0, 0, const_cast<PB_DS_CLASS_C_DEC* const>(this)); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/lu_map_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/lu_map_.hpp new file mode 100644 index 0000000..6a200d4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/lu_map_.hpp @@ -0,0 +1,343 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_map_/lu_map_.hpp + * Contains a list update map. + */ + +#include <utility> +#include <iterator> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/tag_and_trait.hpp> +#include <ext/pb_ds/detail/types_traits.hpp> +#include <ext/pb_ds/detail/list_update_map_/entry_metadata_base.hpp> +#include <ext/pb_ds/exception.hpp> +#ifdef _GLIBCXX_DEBUG +#include <ext/pb_ds/detail/debug_map_base.hpp> +#endif +#ifdef PB_DS_LU_MAP_TRACE_ +#include <iostream> +#endif +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#ifdef PB_DS_DATA_TRUE_INDICATOR +#define PB_DS_LU_NAME lu_map +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR +#define PB_DS_LU_NAME lu_set +#endif + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Mapped, typename Eq_Fn, \ + typename _Alloc, typename Update_Policy> + +#define PB_DS_CLASS_C_DEC \ + PB_DS_LU_NAME<Key, Mapped, Eq_Fn, _Alloc, Update_Policy> + +#define PB_DS_LU_TRAITS_BASE \ + types_traits<Key, Mapped, _Alloc, false> + +#ifdef _GLIBCXX_DEBUG +#define PB_DS_DEBUG_MAP_BASE_C_DEC \ + debug_map_base<Key, Eq_Fn, \ + typename _Alloc::template rebind<Key>::other::const_reference> +#endif + + /// list-based (with updates) associative container. + /// Skip to the lu, my darling. + template<typename Key, + typename Mapped, + typename Eq_Fn, + typename _Alloc, + typename Update_Policy> + class PB_DS_LU_NAME : +#ifdef _GLIBCXX_DEBUG + protected PB_DS_DEBUG_MAP_BASE_C_DEC, +#endif + public PB_DS_LU_TRAITS_BASE + { + private: + typedef PB_DS_LU_TRAITS_BASE traits_base; + + struct entry + : public lu_map_entry_metadata_base<typename Update_Policy::metadata_type> + { + typename traits_base::value_type m_value; + typename _Alloc::template rebind<entry>::other::pointer m_p_next; + }; + + typedef typename _Alloc::template rebind<entry>::other entry_allocator; + typedef typename entry_allocator::pointer entry_pointer; + typedef typename entry_allocator::const_pointer const_entry_pointer; + typedef typename entry_allocator::reference entry_reference; + typedef typename entry_allocator::const_reference const_entry_reference; + + typedef typename _Alloc::template rebind<entry_pointer>::other entry_pointer_allocator; + typedef typename entry_pointer_allocator::pointer entry_pointer_array; + + typedef typename traits_base::value_type value_type_; + typedef typename traits_base::pointer pointer_; + typedef typename traits_base::const_pointer const_pointer_; + typedef typename traits_base::reference reference_; + typedef typename traits_base::const_reference const_reference_; + +#define PB_DS_GEN_POS entry_pointer + +#include <ext/pb_ds/detail/unordered_iterator/point_const_iterator.hpp> +#include <ext/pb_ds/detail/unordered_iterator/point_iterator.hpp> +#include <ext/pb_ds/detail/unordered_iterator/const_iterator.hpp> +#include <ext/pb_ds/detail/unordered_iterator/iterator.hpp> + +#undef PB_DS_GEN_POS + + +#ifdef _GLIBCXX_DEBUG + typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base; +#endif + + typedef cond_dealtor<entry, _Alloc> cond_dealtor_t; + + public: + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef Eq_Fn eq_fn; + typedef Update_Policy update_policy; + typedef typename Update_Policy::metadata_type update_metadata; + typedef typename traits_base::key_type key_type; + typedef typename traits_base::key_pointer key_pointer; + typedef typename traits_base::key_const_pointer key_const_pointer; + typedef typename traits_base::key_reference key_reference; + typedef typename traits_base::key_const_reference key_const_reference; + typedef typename traits_base::mapped_type mapped_type; + typedef typename traits_base::mapped_pointer mapped_pointer; + typedef typename traits_base::mapped_const_pointer mapped_const_pointer; + typedef typename traits_base::mapped_reference mapped_reference; + typedef typename traits_base::mapped_const_reference mapped_const_reference; + typedef typename traits_base::value_type value_type; + typedef typename traits_base::pointer pointer; + typedef typename traits_base::const_pointer const_pointer; + typedef typename traits_base::reference reference; + typedef typename traits_base::const_reference const_reference; + +#ifdef PB_DS_DATA_TRUE_INDICATOR + typedef point_iterator_ point_iterator; +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR + typedef point_const_iterator_ point_iterator; +#endif + + typedef point_const_iterator_ point_const_iterator; + +#ifdef PB_DS_DATA_TRUE_INDICATOR + typedef iterator_ iterator; +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR + typedef const_iterator_ iterator; +#endif + + typedef const_iterator_ const_iterator; + + public: + PB_DS_LU_NAME(); + + PB_DS_LU_NAME(const PB_DS_CLASS_C_DEC&); + + virtual + ~PB_DS_LU_NAME(); + + template<typename It> + PB_DS_LU_NAME(It, It); + + void + swap(PB_DS_CLASS_C_DEC&); + + inline size_type + size() const; + + inline size_type + max_size() const; + + inline bool + empty() const; + + inline mapped_reference + operator[](key_const_reference r_key) + { +#ifdef PB_DS_DATA_TRUE_INDICATOR + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + return insert(std::make_pair(r_key, mapped_type())).first->second; +#else + insert(r_key); + return traits_base::s_null_type; +#endif + } + + inline std::pair<point_iterator, bool> + insert(const_reference); + + inline point_iterator + find(key_const_reference r_key) + { + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + entry_pointer p_e = find_imp(r_key); + return point_iterator(p_e == 0 ? 0: &p_e->m_value); + } + + inline point_const_iterator + find(key_const_reference r_key) const + { + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + entry_pointer p_e = find_imp(r_key); + return point_const_iterator(p_e == 0 ? 0: &p_e->m_value); + } + + inline bool + erase(key_const_reference); + + template<typename Pred> + inline size_type + erase_if(Pred); + + void + clear(); + + inline iterator + begin(); + + inline const_iterator + begin() const; + + inline iterator + end(); + + inline const_iterator + end() const; + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char* file, int line) const; +#endif + +#ifdef PB_DS_LU_MAP_TRACE_ + void + trace() const; +#endif + + protected: + + template<typename It> + void + copy_from_range(It, It); + + private: +#ifdef PB_DS_DATA_TRUE_INDICATOR + friend class iterator_; +#endif + + friend class const_iterator_; + + inline entry_pointer + allocate_new_entry(const_reference, false_type); + + inline entry_pointer + allocate_new_entry(const_reference, true_type); + + template<typename Metadata> + inline static void + init_entry_metadata(entry_pointer, type_to_type<Metadata>); + + inline static void + init_entry_metadata(entry_pointer, type_to_type<null_type>); + + void + deallocate_all(); + + void + erase_next(entry_pointer); + + void + actual_erase_entry(entry_pointer); + + void + inc_it_state(const_pointer& r_p_value, entry_pointer& r_pos) const + { + r_pos = r_pos->m_p_next; + r_p_value = (r_pos == 0) ? 0 : &r_pos->m_value; + } + + template<typename Metadata> + inline static bool + apply_update(entry_pointer, type_to_type<Metadata>); + + inline static bool + apply_update(entry_pointer, type_to_type<null_type>); + + inline entry_pointer + find_imp(key_const_reference) const; + + static entry_allocator s_entry_allocator; + static Eq_Fn s_eq_fn; + static Update_Policy s_update_policy; + static type_to_type<update_metadata> s_metadata_type_indicator; + static null_type s_null_type; + + mutable entry_pointer m_p_l; + }; + +#include <ext/pb_ds/detail/list_update_map_/constructor_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/list_update_map_/info_fn_imps.hpp> +#include <ext/pb_ds/detail/list_update_map_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/list_update_map_/iterators_fn_imps.hpp> +#include <ext/pb_ds/detail/list_update_map_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/list_update_map_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/list_update_map_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/list_update_map_/trace_fn_imps.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_LU_TRAITS_BASE +#undef PB_DS_DEBUG_MAP_BASE_C_DEC +#undef PB_DS_LU_NAME + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/trace_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/trace_fn_imps.hpp new file mode 100644 index 0000000..208dafb --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_map_/trace_fn_imps.hpp @@ -0,0 +1,59 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_map_/trace_fn_imps.hpp + * Contains implementations of lu_map_. + */ + +#ifdef PB_DS_LU_MAP_TRACE_ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace() const +{ + std::cerr << m_p_l << std::endl << std::endl; + const_entry_pointer p_l = m_p_l; + while (p_l != 0) + { + std::cerr << PB_DS_V2F(p_l->m_value) << std::endl; + p_l = p_l->m_p_next; + } + std::cerr << std::endl; +} + +#endif + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_policy/lu_counter_metadata.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_policy/lu_counter_metadata.hpp new file mode 100644 index 0000000..47f386c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_policy/lu_counter_metadata.hpp @@ -0,0 +1,87 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file lu_counter_metadata.hpp + * Contains implementation of a lu counter policy's metadata. + */ + +namespace __gnu_pbds +{ + namespace detail + { + template<typename Size_Type> + class lu_counter_policy_base; + + /// A list-update metadata type that moves elements to the front of + /// the list based on the counter algorithm. + template<typename Size_Type = std::size_t> + class lu_counter_metadata + { + public: + typedef Size_Type size_type; + + private: + lu_counter_metadata(size_type init_count) : m_count(init_count) + { } + + friend class lu_counter_policy_base<size_type>; + + mutable size_type m_count; + }; + + /// Base class for list-update counter policy. + template<typename Size_Type> + class lu_counter_policy_base + { + protected: + typedef Size_Type size_type; + + lu_counter_metadata<size_type> + operator()(size_type max_size) const + { return lu_counter_metadata<Size_Type>(std::rand() % max_size); } + + template<typename Metadata_Reference> + bool + operator()(Metadata_Reference r_data, size_type m_max_count) const + { + if (++r_data.m_count != m_max_count) + return false; + r_data.m_count = 0; + return true; + } + }; + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_policy/sample_update_policy.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_policy/sample_update_policy.hpp new file mode 100644 index 0000000..170e29b --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/list_update_policy/sample_update_policy.hpp @@ -0,0 +1,76 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file sample_update_policy.hpp + * Contains a sample policy for list update containers. + */ + +#ifndef PB_DS_SAMPLE_UPDATE_POLICY_HPP +#define PB_DS_SAMPLE_UPDATE_POLICY_HPP + +namespace __gnu_pbds +{ + /// A sample list-update policy. + struct sample_update_policy + { + /// Default constructor. + sample_update_policy(); + + /// Copy constructor. + sample_update_policy(const sample_update_policy&); + + /// Swaps content. + inline void + swap(sample_update_policy& other); + + protected: + /// Metadata on which this functor operates. + typedef some_metadata_type metadata_type; + + /// Creates a metadata object. + metadata_type + operator()() const; + + /// Decides whether a metadata object should be moved to the front + /// of the list. A list-update based containers object will call + /// this method to decide whether to move a node to the front of + /// the list. The method shoule return true if the node should be + /// moved to the front of the list. + bool + operator()(metadata_reference) const; + }; +} +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..cb9c998 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,257 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/constructors_destructor_fn_imps.hpp + * Contains an implementation class for ov_tree_. + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::value_allocator +PB_DS_CLASS_C_DEC::s_value_alloc; + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::metadata_allocator +PB_DS_CLASS_C_DEC::s_metadata_alloc; + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_OV_TREE_NAME() : + m_a_values(0), + m_a_metadata(0), + m_end_it(0), + m_size(0) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_OV_TREE_NAME(const Cmp_Fn& r_cmp_fn) : + cmp_fn(r_cmp_fn), + m_a_values(0), + m_a_metadata(0), + m_end_it(0), + m_size(0) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_OV_TREE_NAME(const Cmp_Fn& r_cmp_fn, const node_update& r_nodeu) : + cmp_fn(r_cmp_fn), + node_update(r_nodeu), + m_a_values(0), + m_a_metadata(0), + m_end_it(0), + m_size(0) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_OV_TREE_NAME(const PB_DS_CLASS_C_DEC& other) : +#ifdef PB_DS_TREE_TRACE + trace_base(other), +#endif + cmp_fn(other), + node_update(other), + m_a_values(0), + m_a_metadata(0), + m_end_it(0), + m_size(0) +{ + copy_from_ordered_range(other.begin(), other.end()); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +template<typename It> +inline void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ +#ifdef PB_DS_DATA_TRUE_INDICATOR + typedef std::map<key_type, mapped_type, Cmp_Fn, + typename _Alloc::template rebind<value_type>::other> + map_type; +#else + typedef std::set<key_type, Cmp_Fn, + typename _Alloc::template rebind<Key>::other> + map_type; +#endif + + map_type m(first_it, last_it); + copy_from_ordered_range(m.begin(), m.end()); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_ordered_range(It first_it, It last_it) +{ + const size_type len = std::distance(first_it, last_it); + if (len == 0) + return; + + value_vector a_values = s_value_alloc.allocate(len); + iterator target_it = a_values; + It source_it = first_it; + It source_end_it = last_it; + + cond_dtor<size_type> cd(a_values, target_it, len); + while (source_it != source_end_it) + { + void* __v = const_cast<void*>(static_cast<const void*>(target_it)); + new (__v) value_type(*source_it++); + ++target_it; + } + + reallocate_metadata((node_update*)this, len); + cd.set_no_action(); + m_a_values = a_values; + m_size = len; + m_end_it = m_a_values + m_size; + update(PB_DS_node_begin_imp(), (node_update*)this); + +#ifdef _GLIBCXX_DEBUG + for (const_iterator dbg_it = m_a_values; dbg_it != m_end_it; ++dbg_it) + debug_base::insert_new(PB_DS_V2F(*dbg_it)); +#endif +} + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_ordered_range(It first_it, It last_it, It other_first_it, + It other_last_it) +{ + clear(); + const size_type len = std::distance(first_it, last_it) + + std::distance(other_first_it, other_last_it); + + value_vector a_values = s_value_alloc.allocate(len); + + iterator target_it = a_values; + It source_it = first_it; + It source_end_it = last_it; + + cond_dtor<size_type> cd(a_values, target_it, len); + while (source_it != source_end_it) + { + new (const_cast<void* >(static_cast<const void* >(target_it))) + value_type(*source_it++); + ++target_it; + } + + source_it = other_first_it; + source_end_it = other_last_it; + + while (source_it != source_end_it) + { + new (const_cast<void* >(static_cast<const void* >(target_it))) + value_type(*source_it++); + ++target_it; + } + + reallocate_metadata((node_update* )this, len); + cd.set_no_action(); + m_a_values = a_values; + m_size = len; + m_end_it = m_a_values + m_size; + update(PB_DS_node_begin_imp(), (node_update* )this); + +#ifdef _GLIBCXX_DEBUG + for (const_iterator dbg_it = m_a_values; dbg_it != m_end_it; ++dbg_it) + debug_base::insert_new(PB_DS_V2F(*dbg_it)); +#endif +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + value_swap(other); + std::swap(static_cast<cmp_fn&>(*this), + static_cast<cmp_fn&>(other)); + std::swap(static_cast<traits_base&>(*this), + static_cast<traits_base&>(other)); + PB_DS_ASSERT_VALID(other) + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +value_swap(PB_DS_CLASS_C_DEC& other) +{ + _GLIBCXX_DEBUG_ONLY(debug_base::swap(other);) + std::swap(m_a_values, other.m_a_values); + std::swap(m_a_metadata, other.m_a_metadata); + std::swap(m_size, other.m_size); + std::swap(m_end_it, other.m_end_it); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~PB_DS_OV_TREE_NAME() +{ + PB_DS_ASSERT_VALID((*this)) + cond_dtor<size_type> cd(m_a_values, m_end_it, m_size); + reallocate_metadata((node_update*)this, 0); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +update(node_iterator, null_node_update_pointer) +{ } + +PB_DS_CLASS_T_DEC +template<typename Node_Update> +void +PB_DS_CLASS_C_DEC:: +update(node_iterator nd_it, Node_Update* p_update) +{ + node_const_iterator end_it = PB_DS_node_end_imp(); + if (nd_it != end_it) + { + update(nd_it.get_l_child(), p_update); + update(nd_it.get_r_child(), p_update); + node_update::operator()(nd_it, end_it); + } +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/debug_fn_imps.hpp new file mode 100644 index 0000000..8056876 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/debug_fn_imps.hpp @@ -0,0 +1,79 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/debug_fn_imps.hpp + * Contains an implementation class for ov_tree_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + if (m_a_values == 0 || m_end_it == 0 || m_size == 0) + PB_DS_DEBUG_VERIFY(m_a_values == 0 && m_end_it == 0 && m_size == 0); + + assert_iterators(__file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_iterators(const char* __file, int __line) const +{ + debug_base::check_size(m_size, __file, __line); + size_type iterated_num = 0; + const_iterator prev_it = end(); + PB_DS_DEBUG_VERIFY(m_end_it == m_a_values + m_size); + for (const_iterator it = begin(); it != end(); ++it) + { + ++iterated_num; + debug_base::check_key_exists(PB_DS_V2F(*it), __file, __line); + PB_DS_DEBUG_VERIFY(lower_bound(PB_DS_V2F(*it)) == it); + const_iterator upper_bound_it = upper_bound(PB_DS_V2F(*it)); + --upper_bound_it; + PB_DS_DEBUG_VERIFY(upper_bound_it == it); + if (prev_it != end()) + PB_DS_DEBUG_VERIFY(Cmp_Fn::operator()(PB_DS_V2F(*prev_it), + PB_DS_V2F(*it))); + prev_it = it; + } + PB_DS_DEBUG_VERIFY(iterated_num == m_size); +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp new file mode 100644 index 0000000..42d978b --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp @@ -0,0 +1,191 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/erase_fn_imps.hpp + * Contains an implementation class for ov_tree_. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + PB_DS_ASSERT_VALID((*this)) + if (m_size == 0) + { + return; + } + else + { + reallocate_metadata((node_update* )this, 0); + cond_dtor<size_type> cd(m_a_values, m_end_it, m_size); + } + + _GLIBCXX_DEBUG_ONLY(debug_base::clear();) + m_a_values = 0; + m_size = 0; + m_end_it = m_a_values; + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + PB_DS_ASSERT_VALID((*this)) + +#ifdef PB_DS_REGRESSION + typename _Alloc::group_adjustor adjust(m_size); +#endif + + size_type new_size = 0; + size_type num_val_ersd = 0; + + for (iterator source_it = begin(); source_it != m_end_it; ++source_it) + if (!pred(*source_it)) + ++new_size; + else + ++num_val_ersd; + + if (new_size == 0) + { + clear(); + return num_val_ersd; + } + + value_vector a_new_values = s_value_alloc.allocate(new_size); + iterator target_it = a_new_values; + cond_dtor<size_type> cd(a_new_values, target_it, new_size); + _GLIBCXX_DEBUG_ONLY(debug_base::clear()); + for (iterator source_it = begin(); source_it != m_end_it; ++source_it) + { + if (!pred(*source_it)) + { + new (const_cast<void*>(static_cast<const void*>(target_it))) + value_type(*source_it); + + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(*source_it))); + ++target_it; + } + } + + reallocate_metadata((node_update*)this, new_size); + cd.set_no_action(); + + { + cond_dtor<size_type> cd1(m_a_values, m_end_it, m_size); + } + + m_a_values = a_new_values; + m_size = new_size; + m_end_it = target_it; + update(node_begin(), (node_update*)this); + PB_DS_ASSERT_VALID((*this)) + return num_val_ersd; +} + +PB_DS_CLASS_T_DEC +template<typename It> +It +PB_DS_CLASS_C_DEC:: +erase_imp(It it) +{ + PB_DS_ASSERT_VALID((*this)) + if (it == end()) + return end(); + + PB_DS_CHECK_KEY_EXISTS(PB_DS_V2F(*it)) + +#ifdef PB_DS_REGRESSION + typename _Alloc::group_adjustor adjust(m_size); +#endif + + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + value_vector a_values = s_value_alloc.allocate(m_size - 1); + iterator source_it = begin(); + iterator source_end_it = end(); + iterator target_it = a_values; + iterator ret_it = end(); + + cond_dtor<size_type> cd(a_values, target_it, m_size - 1); + + _GLIBCXX_DEBUG_ONLY(size_type cnt = 0;) + + while (source_it != source_end_it) + { + if (source_it != it) + { + _GLIBCXX_DEBUG_ONLY(++cnt;) + _GLIBCXX_DEBUG_ASSERT(cnt != m_size); + new (const_cast<void*>(static_cast<const void*>(target_it))) + value_type(*source_it); + + ++target_it; + } + else + ret_it = target_it; + ++source_it; + } + + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + reallocate_metadata((node_update*)this, m_size - 1); + cd.set_no_action(); + _GLIBCXX_DEBUG_ONLY(debug_base::erase_existing(PB_DS_V2F(*it));) + { + cond_dtor<size_type> cd1(m_a_values, m_end_it, m_size); + } + + m_a_values = a_values; + --m_size; + m_end_it = m_a_values + m_size; + update(node_begin(), (node_update*)this); + PB_DS_ASSERT_VALID((*this)) + return It(ret_it); +} + +PB_DS_CLASS_T_DEC +bool +PB_DS_CLASS_C_DEC:: +erase(key_const_reference r_key) +{ + point_iterator it = find(r_key); + if (it == end()) + return false; + erase(it); + return true; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/info_fn_imps.hpp new file mode 100644 index 0000000..fbade74 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/info_fn_imps.hpp @@ -0,0 +1,60 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/info_fn_imps.hpp + * Contains an implementation class for ov_tree_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size() const +{ + PB_DS_ASSERT_VALID((*this)) + return m_size; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +max_size() const +{ return s_value_alloc.max_size(); } + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +empty() const +{ return size() == 0; } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/insert_fn_imps.hpp new file mode 100644 index 0000000..2754898 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/insert_fn_imps.hpp @@ -0,0 +1,63 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/insert_fn_imps.hpp + * Contains an implementation class for ov_tree_. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +reallocate_metadata(null_node_update_pointer, size_type) +{ } + +PB_DS_CLASS_T_DEC +template<typename Node_Update_> +void +PB_DS_CLASS_C_DEC:: +reallocate_metadata(Node_Update_* , size_type new_size) +{ + metadata_pointer a_new_metadata_vec =(new_size == 0) ? 0 : s_metadata_alloc.allocate(new_size); + + if (m_a_metadata != 0) + { + for (size_type i = 0; i < m_size; ++i) + m_a_metadata[i].~metadata_type(); + s_metadata_alloc.deallocate(m_a_metadata, m_size); + } + std::swap(m_a_metadata, a_new_metadata_vec); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/iterators_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/iterators_fn_imps.hpp new file mode 100644 index 0000000..87ba113 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/iterators_fn_imps.hpp @@ -0,0 +1,103 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/iterators_fn_imps.hpp + * Contains an implementation class for ov_tree_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_const_iterator +PB_DS_CLASS_C_DEC:: +node_begin() const +{ return PB_DS_node_begin_imp(); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_const_iterator +PB_DS_CLASS_C_DEC:: +node_end() const +{ return PB_DS_node_end_imp(); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_iterator +PB_DS_CLASS_C_DEC:: +node_begin() +{ return PB_DS_node_begin_imp(); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_iterator +PB_DS_CLASS_C_DEC:: +node_end() +{ return PB_DS_node_end_imp(); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_const_iterator +PB_DS_CLASS_C_DEC:: +PB_DS_node_begin_imp() const +{ + return node_const_iterator(const_cast<pointer>(mid_pointer(begin(), end())), + const_cast<pointer>(begin()), + const_cast<pointer>(end()),(m_a_metadata == 0)? + 0 : + mid_pointer(m_a_metadata, m_a_metadata + m_size)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_const_iterator +PB_DS_CLASS_C_DEC:: +PB_DS_node_end_imp() const +{ + return node_const_iterator(end(), end(), end(), + (m_a_metadata == 0) ? 0 : m_a_metadata + m_size); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_iterator +PB_DS_CLASS_C_DEC:: +PB_DS_node_begin_imp() +{ + return node_iterator(mid_pointer(begin(), end()), begin(), end(), + (m_a_metadata == 0) ? 0 : mid_pointer(m_a_metadata, m_a_metadata + m_size)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_iterator +PB_DS_CLASS_C_DEC:: +PB_DS_node_end_imp() +{ + return node_iterator(end(), end(), + end(),(m_a_metadata == 0) ? 0 : m_a_metadata + m_size); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/node_iterators.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/node_iterators.hpp new file mode 100644 index 0000000..adbb345 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/node_iterators.hpp @@ -0,0 +1,291 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/node_iterators.hpp + * Contains an implementation class for ov_tree_. + */ + +#ifndef PB_DS_OV_TREE_NODE_ITERATORS_HPP +#define PB_DS_OV_TREE_NODE_ITERATORS_HPP + +#include <ext/pb_ds/tag_and_trait.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC \ + ov_tree_node_const_it_<Value_Type, Metadata_Type, _Alloc> + + /// Const node reference. + template<typename Value_Type, typename Metadata_Type, typename _Alloc> + class ov_tree_node_const_it_ + { + + protected: + typedef + typename _Alloc::template rebind< + Value_Type>::other::pointer + pointer; + + typedef + typename _Alloc::template rebind< + Value_Type>::other::const_pointer + const_pointer; + + typedef + typename _Alloc::template rebind< + Metadata_Type>::other::const_pointer + const_metadata_pointer; + + typedef PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC this_type; + + protected: + + template<typename Ptr> + inline static Ptr + mid_pointer(Ptr p_begin, Ptr p_end) + { + _GLIBCXX_DEBUG_ASSERT(p_end >= p_begin); + return (p_begin + (p_end - p_begin) / 2); + } + + public: + + typedef trivial_iterator_tag iterator_category; + + typedef trivial_iterator_difference_type difference_type; + + typedef + typename _Alloc::template rebind< + Value_Type>::other::const_pointer + value_type; + + typedef + typename _Alloc::template rebind< + typename remove_const< + Value_Type>::type>::other::const_pointer + reference; + + typedef + typename _Alloc::template rebind< + typename remove_const< + Value_Type>::type>::other::const_pointer + const_reference; + + typedef Metadata_Type metadata_type; + + typedef + typename _Alloc::template rebind< + metadata_type>::other::const_reference + metadata_const_reference; + + public: + inline + ov_tree_node_const_it_(const_pointer p_nd = 0, const_pointer p_begin_nd = 0, const_pointer p_end_nd = 0, const_metadata_pointer p_metadata = 0) : m_p_value(const_cast<pointer>(p_nd)), m_p_begin_value(const_cast<pointer>(p_begin_nd)), m_p_end_value(const_cast<pointer>(p_end_nd)), m_p_metadata(p_metadata) + { } + + inline const_reference + operator*() const + { return m_p_value; } + + inline metadata_const_reference + get_metadata() const + { + enum + { + has_metadata = !is_same<Metadata_Type, null_type>::value + }; + + PB_DS_STATIC_ASSERT(should_have_metadata, has_metadata); + _GLIBCXX_DEBUG_ASSERT(m_p_metadata != 0); + return *m_p_metadata; + } + + /// Returns the node iterator associated with the left node. + inline this_type + get_l_child() const + { + if (m_p_begin_value == m_p_value) + return (this_type(m_p_begin_value, m_p_begin_value, m_p_begin_value)); + + const_metadata_pointer p_begin_metadata = + m_p_metadata - (m_p_value - m_p_begin_value); + + return (this_type(mid_pointer(m_p_begin_value, m_p_value), + m_p_begin_value, + m_p_value, + mid_pointer(p_begin_metadata, m_p_metadata))); + } + + /// Returns the node iterator associated with the right node. + inline this_type + get_r_child() const + { + if (m_p_value == m_p_end_value) + return (this_type(m_p_end_value, m_p_end_value, m_p_end_value)); + + const_metadata_pointer p_end_metadata = + m_p_metadata + (m_p_end_value - m_p_value); + + return (this_type(mid_pointer(m_p_value + 1, m_p_end_value), + m_p_value + 1, + m_p_end_value,(m_p_metadata == 0) ? + 0 : mid_pointer(m_p_metadata + 1, p_end_metadata))); + } + + inline bool + operator==(const this_type& other) const + { + const bool is_end = m_p_begin_value == m_p_end_value; + const bool is_other_end = other.m_p_begin_value == other.m_p_end_value; + + if (is_end) + return (is_other_end); + + if (is_other_end) + return (is_end); + + return m_p_value == other.m_p_value; + } + + inline bool + operator!=(const this_type& other) const + { return !operator==(other); } + + public: + pointer m_p_value; + pointer m_p_begin_value; + pointer m_p_end_value; + + const_metadata_pointer m_p_metadata; + }; + +#define PB_DS_OV_TREE_NODE_ITERATOR_C_DEC \ + ov_tree_node_it_<Value_Type, Metadata_Type, _Alloc> + + /// Node reference. + template<typename Value_Type, typename Metadata_Type, typename _Alloc> + class ov_tree_node_it_ : public PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC + { + private: + typedef PB_DS_OV_TREE_NODE_ITERATOR_C_DEC this_type; + + typedef PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC base_type; + + typedef typename base_type::pointer pointer; + + typedef typename base_type::const_pointer const_pointer; + + typedef + typename base_type::const_metadata_pointer + const_metadata_pointer; + + public: + typedef trivial_iterator_tag iterator_category; + + typedef trivial_iterator_difference_type difference_type; + + typedef + typename _Alloc::template rebind< + Value_Type>::other::pointer + value_type; + + typedef + typename _Alloc::template rebind< + typename remove_const< + Value_Type>::type>::other::pointer + reference; + + typedef + typename _Alloc::template rebind< + typename remove_const< + Value_Type>::type>::other::pointer + const_reference; + + inline + ov_tree_node_it_(const_pointer p_nd = 0, const_pointer p_begin_nd = 0, const_pointer p_end_nd = 0, const_metadata_pointer p_metadata = 0) : base_type(p_nd, p_begin_nd, p_end_nd, p_metadata) + { } + + /// Access. + inline reference + operator*() const + { return reference(base_type::m_p_value); } + + /// Returns the node reference associated with the left node. + inline ov_tree_node_it_ + get_l_child() const + { + if (base_type::m_p_begin_value == base_type::m_p_value) + return (this_type(base_type::m_p_begin_value, base_type::m_p_begin_value, base_type::m_p_begin_value)); + + const_metadata_pointer p_begin_metadata = + base_type::m_p_metadata - (base_type::m_p_value - base_type::m_p_begin_value); + + return (this_type(base_type::mid_pointer(base_type::m_p_begin_value, base_type::m_p_value), + base_type::m_p_begin_value, + base_type::m_p_value, + base_type::mid_pointer(p_begin_metadata, base_type::m_p_metadata))); + } + + /// Returns the node reference associated with the right node. + inline ov_tree_node_it_ + get_r_child() const + { + if (base_type::m_p_value == base_type::m_p_end_value) + return this_type(base_type::m_p_end_value, base_type::m_p_end_value, + base_type::m_p_end_value); + + const_metadata_pointer p_end_metadata = + base_type::m_p_metadata + (base_type::m_p_end_value - base_type::m_p_value); + + return (this_type(base_type::mid_pointer(base_type::m_p_value + 1, base_type::m_p_end_value), + base_type::m_p_value + 1, + base_type::m_p_end_value,(base_type::m_p_metadata == 0)? + 0 : base_type::mid_pointer(base_type::m_p_metadata + 1, p_end_metadata))); + } + + }; + +#undef PB_DS_OV_TREE_NODE_ITERATOR_C_DEC +#undef PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC + +} // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp new file mode 100644 index 0000000..349f268 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp @@ -0,0 +1,542 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/ov_tree_map_.hpp + * Contains an implementation class for ov_tree. + */ + +#include <map> +#include <set> +#include <ext/pb_ds/exception.hpp> +#include <ext/pb_ds/tree_policy.hpp> +#include <ext/pb_ds/detail/eq_fn/eq_by_less.hpp> +#include <ext/pb_ds/detail/types_traits.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/tree_trace_base.hpp> +#ifdef _GLIBCXX_DEBUG +#include <ext/pb_ds/detail/debug_map_base.hpp> +#endif +#include <utility> +#include <functional> +#include <algorithm> +#include <vector> +#include <assert.h> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#ifdef PB_DS_DATA_TRUE_INDICATOR +#define PB_DS_OV_TREE_NAME ov_tree_map +#define PB_DS_CONST_NODE_ITERATOR_NAME ov_tree_node_const_iterator_map +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR +#define PB_DS_OV_TREE_NAME ov_tree_set +#define PB_DS_CONST_NODE_ITERATOR_NAME ov_tree_node_const_iterator_set +#endif + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Mapped, typename Cmp_Fn, \ + typename Node_And_It_Traits, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + PB_DS_OV_TREE_NAME<Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc> + +#define PB_DS_OV_TREE_TRAITS_BASE \ + types_traits<Key, Mapped, _Alloc, false> + +#ifdef _GLIBCXX_DEBUG +#define PB_DS_DEBUG_MAP_BASE_C_DEC \ + debug_map_base<Key, eq_by_less<Key, Cmp_Fn>, \ + typename _Alloc::template rebind<Key>::other::const_reference> +#endif + +#ifdef PB_DS_TREE_TRACE +#define PB_DS_TREE_TRACE_BASE_C_DEC \ + tree_trace_base<typename Node_And_It_Traits::node_const_iterator, \ + typename Node_And_It_Traits::node_iterator, \ + Cmp_Fn, false, _Alloc> +#endif + +#ifndef PB_DS_CHECK_KEY_EXISTS +# error Missing definition +#endif + + /** + * @brief Ordered-vector tree associative-container. + * @ingroup branch-detail + */ + template<typename Key, typename Mapped, typename Cmp_Fn, + typename Node_And_It_Traits, typename _Alloc> + class PB_DS_OV_TREE_NAME : +#ifdef _GLIBCXX_DEBUG + protected PB_DS_DEBUG_MAP_BASE_C_DEC, +#endif +#ifdef PB_DS_TREE_TRACE + public PB_DS_TREE_TRACE_BASE_C_DEC, +#endif + public Cmp_Fn, + public Node_And_It_Traits::node_update, + public PB_DS_OV_TREE_TRAITS_BASE + { + private: + typedef PB_DS_OV_TREE_TRAITS_BASE traits_base; + typedef Node_And_It_Traits traits_type; + + typedef typename remove_const<typename traits_base::value_type>::type non_const_value_type; + + typedef typename _Alloc::template rebind<non_const_value_type>::other value_allocator; + typedef typename value_allocator::pointer value_vector; + +#ifdef _GLIBCXX_DEBUG + typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base; +#endif + +#ifdef PB_DS_TREE_TRACE + typedef PB_DS_TREE_TRACE_BASE_C_DEC trace_base; +#endif + + typedef typename traits_base::pointer mapped_pointer_; + typedef typename traits_base::const_pointer mapped_const_pointer_; + + typedef typename traits_type::metadata_type metadata_type; + + typedef typename _Alloc::template rebind<metadata_type>::other metadata_allocator; + typedef typename metadata_allocator::pointer metadata_pointer; + typedef typename metadata_allocator::const_reference metadata_const_reference; + typedef typename metadata_allocator::reference metadata_reference; + + typedef typename traits_type::null_node_update_pointer + null_node_update_pointer; + + public: + typedef ov_tree_tag container_category; + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef Cmp_Fn cmp_fn; + + typedef typename traits_base::key_type key_type; + typedef typename traits_base::key_pointer key_pointer; + typedef typename traits_base::key_const_pointer key_const_pointer; + typedef typename traits_base::key_reference key_reference; + typedef typename traits_base::key_const_reference key_const_reference; + typedef typename traits_base::mapped_type mapped_type; + typedef typename traits_base::mapped_pointer mapped_pointer; + typedef typename traits_base::mapped_const_pointer mapped_const_pointer; + typedef typename traits_base::mapped_reference mapped_reference; + typedef typename traits_base::mapped_const_reference mapped_const_reference; + typedef typename traits_base::value_type value_type; + typedef typename traits_base::pointer pointer; + typedef typename traits_base::const_pointer const_pointer; + typedef typename traits_base::reference reference; + typedef typename traits_base::const_reference const_reference; + + typedef const_pointer point_const_iterator; +#ifdef PB_DS_DATA_TRUE_INDICATOR + typedef pointer point_iterator; +#else + typedef point_const_iterator point_iterator; +#endif + + typedef point_iterator iterator; + typedef point_const_iterator const_iterator; + + /// Conditional destructor. + template<typename Size_Type> + class cond_dtor + { + public: + cond_dtor(value_vector a_vec, iterator& r_last_it, + Size_Type total_size) + : m_a_vec(a_vec), m_r_last_it(r_last_it), m_max_size(total_size), + m_no_action(false) + { } + + ~cond_dtor() + { + if (m_no_action) + return; + iterator it = m_a_vec; + while (it != m_r_last_it) + { + it->~value_type(); + ++it; + } + + if (m_max_size > 0) + value_allocator().deallocate(m_a_vec, m_max_size); + } + + inline void + set_no_action() + { m_no_action = true; } + + protected: + value_vector m_a_vec; + iterator& m_r_last_it; + const Size_Type m_max_size; + bool m_no_action; + }; + + typedef typename traits_type::node_update node_update; + typedef typename traits_type::node_iterator node_iterator; + typedef typename traits_type::node_const_iterator node_const_iterator; + + + PB_DS_OV_TREE_NAME(); + + PB_DS_OV_TREE_NAME(const Cmp_Fn&); + + PB_DS_OV_TREE_NAME(const Cmp_Fn&, const node_update&); + + PB_DS_OV_TREE_NAME(const PB_DS_CLASS_C_DEC&); + + ~PB_DS_OV_TREE_NAME(); + + void + swap(PB_DS_CLASS_C_DEC&); + + template<typename It> + void + copy_from_range(It, It); + + inline size_type + max_size() const; + + inline bool + empty() const; + + inline size_type + size() const; + + Cmp_Fn& + get_cmp_fn(); + + const Cmp_Fn& + get_cmp_fn() const; + + inline mapped_reference + operator[](key_const_reference r_key) + { +#ifdef PB_DS_DATA_TRUE_INDICATOR + PB_DS_ASSERT_VALID((*this)) + point_iterator it = lower_bound(r_key); + if (it != end() && !Cmp_Fn::operator()(r_key, PB_DS_V2F(*it))) + { + PB_DS_CHECK_KEY_EXISTS(r_key) + PB_DS_ASSERT_VALID((*this)) + return it->second; + } + return insert_new_val(it, std::make_pair(r_key, mapped_type()))->second; +#else + insert(r_key); + return traits_base::s_null_type; +#endif + } + + inline std::pair<point_iterator, bool> + insert(const_reference r_value) + { + PB_DS_ASSERT_VALID((*this)) + key_const_reference r_key = PB_DS_V2F(r_value); + point_iterator it = lower_bound(r_key); + + if (it != end()&& !Cmp_Fn::operator()(r_key, PB_DS_V2F(*it))) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_CHECK_KEY_EXISTS(r_key) + return std::make_pair(it, false); + } + + return std::make_pair(insert_new_val(it, r_value), true); + } + + inline point_iterator + lower_bound(key_const_reference r_key) + { + pointer it = m_a_values; + pointer e_it = m_a_values + m_size; + while (it != e_it) + { + pointer mid_it = it + ((e_it - it) >> 1); + if (cmp_fn::operator()(PB_DS_V2F(*mid_it), r_key)) + it = ++mid_it; + else + e_it = mid_it; + } + return it; + } + + inline point_const_iterator + lower_bound(key_const_reference r_key) const + { return const_cast<PB_DS_CLASS_C_DEC& >(*this).lower_bound(r_key); } + + inline point_iterator + upper_bound(key_const_reference r_key) + { + iterator pot_it = lower_bound(r_key); + if (pot_it != end() && !Cmp_Fn::operator()(r_key, PB_DS_V2F(*pot_it))) + { + PB_DS_CHECK_KEY_EXISTS(r_key) + return ++pot_it; + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return pot_it; + } + + inline point_const_iterator + upper_bound(key_const_reference r_key) const + { return const_cast<PB_DS_CLASS_C_DEC&>(*this).upper_bound(r_key); } + + inline point_iterator + find(key_const_reference r_key) + { + PB_DS_ASSERT_VALID((*this)) + iterator pot_it = lower_bound(r_key); + if (pot_it != end() && !Cmp_Fn::operator()(r_key, PB_DS_V2F(*pot_it))) + { + PB_DS_CHECK_KEY_EXISTS(r_key) + return pot_it; + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return end(); + } + + inline point_const_iterator + find(key_const_reference r_key) const + { return (const_cast<PB_DS_CLASS_C_DEC&>(*this).find(r_key)); } + + bool + erase(key_const_reference); + + template<typename Pred> + inline size_type + erase_if(Pred); + + inline iterator + erase(iterator it) + { return erase_imp<iterator>(it); } + + void + clear(); + + void + join(PB_DS_CLASS_C_DEC&); + + void + split(key_const_reference, PB_DS_CLASS_C_DEC&); + + inline iterator + begin() + { return m_a_values; } + + inline const_iterator + begin() const + { return m_a_values; } + + inline iterator + end() + { return m_end_it; } + + inline const_iterator + end() const + { return m_end_it; } + + /// Returns a const node_iterator corresponding to the node at the + /// root of the tree. + inline node_const_iterator + node_begin() const; + + /// Returns a node_iterator corresponding to the node at the + /// root of the tree. + inline node_iterator + node_begin(); + + /// Returns a const node_iterator corresponding to a node just + /// after a leaf of the tree. + inline node_const_iterator + node_end() const; + + /// Returns a node_iterator corresponding to a node just + /// after a leaf of the tree. + inline node_iterator + node_end(); + + private: + + inline void + update(node_iterator, null_node_update_pointer); + + template<typename Node_Update> + void + update(node_iterator, Node_Update*); + + void + reallocate_metadata(null_node_update_pointer, size_type); + + template<typename Node_Update_> + void + reallocate_metadata(Node_Update_*, size_type); + + template<typename It> + void + copy_from_ordered_range(It, It); + + void + value_swap(PB_DS_CLASS_C_DEC&); + + template<typename It> + void + copy_from_ordered_range(It, It, It, It); + + template<typename Ptr> + inline static Ptr + mid_pointer(Ptr p_begin, Ptr p_end) + { + _GLIBCXX_DEBUG_ASSERT(p_end >= p_begin); + return (p_begin + (p_end - p_begin) / 2); + } + + inline iterator + insert_new_val(iterator it, const_reference r_value) + { +#ifdef PB_DS_REGRESSION + typename _Alloc::group_adjustor adjust(m_size); +#endif + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(PB_DS_V2F(r_value)) + + value_vector a_values = s_value_alloc.allocate(m_size + 1); + + iterator source_it = begin(); + iterator source_end_it = end(); + iterator target_it = a_values; + iterator ret_it; + + cond_dtor<size_type> cd(a_values, target_it, m_size + 1); + while (source_it != it) + { + new (const_cast<void*>(static_cast<const void*>(target_it))) + value_type(*source_it++); + ++target_it; + } + + new (const_cast<void*>(static_cast<const void*>(ret_it = target_it))) + value_type(r_value); + ++target_it; + + while (source_it != source_end_it) + { + new (const_cast<void*>(static_cast<const void*>(target_it))) + value_type(*source_it++); + ++target_it; + } + + reallocate_metadata((node_update*)this, m_size + 1); + cd.set_no_action(); + if (m_size != 0) + { + cond_dtor<size_type> cd1(m_a_values, m_end_it, m_size); + } + + ++m_size; + m_a_values = a_values; + m_end_it = m_a_values + m_size; + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_value))); + update(node_begin(), (node_update* )this); + PB_DS_ASSERT_VALID((*this)) + return ret_it; + } + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; + + void + assert_iterators(const char*, int) const; +#endif + + template<typename It> + It + erase_imp(It); + + inline node_const_iterator + PB_DS_node_begin_imp() const; + + inline node_const_iterator + PB_DS_node_end_imp() const; + + inline node_iterator + PB_DS_node_begin_imp(); + + inline node_iterator + PB_DS_node_end_imp(); + + private: + static value_allocator s_value_alloc; + static metadata_allocator s_metadata_alloc; + + value_vector m_a_values; + metadata_pointer m_a_metadata; + iterator m_end_it; + size_type m_size; + }; + +#include <ext/pb_ds/detail/ov_tree_map_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/ov_tree_map_/iterators_fn_imps.hpp> +#include <ext/pb_ds/detail/ov_tree_map_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/ov_tree_map_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/ov_tree_map_/info_fn_imps.hpp> +#include <ext/pb_ds/detail/ov_tree_map_/split_join_fn_imps.hpp> +#include <ext/pb_ds/detail/bin_search_tree_/policy_access_fn_imps.hpp> + +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_OV_TREE_NAME +#undef PB_DS_OV_TREE_TRAITS_BASE +#undef PB_DS_DEBUG_MAP_BASE_C_DEC +#ifdef PB_DS_TREE_TRACE +#undef PB_DS_TREE_TRACE_BASE_C_DEC +#endif +#undef PB_DS_CONST_NODE_ITERATOR_NAME + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/policy_access_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/policy_access_fn_imps.hpp new file mode 100644 index 0000000..f09949b --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/policy_access_fn_imps.hpp @@ -0,0 +1,51 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/policy_access_fn_imps.hpp + * Contains an implementation class for ov_tree. + */ + +PB_DS_CLASS_T_DEC +Cmp_Fn& +PB_DS_CLASS_C_DEC:: +get_cmp_fn() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Cmp_Fn& +PB_DS_CLASS_C_DEC:: +get_cmp_fn() const +{ return *this; } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/split_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/split_join_fn_imps.hpp new file mode 100644 index 0000000..520dfd7 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/split_join_fn_imps.hpp @@ -0,0 +1,132 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/split_join_fn_imps.hpp + * Contains an implementation class for ov_tree_. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +split(key_const_reference r_key, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + if (m_size == 0) + { + other.clear(); + return; + } + + if (Cmp_Fn::operator()(r_key, PB_DS_V2F(*begin()))) + { + value_swap(other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + if (!Cmp_Fn::operator()(r_key, PB_DS_V2F(*(end() - 1)))) + { + return; + } + + if (m_size == 1) + { + value_swap(other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + iterator it = upper_bound(r_key); + PB_DS_CLASS_C_DEC new_other(other, other); + new_other.copy_from_ordered_range(it, end()); + PB_DS_CLASS_C_DEC new_this(*this, *this); + new_this.copy_from_ordered_range(begin(), it); + + // No exceptions from this point. + other.update(other.node_begin(), (node_update*)(&other)); + update(node_begin(), (node_update*)this); + other.value_swap(new_other); + value_swap(new_this); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +join(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + if (other.m_size == 0) + return; + + if (m_size == 0) + { + value_swap(other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + const bool greater = Cmp_Fn::operator()(PB_DS_V2F(*(end() - 1)), + PB_DS_V2F(*other.begin())); + + const bool lesser = Cmp_Fn::operator()(PB_DS_V2F(*(other.end() - 1)), + PB_DS_V2F(*begin())); + + if (!greater && !lesser) + __throw_join_error(); + + PB_DS_CLASS_C_DEC new_this(*this, *this); + + if (greater) + new_this.copy_from_ordered_range(begin(), end(), + other.begin(), other.end()); + else + new_this.copy_from_ordered_range(other.begin(), other.end(), + begin(), end()); + + // No exceptions from this point. + value_swap(new_this); + other.clear(); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/traits.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/traits.hpp new file mode 100644 index 0000000..a39f0ff --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/traits.hpp @@ -0,0 +1,190 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file ov_tree_map_/traits.hpp + * Contains an implementation class for ov_tree_. + */ + +#ifndef PB_DS_OV_TREE_NODE_AND_IT_TRAITS_HPP +#define PB_DS_OV_TREE_NODE_AND_IT_TRAITS_HPP + +#include <ext/pb_ds/detail/ov_tree_map_/node_iterators.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /// Tree traits. + /// @ingroup traits + template<typename Key, + typename Mapped, + class Cmp_Fn, + template<typename Node_CItr, + class Node_Itr, + class Cmp_Fn_, + typename _Alloc_> + class Node_Update, + typename _Alloc> + struct tree_traits< + Key, + Mapped, + Cmp_Fn, + Node_Update, + ov_tree_tag, + _Alloc> + { + private: + typedef + typename types_traits< + Key, + Mapped, + _Alloc, + false>::value_type + value_type; + + public: + typedef + typename tree_node_metadata_dispatch< + Key, + Mapped, + Cmp_Fn, + Node_Update, + _Alloc>::type + metadata_type; + + /// This is an iterator to an iterator: it iterates over nodes, + /// and de-referencing it returns one of the tree's iterators. + typedef + ov_tree_node_const_it_< + value_type, + metadata_type, + _Alloc> + node_const_iterator; + + typedef + ov_tree_node_it_< + value_type, + metadata_type, + _Alloc> + node_iterator; + + typedef + Node_Update< + node_const_iterator, + node_iterator, + Cmp_Fn, + _Alloc> + node_update; + + typedef + __gnu_pbds::null_node_update< + node_const_iterator, + node_iterator, + Cmp_Fn, + _Alloc>* + null_node_update_pointer; + }; + + + /// Specialization. + /// @ingroup traits + template<typename Key, + class Cmp_Fn, + template<typename Node_CItr, + class Node_Itr, + class Cmp_Fn_, + typename _Alloc_> + class Node_Update, + typename _Alloc> + struct tree_traits< + Key, + null_type, + Cmp_Fn, + Node_Update, + ov_tree_tag, + _Alloc> + { + private: + typedef + typename types_traits< + Key, + null_type, + _Alloc, + false>::value_type + value_type; + + public: + typedef + typename tree_node_metadata_dispatch< + Key, + null_type, + Cmp_Fn, + Node_Update, + _Alloc>::type + metadata_type; + + /// This is an iterator to an iterator: it iterates over nodes, + /// and de-referencing it returns one of the tree's iterators. + typedef + ov_tree_node_const_it_< + value_type, + metadata_type, + _Alloc> + node_const_iterator; + + typedef node_const_iterator node_iterator; + + typedef + Node_Update< + node_const_iterator, + node_const_iterator, + Cmp_Fn, + _Alloc> + node_update; + + typedef + __gnu_pbds::null_node_update< + node_const_iterator, + node_iterator, + Cmp_Fn, + _Alloc>* + null_node_update_pointer; + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_OV_TREE_NODE_AND_IT_TRAITS_HPP + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..6208432 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,82 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pairing_heap_/constructors_destructor_fn_imps.hpp + * Contains an implementation class for a pairing heap. + */ + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + push(*(first_it++)); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +pairing_heap() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +pairing_heap(const Cmp_Fn& r_cmp_fn) +: base_type(r_cmp_fn) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +pairing_heap(const PB_DS_CLASS_C_DEC& other) +: base_type(other) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + base_type::swap(other); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~pairing_heap() +{ } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/debug_fn_imps.hpp new file mode 100644 index 0000000..a662c18 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/debug_fn_imps.hpp @@ -0,0 +1,53 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pairing_heap_/debug_fn_imps.hpp + * Contains an implementation class for a pairing heap. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + PB_DS_DEBUG_VERIFY(base_type::m_p_root == 0 + || base_type::m_p_root->m_p_next_sibling == 0); + base_type::assert_valid(__file, __line); +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/erase_fn_imps.hpp new file mode 100644 index 0000000..4282032 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/erase_fn_imps.hpp @@ -0,0 +1,233 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pairing_heap_/erase_fn_imps.hpp + * Contains an implementation class for a pairing heap. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +pop() +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + + node_pointer p_new_root = join_node_children(base_type::m_p_root); + PB_DS_ASSERT_NODE_CONSISTENT(p_new_root, false) + if (p_new_root != 0) + p_new_root->m_p_prev_or_parent = 0; + + base_type::actual_erase_node(base_type::m_p_root); + base_type::m_p_root = p_new_root; + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase(point_iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + remove_node(it.m_p_nd); + base_type::actual_erase_node(it.m_p_nd); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +remove_node(node_pointer p_nd) +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + node_pointer p_new_child = join_node_children(p_nd); + + PB_DS_ASSERT_NODE_CONSISTENT(p_new_child, false) + + if (p_nd == base_type::m_p_root) + { + if (p_new_child != 0) + p_new_child->m_p_prev_or_parent = 0; + base_type::m_p_root = p_new_child; + PB_DS_ASSERT_NODE_CONSISTENT(base_type::m_p_root, false) + return; + } + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_prev_or_parent != 0); + if (p_nd->m_p_prev_or_parent->m_p_l_child == p_nd) + { + if (p_new_child != 0) + { + p_new_child->m_p_prev_or_parent = p_nd->m_p_prev_or_parent; + p_new_child->m_p_next_sibling = p_nd->m_p_next_sibling; + if (p_new_child->m_p_next_sibling != 0) + p_new_child->m_p_next_sibling->m_p_prev_or_parent = p_new_child; + p_nd->m_p_prev_or_parent->m_p_l_child = p_new_child; + PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent, false) + return; + } + + p_nd->m_p_prev_or_parent->m_p_l_child = p_nd->m_p_next_sibling; + if (p_nd->m_p_next_sibling != 0) + p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd->m_p_prev_or_parent; + PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent, false) + return; + } + + if (p_new_child != 0) + { + p_new_child->m_p_prev_or_parent = p_nd->m_p_prev_or_parent; + p_new_child->m_p_next_sibling = p_nd->m_p_next_sibling; + if (p_new_child->m_p_next_sibling != 0) + p_new_child->m_p_next_sibling->m_p_prev_or_parent = p_new_child; + p_new_child->m_p_prev_or_parent->m_p_next_sibling = p_new_child; + PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent, false) + return; + } + + p_nd->m_p_prev_or_parent->m_p_next_sibling = p_nd->m_p_next_sibling; + if (p_nd->m_p_next_sibling != 0) + p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd->m_p_prev_or_parent; + PB_DS_ASSERT_NODE_CONSISTENT(p_nd->m_p_prev_or_parent, false) +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +join_node_children(node_pointer p_nd) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + node_pointer p_ret = p_nd->m_p_l_child; + if (p_ret == 0) + return 0; + while (p_ret->m_p_next_sibling != 0) + p_ret = forward_join(p_ret, p_ret->m_p_next_sibling); + while (p_ret->m_p_prev_or_parent != p_nd) + p_ret = back_join(p_ret->m_p_prev_or_parent, p_ret); + PB_DS_ASSERT_NODE_CONSISTENT(p_ret, false) + return p_ret; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +forward_join(node_pointer p_nd, node_pointer p_next) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_next_sibling == p_next); + if (Cmp_Fn::operator()(p_nd->m_value, p_next->m_value)) + { + p_next->m_p_prev_or_parent = p_nd->m_p_prev_or_parent; + base_type::make_child_of(p_nd, p_next); + return p_next->m_p_next_sibling == 0 + ? p_next : p_next->m_p_next_sibling; + } + + if (p_next->m_p_next_sibling != 0) + { + p_next->m_p_next_sibling->m_p_prev_or_parent = p_nd; + p_nd->m_p_next_sibling = p_next->m_p_next_sibling; + base_type::make_child_of(p_next, p_nd); + return p_nd->m_p_next_sibling; + } + + p_nd->m_p_next_sibling = 0; + base_type::make_child_of(p_next, p_nd); + PB_DS_ASSERT_NODE_CONSISTENT(p_nd, false) + return p_nd; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +back_join(node_pointer p_nd, node_pointer p_next) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + _GLIBCXX_DEBUG_ASSERT(p_next->m_p_next_sibling == 0); + + if (Cmp_Fn::operator()(p_nd->m_value, p_next->m_value)) + { + p_next->m_p_prev_or_parent = p_nd->m_p_prev_or_parent; + base_type::make_child_of(p_nd, p_next); + PB_DS_ASSERT_NODE_CONSISTENT(p_next, false) + return p_next; + } + + p_nd->m_p_next_sibling = 0; + base_type::make_child_of(p_next, p_nd); + PB_DS_ASSERT_NODE_CONSISTENT(p_nd, false) + return p_nd; +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + PB_DS_ASSERT_VALID((*this)) + if (base_type::empty()) + { + PB_DS_ASSERT_VALID((*this)) + return 0; + } + base_type::to_linked_list(); + node_pointer p_out = base_type::prune(pred); + size_type ersd = 0; + while (p_out != 0) + { + ++ersd; + node_pointer p_next = p_out->m_p_next_sibling; + base_type::actual_erase_node(p_out); + p_out = p_next; + } + + node_pointer p_cur = base_type::m_p_root; + base_type::m_p_root = 0; + while (p_cur != 0) + { + node_pointer p_next = p_cur->m_p_next_sibling; + p_cur->m_p_l_child = p_cur->m_p_next_sibling = p_cur->m_p_prev_or_parent = 0; + + push_imp(p_cur); + p_cur = p_next; + } + PB_DS_ASSERT_VALID((*this)) + return ersd; +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/find_fn_imps.hpp new file mode 100644 index 0000000..b346c9a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/find_fn_imps.hpp @@ -0,0 +1,49 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pairing_heap_/find_fn_imps.hpp + * Contains an implementation class for a pairing heap. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reference +PB_DS_CLASS_C_DEC:: +top() const +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + return base_type::m_p_root->m_value; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/insert_fn_imps.hpp new file mode 100644 index 0000000..9903767 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/insert_fn_imps.hpp @@ -0,0 +1,88 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pairing_heap_/insert_fn_imps.hpp + * Contains an implementation class for a pairing heap. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +push(const_reference r_val) +{ + PB_DS_ASSERT_VALID((*this)) + node_pointer p_new_nd = base_type::get_new_node_for_insert(r_val); + push_imp(p_new_nd); + PB_DS_ASSERT_VALID((*this)) + return point_iterator(p_new_nd); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +push_imp(node_pointer p_nd) +{ + p_nd->m_p_l_child = 0; + if (base_type::m_p_root == 0) + { + p_nd->m_p_next_sibling = p_nd->m_p_prev_or_parent = 0; + base_type::m_p_root = p_nd; + } + else if (Cmp_Fn::operator()(base_type::m_p_root->m_value, p_nd->m_value)) + { + p_nd->m_p_next_sibling = p_nd->m_p_prev_or_parent = 0; + base_type::make_child_of(base_type::m_p_root, p_nd); + PB_DS_ASSERT_NODE_CONSISTENT(p_nd, false) + base_type::m_p_root = p_nd; + } + else + { + base_type::make_child_of(p_nd, base_type::m_p_root); + PB_DS_ASSERT_NODE_CONSISTENT(base_type::m_p_root, false) + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +modify(point_iterator it, const_reference r_new_val) +{ + PB_DS_ASSERT_VALID((*this)) + remove_node(it.m_p_nd); + it.m_p_nd->m_value = r_new_val; + push_imp(it.m_p_nd); + PB_DS_ASSERT_VALID((*this)) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/pairing_heap_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/pairing_heap_.hpp new file mode 100644 index 0000000..dc32a88 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/pairing_heap_.hpp @@ -0,0 +1,185 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pairing_heap_/pairing_heap_.hpp + * Contains an implementation class for a pairing heap. + */ + +/* + * Pairing heap: + * Michael L. Fredman, Robert Sedgewick, Daniel Dominic Sleator, + * and Robert Endre Tarjan, The Pairing Heap: + * A New Form of Self-Adjusting Heap, Algorithmica, 1(1):111-129, 1986. + */ + +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + pairing_heap<Value_Type, Cmp_Fn, _Alloc> + +#ifdef _GLIBCXX_DEBUG +#define PB_DS_P_HEAP_BASE \ + left_child_next_sibling_heap<Value_Type, Cmp_Fn, null_type, _Alloc, false> +#else +#define PB_DS_P_HEAP_BASE \ + left_child_next_sibling_heap<Value_Type, Cmp_Fn, null_type, _Alloc> +#endif + + /** + * Pairing heap. + * + * @ingroup heap-detail + */ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + class pairing_heap : public PB_DS_P_HEAP_BASE + { + private: + typedef PB_DS_P_HEAP_BASE base_type; + typedef typename base_type::node_pointer node_pointer; + + typedef typename _Alloc::template rebind<Value_Type>::other __rebind_a; + + public: + typedef Value_Type value_type; + typedef Cmp_Fn cmp_fn; + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + + typedef typename __rebind_a::pointer pointer; + typedef typename __rebind_a::const_pointer const_pointer; + typedef typename __rebind_a::reference reference; + typedef typename __rebind_a::const_reference const_reference; + + typedef typename base_type::point_const_iterator point_const_iterator; + typedef typename base_type::point_iterator point_iterator; + typedef typename base_type::const_iterator const_iterator; + typedef typename base_type::iterator iterator; + + pairing_heap(); + + pairing_heap(const Cmp_Fn&); + + pairing_heap(const pairing_heap&); + + void + swap(pairing_heap&); + + ~pairing_heap(); + + inline point_iterator + push(const_reference); + + void + modify(point_iterator, const_reference); + + inline const_reference + top() const; + + void + pop(); + + void + erase(point_iterator); + + template<typename Pred> + size_type + erase_if(Pred); + + template<typename Pred> + void + split(Pred, pairing_heap&); + + void + join(pairing_heap&); + + protected: + + template<typename It> + void + copy_from_range(It, It); + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; +#endif + + private: + + inline void + push_imp(node_pointer); + + node_pointer + join_node_children(node_pointer); + + node_pointer + forward_join(node_pointer, node_pointer); + + node_pointer + back_join(node_pointer, node_pointer); + + void + remove_node(node_pointer); + }; + +#define PB_DS_ASSERT_NODE_CONSISTENT(_Node, _Bool) \ + _GLIBCXX_DEBUG_ONLY(base_type::assert_node_consistent(_Node, _Bool, \ + __FILE__, __LINE__);) + +#include <ext/pb_ds/detail/pairing_heap_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/pairing_heap_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/pairing_heap_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/pairing_heap_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/pairing_heap_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/pairing_heap_/split_join_fn_imps.hpp> + +#undef PB_DS_ASSERT_NODE_CONSISTENT +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_P_HEAP_BASE + + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/split_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/split_join_fn_imps.hpp new file mode 100644 index 0000000..a2a4312 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pairing_heap_/split_join_fn_imps.hpp @@ -0,0 +1,123 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pairing_heap_/split_join_fn_imps.hpp + * Contains an implementation class for a pairing heap. + */ + +PB_DS_CLASS_T_DEC +template<typename Pred> +void +PB_DS_CLASS_C_DEC:: +split(Pred pred, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + other.clear(); + + if (base_type::empty()) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + base_type::to_linked_list(); + node_pointer p_out = base_type::prune(pred); + while (p_out != 0) + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_size > 0); + --base_type::m_size; + ++other.m_size; + node_pointer p_next = p_out->m_p_next_sibling; + p_out->m_p_l_child = p_out->m_p_next_sibling = p_out->m_p_prev_or_parent = 0; + + other.push_imp(p_out); + p_out = p_next; + } + + PB_DS_ASSERT_VALID(other) + node_pointer p_cur = base_type::m_p_root; + base_type::m_p_root = 0; + while (p_cur != 0) + { + node_pointer p_next = p_cur->m_p_next_sibling; + p_cur->m_p_l_child = p_cur->m_p_next_sibling = p_cur->m_p_prev_or_parent = 0; + + push_imp(p_cur); + p_cur = p_next; + } + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +join(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + if (other.m_p_root == 0) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + if (base_type::m_p_root == 0) + base_type::m_p_root = other.m_p_root; + else if (Cmp_Fn::operator()(base_type::m_p_root->m_value, other.m_p_root->m_value)) + { + base_type::make_child_of(base_type::m_p_root, other.m_p_root); + PB_DS_ASSERT_NODE_CONSISTENT(other.m_p_root, false) + base_type::m_p_root = other.m_p_root; + } + else + { + base_type::make_child_of(other.m_p_root, base_type::m_p_root); + PB_DS_ASSERT_NODE_CONSISTENT(base_type::m_p_root, false) + } + + base_type::m_size += other.m_size; + other.m_p_root = 0; + other.m_size = 0; + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..c67674c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,214 @@ + // -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/constructors_destructor_fn_imps.hpp + * Contains an implementation class for pat_trie. + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::head_allocator +PB_DS_CLASS_C_DEC::s_head_allocator; + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::inode_allocator +PB_DS_CLASS_C_DEC::s_inode_allocator; + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::leaf_allocator +PB_DS_CLASS_C_DEC::s_leaf_allocator; + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_PAT_TRIE_NAME() : + m_p_head(s_head_allocator.allocate(1)), + m_size(0) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_PAT_TRIE_NAME(const access_traits& r_access_traits) : + synth_access_traits(r_access_traits), + m_p_head(s_head_allocator.allocate(1)), + m_size(0) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_PAT_TRIE_NAME(const PB_DS_CLASS_C_DEC& other) : +#ifdef _GLIBCXX_DEBUG + debug_base(other), +#endif + synth_access_traits(other), + node_update(other), + m_p_head(s_head_allocator.allocate(1)), + m_size(0) +{ + initialize(); + m_size = other.m_size; + PB_DS_ASSERT_VALID(other) + if (other.m_p_head->m_p_parent == 0) + { + PB_DS_ASSERT_VALID((*this)) + return; + } + __try + { + m_p_head->m_p_parent = recursive_copy_node(other.m_p_head->m_p_parent); + } + __catch(...) + { + s_head_allocator.deallocate(m_p_head, 1); + __throw_exception_again; + } + + m_p_head->m_p_min = leftmost_descendant(m_p_head->m_p_parent); + m_p_head->m_p_max = rightmost_descendant(m_p_head->m_p_parent); + m_p_head->m_p_parent->m_p_parent = m_p_head; + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + value_swap(other); + std::swap((access_traits& )(*this), (access_traits& )other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +value_swap(PB_DS_CLASS_C_DEC& other) +{ + _GLIBCXX_DEBUG_ONLY(debug_base::swap(other);) + std::swap(m_p_head, other.m_p_head); + std::swap(m_size, other.m_size); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~PB_DS_PAT_TRIE_NAME() +{ + clear(); + s_head_allocator.deallocate(m_p_head, 1); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +initialize() +{ + new (m_p_head) head(); + m_p_head->m_p_parent = 0; + m_p_head->m_p_min = m_p_head; + m_p_head->m_p_max = m_p_head; + m_size = 0; +} + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + insert(*(first_it++)); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +recursive_copy_node(node_const_pointer p_ncp) +{ + _GLIBCXX_DEBUG_ASSERT(p_ncp != 0); + if (p_ncp->m_type == leaf_node) + { + leaf_const_pointer p_other_lf = static_cast<leaf_const_pointer>(p_ncp); + leaf_pointer p_new_lf = s_leaf_allocator.allocate(1); + cond_dealtor cond(p_new_lf); + new (p_new_lf) leaf(p_other_lf->value()); + apply_update(p_new_lf, (node_update*)this); + cond.set_no_action_dtor(); + return (p_new_lf); + } + + _GLIBCXX_DEBUG_ASSERT(p_ncp->m_type == i_node); + node_pointer a_p_children[inode::arr_size]; + size_type child_i = 0; + inode_const_pointer p_icp = static_cast<inode_const_pointer>(p_ncp); + + typename inode::const_iterator child_it = p_icp->begin(); + + inode_pointer p_ret; + __try + { + while (child_it != p_icp->end()) + { + a_p_children[child_i] = recursive_copy_node(*(child_it)); + child_i++; + child_it++; + } + p_ret = s_inode_allocator.allocate(1); + } + __catch(...) + { + while (child_i-- > 0) + clear_imp(a_p_children[child_i]); + __throw_exception_again; + } + + new (p_ret) inode(p_icp->get_e_ind(), pref_begin(a_p_children[0])); + + --child_i; + _GLIBCXX_DEBUG_ASSERT(child_i >= 1); + do + p_ret->add_child(a_p_children[child_i], pref_begin(a_p_children[child_i]), + pref_end(a_p_children[child_i]), this); + while (child_i-- > 0); + apply_update(p_ret, (node_update*)this); + return p_ret; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/debug_fn_imps.hpp new file mode 100644 index 0000000..f632531 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/debug_fn_imps.hpp @@ -0,0 +1,115 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/debug_fn_imps.hpp + * Contains an implementation class for pat_trie_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + if (m_p_head->m_p_parent != 0) + m_p_head->m_p_parent->assert_valid(this, __file, __line); + assert_iterators(__file, __line); + assert_reverse_iterators(__file, __line); + if (m_p_head->m_p_parent == 0) + { + PB_DS_DEBUG_VERIFY(m_p_head->m_p_min == m_p_head); + PB_DS_DEBUG_VERIFY(m_p_head->m_p_max == m_p_head); + PB_DS_DEBUG_VERIFY(empty()); + return; + } + + PB_DS_DEBUG_VERIFY(m_p_head->m_p_min->m_type == leaf_node); + PB_DS_DEBUG_VERIFY(m_p_head->m_p_max->m_type == leaf_node); + PB_DS_DEBUG_VERIFY(!empty()); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_iterators(const char* __file, int __line) const +{ + size_type calc_size = 0; + for (const_iterator it = begin(); it != end(); ++it) + { + ++calc_size; + debug_base::check_key_exists(PB_DS_V2F(*it), __file, __line); + PB_DS_DEBUG_VERIFY(lower_bound(PB_DS_V2F(*it)) == it); + PB_DS_DEBUG_VERIFY(--upper_bound(PB_DS_V2F(*it)) == it); + } + PB_DS_DEBUG_VERIFY(calc_size == m_size); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_reverse_iterators(const char* __file, int __line) const +{ + size_type calc_size = 0; + for (const_reverse_iterator it = rbegin(); it != rend(); ++it) + { + ++calc_size; + node_const_pointer p_nd = + const_cast<PB_DS_CLASS_C_DEC*>(this)->find_imp(PB_DS_V2F(*it)); + PB_DS_DEBUG_VERIFY(p_nd == it.m_p_nd); + } + PB_DS_DEBUG_VERIFY(calc_size == m_size); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +recursive_count_leafs(node_const_pointer p_nd, const char* __file, int __line) +{ + if (p_nd == 0) + return (0); + if (p_nd->m_type == leaf_node) + return (1); + PB_DS_DEBUG_VERIFY(p_nd->m_type == i_node); + size_type ret = 0; + for (typename inode::const_iterator it = static_cast<inode_const_pointer>(p_nd)->begin(); + it != static_cast<inode_const_pointer>(p_nd)->end(); + ++it) + ret += recursive_count_leafs(*it, __file, __line); + return ret; +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/erase_fn_imps.hpp new file mode 100644 index 0000000..48907ea --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/erase_fn_imps.hpp @@ -0,0 +1,315 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/erase_fn_imps.hpp + * Contains an implementation class for pat_trie. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +erase(key_const_reference r_key) +{ + node_pointer p_nd = find_imp(r_key); + if (p_nd == 0 || p_nd->m_type == i_node) + { + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return false; + } + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == leaf_node); + if (!synth_access_traits::equal_keys(PB_DS_V2F(reinterpret_cast<leaf_pointer>(p_nd)->value()), r_key)) + { + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return false; + } + + PB_DS_CHECK_KEY_EXISTS(r_key) + erase_leaf(static_cast<leaf_pointer>(p_nd)); + PB_DS_ASSERT_VALID((*this)) + return true; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase_fixup(inode_pointer p_nd) +{ + _GLIBCXX_DEBUG_ASSERT(std::distance(p_nd->begin(), p_nd->end()) >= 1); + if (std::distance(p_nd->begin(), p_nd->end()) == 1) + { + node_pointer p_parent = p_nd->m_p_parent; + if (p_parent == m_p_head) + m_p_head->m_p_parent = *p_nd->begin(); + else + { + _GLIBCXX_DEBUG_ASSERT(p_parent->m_type == i_node); + node_pointer p_new_child = *p_nd->begin(); + + typedef inode_pointer inode_ptr; + inode_ptr p_internal = static_cast<inode_ptr>(p_parent); + p_internal->replace_child(p_new_child, pref_begin(p_new_child), + pref_end(p_new_child), this); + } + (*p_nd->begin())->m_p_parent = p_nd->m_p_parent; + p_nd->~inode(); + s_inode_allocator.deallocate(p_nd, 1); + + if (p_parent == m_p_head) + return; + + _GLIBCXX_DEBUG_ASSERT(p_parent->m_type == i_node); + p_nd = static_cast<inode_pointer>(p_parent); + } + + while (true) + { + _GLIBCXX_DEBUG_ASSERT(std::distance(p_nd->begin(), p_nd->end()) > 1); + p_nd->update_prefixes(this); + apply_update(p_nd, (node_update*)this); + PB_DS_ASSERT_NODE_VALID(p_nd) + if (p_nd->m_p_parent->m_type == head_node) + return; + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_parent->m_type == i_node); + + p_nd = static_cast<inode_pointer>(p_nd->m_p_parent); + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +actual_erase_leaf(leaf_pointer p_l) +{ + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + --m_size; + _GLIBCXX_DEBUG_ONLY(debug_base::erase_existing(PB_DS_V2F(p_l->value()))); + p_l->~leaf(); + s_leaf_allocator.deallocate(p_l, 1); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + if (!empty()) + { + clear_imp(m_p_head->m_p_parent); + m_size = 0; + initialize(); + _GLIBCXX_DEBUG_ONLY(debug_base::clear();) + PB_DS_ASSERT_VALID((*this)) + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear_imp(node_pointer p_nd) +{ + if (p_nd->m_type == i_node) + { + _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == i_node); + for (typename inode::iterator it = + static_cast<inode_pointer>(p_nd)->begin(); + it != static_cast<inode_pointer>(p_nd)->end(); + ++it) + { + node_pointer p_child =* it; + clear_imp(p_child); + } + s_inode_allocator.deallocate(static_cast<inode_pointer>(p_nd), 1); + return; + } + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == leaf_node); + static_cast<leaf_pointer>(p_nd)->~leaf(); + s_leaf_allocator.deallocate(static_cast<leaf_pointer>(p_nd), 1); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +erase(const_iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + + if (it == end()) + return it; + + const_iterator ret_it = it; + ++ret_it; + _GLIBCXX_DEBUG_ASSERT(it.m_p_nd->m_type == leaf_node); + erase_leaf(static_cast<leaf_pointer>(it.m_p_nd)); + PB_DS_ASSERT_VALID((*this)) + return ret_it; +} + +#ifdef PB_DS_DATA_TRUE_INDICATOR +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +erase(iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + + if (it == end()) + return it; + iterator ret_it = it; + ++ret_it; + _GLIBCXX_DEBUG_ASSERT(it.m_p_nd->m_type == leaf_node); + erase_leaf(static_cast<leaf_pointer>(it.m_p_nd)); + PB_DS_ASSERT_VALID((*this)) + return ret_it; +} +#endif // #ifdef PB_DS_DATA_TRUE_INDICATOR + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reverse_iterator +PB_DS_CLASS_C_DEC:: +erase(const_reverse_iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + + if (it.m_p_nd == m_p_head) + return it; + const_reverse_iterator ret_it = it; + ++ret_it; + + _GLIBCXX_DEBUG_ASSERT(it.m_p_nd->m_type == leaf_node); + erase_leaf(static_cast<leaf_pointer>(it.m_p_nd)); + PB_DS_ASSERT_VALID((*this)) + return ret_it; +} + +#ifdef PB_DS_DATA_TRUE_INDICATOR +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::reverse_iterator +PB_DS_CLASS_C_DEC:: +erase(reverse_iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + + if (it.m_p_nd == m_p_head) + return it; + reverse_iterator ret_it = it; + ++ret_it; + + _GLIBCXX_DEBUG_ASSERT(it.m_p_nd->m_type == leaf_node); + erase_leaf(static_cast<leaf_pointer>(it.m_p_nd)); + PB_DS_ASSERT_VALID((*this)) + return ret_it; +} +#endif // #ifdef PB_DS_DATA_TRUE_INDICATOR + +PB_DS_CLASS_T_DEC +template<typename Pred> +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + size_type num_ersd = 0; + PB_DS_ASSERT_VALID((*this)) + + iterator it = begin(); + while (it != end()) + { + PB_DS_ASSERT_VALID((*this)) + if (pred(*it)) + { + ++num_ersd; + it = erase(it); + } + else + ++it; + } + + PB_DS_ASSERT_VALID((*this)) + return num_ersd; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase_leaf(leaf_pointer p_l) +{ + update_min_max_for_erased_leaf(p_l); + if (p_l->m_p_parent->m_type == head_node) + { + _GLIBCXX_DEBUG_ASSERT(size() == 1); + clear(); + return; + } + + _GLIBCXX_DEBUG_ASSERT(size() > 1); + _GLIBCXX_DEBUG_ASSERT(p_l->m_p_parent->m_type == i_node); + + inode_pointer p_parent = static_cast<inode_pointer>(p_l->m_p_parent); + + p_parent->remove_child(p_l); + erase_fixup(p_parent); + actual_erase_leaf(p_l); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +update_min_max_for_erased_leaf(leaf_pointer p_l) +{ + if (m_size == 1) + { + m_p_head->m_p_min = m_p_head; + m_p_head->m_p_max = m_p_head; + return; + } + + if (p_l == static_cast<leaf_const_pointer>(m_p_head->m_p_min)) + { + iterator it(p_l); + ++it; + m_p_head->m_p_min = it.m_p_nd; + return; + } + + if (p_l == static_cast<leaf_const_pointer>(m_p_head->m_p_max)) + { + iterator it(p_l); + --it; + m_p_head->m_p_max = it.m_p_nd; + } +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/find_fn_imps.hpp new file mode 100644 index 0000000..a5ca850 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/find_fn_imps.hpp @@ -0,0 +1,269 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/find_fn_imps.hpp + * Contains an implementation class for pat_trie. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +find(key_const_reference r_key) +{ + PB_DS_ASSERT_VALID((*this)) + node_pointer p_nd = find_imp(r_key); + + if (p_nd == 0 || p_nd->m_type != leaf_node) + { + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return end(); + } + + if (synth_access_traits::equal_keys(PB_DS_V2F(static_cast<leaf_pointer>(p_nd)->value()), r_key)) + { + PB_DS_CHECK_KEY_EXISTS(r_key) + return iterator(p_nd); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return end(); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +find(key_const_reference r_key) const +{ + PB_DS_ASSERT_VALID((*this)) + + node_const_pointer p_nd = const_cast<PB_DS_CLASS_C_DEC* >(this)->find_imp(r_key); + + if (p_nd == 0 || p_nd->m_type != leaf_node) + { + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return end(); + } + + if (synth_access_traits::equal_keys(PB_DS_V2F(static_cast<leaf_const_pointer>(p_nd)->value()), r_key)) + { + PB_DS_CHECK_KEY_EXISTS(r_key) + return const_iterator(const_cast<node_pointer>(p_nd)); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key) + return end(); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +find_imp(key_const_reference r_key) +{ + if (empty()) + return 0; + + typename synth_access_traits::const_iterator b_it = + synth_access_traits::begin(r_key); + typename synth_access_traits::const_iterator e_it = + synth_access_traits::end(r_key); + + node_pointer p_nd = m_p_head->m_p_parent; + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + + while (p_nd->m_type != leaf_node) + { + _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == i_node); + node_pointer p_next_nd = static_cast<inode_pointer>(p_nd)->get_child_node(b_it, e_it, this); + + if (p_next_nd == 0) + return p_nd; + p_nd = p_next_nd; + } + return p_nd; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +lower_bound_imp(key_const_reference r_key) +{ + if (empty()) + return (m_p_head); + + node_pointer p_nd = m_p_head->m_p_parent; + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + + typename PB_DS_CLASS_C_DEC::a_const_iterator b_it = + synth_access_traits::begin(r_key); + + typename PB_DS_CLASS_C_DEC::a_const_iterator e_it = + synth_access_traits::end(r_key); + + size_type checked_ind = 0; + while (true) + { + if (p_nd->m_type == leaf_node) + { + if (!synth_access_traits::cmp_keys(PB_DS_V2F(static_cast<leaf_const_pointer>(p_nd)->value()), r_key)) + return p_nd; + iterator it(p_nd); + ++it; + return it.m_p_nd; + } + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == i_node); + const size_type new_checked_ind = + static_cast<inode_pointer>(p_nd)->get_e_ind(); + + p_nd = + static_cast<inode_pointer>(p_nd)->get_lower_bound_child_node( b_it, e_it, checked_ind, this); + checked_ind = new_checked_ind; + } +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +lower_bound(key_const_reference r_key) +{ return point_iterator(lower_bound_imp(r_key)); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +lower_bound(key_const_reference r_key) const +{ + return point_const_iterator(const_cast<PB_DS_CLASS_C_DEC* >(this)->lower_bound_imp(r_key)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +upper_bound(key_const_reference r_key) +{ + point_iterator l_bound_it = lower_bound(r_key); + + _GLIBCXX_DEBUG_ASSERT(l_bound_it == end() || + !synth_access_traits::cmp_keys(PB_DS_V2F(*l_bound_it), + r_key)); + + if (l_bound_it == end() || + synth_access_traits::cmp_keys(r_key, PB_DS_V2F(*l_bound_it))) + return l_bound_it; + + return ++l_bound_it; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +upper_bound(key_const_reference r_key) const +{ + point_const_iterator l_bound_it = lower_bound(r_key); + + _GLIBCXX_DEBUG_ASSERT(l_bound_it == end() || + !synth_access_traits::cmp_keys(PB_DS_V2F(*l_bound_it), + r_key)); + + if (l_bound_it == end() || + synth_access_traits::cmp_keys(r_key, PB_DS_V2F(*l_bound_it))) + return l_bound_it; + return ++l_bound_it; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::a_const_iterator +PB_DS_CLASS_C_DEC:: +pref_begin(node_const_pointer p_nd) +{ + if (p_nd->m_type == leaf_node) + return (synth_access_traits::begin(PB_DS_V2F(static_cast<leaf_const_pointer>(p_nd)->value()))); + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == i_node); + return static_cast<inode_const_pointer>(p_nd)->pref_b_it(); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::a_const_iterator +PB_DS_CLASS_C_DEC:: +pref_end(node_const_pointer p_nd) +{ + if (p_nd->m_type == leaf_node) + return (synth_access_traits::end(PB_DS_V2F(static_cast<leaf_const_pointer>(p_nd)->value()))); + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == i_node); + return static_cast<inode_const_pointer>(p_nd)->pref_e_it(); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::leaf_const_pointer +PB_DS_CLASS_C_DEC:: +leftmost_descendant(node_const_pointer p_nd) +{ + if (p_nd->m_type == leaf_node) + return static_cast<leaf_const_pointer>(p_nd); + return static_cast<inode_const_pointer>(p_nd)->leftmost_descendant(); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::leaf_pointer +PB_DS_CLASS_C_DEC:: +leftmost_descendant(node_pointer p_nd) +{ + if (p_nd->m_type == leaf_node) + return static_cast<leaf_pointer>(p_nd); + return static_cast<inode_pointer>(p_nd)->leftmost_descendant(); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::leaf_const_pointer +PB_DS_CLASS_C_DEC:: +rightmost_descendant(node_const_pointer p_nd) +{ + if (p_nd->m_type == leaf_node) + return static_cast<leaf_const_pointer>(p_nd); + return static_cast<inode_const_pointer>(p_nd)->rightmost_descendant(); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::leaf_pointer +PB_DS_CLASS_C_DEC:: +rightmost_descendant(node_pointer p_nd) +{ + if (p_nd->m_type == leaf_node) + return static_cast<leaf_pointer>(p_nd); + return static_cast<inode_pointer>(p_nd)->rightmost_descendant(); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/info_fn_imps.hpp new file mode 100644 index 0000000..505b054 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/info_fn_imps.hpp @@ -0,0 +1,58 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/info_fn_imps.hpp + * Contains an implementation class for pat_trie. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +empty() const +{ return (m_size == 0); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size() const +{ return m_size; } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +max_size() const +{ return s_inode_allocator.max_size(); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/insert_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/insert_join_fn_imps.hpp new file mode 100644 index 0000000..e22b81c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/insert_join_fn_imps.hpp @@ -0,0 +1,472 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/insert_join_fn_imps.hpp + * Contains an implementation class for pat_trie. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +join(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + branch_bag bag; + if (!join_prep(other, bag)) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + m_p_head->m_p_parent = rec_join(m_p_head->m_p_parent, + other.m_p_head->m_p_parent, 0, bag); + + m_p_head->m_p_parent->m_p_parent = m_p_head; + m_size += other.m_size; + other.initialize(); + PB_DS_ASSERT_VALID(other) + m_p_head->m_p_min = leftmost_descendant(m_p_head->m_p_parent); + m_p_head->m_p_max = rightmost_descendant(m_p_head->m_p_parent); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +bool +PB_DS_CLASS_C_DEC:: +join_prep(PB_DS_CLASS_C_DEC& other, branch_bag& r_bag) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + if (other.m_size == 0) + return false; + + if (m_size == 0) + { + value_swap(other); + return false; + } + + const bool greater = + synth_access_traits::cmp_keys(PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_max)->value()), + PB_DS_V2F(static_cast<leaf_const_pointer>(other.m_p_head->m_p_min)->value())); + + const bool lesser = + synth_access_traits::cmp_keys(PB_DS_V2F(static_cast<leaf_const_pointer>(other.m_p_head->m_p_max)->value()), + PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_min)->value())); + + if (!greater && !lesser) + __throw_join_error(); + + rec_join_prep(m_p_head->m_p_parent, other.m_p_head->m_p_parent, r_bag); + _GLIBCXX_DEBUG_ONLY(debug_base::join(other, false);) + return true; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +rec_join_prep(node_const_pointer p_l, node_const_pointer p_r, + branch_bag& r_bag) +{ + if (p_l->m_type == leaf_node) + { + if (p_r->m_type == leaf_node) + { + rec_join_prep(static_cast<leaf_const_pointer>(p_l), + static_cast<leaf_const_pointer>(p_r), r_bag); + return; + } + + _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node); + rec_join_prep(static_cast<leaf_const_pointer>(p_l), + static_cast<inode_const_pointer>(p_r), r_bag); + return; + } + + _GLIBCXX_DEBUG_ASSERT(p_l->m_type == i_node); + if (p_r->m_type == leaf_node) + { + rec_join_prep(static_cast<inode_const_pointer>(p_l), + static_cast<leaf_const_pointer>(p_r), r_bag); + return; + } + + _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node); + + rec_join_prep(static_cast<inode_const_pointer>(p_l), + static_cast<inode_const_pointer>(p_r), r_bag); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +rec_join_prep(leaf_const_pointer /*p_l*/, leaf_const_pointer /*p_r*/, + branch_bag& r_bag) +{ r_bag.add_branch(); } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +rec_join_prep(leaf_const_pointer /*p_l*/, inode_const_pointer /*p_r*/, + branch_bag& r_bag) +{ r_bag.add_branch(); } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +rec_join_prep(inode_const_pointer /*p_l*/, leaf_const_pointer /*p_r*/, + branch_bag& r_bag) +{ r_bag.add_branch(); } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +rec_join_prep(inode_const_pointer p_l, inode_const_pointer p_r, + branch_bag& r_bag) +{ + if (p_l->get_e_ind() == p_r->get_e_ind() && + synth_access_traits::equal_prefixes(p_l->pref_b_it(), p_l->pref_e_it(), + p_r->pref_b_it(), p_r->pref_e_it())) + { + for (typename inode::const_iterator it = p_r->begin(); + it != p_r->end(); ++ it) + { + node_const_pointer p_l_join_child = p_l->get_join_child(*it, this); + if (p_l_join_child != 0) + rec_join_prep(p_l_join_child, * it, r_bag); + } + return; + } + + if (p_r->get_e_ind() < p_l->get_e_ind() && + p_r->should_be_mine(p_l->pref_b_it(), p_l->pref_e_it(), 0, this)) + { + node_const_pointer p_r_join_child = p_r->get_join_child(p_l, this); + if (p_r_join_child != 0) + rec_join_prep(p_r_join_child, p_l, r_bag); + return; + } + + if (p_r->get_e_ind() < p_l->get_e_ind() && + p_r->should_be_mine(p_l->pref_b_it(), p_l->pref_e_it(), 0, this)) + { + node_const_pointer p_r_join_child = p_r->get_join_child(p_l, this); + if (p_r_join_child != 0) + rec_join_prep(p_r_join_child, p_l, r_bag); + return; + } + r_bag.add_branch(); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +rec_join(node_pointer p_l, node_pointer p_r, size_type checked_ind, + branch_bag& r_bag) +{ + _GLIBCXX_DEBUG_ASSERT(p_r != 0); + if (p_l == 0) + { + apply_update(p_r, (node_update*)this); + return (p_r); + } + + if (p_l->m_type == leaf_node) + { + if (p_r->m_type == leaf_node) + { + node_pointer p_ret = rec_join(static_cast<leaf_pointer>(p_l), + static_cast<leaf_pointer>(p_r), r_bag); + apply_update(p_ret, (node_update*)this); + return p_ret; + } + + _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node); + node_pointer p_ret = rec_join(static_cast<leaf_pointer>(p_l), + static_cast<inode_pointer>(p_r), + checked_ind, r_bag); + apply_update(p_ret, (node_update*)this); + return p_ret; + } + + _GLIBCXX_DEBUG_ASSERT(p_l->m_type == i_node); + if (p_r->m_type == leaf_node) + { + node_pointer p_ret = rec_join(static_cast<inode_pointer>(p_l), + static_cast<leaf_pointer>(p_r), + checked_ind, r_bag); + apply_update(p_ret, (node_update*)this); + return p_ret; + } + + _GLIBCXX_DEBUG_ASSERT(p_r->m_type == i_node); + node_pointer p_ret = rec_join(static_cast<inode_pointer>(p_l), + static_cast<inode_pointer>(p_r), + r_bag); + + apply_update(p_ret, (node_update*)this); + return p_ret; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +rec_join(leaf_pointer p_l, leaf_pointer p_r, branch_bag& r_bag) +{ + _GLIBCXX_DEBUG_ASSERT(p_r != 0); + if (p_l == 0) + return (p_r); + node_pointer p_ret = insert_branch(p_l, p_r, r_bag); + _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) == 2); + return p_ret; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +rec_join(leaf_pointer p_l, inode_pointer p_r, size_type checked_ind, + branch_bag& r_bag) +{ +#ifdef _GLIBCXX_DEBUG + const size_type lhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_l); + const size_type rhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_r); +#endif + + _GLIBCXX_DEBUG_ASSERT(p_r != 0); + node_pointer p_ret = rec_join(p_r, p_l, checked_ind, r_bag); + _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) == lhs_leafs + rhs_leafs); + return p_ret; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +rec_join(inode_pointer p_l, leaf_pointer p_r, size_type checked_ind, branch_bag& r_bag) +{ + _GLIBCXX_DEBUG_ASSERT(p_l != 0); + _GLIBCXX_DEBUG_ASSERT(p_r != 0); + +#ifdef _GLIBCXX_DEBUG + const size_type lhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_l); + const size_type rhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_r); +#endif + + if (!p_l->should_be_mine(pref_begin(p_r), pref_end(p_r), checked_ind, this)) + { + node_pointer p_ret = insert_branch(p_l, p_r, r_bag); + PB_DS_ASSERT_NODE_VALID(p_ret) + _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) == + lhs_leafs + rhs_leafs); + return p_ret; + } + + node_pointer p_pot_child = p_l->add_child(p_r, pref_begin(p_r), + pref_end(p_r), this); + if (p_pot_child != p_r) + { + node_pointer p_new_child = rec_join(p_pot_child, p_r, p_l->get_e_ind(), + r_bag); + + p_l->replace_child(p_new_child, pref_begin(p_new_child), + pref_end(p_new_child), this); + } + + PB_DS_ASSERT_NODE_VALID(p_l) + _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_l) == lhs_leafs + rhs_leafs); + return p_l; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +rec_join(inode_pointer p_l, inode_pointer p_r, + branch_bag& r_bag) +{ + _GLIBCXX_DEBUG_ASSERT(p_l != 0); + _GLIBCXX_DEBUG_ASSERT(p_r != 0); + +#ifdef _GLIBCXX_DEBUG + const size_type lhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_l); + const size_type rhs_leafs = PB_DS_RECURSIVE_COUNT_LEAFS(p_r); +#endif + + if (p_l->get_e_ind() == p_r->get_e_ind() && + synth_access_traits::equal_prefixes(p_l->pref_b_it(), p_l->pref_e_it(), + p_r->pref_b_it(), p_r->pref_e_it())) + { + for (typename inode::iterator it = p_r->begin(); + it != p_r->end(); ++ it) + { + node_pointer p_new_child = rec_join(p_l->get_join_child(*it, this), + * it, 0, r_bag); + p_l->replace_child(p_new_child, pref_begin(p_new_child), + pref_end(p_new_child), this); + } + + p_r->~inode(); + s_inode_allocator.deallocate(p_r, 1); + PB_DS_ASSERT_NODE_VALID(p_l) + _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_l) == lhs_leafs + rhs_leafs); + return p_l; + } + + if (p_l->get_e_ind() < p_r->get_e_ind() && + p_l->should_be_mine(p_r->pref_b_it(), p_r->pref_e_it(), 0, this)) + { + node_pointer p_new_child = rec_join(p_l->get_join_child(p_r, this), + p_r, 0, r_bag); + p_l->replace_child(p_new_child, pref_begin(p_new_child), + pref_end(p_new_child), this); + PB_DS_ASSERT_NODE_VALID(p_l) + return p_l; + } + + if (p_r->get_e_ind() < p_l->get_e_ind() && + p_r->should_be_mine(p_l->pref_b_it(), p_l->pref_e_it(), 0, this)) + { + node_pointer p_new_child = rec_join(p_r->get_join_child(p_l, this), p_l, + 0, r_bag); + + p_r->replace_child(p_new_child, pref_begin(p_new_child), + pref_end(p_new_child), this); + + PB_DS_ASSERT_NODE_VALID(p_r) + _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_r) == lhs_leafs + rhs_leafs); + return p_r; + } + + node_pointer p_ret = insert_branch(p_l, p_r, r_bag); + PB_DS_ASSERT_NODE_VALID(p_ret) + _GLIBCXX_DEBUG_ASSERT(PB_DS_RECURSIVE_COUNT_LEAFS(p_ret) == lhs_leafs + rhs_leafs); + return p_ret; +} + +PB_DS_CLASS_T_DEC +inline std::pair<typename PB_DS_CLASS_C_DEC::iterator, bool> +PB_DS_CLASS_C_DEC:: +insert(const_reference r_val) +{ + node_pointer p_lf = find_imp(PB_DS_V2F(r_val)); + if (p_lf != 0 && p_lf->m_type == leaf_node && + synth_access_traits::equal_keys(PB_DS_V2F(static_cast<leaf_pointer>(p_lf)->value()), PB_DS_V2F(r_val))) + { + PB_DS_CHECK_KEY_EXISTS(PB_DS_V2F(r_val)) + PB_DS_ASSERT_VALID((*this)) + return std::make_pair(iterator(p_lf), false); + } + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(PB_DS_V2F(r_val)) + + leaf_pointer p_new_lf = s_leaf_allocator.allocate(1); + cond_dealtor cond(p_new_lf); + + new (p_new_lf) leaf(r_val); + apply_update(p_new_lf, (node_update*)this); + cond.set_call_destructor(); + branch_bag bag; + bag.add_branch(); + m_p_head->m_p_parent = rec_join(m_p_head->m_p_parent, p_new_lf, 0, bag); + m_p_head->m_p_parent->m_p_parent = m_p_head; + cond.set_no_action_dtor(); + ++m_size; + update_min_max_for_inserted_leaf(p_new_lf); + _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_val));) + PB_DS_ASSERT_VALID((*this)) + return std::make_pair(point_iterator(p_new_lf), true); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +keys_diff_ind(typename access_traits::const_iterator b_l, + typename access_traits::const_iterator e_l, + typename access_traits::const_iterator b_r, + typename access_traits::const_iterator e_r) +{ + size_type diff_pos = 0; + while (b_l != e_l) + { + if (b_r == e_r) + return (diff_pos); + if (access_traits::e_pos(*b_l) != access_traits::e_pos(*b_r)) + return (diff_pos); + ++b_l; + ++b_r; + ++diff_pos; + } + _GLIBCXX_DEBUG_ASSERT(b_r != e_r); + return diff_pos; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::inode_pointer +PB_DS_CLASS_C_DEC:: +insert_branch(node_pointer p_l, node_pointer p_r, branch_bag& r_bag) +{ + typename synth_access_traits::const_iterator left_b_it = pref_begin(p_l); + typename synth_access_traits::const_iterator left_e_it = pref_end(p_l); + typename synth_access_traits::const_iterator right_b_it = pref_begin(p_r); + typename synth_access_traits::const_iterator right_e_it = pref_end(p_r); + + const size_type diff_ind = keys_diff_ind(left_b_it, left_e_it, + right_b_it, right_e_it); + + inode_pointer p_new_nd = r_bag.get_branch(); + new (p_new_nd) inode(diff_ind, left_b_it); + p_new_nd->add_child(p_l, left_b_it, left_e_it, this); + p_new_nd->add_child(p_r, right_b_it, right_e_it, this); + p_l->m_p_parent = p_new_nd; + p_r->m_p_parent = p_new_nd; + PB_DS_ASSERT_NODE_VALID(p_new_nd) + return (p_new_nd); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +update_min_max_for_inserted_leaf(leaf_pointer p_new_lf) +{ + if (m_p_head->m_p_min == m_p_head || + synth_access_traits::cmp_keys(PB_DS_V2F(p_new_lf->value()), + PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_min)->value()))) + m_p_head->m_p_min = p_new_lf; + + if (m_p_head->m_p_max == m_p_head || + synth_access_traits::cmp_keys(PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_max)->value()), PB_DS_V2F(p_new_lf->value()))) + m_p_head->m_p_max = p_new_lf; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/iterators_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/iterators_fn_imps.hpp new file mode 100644 index 0000000..97de417 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/iterators_fn_imps.hpp @@ -0,0 +1,120 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/iterators_fn_imps.hpp + * Contains an implementation class for pat_trie. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +begin() +{ return iterator(m_p_head->m_p_min); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin() const +{ return const_iterator(m_p_head->m_p_min); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +end() +{ return iterator(m_p_head); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end() const +{ return const_iterator(m_p_head); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reverse_iterator +PB_DS_CLASS_C_DEC:: +rbegin() const +{ + if (empty()) + return rend(); + return --end(); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::reverse_iterator +PB_DS_CLASS_C_DEC:: +rbegin() +{ + if (empty()) + return rend(); + return --end(); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::reverse_iterator +PB_DS_CLASS_C_DEC:: +rend() +{ return reverse_iterator(m_p_head); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reverse_iterator +PB_DS_CLASS_C_DEC:: +rend() const +{ return const_reverse_iterator(m_p_head); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_const_iterator +PB_DS_CLASS_C_DEC:: +node_begin() const +{ return node_const_iterator(m_p_head->m_p_parent, this); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_iterator +PB_DS_CLASS_C_DEC:: +node_begin() +{ return node_iterator(m_p_head->m_p_parent, this); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_const_iterator +PB_DS_CLASS_C_DEC:: +node_end() const +{ return node_const_iterator(0, this); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_iterator +PB_DS_CLASS_C_DEC:: +node_end() +{ return node_iterator(0, this); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp new file mode 100644 index 0000000..7a498bf --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp @@ -0,0 +1,596 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/pat_trie_.hpp + * Contains an implementation class for a patricia tree. + */ + +#include <iterator> +#include <utility> +#include <algorithm> +#include <functional> +#include <assert.h> +#include <list> +#include <ext/pb_ds/exception.hpp> +#include <ext/pb_ds/tag_and_trait.hpp> +#include <ext/pb_ds/tree_policy.hpp> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/types_traits.hpp> +#include <ext/pb_ds/detail/eq_fn/eq_by_less.hpp> +#include <ext/pb_ds/detail/pat_trie_/synth_access_traits.hpp> +#include <ext/pb_ds/detail/pat_trie_/pat_trie_base.hpp> +#ifdef _GLIBCXX_DEBUG +#include <ext/pb_ds/detail/debug_map_base.hpp> +#endif +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#ifdef PB_DS_DATA_TRUE_INDICATOR +#define PB_DS_PAT_TRIE_NAME pat_trie_map +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR +#define PB_DS_PAT_TRIE_NAME pat_trie_set +#endif + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Mapped, typename Node_And_It_Traits, \ + typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + PB_DS_PAT_TRIE_NAME<Key, Mapped, Node_And_It_Traits, _Alloc> + +#define PB_DS_PAT_TRIE_TRAITS_BASE \ + types_traits<Key, Mapped, _Alloc, false> + +#ifdef _GLIBCXX_DEBUG +#define PB_DS_DEBUG_MAP_BASE_C_DEC \ + debug_map_base<Key, eq_by_less<Key, std::less<Key> >, \ + typename _Alloc::template rebind<Key>::other::const_reference> +#endif + + + /** + * @brief PATRICIA trie. + * @ingroup branch-detail + * + * This implementation loosely borrows ideas from: + * 1) Fast Mergeable Integer Maps, Okasaki, Gill 1998 + * 2) Ptset: Sets of integers implemented as Patricia trees, + * Jean-Christophe Filliatr, 2000 + */ + template<typename Key, typename Mapped, typename Node_And_It_Traits, + typename _Alloc> + class PB_DS_PAT_TRIE_NAME : +#ifdef _GLIBCXX_DEBUG + public PB_DS_DEBUG_MAP_BASE_C_DEC, +#endif + public Node_And_It_Traits::synth_access_traits, + public Node_And_It_Traits::node_update, + public PB_DS_PAT_TRIE_TRAITS_BASE, + public pat_trie_base + { + private: + typedef pat_trie_base base_type; + typedef PB_DS_PAT_TRIE_TRAITS_BASE traits_base; + typedef Node_And_It_Traits traits_type; + + typedef typename traits_type::synth_access_traits synth_access_traits; + typedef typename synth_access_traits::const_iterator a_const_iterator; + + typedef typename traits_type::node node; + typedef typename _Alloc::template rebind<node> __rebind_n; + typedef typename __rebind_n::other::const_pointer node_const_pointer; + typedef typename __rebind_n::other::pointer node_pointer; + + typedef typename traits_type::head head; + typedef typename _Alloc::template rebind<head> __rebind_h; + typedef typename __rebind_h::other head_allocator; + typedef typename head_allocator::pointer head_pointer; + + typedef typename traits_type::leaf leaf; + typedef typename _Alloc::template rebind<leaf> __rebind_l; + typedef typename __rebind_l::other leaf_allocator; + typedef typename leaf_allocator::pointer leaf_pointer; + typedef typename leaf_allocator::const_pointer leaf_const_pointer; + + typedef typename traits_type::inode inode; + typedef typename inode::iterator inode_iterator; + typedef typename _Alloc::template rebind<inode> __rebind_in; + typedef typename __rebind_in::other __rebind_ina; + typedef typename __rebind_in::other inode_allocator; + typedef typename __rebind_ina::pointer inode_pointer; + typedef typename __rebind_ina::const_pointer inode_const_pointer; + + + /// Conditional deallocator. + class cond_dealtor + { + protected: + leaf_pointer m_p_nd; + bool m_no_action_dtor; + bool m_call_destructor; + + public: + cond_dealtor(leaf_pointer p_nd) + : m_p_nd(p_nd), m_no_action_dtor(false), m_call_destructor(false) + { } + + void + set_no_action_dtor() + { m_no_action_dtor = true; } + + void + set_call_destructor() + { m_call_destructor = true; } + + ~cond_dealtor() + { + if (m_no_action_dtor) + return; + + if (m_call_destructor) + m_p_nd->~leaf(); + + s_leaf_allocator.deallocate(m_p_nd, 1); + } + }; + + + /// Branch bag, for split-join. + class branch_bag + { + private: + typedef inode_pointer __inp; + typedef typename _Alloc::template rebind<__inp>::other __rebind_inp; + +#ifdef _GLIBCXX_DEBUG + typedef std::_GLIBCXX_STD_C::list<__inp, __rebind_inp> bag_type; +#else + typedef std::list<__inp, __rebind_inp> bag_type; +#endif + + bag_type m_bag; + public: + void + add_branch() + { + inode_pointer p_nd = s_inode_allocator.allocate(1); + __try + { + m_bag.push_back(p_nd); + } + __catch(...) + { + s_inode_allocator.deallocate(p_nd, 1); + __throw_exception_again; + } + } + + inode_pointer + get_branch() + { + _GLIBCXX_DEBUG_ASSERT(!m_bag.empty()); + inode_pointer p_nd = *m_bag.begin(); + m_bag.pop_front(); + return p_nd; + } + + ~branch_bag() + { + while (!m_bag.empty()) + { + inode_pointer p_nd = *m_bag.begin(); + s_inode_allocator.deallocate(p_nd, 1); + m_bag.pop_front(); + } + } + + inline bool + empty() const + { return m_bag.empty(); } + }; + +#ifdef _GLIBCXX_DEBUG + typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base; +#endif + + typedef typename traits_type::null_node_update_pointer null_node_update_pointer; + + public: + typedef pat_trie_tag container_category; + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + + typedef typename traits_base::key_type key_type; + typedef typename traits_base::key_pointer key_pointer; + typedef typename traits_base::key_const_pointer key_const_pointer; + typedef typename traits_base::key_reference key_reference; + typedef typename traits_base::key_const_reference key_const_reference; + typedef typename traits_base::mapped_type mapped_type; + typedef typename traits_base::mapped_pointer mapped_pointer; + typedef typename traits_base::mapped_const_pointer mapped_const_pointer; + typedef typename traits_base::mapped_reference mapped_reference; + typedef typename traits_base::mapped_const_reference mapped_const_reference; + typedef typename traits_base::value_type value_type; + typedef typename traits_base::pointer pointer; + typedef typename traits_base::const_pointer const_pointer; + typedef typename traits_base::reference reference; + typedef typename traits_base::const_reference const_reference; + + typedef typename traits_type::access_traits access_traits; + typedef typename traits_type::const_iterator point_const_iterator; + typedef typename traits_type::iterator point_iterator; + typedef point_const_iterator const_iterator; + typedef point_iterator iterator; + + typedef typename traits_type::reverse_iterator reverse_iterator; + typedef typename traits_type::const_reverse_iterator const_reverse_iterator; + typedef typename traits_type::node_const_iterator node_const_iterator; + typedef typename traits_type::node_iterator node_iterator; + typedef typename traits_type::node_update node_update; + + PB_DS_PAT_TRIE_NAME(); + + PB_DS_PAT_TRIE_NAME(const access_traits&); + + PB_DS_PAT_TRIE_NAME(const PB_DS_CLASS_C_DEC&); + + void + swap(PB_DS_CLASS_C_DEC&); + + ~PB_DS_PAT_TRIE_NAME(); + + inline bool + empty() const; + + inline size_type + size() const; + + inline size_type + max_size() const; + + access_traits& + get_access_traits(); + + const access_traits& + get_access_traits() const; + + node_update& + get_node_update(); + + const node_update& + get_node_update() const; + + inline std::pair<point_iterator, bool> + insert(const_reference); + + inline mapped_reference + operator[](key_const_reference r_key) + { +#ifdef PB_DS_DATA_TRUE_INDICATOR + return insert(std::make_pair(r_key, mapped_type())).first->second; +#else + insert(r_key); + return traits_base::s_null_type; +#endif + } + + inline point_iterator + find(key_const_reference); + + inline point_const_iterator + find(key_const_reference) const; + + inline point_iterator + lower_bound(key_const_reference); + + inline point_const_iterator + lower_bound(key_const_reference) const; + + inline point_iterator + upper_bound(key_const_reference); + + inline point_const_iterator + upper_bound(key_const_reference) const; + + void + clear(); + + inline bool + erase(key_const_reference); + + inline const_iterator + erase(const_iterator); + +#ifdef PB_DS_DATA_TRUE_INDICATOR + inline iterator + erase(iterator); +#endif + + inline const_reverse_iterator + erase(const_reverse_iterator); + +#ifdef PB_DS_DATA_TRUE_INDICATOR + inline reverse_iterator + erase(reverse_iterator); +#endif + + template<typename Pred> + inline size_type + erase_if(Pred); + + void + join(PB_DS_CLASS_C_DEC&); + + void + split(key_const_reference, PB_DS_CLASS_C_DEC&); + + inline iterator + begin(); + + inline const_iterator + begin() const; + + inline iterator + end(); + + inline const_iterator + end() const; + + inline reverse_iterator + rbegin(); + + inline const_reverse_iterator + rbegin() const; + + inline reverse_iterator + rend(); + + inline const_reverse_iterator + rend() const; + + /// Returns a const node_iterator corresponding to the node at the + /// root of the tree. + inline node_const_iterator + node_begin() const; + + /// Returns a node_iterator corresponding to the node at the + /// root of the tree. + inline node_iterator + node_begin(); + + /// Returns a const node_iterator corresponding to a node just + /// after a leaf of the tree. + inline node_const_iterator + node_end() const; + + /// Returns a node_iterator corresponding to a node just + /// after a leaf of the tree. + inline node_iterator + node_end(); + +#ifdef PB_DS_PAT_TRIE_TRACE_ + void + trace() const; +#endif + + protected: + template<typename It> + void + copy_from_range(It, It); + + void + value_swap(PB_DS_CLASS_C_DEC&); + + node_pointer + recursive_copy_node(node_const_pointer); + + private: + void + initialize(); + + inline void + apply_update(node_pointer, null_node_update_pointer); + + template<typename Node_Update_> + inline void + apply_update(node_pointer, Node_Update_*); + + bool + join_prep(PB_DS_CLASS_C_DEC&, branch_bag&); + + void + rec_join_prep(node_const_pointer, node_const_pointer, branch_bag&); + + void + rec_join_prep(leaf_const_pointer, leaf_const_pointer, branch_bag&); + + void + rec_join_prep(leaf_const_pointer, inode_const_pointer, branch_bag&); + + void + rec_join_prep(inode_const_pointer, leaf_const_pointer, branch_bag&); + + void + rec_join_prep(inode_const_pointer, inode_const_pointer, branch_bag&); + + node_pointer + rec_join(node_pointer, node_pointer, size_type, branch_bag&); + + node_pointer + rec_join(leaf_pointer, leaf_pointer, branch_bag&); + + node_pointer + rec_join(leaf_pointer, inode_pointer, size_type, branch_bag&); + + node_pointer + rec_join(inode_pointer, leaf_pointer, size_type, branch_bag&); + + node_pointer + rec_join(inode_pointer, inode_pointer, branch_bag&); + + size_type + keys_diff_ind(typename access_traits::const_iterator, + typename access_traits::const_iterator, + typename access_traits::const_iterator, + typename access_traits::const_iterator); + + inode_pointer + insert_branch(node_pointer, node_pointer, branch_bag&); + + void + update_min_max_for_inserted_leaf(leaf_pointer); + + void + erase_leaf(leaf_pointer); + + inline void + actual_erase_leaf(leaf_pointer); + + void + clear_imp(node_pointer); + + void + erase_fixup(inode_pointer); + + void + update_min_max_for_erased_leaf(leaf_pointer); + + static inline a_const_iterator + pref_begin(node_const_pointer); + + static inline a_const_iterator + pref_end(node_const_pointer); + + inline node_pointer + find_imp(key_const_reference); + + inline node_pointer + lower_bound_imp(key_const_reference); + + inline node_pointer + upper_bound_imp(key_const_reference); + + inline static leaf_const_pointer + leftmost_descendant(node_const_pointer); + + inline static leaf_pointer + leftmost_descendant(node_pointer); + + inline static leaf_const_pointer + rightmost_descendant(node_const_pointer); + + inline static leaf_pointer + rightmost_descendant(node_pointer); + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; + + void + assert_iterators(const char*, int) const; + + void + assert_reverse_iterators(const char*, int) const; + + static size_type + recursive_count_leafs(node_const_pointer, const char*, int); +#endif + +#ifdef PB_DS_PAT_TRIE_TRACE_ + static void + trace_node(node_const_pointer, size_type); + + template<typename Metadata_> + static void + trace_node_metadata(node_const_pointer, type_to_type<Metadata_>); + + static void + trace_node_metadata(node_const_pointer, type_to_type<null_type>); +#endif + + leaf_pointer + split_prep(key_const_reference, PB_DS_CLASS_C_DEC&, branch_bag&); + + node_pointer + rec_split(node_pointer, a_const_iterator, a_const_iterator, + PB_DS_CLASS_C_DEC&, branch_bag&); + + void + split_insert_branch(size_type, a_const_iterator, inode_iterator, + size_type, branch_bag&); + + static head_allocator s_head_allocator; + static inode_allocator s_inode_allocator; + static leaf_allocator s_leaf_allocator; + + head_pointer m_p_head; + size_type m_size; + }; + +#define PB_DS_ASSERT_NODE_VALID(X) \ + _GLIBCXX_DEBUG_ONLY(X->assert_valid(this, __FILE__, __LINE__);) + +#define PB_DS_RECURSIVE_COUNT_LEAFS(X) \ + recursive_count_leafs(X, __FILE__, __LINE__) + +#include <ext/pb_ds/detail/pat_trie_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/pat_trie_/iterators_fn_imps.hpp> +#include <ext/pb_ds/detail/pat_trie_/insert_join_fn_imps.hpp> +#include <ext/pb_ds/detail/pat_trie_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/pat_trie_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/pat_trie_/info_fn_imps.hpp> +#include <ext/pb_ds/detail/pat_trie_/policy_access_fn_imps.hpp> +#include <ext/pb_ds/detail/pat_trie_/split_fn_imps.hpp> +#include <ext/pb_ds/detail/pat_trie_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/pat_trie_/trace_fn_imps.hpp> +#include <ext/pb_ds/detail/pat_trie_/update_fn_imps.hpp> + +#undef PB_DS_RECURSIVE_COUNT_LEAFS +#undef PB_DS_ASSERT_NODE_VALID +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_PAT_TRIE_NAME +#undef PB_DS_PAT_TRIE_TRAITS_BASE +#undef PB_DS_DEBUG_MAP_BASE_C_DEC + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/pat_trie_base.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/pat_trie_base.hpp new file mode 100644 index 0000000..c14b1bc --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/pat_trie_base.hpp @@ -0,0 +1,1361 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/pat_trie_base.hpp + * Contains the base class for a patricia tree. + */ + +#ifndef PB_DS_PAT_TRIE_BASE +#define PB_DS_PAT_TRIE_BASE + +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { + /// Base type for PATRICIA trees. + struct pat_trie_base + { + /** + * @brief Three types of nodes. + * + * i_node is used by _Inode, leaf_node by _Leaf, and head_node by _Head. + */ + enum node_type + { + i_node, + leaf_node, + head_node + }; + + /// Metadata base primary template. + template<typename Metadata, typename _Alloc> + struct _Metadata + { + typedef Metadata metadata_type; + typedef _Alloc allocator_type; + typedef typename _Alloc::template rebind<Metadata> __rebind_m; + typedef typename __rebind_m::other::const_reference const_reference; + + const_reference + get_metadata() const + { return m_metadata; } + + metadata_type m_metadata; + }; + + /// Specialization for null metadata. + template<typename _Alloc> + struct _Metadata<null_type, _Alloc> + { + typedef null_type metadata_type; + typedef _Alloc allocator_type; + }; + + + /// Node base. + template<typename _ATraits, typename Metadata> + struct _Node_base + : public Metadata + { + private: + typedef typename Metadata::allocator_type _Alloc; + + public: + typedef _Alloc allocator_type; + typedef _ATraits access_traits; + typedef typename _ATraits::type_traits type_traits; + typedef typename _Alloc::template rebind<_Node_base> __rebind_n; + typedef typename __rebind_n::other::pointer node_pointer; + + node_pointer m_p_parent; + const node_type m_type; + + _Node_base(node_type type) : m_type(type) + { } + + typedef typename _Alloc::template rebind<_ATraits> __rebind_at; + typedef typename __rebind_at::other::const_pointer a_const_pointer; + typedef typename _ATraits::const_iterator a_const_iterator; + +#ifdef _GLIBCXX_DEBUG + typedef std::pair<a_const_iterator, a_const_iterator> node_debug_info; + + void + assert_valid(a_const_pointer p_traits, + const char* __file, int __line) const + { assert_valid_imp(p_traits, __file, __line); } + + virtual node_debug_info + assert_valid_imp(a_const_pointer, const char*, int) const = 0; +#endif + }; + + + /// Head node for PATRICIA tree. + template<typename _ATraits, typename Metadata> + struct _Head + : public _Node_base<_ATraits, Metadata> + { + typedef _Node_base<_ATraits, Metadata> base_type; + typedef typename base_type::type_traits type_traits; + typedef typename base_type::node_pointer node_pointer; + + node_pointer m_p_min; + node_pointer m_p_max; + + _Head() : base_type(head_node) { } + +#ifdef _GLIBCXX_DEBUG + typedef typename base_type::node_debug_info node_debug_info; + typedef typename base_type::a_const_pointer a_const_pointer; + + virtual node_debug_info + assert_valid_imp(a_const_pointer, const char* __file, int __line) const + { + _GLIBCXX_DEBUG_VERIFY_AT(false, + _M_message("Assertion from %1;:%2;") + ._M_string(__FILE__)._M_integer(__LINE__), + __file, __line); + return node_debug_info(); + } +#endif + }; + + + /// Leaf node for PATRICIA tree. + template<typename _ATraits, typename Metadata> + struct _Leaf + : public _Node_base<_ATraits, Metadata> + { + typedef _Node_base<_ATraits, Metadata> base_type; + typedef typename base_type::type_traits type_traits; + typedef typename type_traits::value_type value_type; + typedef typename type_traits::reference reference; + typedef typename type_traits::const_reference const_reference; + + private: + value_type m_value; + + _Leaf(const _Leaf&); + + public: + _Leaf(const_reference other) + : base_type(leaf_node), m_value(other) { } + + reference + value() + { return m_value; } + + const_reference + value() const + { return m_value; } + +#ifdef _GLIBCXX_DEBUG + typedef typename base_type::node_debug_info node_debug_info; + typedef typename base_type::a_const_pointer a_const_pointer; + + virtual node_debug_info + assert_valid_imp(a_const_pointer p_traits, + const char* __file, int __line) const + { + PB_DS_DEBUG_VERIFY(base_type::m_type == leaf_node); + node_debug_info ret; + const_reference r_val = value(); + return std::make_pair(p_traits->begin(p_traits->extract_key(r_val)), + p_traits->end(p_traits->extract_key(r_val))); + } + + virtual + ~_Leaf() { } +#endif + }; + + + /// Internal node type, PATRICIA tree. + template<typename _ATraits, typename Metadata> + struct _Inode + : public _Node_base<_ATraits, Metadata> + { + typedef _Node_base<_ATraits, Metadata> base_type; + typedef typename base_type::type_traits type_traits; + typedef typename base_type::access_traits access_traits; + typedef typename type_traits::value_type value_type; + typedef typename base_type::allocator_type _Alloc; + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + + private: + typedef typename base_type::a_const_pointer a_const_pointer; + typedef typename base_type::a_const_iterator a_const_iterator; + + typedef typename base_type::node_pointer node_pointer; + typedef typename _Alloc::template rebind<base_type> __rebind_n; + typedef typename __rebind_n::other::const_pointer node_const_pointer; + + typedef _Leaf<_ATraits, Metadata> leaf; + typedef typename _Alloc::template rebind<leaf>::other __rebind_l; + typedef typename __rebind_l::pointer leaf_pointer; + typedef typename __rebind_l::const_pointer leaf_const_pointer; + + typedef typename _Alloc::template rebind<_Inode>::other __rebind_in; + typedef typename __rebind_in::pointer inode_pointer; + typedef typename __rebind_in::const_pointer inode_const_pointer; + + inline size_type + get_pref_pos(a_const_iterator, a_const_iterator, a_const_pointer) const; + + public: + typedef typename _Alloc::template rebind<node_pointer>::other __rebind_np; + typedef typename __rebind_np::pointer node_pointer_pointer; + typedef typename __rebind_np::reference node_pointer_reference; + + enum + { + arr_size = _ATraits::max_size + 1 + }; + PB_DS_STATIC_ASSERT(min_arr_size, arr_size >= 2); + + + /// Constant child iterator. + struct const_iterator + { + node_pointer_pointer m_p_p_cur; + node_pointer_pointer m_p_p_end; + + typedef std::forward_iterator_tag iterator_category; + typedef typename _Alloc::difference_type difference_type; + typedef node_pointer value_type; + typedef node_pointer_pointer pointer; + typedef node_pointer_reference reference; + + const_iterator(node_pointer_pointer p_p_cur = 0, + node_pointer_pointer p_p_end = 0) + : m_p_p_cur(p_p_cur), m_p_p_end(p_p_end) + { } + + bool + operator==(const const_iterator& other) const + { return m_p_p_cur == other.m_p_p_cur; } + + bool + operator!=(const const_iterator& other) const + { return m_p_p_cur != other.m_p_p_cur; } + + const_iterator& + operator++() + { + do + ++m_p_p_cur; + while (m_p_p_cur != m_p_p_end && *m_p_p_cur == 0); + return *this; + } + + const_iterator + operator++(int) + { + const_iterator ret_it(*this); + operator++(); + return ret_it; + } + + const node_pointer_pointer + operator->() const + { + _GLIBCXX_DEBUG_ONLY(assert_referencible();) + return m_p_p_cur; + } + + node_const_pointer + operator*() const + { + _GLIBCXX_DEBUG_ONLY(assert_referencible();) + return *m_p_p_cur; + } + + protected: +#ifdef _GLIBCXX_DEBUG + void + assert_referencible() const + { _GLIBCXX_DEBUG_ASSERT(m_p_p_cur != m_p_p_end && *m_p_p_cur != 0); } +#endif + }; + + + /// Child iterator. + struct iterator : public const_iterator + { + public: + typedef std::forward_iterator_tag iterator_category; + typedef typename _Alloc::difference_type difference_type; + typedef node_pointer value_type; + typedef node_pointer_pointer pointer; + typedef node_pointer_reference reference; + + inline + iterator(node_pointer_pointer p_p_cur = 0, + node_pointer_pointer p_p_end = 0) + : const_iterator(p_p_cur, p_p_end) { } + + bool + operator==(const iterator& other) const + { return const_iterator::m_p_p_cur == other.m_p_p_cur; } + + bool + operator!=(const iterator& other) const + { return const_iterator::m_p_p_cur != other.m_p_p_cur; } + + iterator& + operator++() + { + const_iterator::operator++(); + return *this; + } + + iterator + operator++(int) + { + iterator ret_it(*this); + operator++(); + return ret_it; + } + + node_pointer_pointer + operator->() + { + _GLIBCXX_DEBUG_ONLY(const_iterator::assert_referencible();) + return const_iterator::m_p_p_cur; + } + + node_pointer + operator*() + { + _GLIBCXX_DEBUG_ONLY(const_iterator::assert_referencible();) + return *const_iterator::m_p_p_cur; + } + }; + + + _Inode(size_type, const a_const_iterator); + + void + update_prefixes(a_const_pointer); + + const_iterator + begin() const; + + iterator + begin(); + + const_iterator + end() const; + + iterator + end(); + + inline node_pointer + get_child_node(a_const_iterator, a_const_iterator, a_const_pointer); + + inline node_const_pointer + get_child_node(a_const_iterator, a_const_iterator, a_const_pointer) const; + + inline iterator + get_child_it(a_const_iterator, a_const_iterator, a_const_pointer); + + inline node_pointer + get_lower_bound_child_node(a_const_iterator, a_const_iterator, + size_type, a_const_pointer); + + inline node_pointer + add_child(node_pointer, a_const_iterator, a_const_iterator, + a_const_pointer); + + inline node_const_pointer + get_join_child(node_const_pointer, a_const_pointer) const; + + inline node_pointer + get_join_child(node_pointer, a_const_pointer); + + void + remove_child(node_pointer); + + void + remove_child(iterator); + + void + replace_child(node_pointer, a_const_iterator, a_const_iterator, + a_const_pointer); + + inline a_const_iterator + pref_b_it() const; + + inline a_const_iterator + pref_e_it() const; + + bool + should_be_mine(a_const_iterator, a_const_iterator, size_type, + a_const_pointer) const; + + leaf_pointer + leftmost_descendant(); + + leaf_const_pointer + leftmost_descendant() const; + + leaf_pointer + rightmost_descendant(); + + leaf_const_pointer + rightmost_descendant() const; + +#ifdef _GLIBCXX_DEBUG + typedef typename base_type::node_debug_info node_debug_info; + + virtual node_debug_info + assert_valid_imp(a_const_pointer, const char*, int) const; +#endif + + size_type + get_e_ind() const + { return m_e_ind; } + + private: + _Inode(const _Inode&); + + size_type + get_begin_pos() const; + + static __rebind_l s_leaf_alloc; + static __rebind_in s_inode_alloc; + + const size_type m_e_ind; + a_const_iterator m_pref_b_it; + a_const_iterator m_pref_e_it; + node_pointer m_a_p_children[arr_size]; + }; + +#define PB_DS_CONST_IT_C_DEC \ + _CIter<Node, Leaf, Head, Inode, Is_Forward_Iterator> + +#define PB_DS_CONST_ODIR_IT_C_DEC \ + _CIter<Node, Leaf, Head, Inode, !Is_Forward_Iterator> + +#define PB_DS_IT_C_DEC \ + _Iter<Node, Leaf, Head, Inode, Is_Forward_Iterator> + +#define PB_DS_ODIR_IT_C_DEC \ + _Iter<Node, Leaf, Head, Inode, !Is_Forward_Iterator> + + + /// Const iterator. + template<typename Node, typename Leaf, typename Head, typename Inode, + bool Is_Forward_Iterator> + class _CIter + { + public: + // These types are all the same for the first four template arguments. + typedef typename Node::allocator_type allocator_type; + typedef typename Node::type_traits type_traits; + + typedef std::bidirectional_iterator_tag iterator_category; + typedef typename allocator_type::difference_type difference_type; + typedef typename type_traits::value_type value_type; + typedef typename type_traits::pointer pointer; + typedef typename type_traits::reference reference; + typedef typename type_traits::const_pointer const_pointer; + typedef typename type_traits::const_reference const_reference; + + typedef allocator_type _Alloc; + typedef typename _Alloc::template rebind<Node> __rebind_n; + typedef typename __rebind_n::other::pointer node_pointer; + typedef typename _Alloc::template rebind<Leaf> __rebind_l; + typedef typename __rebind_l::other::pointer leaf_pointer; + typedef typename __rebind_l::other::const_pointer leaf_const_pointer; + typedef typename _Alloc::template rebind<Head> __rebind_h; + typedef typename __rebind_h::other::pointer head_pointer; + + typedef typename _Alloc::template rebind<Inode> __rebind_in; + typedef typename __rebind_in::other::pointer inode_pointer; + typedef typename Inode::iterator inode_iterator; + + node_pointer m_p_nd; + + _CIter(node_pointer p_nd = 0) : m_p_nd(p_nd) + { } + + _CIter(const PB_DS_CONST_ODIR_IT_C_DEC& other) + : m_p_nd(other.m_p_nd) + { } + + _CIter& + operator=(const _CIter& other) + { + m_p_nd = other.m_p_nd; + return *this; + } + + _CIter& + operator=(const PB_DS_CONST_ODIR_IT_C_DEC& other) + { + m_p_nd = other.m_p_nd; + return *this; + } + + const_pointer + operator->() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_nd->m_type == leaf_node); + return &static_cast<leaf_pointer>(m_p_nd)->value(); + } + + const_reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_nd->m_type == leaf_node); + return static_cast<leaf_pointer>(m_p_nd)->value(); + } + + bool + operator==(const _CIter& other) const + { return m_p_nd == other.m_p_nd; } + + bool + operator==(const PB_DS_CONST_ODIR_IT_C_DEC& other) const + { return m_p_nd == other.m_p_nd; } + + bool + operator!=(const _CIter& other) const + { return m_p_nd != other.m_p_nd; } + + bool + operator!=(const PB_DS_CONST_ODIR_IT_C_DEC& other) const + { return m_p_nd != other.m_p_nd; } + + _CIter& + operator++() + { + inc(integral_constant<int, Is_Forward_Iterator>()); + return *this; + } + + _CIter + operator++(int) + { + _CIter ret_it(m_p_nd); + operator++(); + return ret_it; + } + + _CIter& + operator--() + { + dec(integral_constant<int, Is_Forward_Iterator>()); + return *this; + } + + _CIter + operator--(int) + { + _CIter ret_it(m_p_nd); + operator--(); + return ret_it; + } + + protected: + void + inc(false_type) + { dec(true_type()); } + + void + inc(true_type) + { + if (m_p_nd->m_type == head_node) + { + m_p_nd = static_cast<head_pointer>(m_p_nd)->m_p_min; + return; + } + + node_pointer p_y = m_p_nd->m_p_parent; + while (p_y->m_type != head_node && get_larger_sibling(m_p_nd) == 0) + { + m_p_nd = p_y; + p_y = p_y->m_p_parent; + } + + if (p_y->m_type == head_node) + { + m_p_nd = p_y; + return; + } + m_p_nd = leftmost_descendant(get_larger_sibling(m_p_nd)); + } + + void + dec(false_type) + { inc(true_type()); } + + void + dec(true_type) + { + if (m_p_nd->m_type == head_node) + { + m_p_nd = static_cast<head_pointer>(m_p_nd)->m_p_max; + return; + } + + node_pointer p_y = m_p_nd->m_p_parent; + while (p_y->m_type != head_node && get_smaller_sibling(m_p_nd) == 0) + { + m_p_nd = p_y; + p_y = p_y->m_p_parent; + } + + if (p_y->m_type == head_node) + { + m_p_nd = p_y; + return; + } + m_p_nd = rightmost_descendant(get_smaller_sibling(m_p_nd)); + } + + static node_pointer + get_larger_sibling(node_pointer p_nd) + { + inode_pointer p_parent = static_cast<inode_pointer>(p_nd->m_p_parent); + + inode_iterator it = p_parent->begin(); + while (*it != p_nd) + ++it; + + inode_iterator next_it = it; + ++next_it; + return (next_it == p_parent->end())? 0 : *next_it; + } + + static node_pointer + get_smaller_sibling(node_pointer p_nd) + { + inode_pointer p_parent = static_cast<inode_pointer>(p_nd->m_p_parent); + + inode_iterator it = p_parent->begin(); + if (*it == p_nd) + return 0; + + inode_iterator prev_it; + do + { + prev_it = it; + ++it; + if (*it == p_nd) + return *prev_it; + } + while (true); + + _GLIBCXX_DEBUG_ASSERT(false); + return 0; + } + + static leaf_pointer + leftmost_descendant(node_pointer p_nd) + { + if (p_nd->m_type == leaf_node) + return static_cast<leaf_pointer>(p_nd); + return static_cast<inode_pointer>(p_nd)->leftmost_descendant(); + } + + static leaf_pointer + rightmost_descendant(node_pointer p_nd) + { + if (p_nd->m_type == leaf_node) + return static_cast<leaf_pointer>(p_nd); + return static_cast<inode_pointer>(p_nd)->rightmost_descendant(); + } + }; + + + /// Iterator. + template<typename Node, typename Leaf, typename Head, typename Inode, + bool Is_Forward_Iterator> + class _Iter + : public _CIter<Node, Leaf, Head, Inode, Is_Forward_Iterator> + { + public: + typedef _CIter<Node, Leaf, Head, Inode, Is_Forward_Iterator> + base_type; + typedef typename base_type::allocator_type allocator_type; + typedef typename base_type::type_traits type_traits; + typedef typename type_traits::value_type value_type; + typedef typename type_traits::pointer pointer; + typedef typename type_traits::reference reference; + + typedef typename base_type::node_pointer node_pointer; + typedef typename base_type::leaf_pointer leaf_pointer; + typedef typename base_type::leaf_const_pointer leaf_const_pointer; + typedef typename base_type::head_pointer head_pointer; + typedef typename base_type::inode_pointer inode_pointer; + + _Iter(node_pointer p_nd = 0) + : base_type(p_nd) { } + + _Iter(const PB_DS_ODIR_IT_C_DEC& other) + : base_type(other.m_p_nd) { } + + _Iter& + operator=(const _Iter& other) + { + base_type::m_p_nd = other.m_p_nd; + return *this; + } + + _Iter& + operator=(const PB_DS_ODIR_IT_C_DEC& other) + { + base_type::m_p_nd = other.m_p_nd; + return *this; + } + + pointer + operator->() const + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_p_nd->m_type == leaf_node); + return &static_cast<leaf_pointer>(base_type::m_p_nd)->value(); + } + + reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_p_nd->m_type == leaf_node); + return static_cast<leaf_pointer>(base_type::m_p_nd)->value(); + } + + _Iter& + operator++() + { + base_type::operator++(); + return *this; + } + + _Iter + operator++(int) + { + _Iter ret(base_type::m_p_nd); + operator++(); + return ret; + } + + _Iter& + operator--() + { + base_type::operator--(); + return *this; + } + + _Iter + operator--(int) + { + _Iter ret(base_type::m_p_nd); + operator--(); + return ret; + } + }; + +#undef PB_DS_CONST_ODIR_IT_C_DEC +#undef PB_DS_ODIR_IT_C_DEC + + +#define PB_DS_PAT_TRIE_NODE_CONST_ITERATOR_C_DEC \ + _Node_citer<Node, Leaf, Head, Inode, _CIterator, Iterator, _ATraits, _Alloc> + +#define PB_DS_PAT_TRIE_NODE_ITERATOR_C_DEC \ + _Node_iter<Node, Leaf, Head, Inode, _CIterator, Iterator, _ATraits, _Alloc> + + /// Node const iterator. + template<typename Node, + typename Leaf, + typename Head, + typename Inode, + typename _CIterator, + typename Iterator, + typename _Alloc> + class _Node_citer + { + protected: + typedef typename _Alloc::template rebind<Node> __rebind_n; + typedef typename __rebind_n::other::pointer node_pointer; + + typedef typename _Alloc::template rebind<Leaf> __rebind_l; + typedef typename __rebind_l::other::pointer leaf_pointer; + typedef typename __rebind_l::other::const_pointer leaf_const_pointer; + + typedef typename _Alloc::template rebind<Inode> __rebind_in; + typedef typename __rebind_in::other::pointer inode_pointer; + typedef typename __rebind_in::other::const_pointer inode_const_pointer; + + typedef typename Node::a_const_pointer a_const_pointer; + typedef typename Node::a_const_iterator a_const_iterator; + + private: + a_const_iterator + pref_begin() const + { + if (m_p_nd->m_type == leaf_node) + { + leaf_const_pointer lcp = static_cast<leaf_const_pointer>(m_p_nd); + return m_p_traits->begin(m_p_traits->extract_key(lcp->value())); + } + _GLIBCXX_DEBUG_ASSERT(m_p_nd->m_type == i_node); + return static_cast<inode_const_pointer>(m_p_nd)->pref_b_it(); + } + + a_const_iterator + pref_end() const + { + if (m_p_nd->m_type == leaf_node) + { + leaf_const_pointer lcp = static_cast<leaf_const_pointer>(m_p_nd); + return m_p_traits->end(m_p_traits->extract_key(lcp->value())); + } + _GLIBCXX_DEBUG_ASSERT(m_p_nd->m_type == i_node); + return static_cast<inode_const_pointer>(m_p_nd)->pref_e_it(); + } + + public: + typedef trivial_iterator_tag iterator_category; + typedef trivial_iterator_difference_type difference_type; + typedef typename _Alloc::size_type size_type; + + typedef _CIterator value_type; + typedef value_type reference; + typedef value_type const_reference; + + /// Metadata type. + typedef typename Node::metadata_type metadata_type; + + /// Const metadata reference type. + typedef typename _Alloc::template rebind<metadata_type> __rebind_m; + typedef typename __rebind_m::other __rebind_ma; + typedef typename __rebind_ma::const_reference metadata_const_reference; + + inline + _Node_citer(node_pointer p_nd = 0, a_const_pointer p_traits = 0) + : m_p_nd(const_cast<node_pointer>(p_nd)), m_p_traits(p_traits) + { } + + /// Subtree valid prefix. + std::pair<a_const_iterator, a_const_iterator> + valid_prefix() const + { return std::make_pair(pref_begin(), pref_end()); } + + /// Const access; returns the __const iterator* associated with + /// the current leaf. + const_reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(num_children() == 0); + return _CIterator(m_p_nd); + } + + /// Metadata access. + metadata_const_reference + get_metadata() const + { return m_p_nd->get_metadata(); } + + /// Returns the number of children in the corresponding node. + size_type + num_children() const + { + if (m_p_nd->m_type == leaf_node) + return 0; + _GLIBCXX_DEBUG_ASSERT(m_p_nd->m_type == i_node); + inode_pointer inp = static_cast<inode_pointer>(m_p_nd); + return std::distance(inp->begin(), inp->end()); + } + + /// Returns a __const node __iterator to the corresponding node's + /// i-th child. + _Node_citer + get_child(size_type i) const + { + _GLIBCXX_DEBUG_ASSERT(m_p_nd->m_type == i_node); + inode_pointer inp = static_cast<inode_pointer>(m_p_nd); + typename Inode::iterator it = inp->begin(); + std::advance(it, i); + return _Node_citer(*it, m_p_traits); + } + + /// Compares content to a different iterator object. + bool + operator==(const _Node_citer& other) const + { return m_p_nd == other.m_p_nd; } + + /// Compares content (negatively) to a different iterator object. + bool + operator!=(const _Node_citer& other) const + { return m_p_nd != other.m_p_nd; } + + node_pointer m_p_nd; + a_const_pointer m_p_traits; + }; + + + /// Node iterator. + template<typename Node, + typename Leaf, + typename Head, + typename Inode, + typename _CIterator, + typename Iterator, + typename _Alloc> + class _Node_iter + : public _Node_citer<Node, Leaf, Head, Inode, _CIterator, Iterator, _Alloc> + { + private: + typedef _Node_citer<Node, Leaf, Head, Inode, + _CIterator, Iterator, _Alloc> base_type; + typedef typename _Alloc::template rebind<Node> __rebind_n; + typedef typename __rebind_n::other::pointer node_pointer; + typedef typename base_type::inode_pointer inode_pointer; + typedef typename base_type::a_const_pointer a_const_pointer; + typedef Iterator iterator; + + public: + typedef typename base_type::size_type size_type; + + typedef Iterator value_type; + typedef value_type reference; + typedef value_type const_reference; + + _Node_iter(node_pointer p_nd = 0, a_const_pointer p_traits = 0) + : base_type(p_nd, p_traits) + { } + + /// Access; returns the iterator* associated with the current leaf. + reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(base_type::num_children() == 0); + return iterator(base_type::m_p_nd); + } + + /// Returns a node __iterator to the corresponding node's i-th child. + _Node_iter + get_child(size_type i) const + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_p_nd->m_type == i_node); + + typename Inode::iterator it = + static_cast<inode_pointer>(base_type::m_p_nd)->begin(); + + std::advance(it, i); + return _Node_iter(*it, base_type::m_p_traits); + } + }; + }; + + +#define PB_DS_CLASS_T_DEC \ + template<typename _ATraits, typename Metadata> + +#define PB_DS_CLASS_C_DEC \ + pat_trie_base::_Inode<_ATraits, Metadata> + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::__rebind_l + PB_DS_CLASS_C_DEC::s_leaf_alloc; + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::__rebind_in + PB_DS_CLASS_C_DEC::s_inode_alloc; + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::size_type + PB_DS_CLASS_C_DEC:: + get_pref_pos(a_const_iterator b_it, a_const_iterator e_it, + a_const_pointer p_traits) const + { + if (static_cast<std::size_t>(std::distance(b_it, e_it)) <= m_e_ind) + return 0; + std::advance(b_it, m_e_ind); + return 1 + p_traits->e_pos(*b_it); + } + + PB_DS_CLASS_T_DEC + PB_DS_CLASS_C_DEC:: + _Inode(size_type len, const a_const_iterator it) + : base_type(i_node), m_e_ind(len), m_pref_b_it(it), m_pref_e_it(it) + { + std::advance(m_pref_e_it, m_e_ind); + std::fill(m_a_p_children, m_a_p_children + arr_size, + static_cast<node_pointer>(0)); + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + update_prefixes(a_const_pointer p_traits) + { + node_pointer p_first = *begin(); + if (p_first->m_type == leaf_node) + { + leaf_const_pointer p = static_cast<leaf_const_pointer>(p_first); + m_pref_b_it = p_traits->begin(access_traits::extract_key(p->value())); + } + else + { + inode_pointer p = static_cast<inode_pointer>(p_first); + _GLIBCXX_DEBUG_ASSERT(p_first->m_type == i_node); + m_pref_b_it = p->pref_b_it(); + } + m_pref_e_it = m_pref_b_it; + std::advance(m_pref_e_it, m_e_ind); + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::const_iterator + PB_DS_CLASS_C_DEC:: + begin() const + { + typedef node_pointer_pointer pointer_type; + pointer_type p = const_cast<pointer_type>(m_a_p_children); + return const_iterator(p + get_begin_pos(), p + arr_size); + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::iterator + PB_DS_CLASS_C_DEC:: + begin() + { + return iterator(m_a_p_children + get_begin_pos(), + m_a_p_children + arr_size); + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::const_iterator + PB_DS_CLASS_C_DEC:: + end() const + { + typedef node_pointer_pointer pointer_type; + pointer_type p = const_cast<pointer_type>(m_a_p_children) + arr_size; + return const_iterator(p, p); + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::iterator + PB_DS_CLASS_C_DEC:: + end() + { return iterator(m_a_p_children + arr_size, m_a_p_children + arr_size); } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::node_pointer + PB_DS_CLASS_C_DEC:: + get_child_node(a_const_iterator b_it, a_const_iterator e_it, + a_const_pointer p_traits) + { + const size_type i = get_pref_pos(b_it, e_it, p_traits); + _GLIBCXX_DEBUG_ASSERT(i < arr_size); + return m_a_p_children[i]; + } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::iterator + PB_DS_CLASS_C_DEC:: + get_child_it(a_const_iterator b_it, a_const_iterator e_it, + a_const_pointer p_traits) + { + const size_type i = get_pref_pos(b_it, e_it, p_traits); + _GLIBCXX_DEBUG_ASSERT(i < arr_size); + _GLIBCXX_DEBUG_ASSERT(m_a_p_children[i] != 0); + return iterator(m_a_p_children + i, m_a_p_children + i); + } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::node_const_pointer + PB_DS_CLASS_C_DEC:: + get_child_node(a_const_iterator b_it, a_const_iterator e_it, + a_const_pointer p_traits) const + { return const_cast<node_pointer>(get_child_node(b_it, e_it, p_traits)); } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::node_pointer + PB_DS_CLASS_C_DEC:: + get_lower_bound_child_node(a_const_iterator b_it, a_const_iterator e_it, + size_type checked_ind, + a_const_pointer p_traits) + { + if (!should_be_mine(b_it, e_it, checked_ind, p_traits)) + { + if (p_traits->cmp_prefixes(b_it, e_it, m_pref_b_it, + m_pref_e_it, true)) + return leftmost_descendant(); + return rightmost_descendant(); + } + + size_type i = get_pref_pos(b_it, e_it, p_traits); + _GLIBCXX_DEBUG_ASSERT(i < arr_size); + + if (m_a_p_children[i] != 0) + return m_a_p_children[i]; + + while (++i < arr_size) + if (m_a_p_children[i] != 0) + { + const node_type& __nt = m_a_p_children[i]->m_type; + node_pointer ret = m_a_p_children[i]; + + if (__nt == leaf_node) + return ret; + + _GLIBCXX_DEBUG_ASSERT(__nt == i_node); + inode_pointer inp = static_cast<inode_pointer>(ret); + return inp->leftmost_descendant(); + } + + return rightmost_descendant(); + } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::node_pointer + PB_DS_CLASS_C_DEC:: + add_child(node_pointer p_nd, a_const_iterator b_it, a_const_iterator e_it, + a_const_pointer p_traits) + { + const size_type i = get_pref_pos(b_it, e_it, p_traits); + _GLIBCXX_DEBUG_ASSERT(i < arr_size); + if (m_a_p_children[i] == 0) + { + m_a_p_children[i] = p_nd; + p_nd->m_p_parent = this; + return p_nd; + } + return m_a_p_children[i]; + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::node_const_pointer + PB_DS_CLASS_C_DEC:: + get_join_child(node_const_pointer p_nd, + a_const_pointer p_tr) const + { + node_pointer p = const_cast<node_pointer>(p_nd); + return const_cast<inode_pointer>(this)->get_join_child(p, p_tr); + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::node_pointer + PB_DS_CLASS_C_DEC:: + get_join_child(node_pointer p_nd, a_const_pointer p_traits) + { + size_type i; + a_const_iterator b_it; + a_const_iterator e_it; + if (p_nd->m_type == leaf_node) + { + leaf_const_pointer p = static_cast<leaf_const_pointer>(p_nd); + + typedef typename type_traits::key_const_reference kcr; + kcr r_key = access_traits::extract_key(p->value()); + b_it = p_traits->begin(r_key); + e_it = p_traits->end(r_key); + } + else + { + b_it = static_cast<inode_pointer>(p_nd)->pref_b_it(); + e_it = static_cast<inode_pointer>(p_nd)->pref_e_it(); + } + i = get_pref_pos(b_it, e_it, p_traits); + _GLIBCXX_DEBUG_ASSERT(i < arr_size); + return m_a_p_children[i]; + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + remove_child(node_pointer p_nd) + { + size_type i = 0; + for (; i < arr_size; ++i) + if (m_a_p_children[i] == p_nd) + { + m_a_p_children[i] = 0; + return; + } + _GLIBCXX_DEBUG_ASSERT(i != arr_size); + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + remove_child(iterator it) + { *it.m_p_p_cur = 0; } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + replace_child(node_pointer p_nd, a_const_iterator b_it, + a_const_iterator e_it, + a_const_pointer p_traits) + { + const size_type i = get_pref_pos(b_it, e_it, p_traits); + _GLIBCXX_DEBUG_ASSERT(i < arr_size); + m_a_p_children[i] = p_nd; + p_nd->m_p_parent = this; + } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::a_const_iterator + PB_DS_CLASS_C_DEC:: + pref_b_it() const + { return m_pref_b_it; } + + PB_DS_CLASS_T_DEC + inline typename PB_DS_CLASS_C_DEC::a_const_iterator + PB_DS_CLASS_C_DEC:: + pref_e_it() const + { return m_pref_e_it; } + + PB_DS_CLASS_T_DEC + bool + PB_DS_CLASS_C_DEC:: + should_be_mine(a_const_iterator b_it, a_const_iterator e_it, + size_type checked_ind, + a_const_pointer p_traits) const + { + if (m_e_ind == 0) + return true; + + const size_type num_es = std::distance(b_it, e_it); + if (num_es < m_e_ind) + return false; + + a_const_iterator key_b_it = b_it; + std::advance(key_b_it, checked_ind); + a_const_iterator key_e_it = b_it; + std::advance(key_e_it, m_e_ind); + + a_const_iterator value_b_it = m_pref_b_it; + std::advance(value_b_it, checked_ind); + a_const_iterator value_e_it = m_pref_b_it; + std::advance(value_e_it, m_e_ind); + + return p_traits->equal_prefixes(key_b_it, key_e_it, value_b_it, + value_e_it); + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::leaf_pointer + PB_DS_CLASS_C_DEC:: + leftmost_descendant() + { + node_pointer p_pot = *begin(); + if (p_pot->m_type == leaf_node) + return (static_cast<leaf_pointer>(p_pot)); + _GLIBCXX_DEBUG_ASSERT(p_pot->m_type == i_node); + return static_cast<inode_pointer>(p_pot)->leftmost_descendant(); + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::leaf_const_pointer + PB_DS_CLASS_C_DEC:: + leftmost_descendant() const + { return const_cast<inode_pointer>(this)->leftmost_descendant(); } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::leaf_pointer + PB_DS_CLASS_C_DEC:: + rightmost_descendant() + { + const size_type num_children = std::distance(begin(), end()); + _GLIBCXX_DEBUG_ASSERT(num_children >= 2); + + iterator it = begin(); + std::advance(it, num_children - 1); + node_pointer p_pot =* it; + if (p_pot->m_type == leaf_node) + return static_cast<leaf_pointer>(p_pot); + _GLIBCXX_DEBUG_ASSERT(p_pot->m_type == i_node); + return static_cast<inode_pointer>(p_pot)->rightmost_descendant(); + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::leaf_const_pointer + PB_DS_CLASS_C_DEC:: + rightmost_descendant() const + { return const_cast<inode_pointer>(this)->rightmost_descendant(); } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::size_type + PB_DS_CLASS_C_DEC:: + get_begin_pos() const + { + size_type i = 0; + for (; i < arr_size && m_a_p_children[i] == 0; ++i) + ; + return i; + } + +#ifdef _GLIBCXX_DEBUG + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::node_debug_info + PB_DS_CLASS_C_DEC:: + assert_valid_imp(a_const_pointer p_traits, + const char* __file, int __line) const + { + PB_DS_DEBUG_VERIFY(base_type::m_type == i_node); + PB_DS_DEBUG_VERIFY(static_cast<size_type>(std::distance(pref_b_it(), pref_e_it())) == m_e_ind); + PB_DS_DEBUG_VERIFY(std::distance(begin(), end()) >= 2); + + for (typename _Inode::const_iterator it = begin(); it != end(); ++it) + { + node_const_pointer p_nd = *it; + PB_DS_DEBUG_VERIFY(p_nd->m_p_parent == this); + node_debug_info child_ret = p_nd->assert_valid_imp(p_traits, + __file, __line); + + PB_DS_DEBUG_VERIFY(static_cast<size_type>(std::distance(child_ret.first, child_ret.second)) >= m_e_ind); + PB_DS_DEBUG_VERIFY(should_be_mine(child_ret.first, child_ret.second, 0, p_traits)); + PB_DS_DEBUG_VERIFY(get_pref_pos(child_ret.first, child_ret.second, p_traits) == static_cast<size_type>(it.m_p_p_cur - m_a_p_children)); + } + return std::make_pair(pref_b_it(), pref_e_it()); + } +#endif + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/policy_access_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/policy_access_fn_imps.hpp new file mode 100644 index 0000000..56f7616 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/policy_access_fn_imps.hpp @@ -0,0 +1,63 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/policy_access_fn_imps.hpp + * Contains an implementation class for pat_trie. + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::access_traits& +PB_DS_CLASS_C_DEC:: +get_access_traits() +{ return *this; } + +PB_DS_CLASS_T_DEC +const typename PB_DS_CLASS_C_DEC::access_traits& +PB_DS_CLASS_C_DEC:: +get_access_traits() const +{ return *this; } + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_update& +PB_DS_CLASS_C_DEC:: +get_node_update() +{ return *this; } + +PB_DS_CLASS_T_DEC +const typename PB_DS_CLASS_C_DEC::node_update& +PB_DS_CLASS_C_DEC:: +get_node_update() const +{ return *this; } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/r_erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/r_erase_fn_imps.hpp new file mode 100644 index 0000000..38d6062 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/r_erase_fn_imps.hpp @@ -0,0 +1,103 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/r_erase_fn_imps.hpp + * Contains an implementation class for pat_trie. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +actual_erase_node(node_pointer p_z) +{ + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + --m_size; + _GLIBCXX_DEBUG_ONLY(debug_base::erase_existing(PB_DS_V2F(p_z->m_value))); + p_z->~node(); + s_node_allocator.deallocate(p_z, 1); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +update_min_max_for_erased_node(node_pointer p_z) +{ + if (m_size == 1) + { + m_p_head->m_p_left = m_p_head->m_p_right = m_p_head; + return; + } + + if (m_p_head->m_p_left == p_z) + { + iterator it(p_z); + ++it; + m_p_head->m_p_left = it.m_p_nd; + } + else if (m_p_head->m_p_right == p_z) + { + iterator it(p_z); + --it; + m_p_head->m_p_right = it.m_p_nd; + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + _GLIBCXX_DEBUG_ONLY(assert_valid(true, true);) + clear_imp(m_p_head->m_p_parent); + m_size = 0; + initialize(); + _GLIBCXX_DEBUG_ONLY(debug_base::clear();) + _GLIBCXX_DEBUG_ONLY(assert_valid(true, true);) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear_imp(node_pointer p_nd) +{ + if (p_nd == 0) + return; + clear_imp(p_nd->m_p_left); + clear_imp(p_nd->m_p_right); + p_nd->~Node(); + s_node_allocator.deallocate(p_nd, 1); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/rotate_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/rotate_fn_imps.hpp new file mode 100644 index 0000000..f240bfa --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/rotate_fn_imps.hpp @@ -0,0 +1,150 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/rotate_fn_imps.hpp + * Contains imps for rotating nodes. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +rotate_left(node_pointer p_x) +{ + node_pointer p_y = p_x->m_p_right; + p_x->m_p_right = p_y->m_p_left; + + if (p_y->m_p_left != 0) + p_y->m_p_left->m_p_parent = p_x; + + p_y->m_p_parent = p_x->m_p_parent; + if (p_x == m_p_head->m_p_parent) + m_p_head->m_p_parent = p_y; + else if (p_x == p_x->m_p_parent->m_p_left) + p_x->m_p_parent->m_p_left = p_y; + else + p_x->m_p_parent->m_p_right = p_y; + + p_y->m_p_left = p_x; + p_x->m_p_parent = p_y; + + _GLIBCXX_DEBUG_ONLY(assert_node_consistent(p_x);) + _GLIBCXX_DEBUG_ONLY(assert_node_consistent(p_y);) + + apply_update(p_x, (Node_Update*)this); + apply_update(p_x->m_p_parent, (Node_Update*)this); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +rotate_right(node_pointer p_x) +{ + node_pointer p_y = p_x->m_p_left; + p_x->m_p_left = p_y->m_p_right; + + if (p_y->m_p_right != 0) + p_y->m_p_right->m_p_parent = p_x; + + p_y->m_p_parent = p_x->m_p_parent; + if (p_x == m_p_head->m_p_parent) + m_p_head->m_p_parent = p_y; + else if (p_x == p_x->m_p_parent->m_p_right) + p_x->m_p_parent->m_p_right = p_y; + else + p_x->m_p_parent->m_p_left = p_y; + + p_y->m_p_right = p_x; + p_x->m_p_parent = p_y; + + _GLIBCXX_DEBUG_ONLY(assert_node_consistent(p_x);) + _GLIBCXX_DEBUG_ONLY(assert_node_consistent(p_y);) + + apply_update(p_x, (Node_Update*)this); + apply_update(p_x->m_p_parent, (Node_Update*)this); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +rotate_parent(node_pointer p_nd) +{ + node_pointer p_parent = p_nd->m_p_parent; + if (p_nd == p_parent->m_p_left) + rotate_right(p_parent); + else + rotate_left(p_parent); + _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_parent = p_nd); + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_left == p_parent || p_nd->m_p_right == p_parent); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +apply_update(node_pointer /*p_nd*/, __gnu_pbds::null_node_update* /*p_update*/) +{ } + +PB_DS_CLASS_T_DEC +template<typename Node_Update_> +inline void +PB_DS_CLASS_C_DEC:: +apply_update(node_pointer p_nd, Node_Update_* p_update) +{ + p_update->operator()(& PB_DS_V2F(p_nd->m_value),(p_nd->m_p_left == 0) ? + 0 : + & PB_DS_V2F(p_nd->m_p_left->m_value),(p_nd->m_p_right == 0) ? + 0 : + & PB_DS_V2F(p_nd->m_p_right->m_value)); +} + +PB_DS_CLASS_T_DEC +template<typename Node_Update_> +inline void +PB_DS_CLASS_C_DEC:: +update_to_top(node_pointer p_nd, Node_Update_* p_update) +{ + while (p_nd != m_p_head) + { + apply_update(p_nd, p_update); + p_nd = p_nd->m_p_parent; + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +update_to_top(node_pointer /*p_nd*/, __gnu_pbds::null_node_update* /*p_update*/) +{ } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/split_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/split_fn_imps.hpp new file mode 100644 index 0000000..56a79d4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/split_fn_imps.hpp @@ -0,0 +1,250 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/split_fn_imps.hpp + * Contains an implementation class for pat_trie. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +split(key_const_reference r_key, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + branch_bag bag; + leaf_pointer p_split_lf = split_prep(r_key, other, bag); + if (p_split_lf == 0) + { + _GLIBCXX_DEBUG_ASSERT(bag.empty()); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + _GLIBCXX_DEBUG_ASSERT(!bag.empty()); + other.clear(); + + m_p_head->m_p_parent = rec_split(m_p_head->m_p_parent, pref_begin(p_split_lf), + pref_end(p_split_lf), other, bag); + + m_p_head->m_p_parent->m_p_parent = m_p_head; + + head_pointer __ohead = other.m_p_head; + __ohead->m_p_max = m_p_head->m_p_max; + m_p_head->m_p_max = rightmost_descendant(m_p_head->m_p_parent); + __ohead->m_p_min = other.leftmost_descendant(__ohead->m_p_parent); + + other.m_size = std::distance(other.PB_DS_CLASS_C_DEC::begin(), + other.PB_DS_CLASS_C_DEC::end()); + m_size -= other.m_size; + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::leaf_pointer +PB_DS_CLASS_C_DEC:: +split_prep(key_const_reference r_key, PB_DS_CLASS_C_DEC& other, + branch_bag& r_bag) +{ + _GLIBCXX_DEBUG_ASSERT(r_bag.empty()); + if (m_size == 0) + { + other.clear(); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return 0; + } + + if (synth_access_traits::cmp_keys(r_key, + PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_min)->value()))) + { + other.clear(); + value_swap(other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return 0; + } + + if (!synth_access_traits::cmp_keys(r_key, + PB_DS_V2F(static_cast<leaf_const_pointer>(m_p_head->m_p_max)->value()))) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return 0; + } + + iterator it = lower_bound(r_key); + + if (!synth_access_traits::equal_keys(PB_DS_V2F(*it), r_key)) + --it; + + node_pointer p_nd = it.m_p_nd; + _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == leaf_node); + leaf_pointer p_ret_l = static_cast<leaf_pointer>(p_nd); + while (p_nd->m_type != head_node) + { + r_bag.add_branch(); + p_nd = p_nd->m_p_parent; + } + _GLIBCXX_DEBUG_ONLY(debug_base::split(r_key,(synth_access_traits&)(*this), other);) + + return p_ret_l; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +rec_split(node_pointer p_nd, a_const_iterator b_it, a_const_iterator e_it, + PB_DS_CLASS_C_DEC& other, branch_bag& r_bag) +{ + if (p_nd->m_type == leaf_node) + { + _GLIBCXX_DEBUG_ASSERT(other.m_p_head->m_p_parent == 0); + return p_nd; + } + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_type == i_node); + inode_pointer p_ind = static_cast<inode_pointer>(p_nd); + + node_pointer pfirst = p_ind->get_child_node(b_it, e_it, this); + node_pointer p_child_ret = rec_split(pfirst, b_it, e_it, other, r_bag); + PB_DS_ASSERT_NODE_VALID(p_child_ret) + p_ind->replace_child(p_child_ret, b_it, e_it, this); + apply_update(p_ind, (node_update*)this); + + inode_iterator child_it = p_ind->get_child_it(b_it, e_it, this); + const size_type lhs_dist = std::distance(p_ind->begin(), child_it); + const size_type lhs_num_children = lhs_dist + 1; + _GLIBCXX_DEBUG_ASSERT(lhs_num_children > 0); + + const size_type rhs_dist = std::distance(p_ind->begin(), p_ind->end()); + size_type rhs_num_children = rhs_dist - lhs_num_children; + if (rhs_num_children == 0) + { + apply_update(p_ind, (node_update*)this); + return p_ind; + } + + other.split_insert_branch(p_ind->get_e_ind(), b_it, child_it, + rhs_num_children, r_bag); + + child_it = p_ind->get_child_it(b_it, e_it, this); + while (rhs_num_children != 0) + { + ++child_it; + p_ind->remove_child(child_it); + --rhs_num_children; + } + apply_update(p_ind, (node_update*)this); + + const size_type int_dist = std::distance(p_ind->begin(), p_ind->end()); + _GLIBCXX_DEBUG_ASSERT(int_dist >= 1); + if (int_dist > 1) + { + p_ind->update_prefixes(this); + PB_DS_ASSERT_NODE_VALID(p_ind) + apply_update(p_ind, (node_update*)this); + return p_ind; + } + + node_pointer p_ret = *p_ind->begin(); + p_ind->~inode(); + s_inode_allocator.deallocate(p_ind, 1); + apply_update(p_ret, (node_update*)this); + return p_ret; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +split_insert_branch(size_type e_ind, a_const_iterator b_it, + inode_iterator child_b_it, + size_type num_children, branch_bag& r_bag) +{ +#ifdef _GLIBCXX_DEBUG + if (m_p_head->m_p_parent != 0) + PB_DS_ASSERT_NODE_VALID(m_p_head->m_p_parent) +#endif + + const size_type start = m_p_head->m_p_parent == 0 ? 0 : 1; + const size_type total_num_children = start + num_children; + if (total_num_children == 0) + { + _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_parent == 0); + return; + } + + if (total_num_children == 1) + { + if (m_p_head->m_p_parent != 0) + { + PB_DS_ASSERT_NODE_VALID(m_p_head->m_p_parent) + return; + } + + _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_parent == 0); + ++child_b_it; + m_p_head->m_p_parent = *child_b_it; + m_p_head->m_p_parent->m_p_parent = m_p_head; + apply_update(m_p_head->m_p_parent, (node_update*)this); + PB_DS_ASSERT_NODE_VALID(m_p_head->m_p_parent) + return; + } + + _GLIBCXX_DEBUG_ASSERT(total_num_children > 1); + inode_pointer p_new_root = r_bag.get_branch(); + new (p_new_root) inode(e_ind, b_it); + size_type num_inserted = 0; + while (num_inserted++ < num_children) + { + ++child_b_it; + PB_DS_ASSERT_NODE_VALID((*child_b_it)) + p_new_root->add_child(*child_b_it, pref_begin(*child_b_it), + pref_end(*child_b_it), this); + } + + if (m_p_head->m_p_parent != 0) + p_new_root->add_child(m_p_head->m_p_parent, + pref_begin(m_p_head->m_p_parent), + pref_end(m_p_head->m_p_parent), this); + + m_p_head->m_p_parent = p_new_root; + p_new_root->m_p_parent = m_p_head; + apply_update(m_p_head->m_p_parent, (node_update*)this); + PB_DS_ASSERT_NODE_VALID(m_p_head->m_p_parent) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/synth_access_traits.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/synth_access_traits.hpp new file mode 100644 index 0000000..10615e2 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/synth_access_traits.hpp @@ -0,0 +1,218 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/synth_access_traits.hpp + * Contains an implementation class for a patricia tree. + */ + +#ifndef PB_DS_SYNTH_E_ACCESS_TRAITS_HPP +#define PB_DS_SYNTH_E_ACCESS_TRAITS_HPP + +#include <ext/pb_ds/detail/type_utils.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + +#define PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC \ + template<typename Type_Traits, bool Set, typename _ATraits> + +#define PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC \ + synth_access_traits<Type_Traits, Set, _ATraits> + + /// Synthetic element access traits. + template<typename Type_Traits, bool Set, typename _ATraits> + struct synth_access_traits : public _ATraits + { + typedef _ATraits base_type; + typedef typename base_type::const_iterator const_iterator; + typedef Type_Traits type_traits; + typedef typename type_traits::const_reference const_reference; + typedef typename type_traits::key_const_reference key_const_reference; + + synth_access_traits(); + + synth_access_traits(const base_type&); + + inline bool + equal_prefixes(const_iterator, const_iterator, const_iterator, + const_iterator, bool compare_after = true) const; + + bool + equal_keys(key_const_reference, key_const_reference) const; + + bool + cmp_prefixes(const_iterator, const_iterator, const_iterator, + const_iterator, bool compare_after = false) const; + + bool + cmp_keys(key_const_reference, key_const_reference) const; + + inline static key_const_reference + extract_key(const_reference); + +#ifdef _GLIBCXX_DEBUG + bool + operator()(key_const_reference, key_const_reference); +#endif + + private: + inline static key_const_reference + extract_key(const_reference, true_type); + + inline static key_const_reference + extract_key(const_reference, false_type); + + static integral_constant<int, Set> s_set_ind; + }; + + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + integral_constant<int,Set> + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::s_set_ind; + + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: + synth_access_traits() + { } + + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: + synth_access_traits(const _ATraits& r_traits) + : _ATraits(r_traits) + { } + + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + inline bool + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: + equal_prefixes(const_iterator b_l, const_iterator e_l, const_iterator b_r, + const_iterator e_r, bool compare_after /*= false */) const + { + while (b_l != e_l) + { + if (b_r == e_r) + return false; + if (base_type::e_pos(*b_l) != base_type::e_pos(*b_r)) + return false; + ++b_l; + ++b_r; + } + return (!compare_after || b_r == e_r); + } + + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + bool + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: + equal_keys(key_const_reference r_lhs_key, + key_const_reference r_rhs_key) const + { + return equal_prefixes(base_type::begin(r_lhs_key), + base_type::end(r_lhs_key), + base_type::begin(r_rhs_key), + base_type::end(r_rhs_key), + true); + } + + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + bool + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: + cmp_prefixes(const_iterator b_l, const_iterator e_l, const_iterator b_r, + const_iterator e_r, bool compare_after /* = false*/) const + { + while (b_l != e_l) + { + if (b_r == e_r) + return false; + + const typename base_type::size_type l_pos = base_type::e_pos(*b_l); + const typename base_type::size_type r_pos = base_type::e_pos(*b_r); + if (l_pos != r_pos) + return l_pos < r_pos; + ++b_l; + ++b_r; + } + + if (!compare_after) + return false; + return b_r != e_r; + } + + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + bool + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: + cmp_keys(key_const_reference r_lhs_key, + key_const_reference r_rhs_key) const + { + return cmp_prefixes(base_type::begin(r_lhs_key), + base_type::end(r_lhs_key), + base_type::begin(r_rhs_key), + base_type::end(r_rhs_key), + true); + } + + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + inline typename PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::key_const_reference + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: + extract_key(const_reference r_val) + { return extract_key(r_val, s_set_ind); } + + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + inline typename PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::key_const_reference + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: + extract_key(const_reference r_val, true_type) + { return r_val; } + + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + inline typename PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC::key_const_reference + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: + extract_key(const_reference r_val, false_type) + { return r_val.first; } + +#ifdef _GLIBCXX_DEBUG + PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC + bool + PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC:: + operator()(key_const_reference r_lhs, key_const_reference r_rhs) + { return cmp_keys(r_lhs, r_rhs); } +#endif + +#undef PB_DS_SYNTH_E_ACCESS_TRAITS_T_DEC +#undef PB_DS_SYNTH_E_ACCESS_TRAITS_C_DEC + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/trace_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/trace_fn_imps.hpp new file mode 100644 index 0000000..73d98f4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/trace_fn_imps.hpp @@ -0,0 +1,111 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/trace_fn_imps.hpp + * Contains an implementation class for pat_trie_. + */ + +#ifdef PB_DS_PAT_TRIE_TRACE_ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace() const +{ + std::cerr << std::endl; + if (m_p_head->m_p_parent == 0) + return; + trace_node(m_p_head->m_p_parent, 0); + std::cerr << std::endl; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace_node(node_const_pointer p_nd, size_type level) +{ + for (size_type i = 0; i < level; ++i) + std::cerr << ' '; + std::cerr << p_nd << " "; + std::cerr << ((p_nd->m_type == pat_trie_leaf_node_type) ? "l " : "i "); + + trace_node_metadata(p_nd, type_to_type<typename node::metadata_type>()); + typename access_traits::const_iterator el_it = pref_begin(p_nd); + while (el_it != pref_end(p_nd)) + { + std::cerr <<* el_it; + ++el_it; + } + + if (p_nd->m_type == pat_trie_leaf_node_type) + { + std::cerr << std::endl; + return; + } + + inode_const_pointer p_internal = static_cast<inode_const_pointer>(p_nd); + + std::cerr << " " << + static_cast<unsigned long>(p_internal->get_e_ind()) << std::endl; + + const size_type num_children = std::distance(p_internal->begin(), + p_internal->end()); + + for (size_type child_i = 0; child_i < num_children; ++child_i) + { + typename inode::const_iterator child_it = p_internal->begin(); + std::advance(child_it, num_children - child_i - 1); + trace_node(*child_it, level + 1); + } +} + +PB_DS_CLASS_T_DEC +template<typename Metadata_> +void +PB_DS_CLASS_C_DEC:: +trace_node_metadata(node_const_pointer p_nd, type_to_type<Metadata_>) +{ + std::cerr << "(" << static_cast<unsigned long>(p_nd->get_metadata()) << ") "; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace_node_metadata(node_const_pointer, type_to_type<null_type>) +{ } + +#endif + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/traits.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/traits.hpp new file mode 100644 index 0000000..65bfee2 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/traits.hpp @@ -0,0 +1,148 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/traits.hpp + * Contains an implementation class for pat_trie_. + */ + +#ifndef PB_DS_PAT_TRIE_NODE_AND_IT_TRAITS_HPP +#define PB_DS_PAT_TRIE_NODE_AND_IT_TRAITS_HPP + +#include <ext/pb_ds/detail/pat_trie_/pat_trie_base.hpp> +#include <ext/pb_ds/detail/pat_trie_/synth_access_traits.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /// Specialization. + /// @ingroup traits + template<typename Key, + typename Mapped, + typename _ATraits, + template<typename Node_CItr, + typename Node_Itr, + typename Cmp_Fn_, + typename _Alloc_> + class Node_Update, + typename _Alloc> + struct trie_traits<Key, Mapped, _ATraits, Node_Update, pat_trie_tag, _Alloc> + { + private: + typedef pat_trie_base base_type; + typedef types_traits<Key, Mapped, _Alloc, false> type_traits; + + public: + typedef typename trie_node_metadata_dispatch<Key, Mapped, _ATraits, Node_Update, _Alloc>::type metadata_type; + typedef base_type::_Metadata<metadata_type, _Alloc> metadata; + typedef _ATraits access_traits; + + /// Type for synthesized traits. + typedef __gnu_pbds::detail::synth_access_traits<type_traits, false, access_traits> synth_access_traits; + + typedef base_type::_Node_base<synth_access_traits, metadata> node; + typedef base_type::_Head<synth_access_traits, metadata> head; + typedef base_type::_Leaf<synth_access_traits, metadata> leaf; + typedef base_type::_Inode<synth_access_traits, metadata> inode; + + typedef base_type::_Iter<node, leaf, head, inode, true> iterator; + typedef base_type::_CIter<node, leaf, head, inode, true> const_iterator; + typedef base_type::_Iter<node, leaf, head, inode, false> reverse_iterator; + typedef base_type::_CIter<node, leaf, head, inode, false> const_reverse_iterator; + + /// This is an iterator to an iterator: it iterates over nodes, + /// and de-referencing it returns one of the tree's iterators. + typedef base_type::_Node_citer<node, leaf, head, inode, const_iterator, iterator, _Alloc> node_const_iterator; + + typedef base_type::_Node_iter<node, leaf, head, inode, const_iterator, iterator, _Alloc> node_iterator; + + /// Type for node update. + typedef Node_Update<node_const_iterator, node_iterator, _ATraits, _Alloc> node_update; + + typedef null_node_update<node_const_iterator, node_iterator, _ATraits, _Alloc>* null_node_update_pointer; + }; + + + /// Specialization. + /// @ingroup traits + template<typename Key, + typename _ATraits, + template<typename Node_CItr, + typename Node_Itr, + typename Cmp_Fn_, + typename _Alloc_> + class Node_Update, + typename _Alloc> + struct trie_traits<Key, null_type, _ATraits, Node_Update, pat_trie_tag, _Alloc> + { + private: + typedef pat_trie_base base_type; + typedef types_traits<Key, null_type, _Alloc, false> type_traits; + + public: + typedef typename trie_node_metadata_dispatch<Key, null_type, _ATraits, Node_Update, _Alloc>::type metadata_type; + typedef base_type::_Metadata<metadata_type, _Alloc> metadata; + typedef _ATraits access_traits; + + /// Type for synthesized traits. + typedef __gnu_pbds::detail::synth_access_traits<type_traits, true, access_traits> synth_access_traits; + + typedef base_type::_Node_base<synth_access_traits, metadata> node; + typedef base_type::_Head<synth_access_traits, metadata> head; + typedef base_type::_Leaf<synth_access_traits, metadata> leaf; + typedef base_type::_Inode<synth_access_traits, metadata> inode; + + typedef base_type::_CIter<node, leaf, head, inode, true> const_iterator; + typedef const_iterator iterator; + typedef base_type::_CIter<node, leaf, head, inode, false> const_reverse_iterator; + typedef const_reverse_iterator reverse_iterator; + + /// This is an iterator to an iterator: it iterates over nodes, + /// and de-referencing it returns one of the tree's iterators. + typedef base_type::_Node_citer<node, leaf, head, inode, const_iterator, iterator, _Alloc> node_const_iterator; + + typedef node_const_iterator node_iterator; + + /// Type for node update. + typedef Node_Update<node_const_iterator, node_iterator, _ATraits, _Alloc> node_update; + + typedef null_node_update<node_const_iterator, node_const_iterator, _ATraits, _Alloc>* null_node_update_pointer; + }; + + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_PAT_TRIE_NODE_AND_IT_TRAITS_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/update_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/update_fn_imps.hpp new file mode 100644 index 0000000..8b4e532 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/update_fn_imps.hpp @@ -0,0 +1,55 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file pat_trie_/update_fn_imps.hpp + * Contains an implementation class for pat_trie_. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +apply_update(node_pointer, null_node_update_pointer) +{ } + +PB_DS_CLASS_T_DEC +template<typename Node_Update_> +inline void +PB_DS_CLASS_C_DEC:: +apply_update(node_pointer p_nd, Node_Update_*) +{ + Node_Update_::operator()(node_iterator(p_nd, this), + node_const_iterator(0, this)); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/priority_queue_base_dispatch.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/priority_queue_base_dispatch.hpp new file mode 100644 index 0000000..c20bcd1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/priority_queue_base_dispatch.hpp @@ -0,0 +1,114 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file detail/priority_queue_base_dispatch.hpp + * Contains an pqiative container dispatching base. + */ + +#ifndef PB_DS_PRIORITY_QUEUE_BASE_DS_DISPATCHER_HPP +#define PB_DS_PRIORITY_QUEUE_BASE_DS_DISPATCHER_HPP + +#define PB_DS_ASSERT_VALID(X) \ + _GLIBCXX_DEBUG_ONLY(X.assert_valid(__FILE__, __LINE__);) + +#define PB_DS_DEBUG_VERIFY(_Cond) \ + _GLIBCXX_DEBUG_VERIFY_AT(_Cond, \ + _M_message(#_Cond" assertion from %1;:%2;") \ + ._M_string(__FILE__)._M_integer(__LINE__) \ + ,__file,__line) + +#include <ext/pb_ds/detail/pairing_heap_/pairing_heap_.hpp> +#include <ext/pb_ds/detail/binomial_heap_/binomial_heap_.hpp> +#include <ext/pb_ds/detail/rc_binomial_heap_/rc_binomial_heap_.hpp> +#include <ext/pb_ds/detail/binary_heap_/binary_heap_.hpp> +#include <ext/pb_ds/detail/thin_heap_/thin_heap_.hpp> + +#undef PB_DS_DEBUG_VERIFY +#undef PB_DS_ASSERT_VALID + +namespace __gnu_pbds +{ + namespace detail + { + /// Specialization for pairing_heap. + template<typename _VTp, typename Cmp_Fn, typename _Alloc> + struct container_base_dispatch<_VTp, Cmp_Fn, _Alloc, pairing_heap_tag, + null_type> + { + /// Dispatched type. + typedef pairing_heap<_VTp, Cmp_Fn, _Alloc> type; + }; + + /// Specialization for binomial_heap. + template<typename _VTp, typename Cmp_Fn, typename _Alloc> + struct container_base_dispatch<_VTp, Cmp_Fn, _Alloc, binomial_heap_tag, + null_type> + { + /// Dispatched type. + typedef binomial_heap<_VTp, Cmp_Fn, _Alloc> type; + }; + + /// Specialization for rc_binary_heap. + template<typename _VTp, typename Cmp_Fn, typename _Alloc> + struct container_base_dispatch<_VTp, Cmp_Fn, _Alloc, rc_binomial_heap_tag, + null_type> + { + /// Dispatched type. + typedef rc_binomial_heap<_VTp, Cmp_Fn, _Alloc> type; + }; + + /// Specialization for binary_heap. + template<typename _VTp, typename Cmp_Fn, typename _Alloc> + struct container_base_dispatch<_VTp, Cmp_Fn, _Alloc, binary_heap_tag, + null_type> + { + /// Dispatched type. + typedef binary_heap<_VTp, Cmp_Fn, _Alloc> type; + }; + + /// Specialization for thin_heap. + template<typename _VTp, typename Cmp_Fn, typename _Alloc> + struct container_base_dispatch<_VTp, Cmp_Fn, _Alloc, thin_heap_tag, + null_type> + { + /// Dispatched type. + typedef thin_heap<_VTp, Cmp_Fn, _Alloc> type; + }; + //@} group pbds + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_PRIORITY_QUEUE_BASE_DS_DISPATCHER_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..9f17857 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,100 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rb_tree_map_/constructors_destructor_fn_imps.hpp + * Contains an implementation for rb_tree_. + */ + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + insert(*(first_it++)); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_RB_TREE_NAME() +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_RB_TREE_NAME(const Cmp_Fn& r_cmp_fn) : + base_type(r_cmp_fn) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_RB_TREE_NAME(const Cmp_Fn& r_cmp_fn, const node_update& r_node_update) : + base_type(r_cmp_fn, r_node_update) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_RB_TREE_NAME(const PB_DS_CLASS_C_DEC& other) : + base_type(other) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + base_type::swap(other); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +initialize() +{ base_type::m_p_head->m_red = true; } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/debug_fn_imps.hpp new file mode 100644 index 0000000..907c42c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/debug_fn_imps.hpp @@ -0,0 +1,81 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rb_tree_map_/debug_fn_imps.hpp + * Contains an implementation for rb_tree_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +assert_node_consistent(const node_pointer p_nd, const char* __file, + int __line) const +{ + if (p_nd == 0) + return 1; + + const size_type l_height = + assert_node_consistent(p_nd->m_p_left, __file, __line); + const size_type r_height = + assert_node_consistent(p_nd->m_p_right, __file, __line); + if (p_nd->m_red) + { + PB_DS_DEBUG_VERIFY(is_effectively_black(p_nd->m_p_left)); + PB_DS_DEBUG_VERIFY(is_effectively_black(p_nd->m_p_right)); + } + PB_DS_DEBUG_VERIFY(l_height == r_height); + return (p_nd->m_red ? 0 : 1) + l_height; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + base_type::assert_valid(__file, __line); + const node_pointer p_head = base_type::m_p_head; + PB_DS_DEBUG_VERIFY(p_head->m_red); + if (p_head->m_p_parent != 0) + { + PB_DS_DEBUG_VERIFY(!p_head->m_p_parent->m_red); + assert_node_consistent(p_head->m_p_parent, __file, __line); + } +} + +#endif + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/erase_fn_imps.hpp new file mode 100644 index 0000000..9b15edc --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/erase_fn_imps.hpp @@ -0,0 +1,289 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rb_tree_map_/erase_fn_imps.hpp + * Contains an implementation for rb_tree_. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +erase(key_const_reference r_key) +{ + point_iterator it = this->find(r_key); + if (it == base_type::end()) + return false; + erase(it); + return true; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +erase(iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + if (it == base_type::end()) + return it; + + iterator ret_it = it; + ++ret_it; + erase_node(it.m_p_nd); + PB_DS_ASSERT_VALID((*this)) + return ret_it; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::reverse_iterator +PB_DS_CLASS_C_DEC:: +erase(reverse_iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + if (it.m_p_nd == base_type::m_p_head) + return it; + + reverse_iterator ret_it = it; + ++ret_it; + erase_node(it.m_p_nd); + PB_DS_ASSERT_VALID((*this)) + return ret_it; +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + PB_DS_ASSERT_VALID((*this)) + size_type num_ersd = 0; + iterator it = base_type::begin(); + while (it != base_type::end()) + { + if (pred(*it)) + { + ++num_ersd; + it = erase(it); + } + else + ++it; + } + + PB_DS_ASSERT_VALID((*this)) + return num_ersd; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase_node(node_pointer p_nd) +{ + remove_node(p_nd); + base_type::actual_erase_node(p_nd); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +remove_node(node_pointer p_z) +{ + this->update_min_max_for_erased_node(p_z); + node_pointer p_y = p_z; + node_pointer p_x = 0; + node_pointer p_new_x_parent = 0; + + if (p_y->m_p_left == 0) + p_x = p_y->m_p_right; + else if (p_y->m_p_right == 0) + p_x = p_y->m_p_left; + else + { + p_y = p_y->m_p_right; + while (p_y->m_p_left != 0) + p_y = p_y->m_p_left; + p_x = p_y->m_p_right; + } + + if (p_y == p_z) + { + p_new_x_parent = p_y->m_p_parent; + if (p_x != 0) + p_x->m_p_parent = p_y->m_p_parent; + + if (base_type::m_p_head->m_p_parent == p_z) + base_type::m_p_head->m_p_parent = p_x; + else if (p_z->m_p_parent->m_p_left == p_z) + { + p_y->m_p_left = p_z->m_p_parent; + p_z->m_p_parent->m_p_left = p_x; + } + else + { + p_y->m_p_left = 0; + p_z->m_p_parent->m_p_right = p_x; + } + } + else + { + p_z->m_p_left->m_p_parent = p_y; + p_y->m_p_left = p_z->m_p_left; + if (p_y != p_z->m_p_right) + { + p_new_x_parent = p_y->m_p_parent; + if (p_x != 0) + p_x->m_p_parent = p_y->m_p_parent; + p_y->m_p_parent->m_p_left = p_x; + p_y->m_p_right = p_z->m_p_right; + p_z->m_p_right->m_p_parent = p_y; + } + else + p_new_x_parent = p_y; + + if (base_type::m_p_head->m_p_parent == p_z) + base_type::m_p_head->m_p_parent = p_y; + else if (p_z->m_p_parent->m_p_left == p_z) + p_z->m_p_parent->m_p_left = p_y; + else + p_z->m_p_parent->m_p_right = p_y; + + p_y->m_p_parent = p_z->m_p_parent; + std::swap(p_y->m_red, p_z->m_red); + p_y = p_z; + } + + this->update_to_top(p_new_x_parent, (node_update* )this); + + if (p_y->m_red) + return; + + remove_fixup(p_x, p_new_x_parent); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +remove_fixup(node_pointer p_x, node_pointer p_new_x_parent) +{ + _GLIBCXX_DEBUG_ASSERT(p_x == 0 || p_x->m_p_parent == p_new_x_parent); + + while (p_x != base_type::m_p_head->m_p_parent && is_effectively_black(p_x)) + if (p_x == p_new_x_parent->m_p_left) + { + node_pointer p_w = p_new_x_parent->m_p_right; + if (p_w->m_red) + { + p_w->m_red = false; + p_new_x_parent->m_red = true; + base_type::rotate_left(p_new_x_parent); + p_w = p_new_x_parent->m_p_right; + } + + if (is_effectively_black(p_w->m_p_left) + && is_effectively_black(p_w->m_p_right)) + { + p_w->m_red = true; + p_x = p_new_x_parent; + p_new_x_parent = p_new_x_parent->m_p_parent; + } + else + { + if (is_effectively_black(p_w->m_p_right)) + { + if (p_w->m_p_left != 0) + p_w->m_p_left->m_red = false; + + p_w->m_red = true; + base_type::rotate_right(p_w); + p_w = p_new_x_parent->m_p_right; + } + + p_w->m_red = p_new_x_parent->m_red; + p_new_x_parent->m_red = false; + + if (p_w->m_p_right != 0) + p_w->m_p_right->m_red = false; + + base_type::rotate_left(p_new_x_parent); + this->update_to_top(p_new_x_parent, (node_update* )this); + break; + } + } + else + { + node_pointer p_w = p_new_x_parent->m_p_left; + if (p_w->m_red == true) + { + p_w->m_red = false; + p_new_x_parent->m_red = true; + base_type::rotate_right(p_new_x_parent); + p_w = p_new_x_parent->m_p_left; + } + + if (is_effectively_black(p_w->m_p_right) + && is_effectively_black(p_w->m_p_left)) + { + p_w->m_red = true; + p_x = p_new_x_parent; + p_new_x_parent = p_new_x_parent->m_p_parent; + } + else + { + if (is_effectively_black(p_w->m_p_left)) + { + if (p_w->m_p_right != 0) + p_w->m_p_right->m_red = false; + + p_w->m_red = true; + base_type::rotate_left(p_w); + p_w = p_new_x_parent->m_p_left; + } + + p_w->m_red = p_new_x_parent->m_red; + p_new_x_parent->m_red = false; + + if (p_w->m_p_left != 0) + p_w->m_p_left->m_red = false; + + base_type::rotate_right(p_new_x_parent); + this->update_to_top(p_new_x_parent, (node_update* )this); + break; + } + } + + if (p_x != 0) + p_x->m_red = false; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/find_fn_imps.hpp new file mode 100644 index 0000000..838b92f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/find_fn_imps.hpp @@ -0,0 +1,39 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rb_tree_map_/find_fn_imps.hpp + * Contains an implementation for rb_tree_. + */ diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/info_fn_imps.hpp new file mode 100644 index 0000000..8fa593e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/info_fn_imps.hpp @@ -0,0 +1,46 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rb_tree_map_/info_fn_imps.hpp + * Contains an implementation for rb_tree_. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +is_effectively_black(const node_pointer p_nd) +{ return (p_nd == 0 || !p_nd->m_red); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/insert_fn_imps.hpp new file mode 100644 index 0000000..40cb248 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/insert_fn_imps.hpp @@ -0,0 +1,115 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rb_tree_map_/insert_fn_imps.hpp + * Contains an implementation for rb_tree_. + */ + +PB_DS_CLASS_T_DEC +inline std::pair<typename PB_DS_CLASS_C_DEC::point_iterator, bool> +PB_DS_CLASS_C_DEC:: +insert(const_reference r_value) +{ + PB_DS_ASSERT_VALID((*this)) + std::pair<point_iterator, bool> ins_pair = base_type::insert_leaf(r_value); + if (ins_pair.second == true) + { + ins_pair.first.m_p_nd->m_red = true; + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + insert_fixup(ins_pair.first.m_p_nd); + } + + PB_DS_ASSERT_VALID((*this)) + return ins_pair; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +insert_fixup(node_pointer p_nd) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd->m_red == true); + while (p_nd != base_type::m_p_head->m_p_parent && p_nd->m_p_parent->m_red) + { + if (p_nd->m_p_parent == p_nd->m_p_parent->m_p_parent->m_p_left) + { + node_pointer p_y = p_nd->m_p_parent->m_p_parent->m_p_right; + if (p_y != 0 && p_y->m_red) + { + p_nd->m_p_parent->m_red = false; + p_y->m_red = false; + p_nd->m_p_parent->m_p_parent->m_red = true; + p_nd = p_nd->m_p_parent->m_p_parent; + } + else + { + if (p_nd == p_nd->m_p_parent->m_p_right) + { + p_nd = p_nd->m_p_parent; + base_type::rotate_left(p_nd); + } + p_nd->m_p_parent->m_red = false; + p_nd->m_p_parent->m_p_parent->m_red = true; + base_type::rotate_right(p_nd->m_p_parent->m_p_parent); + } + } + else + { + node_pointer p_y = p_nd->m_p_parent->m_p_parent->m_p_left; + if (p_y != 0 && p_y->m_red) + { + p_nd->m_p_parent->m_red = false; + p_y->m_red = false; + p_nd->m_p_parent->m_p_parent->m_red = true; + p_nd = p_nd->m_p_parent->m_p_parent; + } + else + { + if (p_nd == p_nd->m_p_parent->m_p_left) + { + p_nd = p_nd->m_p_parent; + base_type::rotate_right(p_nd); + } + p_nd->m_p_parent->m_red = false; + p_nd->m_p_parent->m_p_parent->m_red = true; + base_type::rotate_left(p_nd->m_p_parent->m_p_parent); + } + } + } + + base_type::update_to_top(p_nd, (node_update* )this); + base_type::m_p_head->m_p_parent->m_red = false; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/node.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/node.hpp new file mode 100644 index 0000000..3859ab3 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/node.hpp @@ -0,0 +1,139 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rb_tree_map_/node.hpp + * Contains an implementation for rb_tree_. + */ + +#ifndef PB_DS_RB_TREE_NODE_HPP +#define PB_DS_RB_TREE_NODE_HPP + +#include <ext/pb_ds/detail/branch_policy/null_node_metadata.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /// Node for Red-Black trees. + template<typename Value_Type, class Metadata, typename _Alloc> + struct rb_tree_node_ + { + public: + typedef Value_Type value_type; + typedef Metadata metadata_type; + + typedef + typename _Alloc::template rebind< + rb_tree_node_< + Value_Type, + Metadata, + _Alloc> >::other::pointer + node_pointer; + + typedef + typename _Alloc::template rebind< + metadata_type>::other::reference + metadata_reference; + + typedef + typename _Alloc::template rebind< + metadata_type>::other::const_reference + metadata_const_reference; + + bool + special() const + { return m_red; } + + metadata_const_reference + get_metadata() const + { return m_metadata; } + + metadata_reference + get_metadata() + { return m_metadata; } + +#ifdef PB_DS_BIN_SEARCH_TREE_TRACE_ + void + trace() const + { + std::cout << PB_DS_V2F(m_value) <<(m_red? " <r> " : " <b> ") + << "(" << m_metadata << ")"; + } +#endif + + node_pointer m_p_left; + node_pointer m_p_right; + node_pointer m_p_parent; + value_type m_value; + bool m_red; + metadata_type m_metadata; + }; + + template<typename Value_Type, typename _Alloc> + struct rb_tree_node_<Value_Type, null_type, _Alloc> + { + public: + typedef Value_Type value_type; + typedef null_type metadata_type; + + typedef + typename _Alloc::template rebind< + rb_tree_node_< + Value_Type, + null_type, + _Alloc> >::other::pointer + node_pointer; + + bool + special() const + { return m_red; } + +#ifdef PB_DS_BIN_SEARCH_TREE_TRACE_ + void + trace() const + { std::cout << PB_DS_V2F(m_value) <<(m_red? " <r> " : " <b> "); } +#endif + + node_pointer m_p_left; + node_pointer m_p_right; + node_pointer m_p_parent; + value_type m_value; + bool m_red; + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/rb_tree_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/rb_tree_.hpp new file mode 100644 index 0000000..a5f66f2 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/rb_tree_.hpp @@ -0,0 +1,248 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rb_tree_map_/rb_tree_.hpp + * Contains an implementation for Red Black trees. + */ + +#include <ext/pb_ds/detail/standard_policies.hpp> +#include <utility> +#include <vector> +#include <assert.h> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Mapped, typename Cmp_Fn, \ + typename Node_And_It_Traits, typename _Alloc> + +#ifdef PB_DS_DATA_TRUE_INDICATOR +# define PB_DS_RB_TREE_NAME rb_tree_map +# define PB_DS_RB_TREE_BASE_NAME bin_search_tree_map +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR +# define PB_DS_RB_TREE_NAME rb_tree_set +# define PB_DS_RB_TREE_BASE_NAME bin_search_tree_set +#endif + +#define PB_DS_CLASS_C_DEC \ + PB_DS_RB_TREE_NAME<Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc> + +#define PB_DS_RB_TREE_BASE \ + PB_DS_RB_TREE_BASE_NAME<Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc> + + + /** + * @brief Red-Black tree. + * @ingroup branch-detail + * + * This implementation uses an idea from the SGI STL (using a + * @a header node which is needed for efficient iteration). + */ + template<typename Key, + typename Mapped, + typename Cmp_Fn, + typename Node_And_It_Traits, + typename _Alloc> + class PB_DS_RB_TREE_NAME : public PB_DS_RB_TREE_BASE + { + private: + typedef PB_DS_RB_TREE_BASE base_type; + typedef typename base_type::node_pointer node_pointer; + + public: + typedef rb_tree_tag container_category; + typedef Cmp_Fn cmp_fn; + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef typename base_type::key_type key_type; + typedef typename base_type::key_pointer key_pointer; + typedef typename base_type::key_const_pointer key_const_pointer; + typedef typename base_type::key_reference key_reference; + typedef typename base_type::key_const_reference key_const_reference; + typedef typename base_type::mapped_type mapped_type; + typedef typename base_type::mapped_pointer mapped_pointer; + typedef typename base_type::mapped_const_pointer mapped_const_pointer; + typedef typename base_type::mapped_reference mapped_reference; + typedef typename base_type::mapped_const_reference mapped_const_reference; + typedef typename base_type::value_type value_type; + typedef typename base_type::pointer pointer; + typedef typename base_type::const_pointer const_pointer; + typedef typename base_type::reference reference; + typedef typename base_type::const_reference const_reference; + typedef typename base_type::point_iterator point_iterator; + typedef typename base_type::const_iterator point_const_iterator; + typedef typename base_type::iterator iterator; + typedef typename base_type::const_iterator const_iterator; + typedef typename base_type::reverse_iterator reverse_iterator; + typedef typename base_type::const_reverse_iterator const_reverse_iterator; + typedef typename base_type::node_update node_update; + + PB_DS_RB_TREE_NAME(); + + PB_DS_RB_TREE_NAME(const Cmp_Fn&); + + PB_DS_RB_TREE_NAME(const Cmp_Fn&, const node_update&); + + PB_DS_RB_TREE_NAME(const PB_DS_CLASS_C_DEC&); + + void + swap(PB_DS_CLASS_C_DEC&); + + template<typename It> + void + copy_from_range(It, It); + + inline std::pair<point_iterator, bool> + insert(const_reference); + + inline mapped_reference + operator[](key_const_reference r_key) + { +#ifdef PB_DS_DATA_TRUE_INDICATOR + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + std::pair<point_iterator, bool> ins_pair = + base_type::insert_leaf(value_type(r_key, mapped_type())); + + if (ins_pair.second == true) + { + ins_pair.first.m_p_nd->m_red = true; + _GLIBCXX_DEBUG_ONLY(this->structure_only_assert_valid(__FILE__, __LINE__);) + insert_fixup(ins_pair.first.m_p_nd); + } + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + return ins_pair.first.m_p_nd->m_value.second; +#else + insert(r_key); + return base_type::s_null_type; +#endif + } + + inline bool + erase(key_const_reference); + + inline iterator + erase(iterator); + + inline reverse_iterator + erase(reverse_iterator); + + template<typename Pred> + inline size_type + erase_if(Pred); + + void + join(PB_DS_CLASS_C_DEC&); + + void + split(key_const_reference, PB_DS_CLASS_C_DEC&); + + private: + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; + + size_type + assert_node_consistent(const node_pointer, const char*, int) const; +#endif + + inline static bool + is_effectively_black(const node_pointer); + + void + initialize(); + + void + insert_fixup(node_pointer); + + void + erase_node(node_pointer); + + void + remove_node(node_pointer); + + void + remove_fixup(node_pointer, node_pointer); + + void + split_imp(node_pointer, PB_DS_CLASS_C_DEC&); + + inline node_pointer + split_min(); + + std::pair<node_pointer, node_pointer> + split_min_imp(); + + void + join_imp(node_pointer, node_pointer); + + std::pair<node_pointer, node_pointer> + find_join_pos_right(node_pointer, size_type, size_type); + + std::pair<node_pointer, node_pointer> + find_join_pos_left(node_pointer, size_type, size_type); + + inline size_type + black_height(node_pointer); + + void + split_at_node(node_pointer, PB_DS_CLASS_C_DEC&); + }; + +#define PB_DS_STRUCT_ONLY_ASSERT_VALID(X) \ + _GLIBCXX_DEBUG_ONLY(X.structure_only_assert_valid(__FILE__, __LINE__);) + +#include <ext/pb_ds/detail/rb_tree_map_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/rb_tree_map_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/rb_tree_map_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/rb_tree_map_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/rb_tree_map_/split_join_fn_imps.hpp> +#include <ext/pb_ds/detail/rb_tree_map_/info_fn_imps.hpp> + +#undef PB_DS_STRUCT_ONLY_ASSERT_VALID +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_RB_TREE_NAME +#undef PB_DS_RB_TREE_BASE_NAME +#undef PB_DS_RB_TREE_BASE + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/split_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/split_join_fn_imps.hpp new file mode 100644 index 0000000..ea26574 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/split_join_fn_imps.hpp @@ -0,0 +1,306 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rb_tree_map_/split_join_fn_imps.hpp + * Contains an implementation for rb_tree_. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +join(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + if (base_type::join_prep(other) == false) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + const node_pointer p_x = other.split_min(); + join_imp(p_x, other.m_p_head->m_p_parent); + base_type::join_finish(other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +join_imp(node_pointer p_x, node_pointer p_r) +{ + _GLIBCXX_DEBUG_ASSERT(p_x != 0); + if (p_r != 0) + p_r->m_red = false; + + const size_type h = black_height(base_type::m_p_head->m_p_parent); + const size_type other_h = black_height(p_r); + node_pointer p_x_l; + node_pointer p_x_r; + std::pair<node_pointer, node_pointer> join_pos; + const bool right_join = h >= other_h; + if (right_join) + { + join_pos = find_join_pos_right(base_type::m_p_head->m_p_parent, + h, other_h); + p_x_l = join_pos.first; + p_x_r = p_r; + } + else + { + p_x_l = base_type::m_p_head->m_p_parent; + base_type::m_p_head->m_p_parent = p_r; + if (p_r != 0) + p_r->m_p_parent = base_type::m_p_head; + + join_pos = find_join_pos_left(base_type::m_p_head->m_p_parent, + h, other_h); + p_x_r = join_pos.first; + } + + node_pointer p_parent = join_pos.second; + if (p_parent == base_type::m_p_head) + { + base_type::m_p_head->m_p_parent = p_x; + p_x->m_p_parent = base_type::m_p_head; + } + else + { + p_x->m_p_parent = p_parent; + if (right_join) + p_x->m_p_parent->m_p_right = p_x; + else + p_x->m_p_parent->m_p_left = p_x; + } + + p_x->m_p_left = p_x_l; + if (p_x_l != 0) + p_x_l->m_p_parent = p_x; + + p_x->m_p_right = p_x_r; + if (p_x_r != 0) + p_x_r->m_p_parent = p_x; + + p_x->m_red = true; + + base_type::initialize_min_max(); + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + base_type::update_to_top(p_x, (node_update* )this); + insert_fixup(p_x); + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +split_min() +{ + node_pointer p_min = base_type::m_p_head->m_p_left; + +#ifdef _GLIBCXX_DEBUG + const node_pointer p_head = base_type::m_p_head; + _GLIBCXX_DEBUG_ASSERT(p_min != p_head); +#endif + + remove_node(p_min); + return p_min; +} + +PB_DS_CLASS_T_DEC +std::pair< + typename PB_DS_CLASS_C_DEC::node_pointer, + typename PB_DS_CLASS_C_DEC::node_pointer> +PB_DS_CLASS_C_DEC:: +find_join_pos_right(node_pointer p_l, size_type h_l, size_type h_r) +{ + _GLIBCXX_DEBUG_ASSERT(h_l >= h_r); + + if (base_type::m_p_head->m_p_parent == 0) + return (std::make_pair((node_pointer)0, base_type::m_p_head)); + + node_pointer p_l_parent = base_type::m_p_head; + while (h_l > h_r) + { + if (p_l->m_red == false) + { + _GLIBCXX_DEBUG_ASSERT(h_l > 0); + --h_l; + } + + p_l_parent = p_l; + p_l = p_l->m_p_right; + } + + if (!is_effectively_black(p_l)) + { + p_l_parent = p_l; + p_l = p_l->m_p_right; + } + + _GLIBCXX_DEBUG_ASSERT(is_effectively_black(p_l)); + _GLIBCXX_DEBUG_ASSERT(black_height(p_l) == h_r); + _GLIBCXX_DEBUG_ASSERT(p_l == 0 || p_l->m_p_parent == p_l_parent); + return std::make_pair(p_l, p_l_parent); +} + +PB_DS_CLASS_T_DEC +std::pair< + typename PB_DS_CLASS_C_DEC::node_pointer, + typename PB_DS_CLASS_C_DEC::node_pointer> +PB_DS_CLASS_C_DEC:: +find_join_pos_left(node_pointer p_r, size_type h_l, size_type h_r) +{ + _GLIBCXX_DEBUG_ASSERT(h_r > h_l); + if (base_type::m_p_head->m_p_parent == 0) + return (std::make_pair((node_pointer)0, + base_type::m_p_head)); + node_pointer p_r_parent = base_type::m_p_head; + while (h_r > h_l) + { + if (p_r->m_red == false) + { + _GLIBCXX_DEBUG_ASSERT(h_r > 0); + --h_r; + } + + p_r_parent = p_r; + p_r = p_r->m_p_left; + } + + if (!is_effectively_black(p_r)) + { + p_r_parent = p_r; + p_r = p_r->m_p_left; + } + + _GLIBCXX_DEBUG_ASSERT(is_effectively_black(p_r)); + _GLIBCXX_DEBUG_ASSERT(black_height(p_r) == h_l); + _GLIBCXX_DEBUG_ASSERT(p_r == 0 || p_r->m_p_parent == p_r_parent); + return std::make_pair(p_r, p_r_parent); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +black_height(node_pointer p_nd) +{ + size_type h = 1; + while (p_nd != 0) + { + if (p_nd->m_red == false) + ++h; + p_nd = p_nd->m_p_left; + } + return h; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +split(key_const_reference r_key, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + if (base_type::split_prep(r_key, other) == false) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + PB_DS_STRUCT_ONLY_ASSERT_VALID(other) + node_pointer p_nd = this->upper_bound(r_key).m_p_nd; + do + { + node_pointer p_next_nd = p_nd->m_p_parent; + if (Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value))) + split_at_node(p_nd, other); + + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + PB_DS_STRUCT_ONLY_ASSERT_VALID(other) + p_nd = p_next_nd; + } + while (p_nd != base_type::m_p_head); + + base_type::split_finish(other); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +split_at_node(node_pointer p_nd, PB_DS_CLASS_C_DEC& other) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + + node_pointer p_l = p_nd->m_p_left; + node_pointer p_r = p_nd->m_p_right; + node_pointer p_parent = p_nd->m_p_parent; + if (p_parent == base_type::m_p_head) + { + base_type::m_p_head->m_p_parent = p_l; + if (p_l != 0) + { + p_l->m_p_parent = base_type::m_p_head; + p_l->m_red = false; + } + } + else + { + if (p_parent->m_p_left == p_nd) + p_parent->m_p_left = p_l; + else + p_parent->m_p_right = p_l; + + if (p_l != 0) + p_l->m_p_parent = p_parent; + + this->update_to_top(p_parent, (node_update* )this); + + if (!p_nd->m_red) + remove_fixup(p_l, p_parent); + } + + base_type::initialize_min_max(); + other.join_imp(p_nd, p_r); + PB_DS_STRUCT_ONLY_ASSERT_VALID((*this)) + PB_DS_STRUCT_ONLY_ASSERT_VALID(other) +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/traits.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/traits.hpp new file mode 100644 index 0000000..d13b179 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rb_tree_map_/traits.hpp @@ -0,0 +1,102 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rb_tree_map_/traits.hpp + * Contains an implementation for rb_tree_. + */ + +#ifndef PB_DS_RB_TREE_NODE_AND_IT_TRAITS_HPP +#define PB_DS_RB_TREE_NODE_AND_IT_TRAITS_HPP + +#include <ext/pb_ds/detail/rb_tree_map_/node.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /// Specialization. + /// @ingroup traits + template<typename Key, + typename Mapped, + typename Cmp_Fn, + template<typename Node_CItr, + typename Node_Itr, + typename Cmp_Fn_, + typename _Alloc_> + class Node_Update, + typename _Alloc> + struct tree_traits<Key, Mapped, Cmp_Fn, Node_Update, rb_tree_tag,_Alloc> + : public bin_search_tree_traits< + Key, + Mapped, + Cmp_Fn, + Node_Update, + rb_tree_node_< + typename types_traits<Key, Mapped, _Alloc, false>::value_type, + typename tree_node_metadata_dispatch<Key, Mapped, Cmp_Fn, Node_Update, + _Alloc>::type, + _Alloc>, + _Alloc> + { }; + + /// Specialization. + /// @ingroup traits + template<typename Key, + typename Cmp_Fn, + template<typename Node_CItr, + typename Node_Itr, + typename Cmp_Fn_, + typename _Alloc_> + class Node_Update, + typename _Alloc> + struct tree_traits<Key, null_type, Cmp_Fn, Node_Update, rb_tree_tag,_Alloc> + : public bin_search_tree_traits< + Key, + null_type, + Cmp_Fn, + Node_Update, + rb_tree_node_< + typename types_traits<Key, null_type, _Alloc, false>::value_type, + typename tree_node_metadata_dispatch<Key, null_type, Cmp_Fn, Node_Update, + _Alloc>::type, + _Alloc>, + _Alloc> + { }; + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..a563445 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,84 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rc_binomial_heap_/constructors_destructor_fn_imps.hpp + * Contains an implementation for rc_binomial_heap_. + */ + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +rc_binomial_heap() +{ + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +rc_binomial_heap(const Cmp_Fn& r_cmp_fn) +: base_type(r_cmp_fn) +{ + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +rc_binomial_heap(const PB_DS_CLASS_C_DEC& other) +: base_type(other) +{ + make_binomial_heap(); + base_type::find_max(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~rc_binomial_heap() +{ } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + base_type::swap(other); + m_rc.swap(other.m_rc); + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/debug_fn_imps.hpp new file mode 100644 index 0000000..d42f418 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/debug_fn_imps.hpp @@ -0,0 +1,121 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rc_binomial_heap_/debug_fn_imps.hpp + * Contains an implementation for rc_binomial_heap_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + base_type::assert_valid(false, __file, __line); + if (!base_type::empty()) + { + PB_DS_DEBUG_VERIFY(base_type::m_p_max != 0); + base_type::assert_max(__file, __line); + } + + m_rc.assert_valid(__file, __line); + + if (m_rc.empty()) + { + base_type::assert_valid(true, __file, __line); + PB_DS_DEBUG_VERIFY(next_2_pointer(base_type::m_p_root) == 0); + return; + } + + node_const_pointer p_nd = next_2_pointer(base_type::m_p_root); + typename rc_t::const_iterator it = m_rc.end(); + --it; + + while (p_nd != 0) + { + PB_DS_DEBUG_VERIFY(*it == p_nd); + node_const_pointer p_next = p_nd->m_p_next_sibling; + PB_DS_DEBUG_VERIFY(p_next != 0); + PB_DS_DEBUG_VERIFY(p_nd->m_metadata == p_next->m_metadata); + PB_DS_DEBUG_VERIFY(p_next->m_p_next_sibling == 0 || + p_next->m_metadata < p_next->m_p_next_sibling->m_metadata); + + --it; + p_nd = next_2_pointer(next_after_0_pointer(p_nd)); + } + PB_DS_DEBUG_VERIFY(it + 1 == m_rc.begin()); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_const_pointer +PB_DS_CLASS_C_DEC:: +next_2_pointer(node_const_pointer p_nd) +{ + if (p_nd == 0) + return 0; + + node_pointer p_next = p_nd->m_p_next_sibling; + + if (p_next == 0) + return 0; + + if (p_nd->m_metadata == p_next->m_metadata) + return p_nd; + + return next_2_pointer(p_next); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_const_pointer +PB_DS_CLASS_C_DEC:: +next_after_0_pointer(node_const_pointer p_nd) +{ + if (p_nd == 0) + return 0; + + node_pointer p_next = p_nd->m_p_next_sibling; + + if (p_next == 0) + return 0; + + if (p_nd->m_metadata < p_next->m_metadata) + return p_next; + + return next_after_0_pointer(p_next); +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/erase_fn_imps.hpp new file mode 100644 index 0000000..2d6a6e1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/erase_fn_imps.hpp @@ -0,0 +1,107 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rc_binomial_heap_/erase_fn_imps.hpp + * Contains an implementation for rc_binomial_heap_. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +pop() +{ + make_binomial_heap(); + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + base_type::pop(); + base_type::find_max(); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + base_type::clear(); + m_rc.clear(); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +make_binomial_heap() +{ + node_pointer p_nd = base_type::m_p_root; + while (p_nd != 0) + { + node_pointer p_next = p_nd->m_p_next_sibling; + if (p_next == 0) + p_nd = p_next; + else if (p_nd->m_metadata == p_next->m_metadata) + p_nd = link_with_next_sibling(p_nd); + else if (p_nd->m_metadata < p_next->m_metadata) + p_nd = p_next; +#ifdef _GLIBCXX_DEBUG + else + _GLIBCXX_DEBUG_ASSERT(0); +#endif + } + + m_rc.clear(); +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + make_binomial_heap(); + const size_type ersd = base_type::erase_if(pred); + base_type::find_max(); + PB_DS_ASSERT_VALID((*this)) + return ersd; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase(point_iterator it) +{ + make_binomial_heap(); + base_type::erase(it); + base_type::find_max(); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/insert_fn_imps.hpp new file mode 100644 index 0000000..35ae5a0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/insert_fn_imps.hpp @@ -0,0 +1,154 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rc_binomial_heap_/insert_fn_imps.hpp + * Contains an implementation for rc_binomial_heap_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +push(const_reference r_val) +{ + PB_DS_ASSERT_VALID((*this)) + + make_0_exposed(); + + PB_DS_ASSERT_VALID((*this)) + + node_pointer p_nd = base_type::get_new_node_for_insert(r_val); + + p_nd->m_p_l_child = p_nd->m_p_prev_or_parent = 0; + p_nd->m_metadata = 0; + + if (base_type::m_p_max == 0 || Cmp_Fn::operator()(base_type::m_p_max->m_value, r_val)) + base_type::m_p_max = p_nd; + + p_nd->m_p_next_sibling = base_type::m_p_root; + + if (base_type::m_p_root != 0) + base_type::m_p_root->m_p_prev_or_parent = p_nd; + + base_type::m_p_root = p_nd; + + if (p_nd->m_p_next_sibling != 0&& p_nd->m_p_next_sibling->m_metadata == 0) + m_rc.push(p_nd); + + PB_DS_ASSERT_VALID((*this)) + + return point_iterator(p_nd); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +modify(point_iterator it, const_reference r_new_val) +{ + PB_DS_ASSERT_VALID((*this)) + + make_binomial_heap(); + + base_type::modify(it, r_new_val); + + base_type::find_max(); + + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +link_with_next_sibling(node_pointer p_nd) +{ + node_pointer p_next = p_nd->m_p_next_sibling; + + _GLIBCXX_DEBUG_ASSERT(p_next != 0); + _GLIBCXX_DEBUG_ASSERT(p_next->m_p_prev_or_parent == p_nd); + + if (Cmp_Fn::operator()(p_nd->m_value, p_next->m_value)) + { + p_next->m_p_prev_or_parent = p_nd->m_p_prev_or_parent; + + if (p_next->m_p_prev_or_parent == 0) + base_type::m_p_root = p_next; + else + p_next->m_p_prev_or_parent->m_p_next_sibling = p_next; + + if (base_type::m_p_max == p_nd) + base_type::m_p_max = p_next; + + base_type::make_child_of(p_nd, p_next); + + ++p_next->m_metadata; + + return p_next; + } + + p_nd->m_p_next_sibling = p_next->m_p_next_sibling; + + if (p_nd->m_p_next_sibling != 0) + p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd; + + if (base_type::m_p_max == p_next) + base_type::m_p_max = p_nd; + + base_type::make_child_of(p_next, p_nd); + + ++p_nd->m_metadata; + + return p_nd; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +make_0_exposed() +{ + if (m_rc.empty()) + return; + + node_pointer p_nd = m_rc.top(); + + m_rc.pop(); + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_next_sibling != 0); + _GLIBCXX_DEBUG_ASSERT(p_nd->m_metadata == p_nd->m_p_next_sibling->m_metadata); + + node_pointer p_res = link_with_next_sibling(p_nd); + + if (p_res->m_p_next_sibling != 0&& p_res->m_metadata == p_res->m_p_next_sibling->m_metadata) + m_rc.push(p_res); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/rc.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/rc.hpp new file mode 100644 index 0000000..eaf8f48 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/rc.hpp @@ -0,0 +1,240 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rc_binomial_heap_/rc.hpp + * Contains a redundant (binary counter). + */ + +#ifndef PB_DS_RC_HPP +#define PB_DS_RC_HPP + +namespace __gnu_pbds +{ + namespace detail + { + /// Redundant binary counter. + template<typename _Node, typename _Alloc> + class rc + { + private: + typedef _Alloc allocator_type; + typedef typename allocator_type::size_type size_type; + typedef _Node node; + + typedef typename _Alloc::template rebind<node> __rebind_n; + typedef typename __rebind_n::other::pointer node_pointer; + + typedef typename _Alloc::template rebind<node_pointer> __rebind_np; + + typedef typename __rebind_np::other::pointer entry_pointer; + typedef typename __rebind_np::other::const_pointer entry_const_pointer; + + enum + { + max_entries = sizeof(size_type) << 3 + }; + + public: + typedef node_pointer entry; + typedef entry_const_pointer const_iterator; + + rc(); + + rc(const rc&); + + inline void + swap(rc&); + + inline void + push(entry); + + inline node_pointer + top() const; + + inline void + pop(); + + inline bool + empty() const; + + inline size_type + size() const; + + void + clear(); + + const const_iterator + begin() const; + + const const_iterator + end() const; + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; +#endif + +#ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_ + void + trace() const; +#endif + + private: + node_pointer m_a_entries[max_entries]; + size_type m_over_top; + }; + + template<typename _Node, typename _Alloc> + rc<_Node, _Alloc>:: + rc() : m_over_top(0) + { PB_DS_ASSERT_VALID((*this)) } + + template<typename _Node, typename _Alloc> + rc<_Node, _Alloc>:: + rc(const rc<_Node, _Alloc>& other) : m_over_top(0) + { PB_DS_ASSERT_VALID((*this)) } + + template<typename _Node, typename _Alloc> + inline void + rc<_Node, _Alloc>:: + swap(rc<_Node, _Alloc>& other) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + const size_type over_top = std::max(m_over_top, other.m_over_top); + + for (size_type i = 0; i < over_top; ++i) + std::swap(m_a_entries[i], other.m_a_entries[i]); + + std::swap(m_over_top, other.m_over_top); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + } + + template<typename _Node, typename _Alloc> + inline void + rc<_Node, _Alloc>:: + push(entry p_nd) + { + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(m_over_top < max_entries); + m_a_entries[m_over_top++] = p_nd; + PB_DS_ASSERT_VALID((*this)) + } + + template<typename _Node, typename _Alloc> + inline void + rc<_Node, _Alloc>:: + pop() + { + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!empty()); + --m_over_top; + PB_DS_ASSERT_VALID((*this)) + } + + template<typename _Node, typename _Alloc> + inline typename rc<_Node, _Alloc>::node_pointer + rc<_Node, _Alloc>:: + top() const + { + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!empty()); + return *(m_a_entries + m_over_top - 1); + } + + template<typename _Node, typename _Alloc> + inline bool + rc<_Node, _Alloc>:: + empty() const + { + PB_DS_ASSERT_VALID((*this)) + return m_over_top == 0; + } + + template<typename _Node, typename _Alloc> + inline typename rc<_Node, _Alloc>::size_type + rc<_Node, _Alloc>:: + size() const + { return m_over_top; } + + template<typename _Node, typename _Alloc> + void + rc<_Node, _Alloc>:: + clear() + { + PB_DS_ASSERT_VALID((*this)) + m_over_top = 0; + PB_DS_ASSERT_VALID((*this)) + } + + template<typename _Node, typename _Alloc> + const typename rc<_Node, _Alloc>::const_iterator + rc<_Node, _Alloc>:: + begin() const + { return& m_a_entries[0]; } + + template<typename _Node, typename _Alloc> + const typename rc<_Node, _Alloc>::const_iterator + rc<_Node, _Alloc>:: + end() const + { return& m_a_entries[m_over_top]; } + +#ifdef _GLIBCXX_DEBUG + template<typename _Node, typename _Alloc> + void + rc<_Node, _Alloc>:: + assert_valid(const char* __file, int __line) const + { PB_DS_DEBUG_VERIFY(m_over_top < max_entries); } +#endif + +#ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_ + template<typename _Node, typename _Alloc> + void + rc<_Node, _Alloc>:: + trace() const + { + std::cout << "rc" << std::endl; + for (size_type i = 0; i < m_over_top; ++i) + std::cerr << m_a_entries[i] << std::endl; + std::cout << std::endl; + } +#endif +} // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/rc_binomial_heap_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/rc_binomial_heap_.hpp new file mode 100644 index 0000000..189e92e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/rc_binomial_heap_.hpp @@ -0,0 +1,171 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rc_binomial_heap_/rc_binomial_heap_.hpp + * Contains an implementation for redundant-counter binomial heap. + */ + +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/binomial_heap_base_/binomial_heap_base_.hpp> +#include <ext/pb_ds/detail/rc_binomial_heap_/rc.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + rc_binomial_heap<Value_Type, Cmp_Fn, _Alloc> + +#define PB_DS_RC_C_DEC \ + rc<typename binomial_heap_base<Value_Type, Cmp_Fn, _Alloc>::node, _Alloc> + + /** + * Redundant-counter binomial heap. + * + * @ingroup heap-detail + */ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + class rc_binomial_heap + : public binomial_heap_base<Value_Type, Cmp_Fn, _Alloc> + { + private: + typedef binomial_heap_base<Value_Type, Cmp_Fn, _Alloc> + base_type; + typedef typename base_type::node_pointer node_pointer; + typedef typename base_type::node_const_pointer node_const_pointer; + typedef PB_DS_RC_C_DEC rc_t; + + public: + typedef Value_Type value_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef typename base_type::pointer pointer; + typedef typename base_type::const_pointer const_pointer; + typedef typename base_type::reference reference; + typedef typename base_type::const_reference const_reference; + typedef typename base_type::point_const_iterator point_const_iterator; + typedef typename base_type::point_iterator point_iterator; + typedef typename base_type::const_iterator const_iterator; + typedef typename base_type::iterator iterator; + typedef typename base_type::cmp_fn cmp_fn; + typedef typename base_type::allocator_type allocator_type; + + rc_binomial_heap(); + + rc_binomial_heap(const Cmp_Fn&); + + rc_binomial_heap(const PB_DS_CLASS_C_DEC&); + + ~rc_binomial_heap(); + + void + swap(PB_DS_CLASS_C_DEC&); + + inline point_iterator + push(const_reference); + + void + modify(point_iterator, const_reference); + + inline void + pop(); + + void + erase(point_iterator); + + inline void + clear(); + + template<typename Pred> + size_type + erase_if(Pred); + + template<typename Pred> + void + split(Pred, PB_DS_CLASS_C_DEC&); + + void + join(PB_DS_CLASS_C_DEC&); + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; +#endif + +#ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_ + void + trace() const; +#endif + + private: + + inline node_pointer + link_with_next_sibling(node_pointer); + + void + make_0_exposed(); + + void + make_binomial_heap(); + +#ifdef _GLIBCXX_DEBUG + static node_const_pointer + next_2_pointer(node_const_pointer); + + static node_const_pointer + next_after_0_pointer(node_const_pointer); +#endif + + rc_t m_rc; + }; + +#include <ext/pb_ds/detail/rc_binomial_heap_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/rc_binomial_heap_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/rc_binomial_heap_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/rc_binomial_heap_/trace_fn_imps.hpp> +#include <ext/pb_ds/detail/rc_binomial_heap_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/rc_binomial_heap_/split_join_fn_imps.hpp> + +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_RC_C_DEC + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/split_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/split_join_fn_imps.hpp new file mode 100644 index 0000000..9497226 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/split_join_fn_imps.hpp @@ -0,0 +1,77 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rc_binomial_heap_/split_join_fn_imps.hpp + * Contains an implementation for rc_binomial_heap_. + */ + +PB_DS_CLASS_T_DEC +template<typename Pred> +void +PB_DS_CLASS_C_DEC:: +split(Pred pred, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + make_binomial_heap(); + other.make_binomial_heap(); + base_type::split(pred, other); + base_type::find_max(); + other.find_max(); + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +join(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + make_binomial_heap(); + other.make_binomial_heap(); + base_type::join(other); + base_type::find_max(); + other.find_max(); + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/trace_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/trace_fn_imps.hpp new file mode 100644 index 0000000..e4dfd3a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/rc_binomial_heap_/trace_fn_imps.hpp @@ -0,0 +1,52 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file rc_binomial_heap_/trace_fn_imps.hpp + * Contains an implementation for rc_binomial_heap_. + */ + +#ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace() const +{ + base_type::trace(); + m_rc.trace(); +} + +#endif // #ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_ diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/cc_hash_max_collision_check_resize_trigger_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/cc_hash_max_collision_check_resize_trigger_imp.hpp new file mode 100644 index 0000000..3ffe2c5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/cc_hash_max_collision_check_resize_trigger_imp.hpp @@ -0,0 +1,211 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file cc_hash_max_collision_check_resize_trigger_imp.hpp + * Contains a resize trigger implementation. + */ + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +cc_hash_max_collision_check_resize_trigger(float load) : + m_load(load), + m_size(0), + m_num_col(0), + m_max_col(0), + m_resize_needed(false) +{ } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_find_search_start() +{ } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_find_search_collision() +{ } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_find_search_end() +{ } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_insert_search_start() +{ m_num_col = 0; } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_insert_search_collision() +{ ++m_num_col; } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_insert_search_end() +{ calc_resize_needed(); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erase_search_start() +{ } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erase_search_collision() +{ } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erase_search_end() +{ } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_inserted(size_type) +{ } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erased(size_type) +{ m_resize_needed = true; } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +notify_cleared() +{ m_resize_needed = false; } + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +is_resize_needed() const +{ return m_resize_needed; } + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +is_grow_needed(size_type /*size*/, size_type /*num_used_e*/) const +{ return m_num_col >= m_max_col; } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +notify_resized(size_type new_size) +{ + m_size = new_size; + +#ifdef PB_DS_HT_MAP_RESIZE_TRACE_ + std::cerr << "chmccrt::notify_resized " + << static_cast<unsigned long>(new_size) << std::endl; +#endif + + calc_max_num_coll(); + calc_resize_needed(); + m_num_col = 0; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +calc_max_num_coll() +{ + // max_col <-- \sqrt{2 load \ln( 2 m \ln( m ) ) } + const double ln_arg = 2 * m_size * std::log(double(m_size)); + m_max_col = size_type(std::ceil(std::sqrt(2 * m_load * std::log(ln_arg)))); + +#ifdef PB_DS_HT_MAP_RESIZE_TRACE_ + std::cerr << "chmccrt::calc_max_num_coll " + << static_cast<unsigned long>(m_size) << " " + << static_cast<unsigned long>(m_max_col) << std::endl; +#endif +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +notify_externally_resized(size_type new_size) +{ notify_resized(new_size); } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + std::swap(m_load, other.m_load); + std::swap(m_size, other.m_size); + std::swap(m_num_col, other.m_num_col); + std::swap(m_max_col, other.m_max_col); + std::swap(m_resize_needed, other.m_resize_needed); +} + +PB_DS_CLASS_T_DEC +inline float +PB_DS_CLASS_C_DEC:: +get_load() const +{ + PB_DS_STATIC_ASSERT(access, external_load_access); + return m_load; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +calc_resize_needed() +{ m_resize_needed = m_resize_needed || m_num_col >= m_max_col; } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +set_load(float load) +{ + PB_DS_STATIC_ASSERT(access, external_load_access); + m_load = load; + calc_max_num_coll(); + calc_resize_needed(); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_exponential_size_policy_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_exponential_size_policy_imp.hpp new file mode 100644 index 0000000..a30a1ab --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_exponential_size_policy_imp.hpp @@ -0,0 +1,90 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file hash_exponential_size_policy_imp.hpp + * Contains a resize size policy implementation. + */ + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +hash_exponential_size_policy(size_type start_size, size_type grow_factor) : + m_start_size(start_size), + m_grow_factor(grow_factor) +{ } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + std::swap(m_start_size, other.m_start_size); + std::swap(m_grow_factor, other.m_grow_factor); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +get_nearest_larger_size(size_type size) const +{ + size_type ret = m_start_size; + while (ret <= size) + { + const size_type next_ret = ret* m_grow_factor; + if (next_ret < ret) + __throw_insert_error(); + ret = next_ret; + } + return ret; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +get_nearest_smaller_size(size_type size) const +{ + size_type ret = m_start_size; + while (true) + { + const size_type next_ret = ret* m_grow_factor; + if (next_ret < ret) + __throw_resize_error(); + if (next_ret >= size) + return (ret); + ret = next_ret; + } + return ret; +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_imp.hpp new file mode 100644 index 0000000..a20289a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_imp.hpp @@ -0,0 +1,293 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file hash_load_check_resize_trigger_imp.hpp + * Contains a resize trigger implementation. + */ + +#define PB_DS_ASSERT_VALID(X) \ + _GLIBCXX_DEBUG_ONLY(X.assert_valid(__FILE__, __LINE__);) + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +hash_load_check_resize_trigger(float load_min, float load_max) +: m_load_min(load_min), m_load_max(load_max), m_next_shrink_size(0), + m_next_grow_size(0), m_resize_needed(false) +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_find_search_start() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_find_search_collision() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_find_search_end() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_insert_search_start() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_insert_search_collision() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_insert_search_end() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erase_search_start() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erase_search_collision() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erase_search_end() +{ PB_DS_ASSERT_VALID((*this)) } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_inserted(size_type num_entries) +{ + m_resize_needed = (num_entries >= m_next_grow_size); + size_base::set_size(num_entries); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erased(size_type num_entries) +{ + size_base::set_size(num_entries); + m_resize_needed = num_entries <= m_next_shrink_size; + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +is_resize_needed() const +{ + PB_DS_ASSERT_VALID((*this)) + return m_resize_needed; +} + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +is_grow_needed(size_type /*size*/, size_type num_entries) const +{ + _GLIBCXX_DEBUG_ASSERT(m_resize_needed); + return num_entries >= m_next_grow_size; +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~hash_load_check_resize_trigger() { } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +notify_resized(size_type new_size) +{ + m_resize_needed = false; + m_next_grow_size = size_type(m_load_max * new_size - 1); + m_next_shrink_size = size_type(m_load_min * new_size); + +#ifdef PB_DS_HT_MAP_RESIZE_TRACE_ + std::cerr << "hlcrt::notify_resized " << std::endl + << "1 " << new_size << std::endl + << "2 " << m_load_min << std::endl + << "3 " << m_load_max << std::endl + << "4 " << m_next_shrink_size << std::endl + << "5 " << m_next_grow_size << std::endl; +#endif + + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +notify_externally_resized(size_type new_size) +{ + m_resize_needed = false; + size_type new_grow_size = size_type(m_load_max * new_size - 1); + size_type new_shrink_size = size_type(m_load_min * new_size); + +#ifdef PB_DS_HT_MAP_RESIZE_TRACE_ + std::cerr << "hlcrt::notify_externally_resized " << std::endl + << "1 " << new_size << std::endl + << "2 " << m_load_min << std::endl + << "3 " << m_load_max << std::endl + << "4 " << m_next_shrink_size << std::endl + << "5 " << m_next_grow_size << std::endl + << "6 " << new_shrink_size << std::endl + << "7 " << new_grow_size << std::endl; +#endif + + if (new_grow_size >= m_next_grow_size) + { + _GLIBCXX_DEBUG_ASSERT(new_shrink_size >= m_next_shrink_size); + m_next_grow_size = new_grow_size; + } + else + { + _GLIBCXX_DEBUG_ASSERT(new_shrink_size <= m_next_shrink_size); + m_next_shrink_size = new_shrink_size; + } + + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +notify_cleared() +{ + PB_DS_ASSERT_VALID((*this)) + size_base::set_size(0); + m_resize_needed = (0 < m_next_shrink_size); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + size_base::swap(other); + std::swap(m_load_min, other.m_load_min); + std::swap(m_load_max, other.m_load_max); + std::swap(m_resize_needed, other.m_resize_needed); + std::swap(m_next_grow_size, other.m_next_grow_size); + std::swap(m_next_shrink_size, other.m_next_shrink_size); + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +inline std::pair<float, float> +PB_DS_CLASS_C_DEC:: +get_loads() const +{ + PB_DS_STATIC_ASSERT(access, external_load_access); + return std::make_pair(m_load_min, m_load_max); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +set_loads(std::pair<float, float> load_pair) +{ + PB_DS_STATIC_ASSERT(access, external_load_access); + const float old_load_min = m_load_min; + const float old_load_max = m_load_max; + const size_type old_next_shrink_size = m_next_shrink_size; + const size_type old_next_grow_size = m_next_grow_size; + const bool old_resize_needed = m_resize_needed; + + __try + { + m_load_min = load_pair.first; + m_load_max = load_pair.second; + do_resize(static_cast<size_type>(size_base::get_size() / ((m_load_min + m_load_max) / 2))); + } + __catch(...) + { + m_load_min = old_load_min; + m_load_max = old_load_max; + m_next_shrink_size = old_next_shrink_size; + m_next_grow_size = old_next_grow_size; + m_resize_needed = old_resize_needed; + __throw_exception_again; + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +do_resize(size_type) +{ std::abort(); } + +#ifdef _GLIBCXX_DEBUG +# define PB_DS_DEBUG_VERIFY(_Cond) \ + _GLIBCXX_DEBUG_VERIFY_AT(_Cond, \ + _M_message(#_Cond" assertion from %1;:%2;") \ + ._M_string(__FILE__)._M_integer(__LINE__) \ + ,__file,__line) + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + PB_DS_DEBUG_VERIFY(m_load_max > m_load_min); + PB_DS_DEBUG_VERIFY(m_next_grow_size >= m_next_shrink_size); +} +# undef PB_DS_DEBUG_VERIFY +#endif +#undef PB_DS_ASSERT_VALID diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_size_base.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_size_base.hpp new file mode 100644 index 0000000..9670472 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_size_base.hpp @@ -0,0 +1,94 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file hash_load_check_resize_trigger_size_base.hpp + * Contains an base holding size for some resize policies. + */ + +#ifndef PB_DS_HASH_LOAD_CHECK_RESIZE_TRIGGER_SIZE_BASE_HPP +#define PB_DS_HASH_LOAD_CHECK_RESIZE_TRIGGER_SIZE_BASE_HPP + +namespace __gnu_pbds +{ + namespace detail + { + /// Primary template. + template<typename Size_Type, bool Hold_Size> + class hash_load_check_resize_trigger_size_base; + + /// Specializations. + template<typename Size_Type> + class hash_load_check_resize_trigger_size_base<Size_Type, true> + { + protected: + typedef Size_Type size_type; + + hash_load_check_resize_trigger_size_base(): m_size(0) + { } + + inline void + swap(hash_load_check_resize_trigger_size_base& other) + { std::swap(m_size, other.m_size); } + + inline void + set_size(size_type size) + { m_size = size; } + + inline size_type + get_size() const + { return m_size; } + + private: + size_type m_size; + }; + + template<typename Size_Type> + class hash_load_check_resize_trigger_size_base<Size_Type, false> + { + protected: + typedef Size_Type size_type; + + protected: + inline void + swap(hash_load_check_resize_trigger_size_base& other) { } + + inline void + set_size(size_type size) { } + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp new file mode 100644 index 0000000..ad27f58 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp @@ -0,0 +1,161 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file hash_prime_size_policy_imp.hpp + * Contains a resize size policy implementation. + */ + +#pragma GCC system_header + +namespace detail +{ + enum + { + num_distinct_sizes_32_bit = 30, + num_distinct_sizes_64_bit = 62, + num_distinct_sizes = sizeof(std::size_t) != 8 ? + num_distinct_sizes_32_bit : num_distinct_sizes_64_bit, + }; + + // Originally taken from the SGI implementation; acknowledged in the docs. + // Further modified (for 64 bits) from tr1's hashtable. + static const std::size_t g_a_sizes[num_distinct_sizes_64_bit] = + { + /* 0 */ 5ul, + /* 1 */ 11ul, + /* 2 */ 23ul, + /* 3 */ 47ul, + /* 4 */ 97ul, + /* 5 */ 199ul, + /* 6 */ 409ul, + /* 7 */ 823ul, + /* 8 */ 1741ul, + /* 9 */ 3469ul, + /* 10 */ 6949ul, + /* 11 */ 14033ul, + /* 12 */ 28411ul, + /* 13 */ 57557ul, + /* 14 */ 116731ul, + /* 15 */ 236897ul, + /* 16 */ 480881ul, + /* 17 */ 976369ul, + /* 18 */ 1982627ul, + /* 19 */ 4026031ul, + /* 20 */ 8175383ul, + /* 21 */ 16601593ul, + /* 22 */ 33712729ul, + /* 23 */ 68460391ul, + /* 24 */ 139022417ul, + /* 25 */ 282312799ul, + /* 26 */ 573292817ul, + /* 27 */ 1164186217ul, + /* 28 */ 2364114217ul, + /* 29 */ 4294967291ul, + /* 30 */ (std::size_t)8589934583ull, + /* 31 */ (std::size_t)17179869143ull, + /* 32 */ (std::size_t)34359738337ull, + /* 33 */ (std::size_t)68719476731ull, + /* 34 */ (std::size_t)137438953447ull, + /* 35 */ (std::size_t)274877906899ull, + /* 36 */ (std::size_t)549755813881ull, + /* 37 */ (std::size_t)1099511627689ull, + /* 38 */ (std::size_t)2199023255531ull, + /* 39 */ (std::size_t)4398046511093ull, + /* 40 */ (std::size_t)8796093022151ull, + /* 41 */ (std::size_t)17592186044399ull, + /* 42 */ (std::size_t)35184372088777ull, + /* 43 */ (std::size_t)70368744177643ull, + /* 44 */ (std::size_t)140737488355213ull, + /* 45 */ (std::size_t)281474976710597ull, + /* 46 */ (std::size_t)562949953421231ull, + /* 47 */ (std::size_t)1125899906842597ull, + /* 48 */ (std::size_t)2251799813685119ull, + /* 49 */ (std::size_t)4503599627370449ull, + /* 50 */ (std::size_t)9007199254740881ull, + /* 51 */ (std::size_t)18014398509481951ull, + /* 52 */ (std::size_t)36028797018963913ull, + /* 53 */ (std::size_t)72057594037927931ull, + /* 54 */ (std::size_t)144115188075855859ull, + /* 55 */ (std::size_t)288230376151711717ull, + /* 56 */ (std::size_t)576460752303423433ull, + /* 57 */ (std::size_t)1152921504606846883ull, + /* 58 */ (std::size_t)2305843009213693951ull, + /* 59 */ (std::size_t)4611686018427387847ull, + /* 60 */ (std::size_t)9223372036854775783ull, + /* 61 */ (std::size_t)18446744073709551557ull, + }; + +} // namespace detail + +PB_DS_CLASS_T_DEC +inline +PB_DS_CLASS_C_DEC:: +hash_prime_size_policy(size_type n) : m_start_size(n) +{ m_start_size = get_nearest_larger_size(n); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ std::swap(m_start_size, other.m_start_size); } + +PB_DS_CLASS_T_DEC +inline PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +get_nearest_larger_size(size_type n) const +{ + const std::size_t* const p_upper = std::upper_bound(detail::g_a_sizes, + detail::g_a_sizes + detail::num_distinct_sizes, n); + + if (p_upper == detail::g_a_sizes + detail::num_distinct_sizes) + __throw_resize_error(); + return *p_upper; +} + +PB_DS_CLASS_T_DEC +inline PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +get_nearest_smaller_size(size_type n) const +{ + const std::size_t* p_lower = std::lower_bound(detail::g_a_sizes, + detail::g_a_sizes + detail::num_distinct_sizes, n); + + if (*p_lower >= n && p_lower != detail::g_a_sizes) + --p_lower; + if (*p_lower < m_start_size) + return m_start_size; + return *p_lower; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_standard_resize_policy_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_standard_resize_policy_imp.hpp new file mode 100644 index 0000000..16a76f6 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_standard_resize_policy_imp.hpp @@ -0,0 +1,249 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file hash_standard_resize_policy_imp.hpp + * Contains a resize policy implementation. + */ + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +hash_standard_resize_policy() +: m_size(Size_Policy::get_nearest_larger_size(1)) +{ trigger_policy_base::notify_externally_resized(m_size); } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +hash_standard_resize_policy(const Size_Policy& r_size_policy) +: Size_Policy(r_size_policy), m_size(Size_Policy::get_nearest_larger_size(1)) +{ trigger_policy_base::notify_externally_resized(m_size); } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +hash_standard_resize_policy(const Size_Policy& r_size_policy, + const Trigger_Policy& r_trigger_policy) +: Size_Policy(r_size_policy), Trigger_Policy(r_trigger_policy), + m_size(Size_Policy::get_nearest_larger_size(1)) +{ trigger_policy_base::notify_externally_resized(m_size); } + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~hash_standard_resize_policy() +{ } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + trigger_policy_base::swap(other); + size_policy_base::swap(other); + std::swap(m_size, other.m_size); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_find_search_start() +{ trigger_policy_base::notify_find_search_start(); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_find_search_collision() +{ trigger_policy_base::notify_find_search_collision(); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_find_search_end() +{ trigger_policy_base::notify_find_search_end(); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_insert_search_start() +{ trigger_policy_base::notify_insert_search_start(); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_insert_search_collision() +{ trigger_policy_base::notify_insert_search_collision(); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_insert_search_end() +{ trigger_policy_base::notify_insert_search_end(); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erase_search_start() +{ trigger_policy_base::notify_erase_search_start(); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erase_search_collision() +{ trigger_policy_base::notify_erase_search_collision(); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erase_search_end() +{ trigger_policy_base::notify_erase_search_end(); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_inserted(size_type num_e) +{ trigger_policy_base::notify_inserted(num_e); } + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +notify_erased(size_type num_e) +{ trigger_policy_base::notify_erased(num_e); } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +notify_cleared() +{ trigger_policy_base::notify_cleared(); } + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +is_resize_needed() const +{ return trigger_policy_base::is_resize_needed(); } + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +get_new_size(size_type size, size_type num_used_e) const +{ + if (trigger_policy_base::is_grow_needed(size, num_used_e)) + return size_policy_base::get_nearest_larger_size(size); + return size_policy_base::get_nearest_smaller_size(size); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +notify_resized(size_type new_size) +{ + trigger_policy_base::notify_resized(new_size); + m_size = new_size; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +get_actual_size() const +{ + PB_DS_STATIC_ASSERT(access, external_size_access); + return m_size; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +resize(size_type new_size) +{ + PB_DS_STATIC_ASSERT(access, external_size_access); + size_type actual_size = size_policy_base::get_nearest_larger_size(1); + while (actual_size < new_size) + { + const size_type pot = size_policy_base::get_nearest_larger_size(actual_size); + + if (pot == actual_size && pot < new_size) + __throw_resize_error(); + actual_size = pot; + } + + if (actual_size > 0) + --actual_size; + + const size_type old_size = m_size; + __try + { + do_resize(actual_size - 1); + } + __catch(insert_error& ) + { + m_size = old_size; + __throw_resize_error(); + } + __catch(...) + { + m_size = old_size; + __throw_exception_again; + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +do_resize(size_type) +{ + // Do nothing +} + +PB_DS_CLASS_T_DEC +Trigger_Policy& +PB_DS_CLASS_C_DEC:: +get_trigger_policy() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Trigger_Policy& +PB_DS_CLASS_C_DEC:: +get_trigger_policy() const +{ return *this; } + +PB_DS_CLASS_T_DEC +Size_Policy& +PB_DS_CLASS_C_DEC:: +get_size_policy() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Size_Policy& +PB_DS_CLASS_C_DEC:: +get_size_policy() const +{ return *this; } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/sample_resize_policy.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/sample_resize_policy.hpp new file mode 100644 index 0000000..b42fee9 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/sample_resize_policy.hpp @@ -0,0 +1,125 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file sample_resize_policy.hpp + * Contains a sample resize policy for hash tables. + */ + +#ifndef PB_DS_SAMPLE_RESIZE_POLICY_HPP +#define PB_DS_SAMPLE_RESIZE_POLICY_HPP + +namespace __gnu_pbds +{ + /// A sample resize policy. + class sample_resize_policy + { + public: + /// Size type. + typedef std::size_t size_type; + + /// Default constructor. + sample_resize_policy(); + + /// Copy constructor. + sample_range_hashing(const sample_resize_policy& other); + + /// Swaps content. + inline void + swap(sample_resize_policy& other); + + protected: + /// Notifies a search started. + inline void + notify_insert_search_start(); + + /// Notifies a search encountered a collision. + inline void + notify_insert_search_collision(); + + /// Notifies a search ended. + inline void + notify_insert_search_end(); + + /// Notifies a search started. + inline void + notify_find_search_start(); + + /// Notifies a search encountered a collision. + inline void + notify_find_search_collision(); + + /// Notifies a search ended. + inline void + notify_find_search_end(); + + /// Notifies a search started. + inline void + notify_erase_search_start(); + + /// Notifies a search encountered a collision. + inline void + notify_erase_search_collision(); + + /// Notifies a search ended. + inline void + notify_erase_search_end(); + + /// Notifies an element was inserted. + inline void + notify_inserted(size_type num_e); + + /// Notifies an element was erased. + inline void + notify_erased(size_type num_e); + + /// Notifies the table was cleared. + void + notify_cleared(); + + /// Notifies the table was resized to new_size. + void + notify_resized(size_type new_size); + + /// Queries whether a resize is needed. + inline bool + is_resize_needed() const; + + /// Queries what the new size should be. + size_type + get_new_size(size_type size, size_type num_used_e) const; + }; +} +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/sample_resize_trigger.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/sample_resize_trigger.hpp new file mode 100644 index 0000000..2dc587f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/sample_resize_trigger.hpp @@ -0,0 +1,136 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file sample_resize_trigger.hpp + * Contains a sample resize trigger policy class. + */ + +#ifndef PB_DS_SAMPLE_RESIZE_TRIGGER_HPP +#define PB_DS_SAMPLE_RESIZE_TRIGGER_HPP + +namespace __gnu_pbds +{ + /// A sample resize trigger policy. + class sample_resize_trigger + { + public: + /// Size type. + typedef std::size_t size_type; + + /// Default constructor. + sample_resize_trigger(); + + /// Copy constructor. + sample_range_hashing(const sample_resize_trigger&); + + /// Swaps content. + inline void + swap(sample_resize_trigger&); + + protected: + /// Notifies a search started. + inline void + notify_insert_search_start(); + + /// Notifies a search encountered a collision. + inline void + notify_insert_search_collision(); + + /// Notifies a search ended. + inline void + notify_insert_search_end(); + + /// Notifies a search started. + inline void + notify_find_search_start(); + + /// Notifies a search encountered a collision. + inline void + notify_find_search_collision(); + + /// Notifies a search ended. + inline void + notify_find_search_end(); + + /// Notifies a search started. + inline void + notify_erase_search_start(); + + /// Notifies a search encountered a collision. + inline void + notify_erase_search_collision(); + + /// Notifies a search ended. + inline void + notify_erase_search_end(); + + /// Notifies an element was inserted. the total number of entries in + /// the table is num_entries. + inline void + notify_inserted(size_type num_entries); + + /// Notifies an element was erased. + inline void + notify_erased(size_type num_entries); + + /// Notifies the table was cleared. + void + notify_cleared(); + + /// Notifies the table was resized as a result of this object's + /// signifying that a resize is needed. + void + notify_resized(size_type new_size); + + /// Notifies the table was resized externally. + void + notify_externally_resized(size_type new_size); + + /// Queries whether a resize is needed. + inline bool + is_resize_needed() const; + + /// Queries whether a grow is needed. + inline bool + is_grow_needed(size_type size, size_type num_entries) const; + + private: + /// Resizes to new_size. + virtual void + do_resize(size_type); + }; +} +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/sample_size_policy.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/sample_size_policy.hpp new file mode 100644 index 0000000..3558a0d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/resize_policy/sample_size_policy.hpp @@ -0,0 +1,73 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file sample_size_policy.hpp + * Contains a sample size resize-policy. + */ + +#ifndef PB_DS_SAMPLE_SIZE_POLICY_HPP +#define PB_DS_SAMPLE_SIZE_POLICY_HPP + +namespace __gnu_pbds +{ + /// A sample size policy. + class sample_size_policy + { + public: + /// Size type. + typedef std::size_t size_type; + + /// Default constructor. + sample_size_policy(); + + /// Copy constructor. + sample_range_hashing(const sample_size_policy&); + + /// Swaps content. + inline void + swap(sample_size_policy& other); + + protected: + /// Given a __size size, returns a __size that is larger. + inline size_type + get_nearest_larger_size(size_type size) const; + + /// Given a __size size, returns a __size that is smaller. + inline size_type + get_nearest_smaller_size(size_type size) const; + }; +} +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..2d14055 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,102 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/constructors_destructor_fn_imps.hpp + * Contains an implementation class for splay_tree_. + */ + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + insert(*(first_it++)); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_S_TREE_NAME() +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_S_TREE_NAME(const Cmp_Fn& r_cmp_fn) : + base_type(r_cmp_fn) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_S_TREE_NAME(const Cmp_Fn& r_cmp_fn, const node_update& r_node_update) : + base_type(r_cmp_fn, r_node_update) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +PB_DS_S_TREE_NAME(const PB_DS_CLASS_C_DEC& other) : + base_type(other) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + base_type::swap(other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +initialize() +{ base_type::m_p_head->m_special = true; } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/debug_fn_imps.hpp new file mode 100644 index 0000000..0eaaa73 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/debug_fn_imps.hpp @@ -0,0 +1,75 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/debug_fn_imps.hpp + * Contains an implementation class for splay_tree_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + base_type::assert_valid(__file, __line); + const node_pointer p_head = base_type::m_p_head; + assert_special_imp(p_head, __file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_special_imp(const node_pointer p_nd, + const char* __file, int __line) const +{ + if (p_nd == 0) + return; + + if (p_nd == base_type::m_p_head) + { + PB_DS_DEBUG_VERIFY(p_nd->m_special); + assert_special_imp(p_nd->m_p_parent, __file, __line); + return; + } + + PB_DS_DEBUG_VERIFY(!p_nd->m_special); + assert_special_imp(p_nd->m_p_left, __file, __line); + assert_special_imp(p_nd->m_p_right, __file, __line); +} + +#endif + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/erase_fn_imps.hpp new file mode 100644 index 0000000..ef7151c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/erase_fn_imps.hpp @@ -0,0 +1,157 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/erase_fn_imps.hpp + * Contains an implementation class for splay_tree_. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +erase(key_const_reference r_key) +{ + point_iterator it = find(r_key); + if (it == base_type::end()) + return false; + erase(it); + return true; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +erase(iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + if (it == base_type::end()) + return it; + iterator ret_it = it; + ++ret_it; + erase_node(it.m_p_nd); + PB_DS_ASSERT_VALID((*this)) + return ret_it; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::reverse_iterator +PB_DS_CLASS_C_DEC:: +erase(reverse_iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + if (it.m_p_nd == base_type::m_p_head) + return (it); + reverse_iterator ret_it = it; + ++ret_it; + erase_node(it.m_p_nd); + PB_DS_ASSERT_VALID((*this)) + return ret_it; +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + PB_DS_ASSERT_VALID((*this)) + size_type num_ersd = 0; + iterator it = base_type::begin(); + while (it != base_type::end()) + { + if (pred(*it)) + { + ++num_ersd; + it = erase(it); + } + else + ++it; + } + PB_DS_ASSERT_VALID((*this)) + return num_ersd; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase_node(node_pointer p_nd) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + splay(p_nd); + + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(p_nd == this->m_p_head->m_p_parent); + + node_pointer p_l = p_nd->m_p_left; + node_pointer p_r = p_nd->m_p_right; + + base_type::update_min_max_for_erased_node(p_nd); + base_type::actual_erase_node(p_nd); + if (p_r == 0) + { + base_type::m_p_head->m_p_parent = p_l; + if (p_l != 0) + p_l->m_p_parent = base_type::m_p_head; + PB_DS_ASSERT_VALID((*this)) + return; + } + + node_pointer p_target_r = leftmost(p_r); + _GLIBCXX_DEBUG_ASSERT(p_target_r != 0); + p_r->m_p_parent = base_type::m_p_head; + base_type::m_p_head->m_p_parent = p_r; + splay(p_target_r); + + _GLIBCXX_DEBUG_ONLY(p_target_r->m_p_left = 0); + _GLIBCXX_DEBUG_ASSERT(p_target_r->m_p_parent == this->m_p_head); + _GLIBCXX_DEBUG_ASSERT(this->m_p_head->m_p_parent == p_target_r); + + p_target_r->m_p_left = p_l; + if (p_l != 0) + p_l->m_p_parent = p_target_r; + PB_DS_ASSERT_VALID((*this)) + this->apply_update(p_target_r, (node_update*)this); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +leftmost(node_pointer p_nd) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + while (p_nd->m_p_left != 0) + p_nd = p_nd->m_p_left; + return p_nd; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/find_fn_imps.hpp new file mode 100644 index 0000000..8cc0bb1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/find_fn_imps.hpp @@ -0,0 +1,100 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/find_fn_imps.hpp + * Contains an implementation class for splay_tree_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +find(key_const_reference r_key) +{ + node_pointer p_found = find_imp(r_key); + if (p_found != base_type::m_p_head) + splay(p_found); + return point_iterator(p_found); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_const_iterator +PB_DS_CLASS_C_DEC:: +find(key_const_reference r_key) const +{ + const node_pointer p_found = find_imp(r_key); + if (p_found != base_type::m_p_head) + const_cast<PB_DS_CLASS_C_DEC* >(this)->splay(p_found); + return point_iterator(p_found); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +find_imp(key_const_reference r_key) +{ + _GLIBCXX_DEBUG_ONLY(base_type::structure_only_assert_valid(__FILE__, + __LINE__);) + node_pointer p_nd = base_type::m_p_head->m_p_parent; + while (p_nd != 0) + if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) + { + if (!Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value))) + return p_nd; + p_nd = p_nd->m_p_left; + } + else + p_nd = p_nd->m_p_right; + return base_type::m_p_head; +} + +PB_DS_CLASS_T_DEC +inline const typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +find_imp(key_const_reference r_key) const +{ + PB_DS_ASSERT_VALID((*this)) + node_pointer p_nd = base_type::m_p_head->m_p_parent; + while (p_nd != 0) + if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), r_key)) + { + if (!Cmp_Fn::operator()(r_key, PB_DS_V2F(p_nd->m_value))) + return p_nd; + p_nd = p_nd->m_p_left; + } + else + p_nd = p_nd->m_p_right; + return base_type::m_p_head; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/info_fn_imps.hpp new file mode 100644 index 0000000..aacff32 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/info_fn_imps.hpp @@ -0,0 +1,39 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/info_fn_imps.hpp + * Contains an implementation. + */ diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/insert_fn_imps.hpp new file mode 100644 index 0000000..62f7d0a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/insert_fn_imps.hpp @@ -0,0 +1,94 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/insert_fn_imps.hpp + * Contains an implementation class for splay_tree_. + */ + +PB_DS_CLASS_T_DEC +inline std::pair<typename PB_DS_CLASS_C_DEC::point_iterator, bool> +PB_DS_CLASS_C_DEC:: +insert(const_reference r_value) +{ + PB_DS_ASSERT_VALID((*this)) + std::pair<point_iterator, bool> ins_pair = insert_leaf_imp(r_value); + ins_pair.first.m_p_nd->m_special = false; + PB_DS_ASSERT_VALID((*this)) + splay(ins_pair.first.m_p_nd); + PB_DS_ASSERT_VALID((*this)) + return ins_pair; +} + +PB_DS_CLASS_T_DEC +inline std::pair<typename PB_DS_CLASS_C_DEC::point_iterator, bool> +PB_DS_CLASS_C_DEC:: +insert_leaf_imp(const_reference r_value) +{ + _GLIBCXX_DEBUG_ONLY(base_type::structure_only_assert_valid(__FILE__, + __LINE__);) + if (base_type::m_size == 0) + return std::make_pair(base_type::insert_imp_empty(r_value), true); + + node_pointer p_nd = base_type::m_p_head->m_p_parent; + node_pointer p_pot = base_type::m_p_head; + + while (p_nd != 0) + if (!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value), PB_DS_V2F(r_value))) + { + if (!Cmp_Fn::operator()(PB_DS_V2F(r_value), PB_DS_V2F(p_nd->m_value))) + { + return std::make_pair(point_iterator(p_nd), false); + } + p_pot = p_nd; + p_nd = p_nd->m_p_left; + } + else + p_nd = p_nd->m_p_right; + + if (p_pot == base_type::m_p_head) + return std::make_pair(base_type::insert_leaf_new(r_value, base_type::m_p_head->m_p_right, false), true); + + PB_DS_CHECK_KEY_DOES_NOT_EXIST(PB_DS_V2F(r_value)) + + p_nd = p_pot->m_p_left; + if (p_nd == 0) + return (std::make_pair(base_type::insert_leaf_new(r_value, p_pot, true), true)); + + while (p_nd->m_p_right != 0) + p_nd = p_nd->m_p_right; + + return std::make_pair(this->insert_leaf_new(r_value, p_nd, false), true); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/node.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/node.hpp new file mode 100644 index 0000000..9cb4cb5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/node.hpp @@ -0,0 +1,126 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/node.hpp + * Contains an implementation struct for splay_tree_'s node. + */ + +#ifndef PB_DS_SPLAY_TREE_NODE_HPP +#define PB_DS_SPLAY_TREE_NODE_HPP + +namespace __gnu_pbds +{ + namespace detail + { + /// Node for splay tree. + template<typename Value_Type, class Metadata, typename _Alloc> + struct splay_tree_node_ + { + public: + typedef Value_Type value_type; + typedef Metadata metadata_type; + + typedef + typename _Alloc::template rebind< + splay_tree_node_<Value_Type, Metadata, _Alloc> >::other::pointer + node_pointer; + + typedef + typename _Alloc::template rebind<metadata_type>::other::reference + metadata_reference; + + typedef + typename _Alloc::template rebind<metadata_type>::other::const_reference + metadata_const_reference; + +#ifdef PB_DS_BIN_SEARCH_TREE_TRACE_ + void + trace() const + { std::cout << PB_DS_V2F(m_value) << "(" << m_metadata << ")"; } +#endif + + inline bool + special() const + { return m_special; } + + inline metadata_const_reference + get_metadata() const + { return m_metadata; } + + inline metadata_reference + get_metadata() + { return m_metadata; } + + value_type m_value; + bool m_special; + node_pointer m_p_left; + node_pointer m_p_right; + node_pointer m_p_parent; + metadata_type m_metadata; + }; + + template<typename Value_Type, typename _Alloc> + struct splay_tree_node_<Value_Type, null_type, _Alloc> + { + public: + typedef Value_Type value_type; + typedef null_type metadata_type; + + typedef + typename _Alloc::template rebind< + splay_tree_node_<Value_Type, null_type, _Alloc> >::other::pointer + node_pointer; + + inline bool + special() const + { return m_special; } + +#ifdef PB_DS_BIN_SEARCH_TREE_TRACE_ + void + trace() const + { std::cout << PB_DS_V2F(m_value); } +#endif + + node_pointer m_p_left; + node_pointer m_p_right; + node_pointer m_p_parent; + value_type m_value; + bool m_special; + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/splay_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/splay_fn_imps.hpp new file mode 100644 index 0000000..10988a2 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/splay_fn_imps.hpp @@ -0,0 +1,281 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/splay_fn_imps.hpp + * Contains an implementation class for splay_tree_. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +splay(node_pointer p_nd) +{ + while (p_nd->m_p_parent != base_type::m_p_head) + { +#ifdef _GLIBCXX_DEBUG + { + node_pointer p_head = base_type::m_p_head; + assert_special_imp(p_head, __FILE__, __LINE__); + } +#endif + + PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_nd) + + if (p_nd->m_p_parent->m_p_parent == base_type::m_p_head) + { + base_type::rotate_parent(p_nd); + _GLIBCXX_DEBUG_ASSERT(p_nd == this->m_p_head->m_p_parent); + } + else + { + const node_pointer p_parent = p_nd->m_p_parent; + const node_pointer p_grandparent = p_parent->m_p_parent; + +#ifdef _GLIBCXX_DEBUG + const size_type total = + base_type::recursive_count(p_grandparent); + _GLIBCXX_DEBUG_ASSERT(total >= 3); +#endif + + if (p_parent->m_p_left == p_nd && + p_grandparent->m_p_right == p_parent) + splay_zig_zag_left(p_nd, p_parent, p_grandparent); + else if (p_parent->m_p_right == p_nd && + p_grandparent->m_p_left == p_parent) + splay_zig_zag_right(p_nd, p_parent, p_grandparent); + else if (p_parent->m_p_left == p_nd && + p_grandparent->m_p_left == p_parent) + splay_zig_zig_left(p_nd, p_parent, p_grandparent); + else + splay_zig_zig_right(p_nd, p_parent, p_grandparent); + _GLIBCXX_DEBUG_ASSERT(total ==this->recursive_count(p_nd)); + } + + PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_nd) + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +splay_zig_zag_left(node_pointer p_nd, node_pointer p_parent, + node_pointer p_grandparent) +{ + _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent); + _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent); + + PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent) + + _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_left == p_nd && + p_grandparent->m_p_right == p_parent); + + splay_zz_start(p_nd, p_parent, p_grandparent); + + node_pointer p_b = p_nd->m_p_right; + node_pointer p_c = p_nd->m_p_left; + + p_nd->m_p_right = p_parent; + p_parent->m_p_parent = p_nd; + + p_nd->m_p_left = p_grandparent; + p_grandparent->m_p_parent = p_nd; + + p_parent->m_p_left = p_b; + if (p_b != 0) + p_b->m_p_parent = p_parent; + + p_grandparent->m_p_right = p_c; + if (p_c != 0) + p_c->m_p_parent = p_grandparent; + + splay_zz_end(p_nd, p_parent, p_grandparent); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +splay_zig_zag_right(node_pointer p_nd, node_pointer p_parent, + node_pointer p_grandparent) +{ + _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent); + _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent); + + PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent) + + _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_right == p_nd && + p_grandparent->m_p_left == p_parent); + + splay_zz_start(p_nd, p_parent, p_grandparent); + + node_pointer p_b = p_nd->m_p_left; + node_pointer p_c = p_nd->m_p_right; + + p_nd->m_p_left = p_parent; + p_parent->m_p_parent = p_nd; + + p_nd->m_p_right = p_grandparent; + p_grandparent->m_p_parent = p_nd; + + p_parent->m_p_right = p_b; + if (p_b != 0) + p_b->m_p_parent = p_parent; + + p_grandparent->m_p_left = p_c; + if (p_c != 0) + p_c->m_p_parent = p_grandparent; + + splay_zz_end(p_nd, p_parent, p_grandparent); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +splay_zig_zig_left(node_pointer p_nd, node_pointer p_parent, + node_pointer p_grandparent) +{ + _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent); + _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent); + + PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent) + + _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_left == p_nd && + p_nd->m_p_parent->m_p_parent->m_p_left == p_nd->m_p_parent); + + splay_zz_start(p_nd, p_parent, p_grandparent); + + node_pointer p_b = p_nd->m_p_right; + node_pointer p_c = p_parent->m_p_right; + + p_nd->m_p_right = p_parent; + p_parent->m_p_parent = p_nd; + + p_parent->m_p_right = p_grandparent; + p_grandparent->m_p_parent = p_parent; + + p_parent->m_p_left = p_b; + if (p_b != 0) + p_b->m_p_parent = p_parent; + + p_grandparent->m_p_left = p_c; + if (p_c != 0) + p_c->m_p_parent = p_grandparent; + + splay_zz_end(p_nd, p_parent, p_grandparent); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +splay_zig_zig_right(node_pointer p_nd, node_pointer p_parent, + node_pointer p_grandparent) +{ + _GLIBCXX_DEBUG_ASSERT(p_parent == p_nd->m_p_parent); + _GLIBCXX_DEBUG_ASSERT(p_grandparent == p_parent->m_p_parent); + PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_grandparent) + _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_right == p_nd && + p_nd->m_p_parent->m_p_parent->m_p_right == p_nd->m_p_parent); + + splay_zz_start(p_nd, p_parent, p_grandparent); + + node_pointer p_b = p_nd->m_p_left; + node_pointer p_c = p_parent->m_p_left; + + p_nd->m_p_left = p_parent; + p_parent->m_p_parent = p_nd; + + p_parent->m_p_left = p_grandparent; + p_grandparent->m_p_parent = p_parent; + + p_parent->m_p_right = p_b; + if (p_b != 0) + p_b->m_p_parent = p_parent; + + p_grandparent->m_p_right = p_c; + if (p_c != 0) + p_c->m_p_parent = p_grandparent; + + base_type::update_to_top(p_grandparent, (node_update*)this); + splay_zz_end(p_nd, p_parent, p_grandparent); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +splay_zz_start(node_pointer p_nd, +#ifdef _GLIBCXX_DEBUG + node_pointer p_parent, +#else + node_pointer /*p_parent*/, +#endif + node_pointer p_grandparent) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + _GLIBCXX_DEBUG_ASSERT(p_parent != 0); + _GLIBCXX_DEBUG_ASSERT(p_grandparent != 0); + + const bool grandparent_head = p_grandparent->m_p_parent == base_type::m_p_head; + + if (grandparent_head) + { + base_type::m_p_head->m_p_parent = base_type::m_p_head->m_p_parent; + p_nd->m_p_parent = base_type::m_p_head; + return; + } + + node_pointer p_greatgrandparent = p_grandparent->m_p_parent; + + p_nd->m_p_parent = p_greatgrandparent; + + if (p_grandparent == p_greatgrandparent->m_p_left) + p_greatgrandparent->m_p_left = p_nd; + else + p_greatgrandparent->m_p_right = p_nd; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +splay_zz_end(node_pointer p_nd, node_pointer p_parent, + node_pointer p_grandparent) +{ + if (p_nd->m_p_parent == base_type::m_p_head) + base_type::m_p_head->m_p_parent = p_nd; + + this->apply_update(p_grandparent, (node_update*)this); + this->apply_update(p_parent, (node_update*)this); + this->apply_update(p_nd, (node_update*)this); + PB_DS_ASSERT_BASE_NODE_CONSISTENT(p_nd) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/splay_tree_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/splay_tree_.hpp new file mode 100644 index 0000000..e672793 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/splay_tree_.hpp @@ -0,0 +1,275 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/splay_tree_.hpp + * Contains an implementation class for splay trees. + */ +/* + * This implementation uses an idea from the SGI STL (using a @a header node + * which is needed for efficient iteration). Following is the SGI STL + * copyright. + * + * Copyright (c) 1996,1997 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * + * Copyright (c) 1994 + * Hewlett-Packard Company + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Hewlett-Packard Company makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * + */ + +#include <utility> +#include <vector> +#include <assert.h> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#ifdef PB_DS_DATA_TRUE_INDICATOR +# define PB_DS_S_TREE_NAME splay_tree_map +# define PB_DS_S_TREE_BASE_NAME bin_search_tree_map +#endif + +#ifdef PB_DS_DATA_FALSE_INDICATOR +# define PB_DS_S_TREE_NAME splay_tree_set +# define PB_DS_S_TREE_BASE_NAME bin_search_tree_set +#endif + +#define PB_DS_CLASS_T_DEC \ + template<typename Key, typename Mapped, typename Cmp_Fn, \ + typename Node_And_It_Traits, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + PB_DS_S_TREE_NAME<Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc> + +#define PB_DS_S_TREE_BASE \ + PB_DS_S_TREE_BASE_NAME<Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc> + + + /** + * @brief Splay tree. + * @ingroup branch-detail + */ + template<typename Key, typename Mapped, typename Cmp_Fn, + typename Node_And_It_Traits, typename _Alloc> + class PB_DS_S_TREE_NAME : public PB_DS_S_TREE_BASE + { + private: + typedef PB_DS_S_TREE_BASE base_type; +#ifdef _GLIBCXX_DEBUG + typedef base_type debug_base; +#endif + typedef typename base_type::node_pointer node_pointer; + + public: + typedef splay_tree_tag container_category; + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef Cmp_Fn cmp_fn; + typedef typename base_type::key_type key_type; + typedef typename base_type::key_pointer key_pointer; + typedef typename base_type::key_const_pointer key_const_pointer; + typedef typename base_type::key_reference key_reference; + typedef typename base_type::key_const_reference key_const_reference; + typedef typename base_type::mapped_type mapped_type; + typedef typename base_type::mapped_pointer mapped_pointer; + typedef typename base_type::mapped_const_pointer mapped_const_pointer; + typedef typename base_type::mapped_reference mapped_reference; + typedef typename base_type::mapped_const_reference mapped_const_reference; + typedef typename base_type::value_type value_type; + typedef typename base_type::pointer pointer; + typedef typename base_type::const_pointer const_pointer; + typedef typename base_type::reference reference; + typedef typename base_type::const_reference const_reference; + typedef typename base_type::point_iterator point_iterator; + typedef typename base_type::const_iterator point_const_iterator; + typedef typename base_type::iterator iterator; + typedef typename base_type::const_iterator const_iterator; + typedef typename base_type::reverse_iterator reverse_iterator; + typedef typename base_type::const_reverse_iterator const_reverse_iterator; + typedef typename base_type::node_update node_update; + + PB_DS_S_TREE_NAME(); + + PB_DS_S_TREE_NAME(const Cmp_Fn&); + + PB_DS_S_TREE_NAME(const Cmp_Fn&, const node_update&); + + PB_DS_S_TREE_NAME(const PB_DS_CLASS_C_DEC&); + + void + swap(PB_DS_CLASS_C_DEC&); + + template<typename It> + void + copy_from_range(It, It); + + void + initialize(); + + inline std::pair<point_iterator, bool> + insert(const_reference r_value); + + inline mapped_reference + operator[](key_const_reference r_key) + { +#ifdef PB_DS_DATA_TRUE_INDICATOR + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + std::pair<point_iterator, bool> ins_pair = + insert_leaf_imp(value_type(r_key, mapped_type())); + + ins_pair.first.m_p_nd->m_special = false; + _GLIBCXX_DEBUG_ONLY(base_type::assert_valid(__FILE__, __LINE__)); + splay(ins_pair.first.m_p_nd); + _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);) + return ins_pair.first.m_p_nd->m_value.second; +#else + insert(r_key); + return base_type::s_null_type; +#endif + } + + inline point_iterator + find(key_const_reference); + + inline point_const_iterator + find(key_const_reference) const; + + inline bool + erase(key_const_reference); + + inline iterator + erase(iterator it); + + inline reverse_iterator + erase(reverse_iterator); + + template<typename Pred> + inline size_type + erase_if(Pred); + + void + join(PB_DS_CLASS_C_DEC&); + + void + split(key_const_reference, PB_DS_CLASS_C_DEC&); + + private: + inline std::pair<point_iterator, bool> + insert_leaf_imp(const_reference); + + inline node_pointer + find_imp(key_const_reference); + + inline const node_pointer + find_imp(key_const_reference) const; + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char* file, int line) const; + + void + assert_special_imp(const node_pointer, const char* file, int line) const; +#endif + + void + splay(node_pointer); + + inline void + splay_zig_zag_left(node_pointer, node_pointer, node_pointer); + + inline void + splay_zig_zag_right(node_pointer, node_pointer, node_pointer); + + inline void + splay_zig_zig_left(node_pointer, node_pointer, node_pointer); + + inline void + splay_zig_zig_right(node_pointer, node_pointer, node_pointer); + + inline void + splay_zz_start(node_pointer, node_pointer, node_pointer); + + inline void + splay_zz_end(node_pointer, node_pointer, node_pointer); + + inline node_pointer + leftmost(node_pointer); + + void + erase_node(node_pointer); + }; + +#define PB_DS_ASSERT_BASE_NODE_CONSISTENT(_Node) \ + _GLIBCXX_DEBUG_ONLY(base_type::assert_node_consistent(_Node, \ + __FILE__, __LINE__);) + +#include <ext/pb_ds/detail/splay_tree_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/splay_tree_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/splay_tree_/splay_fn_imps.hpp> +#include <ext/pb_ds/detail/splay_tree_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/splay_tree_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/splay_tree_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/splay_tree_/split_join_fn_imps.hpp> + +#undef PB_DS_ASSERT_BASE_NODE_CONSISTENT +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_S_TREE_NAME +#undef PB_DS_S_TREE_BASE_NAME +#undef PB_DS_S_TREE_BASE + } // namespace detail +} // namespace __gnu_pbds diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/split_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/split_join_fn_imps.hpp new file mode 100644 index 0000000..07aec09 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/split_join_fn_imps.hpp @@ -0,0 +1,112 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/split_join_fn_imps.hpp + * Contains an implementation class for splay_tree_. + */ + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +join(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + if (base_type::join_prep(other) == false) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + node_pointer p_target_r = other.leftmost(other.m_p_head); + _GLIBCXX_DEBUG_ASSERT(p_target_r != 0); + other.splay(p_target_r); + + _GLIBCXX_DEBUG_ASSERT(p_target_r == other.m_p_head->m_p_parent); + _GLIBCXX_DEBUG_ASSERT(p_target_r->m_p_left == 0); + + p_target_r->m_p_left = base_type::m_p_head->m_p_parent; + + _GLIBCXX_DEBUG_ASSERT(p_target_r->m_p_left != 0); + p_target_r->m_p_left->m_p_parent = p_target_r; + + base_type::m_p_head->m_p_parent = p_target_r; + p_target_r->m_p_parent = base_type::m_p_head; + + this->apply_update(p_target_r, (node_update*)this); + base_type::join_finish(other); + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +split(key_const_reference r_key, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + if (base_type::split_prep(r_key, other) == false) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + node_pointer p_upper_bound = this->upper_bound(r_key).m_p_nd; + _GLIBCXX_DEBUG_ASSERT(p_upper_bound != 0); + + splay(p_upper_bound); + _GLIBCXX_DEBUG_ASSERT(p_upper_bound->m_p_parent == this->m_p_head); + + node_pointer p_new_root = p_upper_bound->m_p_left; + _GLIBCXX_DEBUG_ASSERT(p_new_root != 0); + + base_type::m_p_head->m_p_parent = p_new_root; + p_new_root->m_p_parent = base_type::m_p_head; + other.m_p_head->m_p_parent = p_upper_bound; + p_upper_bound->m_p_parent = other.m_p_head; + p_upper_bound->m_p_left = 0; + this->apply_update(p_upper_bound, (node_update*)this); + base_type::split_finish(other); + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/traits.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/traits.hpp new file mode 100644 index 0000000..b3e3e25 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/splay_tree_/traits.hpp @@ -0,0 +1,95 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file splay_tree_/traits.hpp + * Contains an implementation for splay_tree_. + */ + +#ifndef PB_DS_SPLAY_TREE_NODE_AND_IT_TRAITS_HPP +#define PB_DS_SPLAY_TREE_NODE_AND_IT_TRAITS_HPP + +#include <ext/pb_ds/detail/splay_tree_/node.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /// Specialization. + /// @ingroup traits + template<typename Key, + typename Mapped, + typename Cmp_Fn, + template<typename Node_CItr, + typename Node_Itr, + typename Cmp_Fn_, + typename _Alloc_> + class Node_Update, + typename _Alloc> + struct tree_traits<Key, Mapped, Cmp_Fn, Node_Update, splay_tree_tag, _Alloc> + : public bin_search_tree_traits<Key, Mapped, Cmp_Fn, Node_Update, + splay_tree_node_< + typename types_traits<Key, Mapped, _Alloc, false>::value_type, + typename tree_node_metadata_dispatch<Key, Mapped, Cmp_Fn, Node_Update, + _Alloc>::type, + _Alloc>, + _Alloc> + { }; + + /// Specialization. + /// @ingroup traits + template<typename Key, + class Cmp_Fn, + template<typename Node_CItr, + class Node_Itr, + class Cmp_Fn_, + typename _Alloc_> + class Node_Update, + typename _Alloc> + struct tree_traits<Key, null_type, Cmp_Fn, Node_Update, + splay_tree_tag, _Alloc> + : public bin_search_tree_traits<Key, null_type, Cmp_Fn, Node_Update, + splay_tree_node_< + typename types_traits<Key, null_type, _Alloc, false>::value_type, + typename tree_node_metadata_dispatch<Key, null_type, Cmp_Fn, Node_Update, + _Alloc>::type, + _Alloc>, + _Alloc> + { }; + + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_SPLAY_TREE_NODE_AND_IT_TRAITS_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/standard_policies.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/standard_policies.hpp new file mode 100644 index 0000000..1086fd8 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/standard_policies.hpp @@ -0,0 +1,158 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file detail/standard_policies.hpp + * Contains standard policies for containers. + */ + +#ifndef PB_DS_STANDARD_POLICIES_HPP +#define PB_DS_STANDARD_POLICIES_HPP + +#include <memory> +#include <ext/pb_ds/hash_policy.hpp> +#include <ext/pb_ds/list_update_policy.hpp> +#include <ext/pb_ds/detail/branch_policy/null_node_metadata.hpp> +#include <ext/pb_ds/tree_policy.hpp> +#include <ext/pb_ds/trie_policy.hpp> +#include <ext/pb_ds/tag_and_trait.hpp> +#include <tr1/functional> + +namespace __gnu_pbds +{ + namespace detail + { + /// Primary template, default_hash_fn. + template<typename Key> + struct default_hash_fn + { + /// Dispatched type. + typedef std::tr1::hash<Key> type; + }; + + /// Primary template, default_eq_fn. + template<typename Key> + struct default_eq_fn + { + /// Dispatched type. + typedef std::equal_to<Key> type; + }; + + /// Enumeration for default behavior of stored hash data. + enum + { + default_store_hash = false + }; + + /// Primary template, default_comb_hash_fn. + struct default_comb_hash_fn + { + /// Dispatched type. + typedef direct_mask_range_hashing<> type; + }; + + /// Primary template, default_resize_policy. + template<typename Comb_Hash_Fn> + struct default_resize_policy + { + private: + typedef typename Comb_Hash_Fn::size_type size_type; + + typedef direct_mask_range_hashing<size_type> default_fn; + typedef is_same<default_fn, Comb_Hash_Fn> same_type; + typedef hash_exponential_size_policy<size_type> iftrue; + typedef hash_prime_size_policy iffalse; + typedef __conditional_type<same_type::value, iftrue, iffalse> cond_type; + typedef typename cond_type::__type size_policy_type; + + typedef hash_load_check_resize_trigger<false, size_type> trigger; + + public: + /// Dispatched type. + typedef hash_standard_resize_policy<size_policy_type, trigger, + false, size_type> type; + }; + + /// Default update policy. + struct default_update_policy + { + /// Dispatched type. + typedef lu_move_to_front_policy<> type; + }; + + /// Primary template, default_probe_fn. + template<typename Comb_Probe_Fn> + struct default_probe_fn + { + private: + typedef typename Comb_Probe_Fn::size_type size_type; + typedef direct_mask_range_hashing<size_type> default_fn; + typedef is_same<default_fn, Comb_Probe_Fn> same_type; + typedef linear_probe_fn<size_type> iftrue; + typedef quadratic_probe_fn<size_type> iffalse; + typedef __conditional_type<same_type::value, iftrue, iffalse> cond_type; + + public: + /// Dispatched type. + typedef typename cond_type::__type type; + }; + + + /// Primary template, default_trie_access_traits. + template<typename Key> + struct default_trie_access_traits; + +#define __dtrie_alloc std::allocator<char> +#define __dtrie_string std::basic_string<Char, Char_Traits, __dtrie_alloc> + + /// Partial specialization, default_trie_access_traits. + template<typename Char, typename Char_Traits> + struct default_trie_access_traits<__dtrie_string> + { + private: + typedef __dtrie_string string_type; + + public: + /// Dispatched type. + typedef trie_string_access_traits<string_type> type; + }; + +#undef __dtrie_alloc +#undef __dtrie_string + + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_STANDARD_POLICIES_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..a01b121 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,105 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/constructors_destructor_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + push(*(first_it++)); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +thin_heap() : m_p_max(0) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +thin_heap(const Cmp_Fn& r_cmp_fn) +: base_type(r_cmp_fn), m_p_max(0) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +thin_heap(const PB_DS_CLASS_C_DEC& other) +: base_type(other) +{ + initialize(); + m_p_max = base_type::m_p_root; + for (node_pointer p_nd = base_type::m_p_root; p_nd != 0; + p_nd = p_nd->m_p_next_sibling) + if (Cmp_Fn::operator()(m_p_max->m_value, p_nd->m_value)) + m_p_max = p_nd; + + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + base_type::swap(other); + std::swap(m_p_max, other.m_p_max); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~thin_heap() +{ } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +initialize() +{ std::fill(m_a_aux, m_a_aux + max_rank, static_cast<node_pointer>(0)); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/debug_fn_imps.hpp new file mode 100644 index 0000000..f99fcaf --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/debug_fn_imps.hpp @@ -0,0 +1,119 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/debug_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + base_type::assert_valid(__file, __line); + assert_node_consistent(base_type::m_p_root, true, __file, __line); + assert_max(__file, __line); + assert_aux_null(__file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_aux_null(const char* __file, int __line) const +{ + for (size_type i = 0; i < max_rank; ++i) + PB_DS_DEBUG_VERIFY(m_a_aux[i] == 0); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_max(const char* __file, int __line) const +{ + if (m_p_max == 0) + { + PB_DS_DEBUG_VERIFY(base_type::empty()); + return; + } + + PB_DS_DEBUG_VERIFY(!base_type::empty()); + PB_DS_DEBUG_VERIFY(base_type::parent(m_p_max) == 0); + PB_DS_DEBUG_VERIFY(m_p_max->m_p_prev_or_parent == 0); + for (const_iterator it = base_type::begin(); it != base_type::end(); ++it) + PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(m_p_max->m_value, it.m_p_nd->m_value)); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_node_consistent(node_const_pointer p_nd, bool root, + const char* __file, int __line) const +{ + base_type::assert_node_consistent(p_nd, root, __file, __line); + if (p_nd == 0) + return; + + assert_node_consistent(p_nd->m_p_next_sibling, root, __file, __line); + assert_node_consistent(p_nd->m_p_l_child, false, __file, __line); + if (!root) + { + if (p_nd->m_metadata == 0) + PB_DS_DEBUG_VERIFY(p_nd->m_p_next_sibling == 0); + else + PB_DS_DEBUG_VERIFY(p_nd->m_metadata == p_nd->m_p_next_sibling->m_metadata + 1); + } + + if (p_nd->m_p_l_child != 0) + PB_DS_DEBUG_VERIFY(p_nd->m_p_l_child->m_metadata + 1 == base_type::degree(p_nd)); + + const bool unmarked_valid = + (p_nd->m_p_l_child == 0 && p_nd->m_metadata == 0) + || (p_nd->m_p_l_child != 0 + && p_nd->m_metadata == p_nd->m_p_l_child->m_metadata + 1); + + const bool marked_valid = + (p_nd->m_p_l_child == 0 && p_nd->m_metadata == 1) + || (p_nd->m_p_l_child != 0 + && p_nd->m_metadata == p_nd->m_p_l_child->m_metadata + 2); + + PB_DS_DEBUG_VERIFY(unmarked_valid || marked_valid); + if (root) + PB_DS_DEBUG_VERIFY(unmarked_valid); +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/erase_fn_imps.hpp new file mode 100644 index 0000000..fbdbbf3 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/erase_fn_imps.hpp @@ -0,0 +1,255 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/erase_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +pop() +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + _GLIBCXX_DEBUG_ASSERT(m_p_max != 0); + + node_pointer p_nd = m_p_max; + remove_max_node(); + base_type::actual_erase_node(p_nd); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +remove_max_node() +{ + to_aux_except_max(); + make_from_aux(); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +to_aux_except_max() +{ + node_pointer p_add = base_type::m_p_root; + while (p_add != m_p_max) + { + node_pointer p_next_add = p_add->m_p_next_sibling; + add_to_aux(p_add); + p_add = p_next_add; + } + + p_add = m_p_max->m_p_l_child; + while (p_add != 0) + { + node_pointer p_next_add = p_add->m_p_next_sibling; + p_add->m_metadata = p_add->m_p_l_child == 0 ? + 0 : p_add->m_p_l_child->m_metadata + 1; + + add_to_aux(p_add); + p_add = p_next_add; + } + + p_add = m_p_max->m_p_next_sibling; + while (p_add != 0) + { + node_pointer p_next_add = p_add->m_p_next_sibling; + add_to_aux(p_add); + p_add = p_next_add; + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +add_to_aux(node_pointer p_nd) +{ + size_type r = p_nd->m_metadata; + while (m_a_aux[r] != 0) + { + _GLIBCXX_DEBUG_ASSERT(p_nd->m_metadata < rank_bound()); + if (Cmp_Fn::operator()(m_a_aux[r]->m_value, p_nd->m_value)) + make_child_of(m_a_aux[r], p_nd); + else + { + make_child_of(p_nd, m_a_aux[r]); + p_nd = m_a_aux[r]; + } + + m_a_aux[r] = 0; + ++r; + } + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_metadata < rank_bound()); + + m_a_aux[r] = p_nd; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +make_child_of(node_pointer p_nd, node_pointer p_new_parent) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd->m_metadata == p_new_parent->m_metadata); + _GLIBCXX_DEBUG_ASSERT(m_a_aux[p_nd->m_metadata] == p_nd || + m_a_aux[p_nd->m_metadata] == p_new_parent); + + ++p_new_parent->m_metadata; + base_type::make_child_of(p_nd, p_new_parent); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +make_from_aux() +{ + base_type::m_p_root = m_p_max = 0; + const size_type rnk_bnd = rank_bound(); + size_type i = 0; + while (i < rnk_bnd) + { + if (m_a_aux[i] != 0) + { + make_root_and_link(m_a_aux[i]); + m_a_aux[i] = 0; + } + ++i; + } + + PB_DS_ASSERT_AUX_NULL((*this)) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +remove_node(node_pointer p_nd) +{ + node_pointer p_parent = p_nd; + while (base_type::parent(p_parent) != 0) + p_parent = base_type::parent(p_parent); + + base_type::bubble_to_top(p_nd); + m_p_max = p_nd; + + node_pointer p_fix = base_type::m_p_root; + while (p_fix != 0&& p_fix->m_p_next_sibling != p_parent) + p_fix = p_fix->m_p_next_sibling; + + if (p_fix != 0) + p_fix->m_p_next_sibling = p_nd; + + remove_max_node(); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +clear() +{ + base_type::clear(); + m_p_max = 0; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase(point_iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + + node_pointer p_nd = it.m_p_nd; + remove_node(p_nd); + base_type::actual_erase_node(p_nd); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + PB_DS_ASSERT_VALID((*this)) + if (base_type::empty()) + { + PB_DS_ASSERT_VALID((*this)) + return 0; + } + + base_type::to_linked_list(); + node_pointer p_out = base_type::prune(pred); + size_type ersd = 0; + while (p_out != 0) + { + ++ersd; + node_pointer p_next = p_out->m_p_next_sibling; + base_type::actual_erase_node(p_out); + p_out = p_next; + } + + node_pointer p_cur = base_type::m_p_root; + m_p_max = base_type::m_p_root = 0; + while (p_cur != 0) + { + node_pointer p_next = p_cur->m_p_next_sibling; + make_root_and_link(p_cur); + p_cur = p_next; + } + + PB_DS_ASSERT_VALID((*this)) + return ersd; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +rank_bound() +{ + using namespace std; + const size_t* const p_upper = + std::upper_bound(g_a_rank_bounds, + g_a_rank_bounds + num_distinct_rank_bounds, + base_type::m_size); + + if (p_upper == g_a_rank_bounds + num_distinct_rank_bounds) + return max_rank; + + return (p_upper - g_a_rank_bounds); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/find_fn_imps.hpp new file mode 100644 index 0000000..9089aef --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/find_fn_imps.hpp @@ -0,0 +1,51 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/find_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reference +PB_DS_CLASS_C_DEC:: +top() const +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + + _GLIBCXX_DEBUG_ASSERT(m_p_max != 0); + return m_p_max->m_value; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/insert_fn_imps.hpp new file mode 100644 index 0000000..60eaffa --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/insert_fn_imps.hpp @@ -0,0 +1,280 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/insert_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +push(const_reference r_val) +{ + PB_DS_ASSERT_VALID((*this)) + node_pointer p_nd = base_type::get_new_node_for_insert(r_val); + p_nd->m_metadata = 0; + p_nd->m_p_prev_or_parent = p_nd->m_p_l_child = 0; + if (base_type::m_p_root == 0) + { + p_nd->m_p_next_sibling = 0; + m_p_max = base_type::m_p_root = p_nd; + PB_DS_ASSERT_VALID((*this)) + return point_iterator(p_nd); + } + + p_nd->m_p_next_sibling = base_type::m_p_root; + base_type::m_p_root->m_p_prev_or_parent = 0; + base_type::m_p_root = p_nd; + update_max(p_nd); + PB_DS_ASSERT_VALID((*this)) + return point_iterator(p_nd); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +make_root(node_pointer p_nd) +{ + p_nd->m_metadata = p_nd->m_p_l_child == 0 + ? 0 : 1 + p_nd->m_p_l_child->m_metadata; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +make_root_and_link(node_pointer p_nd) +{ + make_root(p_nd); + p_nd->m_p_prev_or_parent = 0; + p_nd->m_p_next_sibling = base_type::m_p_root; + if (base_type::m_p_root != 0) + base_type::m_p_root->m_p_prev_or_parent = 0; + + base_type::m_p_root = p_nd; + update_max(p_nd); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix(node_pointer p_y) +{ + while (true) + { + if (p_y->m_p_prev_or_parent == 0) + { + fix_root(p_y); + return; + } + else if (p_y->m_metadata == 1&& p_y->m_p_next_sibling == 0) + { + if (p_y->m_p_l_child != 0) + { + fix_sibling_rank_1_unmarked(p_y); + return; + } + + fix_sibling_rank_1_marked(p_y); + p_y = p_y->m_p_prev_or_parent; + } + else if (p_y->m_metadata > p_y->m_p_next_sibling->m_metadata + 1) + { + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_l_child != 0); + if (p_y->m_metadata != p_y->m_p_l_child->m_metadata + 2) + { + fix_sibling_general_unmarked(p_y); + return; + } + + fix_sibling_general_marked(p_y); + p_y = p_y->m_p_prev_or_parent; + } + else if ((p_y->m_p_l_child == 0&& + p_y->m_metadata == 2) ||(p_y->m_p_l_child != 0&& + p_y->m_metadata == p_y->m_p_l_child->m_metadata + 3)) + { + node_pointer p_z = p_y->m_p_prev_or_parent; + fix_child(p_y); + p_y = p_z; + } + else + return; + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_root(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent == 0); + make_root(p_y); + PB_DS_ASSERT_NODE_CONSISTENT(p_y, true) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_sibling_rank_1_unmarked(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent != 0); + + _GLIBCXX_DEBUG_ONLY(node_pointer p_w = p_y->m_p_l_child;) + _GLIBCXX_DEBUG_ASSERT(p_w != 0); + _GLIBCXX_DEBUG_ASSERT(p_w->m_p_next_sibling == 0); + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_next_sibling == 0); + + p_y->m_p_next_sibling = p_y->m_p_l_child; + p_y->m_p_next_sibling->m_p_prev_or_parent = p_y; + p_y->m_p_l_child = 0; + PB_DS_ASSERT_NODE_CONSISTENT(p_y, false) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_sibling_rank_1_marked(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent != 0); + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_l_child == 0); + p_y->m_metadata = 0; + PB_DS_ASSERT_NODE_CONSISTENT(p_y, false) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_sibling_general_unmarked(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent != 0); + + node_pointer p_w = p_y->m_p_l_child; + _GLIBCXX_DEBUG_ASSERT(p_w != 0); + _GLIBCXX_DEBUG_ASSERT(p_w->m_p_next_sibling != 0); + + p_y->m_p_l_child = p_w->m_p_next_sibling; + p_w->m_p_next_sibling->m_p_prev_or_parent = p_y; + + p_w->m_p_next_sibling = p_y->m_p_next_sibling; + _GLIBCXX_DEBUG_ASSERT(p_w->m_p_next_sibling != 0); + p_w->m_p_next_sibling->m_p_prev_or_parent = p_w; + + p_y->m_p_next_sibling = p_w; + p_w->m_p_prev_or_parent = p_y; + + PB_DS_ASSERT_NODE_CONSISTENT(p_y, false) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_sibling_general_marked(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent != 0); + --p_y->m_metadata; + PB_DS_ASSERT_NODE_CONSISTENT(p_y, false) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_child(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent != 0); + + if (p_y->m_p_next_sibling != 0) + p_y->m_p_next_sibling->m_p_prev_or_parent = p_y->m_p_prev_or_parent; + + if (p_y->m_p_prev_or_parent->m_p_l_child == p_y) + p_y->m_p_prev_or_parent->m_p_l_child = p_y->m_p_next_sibling; + else + p_y->m_p_prev_or_parent->m_p_next_sibling = p_y->m_p_next_sibling; + + make_root_and_link(p_y); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +modify(point_iterator it, const_reference r_new_val) +{ + PB_DS_ASSERT_VALID((*this)) + node_pointer p_nd = it.m_p_nd; + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + + const bool smaller = Cmp_Fn::operator()(r_new_val, p_nd->m_value); + p_nd->m_value = r_new_val; + if (smaller) + { + remove_node(p_nd); + p_nd->m_p_l_child = 0; + make_root_and_link(p_nd); + PB_DS_ASSERT_VALID((*this)) + return; + } + + if (p_nd->m_p_prev_or_parent == 0) + { + update_max(p_nd); + PB_DS_ASSERT_VALID((*this)) + return; + } + + node_pointer p_y = p_nd->m_p_prev_or_parent; + _GLIBCXX_DEBUG_ASSERT(p_y != 0); + + if (p_nd->m_p_next_sibling != 0) + p_nd->m_p_next_sibling->m_p_prev_or_parent = p_y; + + if (p_y->m_p_l_child == p_nd) + p_y->m_p_l_child = p_nd->m_p_next_sibling; + else + p_y->m_p_next_sibling = p_nd->m_p_next_sibling; + + fix(p_y); + make_root_and_link(p_nd); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +update_max(node_pointer p_nd) +{ + if (m_p_max == 0 || Cmp_Fn::operator()(m_p_max->m_value, p_nd->m_value)) + m_p_max = p_nd; +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/split_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/split_join_fn_imps.hpp new file mode 100644 index 0000000..222ecd1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/split_join_fn_imps.hpp @@ -0,0 +1,108 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/split_join_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +PB_DS_CLASS_T_DEC +template<typename Pred> +void +PB_DS_CLASS_C_DEC:: +split(Pred pred, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + other.clear(); + if (base_type::empty()) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + base_type::to_linked_list(); + node_pointer p_out = base_type::prune(pred); + + while (p_out != 0) + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_size > 0); + --base_type::m_size; + ++other.m_size; + node_pointer p_next = p_out->m_p_next_sibling; + other.make_root_and_link(p_out); + p_out = p_next; + } + + PB_DS_ASSERT_VALID(other) + node_pointer p_cur = base_type::m_p_root; + m_p_max = 0; + base_type::m_p_root = 0; + while (p_cur != 0) + { + node_pointer p_next = p_cur->m_p_next_sibling; + make_root_and_link(p_cur); + p_cur = p_next; + } + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +join(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + node_pointer p_other = other.m_p_root; + while (p_other != 0) + { + node_pointer p_next = p_other->m_p_next_sibling; + make_root_and_link(p_other); + p_other = p_next; + } + base_type::m_size += other.m_size; + other.m_p_root = 0; + other.m_size = 0; + other.m_p_max = 0; + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/thin_heap_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/thin_heap_.hpp new file mode 100644 index 0000000..f37c5e4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/thin_heap_.hpp @@ -0,0 +1,324 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/thin_heap_.hpp + * Contains an implementation class for a thin heap. + */ + +#ifndef PB_DS_THIN_HEAP_HPP +#define PB_DS_THIN_HEAP_HPP + +#include <algorithm> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + thin_heap<Value_Type, Cmp_Fn, _Alloc> + +#ifdef _GLIBCXX_DEBUG +#define PB_DS_BASE_T_P \ + <Value_Type, Cmp_Fn, typename _Alloc::size_type, _Alloc, true> +#else +#define PB_DS_BASE_T_P \ + <Value_Type, Cmp_Fn, typename _Alloc::size_type, _Alloc> +#endif + + + /** + * Thin heap. + * + * @ingroup heap-detail + * + * See Tarjan and Kaplan. + */ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + class thin_heap + : public left_child_next_sibling_heap PB_DS_BASE_T_P + { + private: + typedef typename _Alloc::template rebind<Value_Type>::other __rebind_a; + typedef left_child_next_sibling_heap PB_DS_BASE_T_P base_type; + + protected: + typedef typename base_type::node node; + typedef typename base_type::node_pointer node_pointer; + typedef typename base_type::node_const_pointer node_const_pointer; + + public: + typedef Value_Type value_type; + typedef Cmp_Fn cmp_fn; + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + + typedef typename __rebind_a::pointer pointer; + typedef typename __rebind_a::const_pointer const_pointer; + typedef typename __rebind_a::reference reference; + typedef typename __rebind_a::const_reference const_reference; + + typedef typename base_type::point_iterator point_iterator; + typedef typename base_type::point_const_iterator point_const_iterator; + typedef typename base_type::iterator iterator; + typedef typename base_type::const_iterator const_iterator; + + + inline point_iterator + push(const_reference); + + void + modify(point_iterator, const_reference); + + inline const_reference + top() const; + + void + pop(); + + void + erase(point_iterator); + + inline void + clear(); + + template<typename Pred> + size_type + erase_if(Pred); + + template<typename Pred> + void + split(Pred, PB_DS_CLASS_C_DEC&); + + void + join(PB_DS_CLASS_C_DEC&); + + protected: + thin_heap(); + + thin_heap(const Cmp_Fn&); + + thin_heap(const PB_DS_CLASS_C_DEC&); + + void + swap(PB_DS_CLASS_C_DEC&); + + ~thin_heap(); + + template<typename It> + void + copy_from_range(It, It); + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; + + void + assert_max(const char*, int) const; +#endif + +#ifdef PB_DS_THIN_HEAP_TRACE_ + void + trace() const; +#endif + + private: + enum + { + max_rank = (sizeof(size_type) << 4) + 2 + }; + + void + initialize(); + + inline void + update_max(node_pointer); + + inline void + fix(node_pointer); + + inline void + fix_root(node_pointer); + + inline void + fix_sibling_rank_1_unmarked(node_pointer); + + inline void + fix_sibling_rank_1_marked(node_pointer); + + inline void + fix_sibling_general_unmarked(node_pointer); + + inline void + fix_sibling_general_marked(node_pointer); + + inline void + fix_child(node_pointer); + + inline static void + make_root(node_pointer); + + inline void + make_root_and_link(node_pointer); + + inline void + remove_max_node(); + + void + to_aux_except_max(); + + inline void + add_to_aux(node_pointer); + + inline void + make_from_aux(); + + inline size_type + rank_bound(); + + inline void + make_child_of(node_pointer, node_pointer); + + inline void + remove_node(node_pointer); + + inline node_pointer + join(node_pointer, node_pointer) const; + +#ifdef _GLIBCXX_DEBUG + void + assert_node_consistent(node_const_pointer, bool, const char*, int) const; + + void + assert_aux_null(const char*, int) const; +#endif + + node_pointer m_p_max; + node_pointer m_a_aux[max_rank]; + }; + + enum + { + num_distinct_rank_bounds = 48 + }; + + // Taken from the SGI implementation; acknowledged in the docs. + static const std::size_t g_a_rank_bounds[num_distinct_rank_bounds] = + { + /* Dealing cards... */ + /* 0 */ 0ul, + /* 1 */ 1ul, + /* 2 */ 1ul, + /* 3 */ 2ul, + /* 4 */ 4ul, + /* 5 */ 6ul, + /* 6 */ 11ul, + /* 7 */ 17ul, + /* 8 */ 29ul, + /* 9 */ 46ul, + /* 10 */ 76ul, + /* 11 */ 122ul, + /* 12 */ 199ul, + /* 13 */ 321ul, + /* 14 */ 521ul, + /* 15 */ 842ul, + /* 16 */ 1364ul, + /* 17 */ 2206ul, + /* 18 */ 3571ul, + /* 19 */ 5777ul, + /* 20 */ 9349ul, + /* 21 */ 15126ul, + /* 22 */ 24476ul, + /* 23 */ 39602ul, + /* 24 */ 64079ul, + /* 25 */ 103681ul, + /* 26 */ 167761ul, + /* 27 */ 271442ul, + /* 28 */ 439204ul, + /* 29 */ 710646ul, + /* 30 */ 1149851ul, + /* 31 */ 1860497ul, + /* 32 */ 3010349ul, + /* 33 */ 4870846ul, + /* 34 */ 7881196ul, + /* 35 */ 12752042ul, + /* 36 */ 20633239ul, + /* 37 */ 33385282ul, + /* 38 */ 54018521ul, + /* 39 */ 87403803ul, + /* 40 */ 141422324ul, + /* 41 */ 228826127ul, + /* 42 */ 370248451ul, + /* 43 */ 599074578ul, + /* 44 */ 969323029ul, + /* 45 */ 1568397607ul, + /* 46 */ 2537720636ul, + /* 47 */ 4106118243ul + /* Pot's good, let's play */ + }; + +#define PB_DS_ASSERT_NODE_CONSISTENT(_Node, _Bool) \ + _GLIBCXX_DEBUG_ONLY(assert_node_consistent(_Node, _Bool, \ + __FILE__, __LINE__);) + +#define PB_DS_ASSERT_AUX_NULL(X) \ + _GLIBCXX_DEBUG_ONLY(X.assert_aux_null(__FILE__, __LINE__);) + +#include <ext/pb_ds/detail/thin_heap_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/trace_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/split_join_fn_imps.hpp> + +#undef PB_DS_ASSERT_AUX_NULL +#undef PB_DS_ASSERT_NODE_CONSISTENT +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_BASE_T_P + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/trace_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/trace_fn_imps.hpp new file mode 100644 index 0000000..cb6a623 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/trace_fn_imps.hpp @@ -0,0 +1,53 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/trace_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +#ifdef PB_DS_THIN_HEAP_TRACE_ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace() const +{ + std::cerr << std::endl; + std::cerr << "m_p_max " << m_p_max << std::endl; + base_type::trace(); +} + +#endif // #ifdef PB_DS_THIN_HEAP_TRACE_ diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_policy/node_metadata_selector.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_policy/node_metadata_selector.hpp new file mode 100644 index 0000000..6be96f6 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_policy/node_metadata_selector.hpp @@ -0,0 +1,103 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file tree_policy/node_metadata_selector.hpp + * Contains an implementation class for trees. + */ + +#ifndef PB_DS_TREE_NODE_METADATA_DISPATCH_HPP +#define PB_DS_TREE_NODE_METADATA_DISPATCH_HPP + +#include <ext/pb_ds/detail/branch_policy/null_node_metadata.hpp> +#include <ext/pb_ds/detail/types_traits.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /** + * @addtogroup traits Traits + * @{ + */ + + /// Tree metadata helper. + template<typename Node_Update, bool _BTp> + struct tree_metadata_helper; + + /// Specialization, false. + template<typename Node_Update> + struct tree_metadata_helper<Node_Update, false> + { + typedef typename Node_Update::metadata_type type; + }; + + /// Specialization, true. + template<typename Node_Update> + struct tree_metadata_helper<Node_Update, true> + { + typedef null_type type; + }; + + /// Tree node metadata dispatch. + template<typename Key, + typename Data, + typename Cmp_Fn, + template<typename Node_CItr, + typename Const_Iterator, + typename Cmp_Fn_, + typename _Alloc_> + class Node_Update, + typename _Alloc> + struct tree_node_metadata_dispatch + { + private: + typedef dumnode_const_iterator<Key, Data, _Alloc> __it_type; + typedef Node_Update<__it_type, __it_type, Cmp_Fn, _Alloc> __node_u; + typedef null_node_update<__it_type, __it_type, Cmp_Fn, _Alloc> __nnode_u; + + enum + { + null_update = is_same<__node_u, __nnode_u>::value + }; + + public: + typedef typename tree_metadata_helper<__node_u, null_update>::type type; + }; + //@} + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_TREE_NODE_METADATA_DISPATCH_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_policy/order_statistics_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_policy/order_statistics_imp.hpp new file mode 100644 index 0000000..7a4966e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_policy/order_statistics_imp.hpp @@ -0,0 +1,121 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file tree_policy/order_statistics_imp.hpp + * Contains forward declarations for order_statistics_key + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +find_by_order(size_type order) +{ + node_iterator it = node_begin(); + node_iterator end_it = node_end(); + + while (it != end_it) + { + node_iterator l_it = it.get_l_child(); + const size_type o = (l_it == end_it)? 0 : l_it.get_metadata(); + + if (order == o) + return *it; + else if (order < o) + it = l_it; + else + { + order -= o + 1; + it = it.get_r_child(); + } + } + + return base_type::end_iterator(); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +find_by_order(size_type order) const +{ return const_cast<PB_DS_CLASS_C_DEC*>(this)->find_by_order(order); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +order_of_key(key_const_reference r_key) const +{ + node_const_iterator it = node_begin(); + node_const_iterator end_it = node_end(); + + const cmp_fn& r_cmp_fn = const_cast<PB_DS_CLASS_C_DEC*>(this)->get_cmp_fn(); + size_type ord = 0; + while (it != end_it) + { + node_const_iterator l_it = it.get_l_child(); + + if (r_cmp_fn(r_key, this->extract_key(*(*it)))) + it = l_it; + else if (r_cmp_fn(this->extract_key(*(*it)), r_key)) + { + ord += (l_it == end_it)? 1 : 1 + l_it.get_metadata(); + it = it.get_r_child(); + } + else + { + ord += (l_it == end_it)? 0 : l_it.get_metadata(); + it = end_it; + } + } + return ord; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +operator()(node_iterator node_it, node_const_iterator end_nd_it) const +{ + node_iterator l_it = node_it.get_l_child(); + const size_type l_rank = (l_it == end_nd_it) ? 0 : l_it.get_metadata(); + + node_iterator r_it = node_it.get_r_child(); + const size_type r_rank = (r_it == end_nd_it) ? 0 : r_it.get_metadata(); + + const_cast<metadata_reference>(node_it.get_metadata())= 1 + l_rank + r_rank; +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~tree_order_statistics_node_update() +{ } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_policy/sample_tree_node_update.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_policy/sample_tree_node_update.hpp new file mode 100644 index 0000000..dcafdf1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_policy/sample_tree_node_update.hpp @@ -0,0 +1,62 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file tree_policy/sample_tree_node_update.hpp + * Contains a samle node update functor. + */ + +#ifndef PB_DS_SAMPLE_TREE_NODE_UPDATOR_HPP +#define PB_DS_SAMPLE_TREE_NODE_UPDATOR_HPP + +namespace __gnu_pbds +{ + /// A sample node updator. + template<typename Const_Node_Iter, typename Node_Iter, typename Cmp_Fn, + typename _Alloc> + class sample_tree_node_update + { + typedef std::size_t metadata_type; + + /// Default constructor. + sample_tree_node_update(); + + /// Updates the rank of a node through a node_iterator node_it; + /// end_nd_it is the end node iterator. + inline void + operator()(node_iterator node_it, node_const_iterator end_nd_it) const; + }; +} +#endif // #ifndef PB_DS_SAMPLE_TREE_NODE_UPDATOR_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_trace_base.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_trace_base.hpp new file mode 100644 index 0000000..223bb20 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/tree_trace_base.hpp @@ -0,0 +1,179 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file detail/tree_trace_base.hpp + * Contains tree-related policies. + */ + +#ifndef PB_DS_TREE_TRACE_BASE_HPP +#define PB_DS_TREE_TRACE_BASE_HPP + +#ifdef PB_DS_TREE_TRACE + +#include <ext/pb_ds/detail/branch_policy/branch_policy.hpp> +#include <ext/pb_ds/detail/branch_policy/null_node_metadata.hpp> + +namespace __gnu_pbds +{ + namespace detail + { +#ifdef PB_DS_TREE_TRACE + +#define PB_DS_CLASS_T_DEC \ + template<typename Node_CItr, typename Node_Itr, \ + typename Cmp_Fn, bool Node_Based, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + tree_trace_base<Node_CItr, Node_Itr, Cmp_Fn, \ + Node_Based, _Alloc> + +#define PB_DS_TRACE_BASE \ + branch_policy<Node_CItr, Node_Itr, _Alloc> + + /// Tracing base class. + template<typename Node_CItr, typename Node_Itr, + typename Cmp_Fn, bool Node_Based, typename _Alloc> + class tree_trace_base : private PB_DS_TRACE_BASE + { + public: + void + trace() const; + + private: + typedef PB_DS_TRACE_BASE base_type; + typedef Node_CItr node_const_iterator; + typedef typename _Alloc::size_type size_type; + + void + trace_node(node_const_iterator, size_type) const; + + virtual bool + empty() const = 0; + + virtual node_const_iterator + node_begin() const = 0; + + virtual node_const_iterator + node_end() const = 0; + + static void + print_node_pointer(Node_CItr, integral_constant<int,true>); + + static void + print_node_pointer(Node_CItr, integral_constant<int,false>); + + template<typename Metadata_> + static void + trace_it_metadata(Node_CItr, type_to_type<Metadata_>); + + static void + trace_it_metadata(Node_CItr, type_to_type<null_type>); + }; + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + trace() const + { + if (empty()) + return; + trace_node(node_begin(), 0); + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + trace_node(node_const_iterator nd_it, size_type level) const + { + if (nd_it.get_r_child() != node_end()) + trace_node(nd_it.get_r_child(), level + 1); + + for (size_type i = 0; i < level; ++i) + std::cerr << ' '; + + print_node_pointer(nd_it, integral_constant<int,Node_Based>()); + std::cerr << base_type::extract_key(*(*nd_it)); + + typedef type_to_type<typename node_const_iterator::metadata_type> + m_type_ind_t; + + trace_it_metadata(nd_it, m_type_ind_t()); + + std::cerr << std::endl; + + if (nd_it.get_l_child() != node_end()) + trace_node(nd_it.get_l_child(), level + 1); + } + + PB_DS_CLASS_T_DEC + template<typename Metadata_> + void + PB_DS_CLASS_C_DEC:: + trace_it_metadata(Node_CItr nd_it, type_to_type<Metadata_>) + { + const unsigned long ul = static_cast<unsigned long>(nd_it.get_metadata()); + std::cerr << " (" << ul << ") "; + } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + trace_it_metadata(Node_CItr, type_to_type<null_type>) + { } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + print_node_pointer(Node_CItr nd_it, integral_constant<int,true>) + { std::cerr << nd_it.m_p_nd << " "; } + + PB_DS_CLASS_T_DEC + void + PB_DS_CLASS_C_DEC:: + print_node_pointer(Node_CItr nd_it, integral_constant<int,false>) + { std::cerr << *nd_it << " "; } + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_TRACE_BASE +#endif // #ifdef PB_DS_TREE_TRACE + + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifdef PB_DS_TREE_TRACE + +#endif // #ifndef PB_DS_TREE_TRACE_BASE_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/node_metadata_selector.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/node_metadata_selector.hpp new file mode 100644 index 0000000..c022107 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/node_metadata_selector.hpp @@ -0,0 +1,103 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file trie_policy/node_metadata_selector.hpp + * Contains an implementation class for tries. + */ + +#ifndef PB_DS_TRIE_NODE_METADATA_DISPATCH_HPP +#define PB_DS_TRIE_NODE_METADATA_DISPATCH_HPP + +#include <ext/pb_ds/detail/branch_policy/null_node_metadata.hpp> +#include <ext/pb_ds/detail/types_traits.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /** + * @addtogroup traits Traits + * @{ + */ + + /// Trie metadata helper. + template<typename Node_Update, bool _BTp> + struct trie_metadata_helper; + + /// Specialization, false. + template<typename Node_Update> + struct trie_metadata_helper<Node_Update, false> + { + typedef typename Node_Update::metadata_type type; + }; + + /// Specialization, true. + template<typename Node_Update> + struct trie_metadata_helper<Node_Update, true> + { + typedef null_type type; + }; + + /// Trie node metadata dispatch. + template<typename Key, + typename Data, + typename Cmp_Fn, + template<typename Node_CItr, + typename Const_Iterator, + typename Cmp_Fn_, + typename _Alloc_> + class Node_Update, + typename _Alloc> + struct trie_node_metadata_dispatch + { + private: + typedef dumnode_const_iterator<Key, Data, _Alloc> __it_type; + typedef Node_Update<__it_type, __it_type, Cmp_Fn, _Alloc> __node_u; + typedef null_node_update<__it_type, __it_type, Cmp_Fn, _Alloc> __nnode_u; + + enum + { + null_update = is_same<__node_u, __nnode_u>::value + }; + + public: + typedef typename trie_metadata_helper<__node_u, null_update>::type type; + }; + //@} + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_TRIE_NODE_METADATA_DISPATCH_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/order_statistics_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/order_statistics_imp.hpp new file mode 100644 index 0000000..d2f5d64 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/order_statistics_imp.hpp @@ -0,0 +1,160 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file trie_policy/order_statistics_imp.hpp + * Contains forward declarations for order_statistics_key + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +find_by_order(size_type order) +{ + if (empty()) + return end(); + + ++order; + node_iterator nd_it = node_begin(); + + while (true) + { + if (order > nd_it.get_metadata()) + return ++base_type::rightmost_it(nd_it); + + const size_type num_children = nd_it.num_children(); + if (num_children == 0) + return *nd_it; + + for (size_type i = 0; i < num_children; ++i) + { + node_iterator child_nd_it = nd_it.get_child(i); + if (order <= child_nd_it.get_metadata()) + { + i = num_children; + nd_it = child_nd_it; + } + else + order -= child_nd_it.get_metadata(); + } + } +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +find_by_order(size_type order) const +{ return const_cast<PB_DS_CLASS_C_DEC*>(this)->find_by_order(order); } + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +order_of_key(key_const_reference r_key) const +{ + const _ATraits& r_traits = + const_cast<PB_DS_CLASS_C_DEC* >(this)->get_access_traits(); + + return order_of_prefix(r_traits.begin(r_key), r_traits.end(r_key)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +order_of_prefix(typename access_traits::const_iterator b, + typename access_traits::const_iterator e) const +{ + if (empty()) + return 0; + + const _ATraits& r_traits = + const_cast<PB_DS_CLASS_C_DEC*>(this)->get_access_traits(); + + node_const_iterator nd_it = node_begin(); + node_const_iterator end_nd_it = node_end(); + size_type ord = 0; + + while (true) + { + const size_type num_children = nd_it.num_children(); + if (num_children == 0) + { + key_const_reference r_key = base_type::extract_key(*(*nd_it)); + typename access_traits::const_iterator key_b = + r_traits.begin(r_key); + + typename access_traits::const_iterator key_e = + r_traits.end(r_key); + + return (base_type::less(key_b, key_e, b, e, r_traits)) ? + ord + 1 : ord; + } + + node_const_iterator next_nd_it = end_nd_it; + size_type i = num_children - 1; + + do + { + node_const_iterator child_nd_it = nd_it.get_child(i); + + if (next_nd_it != end_nd_it) + ord += child_nd_it.get_metadata(); + else if (!base_type::less(b, e, + child_nd_it.valid_prefix().first, + child_nd_it.valid_prefix().second, + r_traits)) + next_nd_it = child_nd_it; + } + while (i-- > 0); + + if (next_nd_it == end_nd_it) + return ord; + + nd_it = next_nd_it; + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +operator()(node_iterator nd_it, node_const_iterator /*end_nd_it*/) const +{ + const size_type num_children = nd_it.num_children(); + size_type children_rank = 0; + for (size_type i = 0; i < num_children; ++i) + children_rank += nd_it.get_child(i).get_metadata(); + + const size_type res = (num_children == 0) ? 1 : children_rank; + const_cast<size_type&>(nd_it.get_metadata()) = res; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/prefix_search_node_update_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/prefix_search_node_update_imp.hpp new file mode 100644 index 0000000..5be1183 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/prefix_search_node_update_imp.hpp @@ -0,0 +1,139 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file trie_policy/prefix_search_node_update_imp.hpp + * Contains an implementation of prefix_search_node_update. + */ + +PB_DS_CLASS_T_DEC +std::pair< + typename PB_DS_CLASS_C_DEC::const_iterator, + typename PB_DS_CLASS_C_DEC::const_iterator> +PB_DS_CLASS_C_DEC:: +prefix_range(key_const_reference r_key) const +{ + const access_traits& r_traits = get_access_traits(); + return (prefix_range(r_traits.begin(r_key), r_traits.end(r_key))); +} + +PB_DS_CLASS_T_DEC +std::pair< + typename PB_DS_CLASS_C_DEC::iterator, + typename PB_DS_CLASS_C_DEC::iterator> +PB_DS_CLASS_C_DEC:: +prefix_range(key_const_reference r_key) +{ + return (prefix_range(get_access_traits().begin(r_key), + get_access_traits().end(r_key))); +} + +PB_DS_CLASS_T_DEC +std::pair< + typename PB_DS_CLASS_C_DEC::const_iterator, + typename PB_DS_CLASS_C_DEC::const_iterator> +PB_DS_CLASS_C_DEC:: +prefix_range(typename access_traits::const_iterator b, + typename access_traits::const_iterator e) const +{ + const std::pair<iterator, iterator> non_const_ret = + const_cast<PB_DS_CLASS_C_DEC* >(this)->prefix_range(b, e); + + return (std::make_pair(const_iterator(non_const_ret.first), + const_iterator(non_const_ret.second))); +} + +PB_DS_CLASS_T_DEC +std::pair< + typename PB_DS_CLASS_C_DEC::iterator, + typename PB_DS_CLASS_C_DEC::iterator> +PB_DS_CLASS_C_DEC:: +prefix_range(typename access_traits::const_iterator b, + typename access_traits::const_iterator e) +{ + Node_Itr nd_it = node_begin(); + Node_Itr end_nd_it = node_end(); + + const access_traits& r_traits = get_access_traits(); + const size_type given_range_length = std::distance(b, e); + + while (true) + { + if (nd_it == end_nd_it) + return (std::make_pair(end(), end())); + + const size_type common_range_length = + base_type::common_prefix_len(nd_it, b, e, r_traits); + + if (common_range_length >= given_range_length) + { + iterator ret_b = this->leftmost_it(nd_it); + iterator ret_e = this->rightmost_it(nd_it); + return (std::make_pair(ret_b, ++ret_e)); + } + nd_it = next_child(nd_it, b, e, end_nd_it, r_traits); + } +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_iterator +PB_DS_CLASS_C_DEC:: +next_child(node_iterator nd_it, typename access_traits::const_iterator b, + typename access_traits::const_iterator e, node_iterator end_nd_it, + const access_traits& r_traits) +{ + const size_type num_children = nd_it.num_children(); + node_iterator ret = end_nd_it; + size_type max_length = 0; + for (size_type i = 0; i < num_children; ++i) + { + node_iterator pot = nd_it.get_child(i); + const size_type common_range_length = + base_type::common_prefix_len(pot, b, e, r_traits); + + if (common_range_length > max_length) + { + ret = pot; + max_length = common_range_length; + } + } + return (ret); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +operator()(node_iterator /*nd_it*/, node_const_iterator /*end_nd_it*/) const +{ } diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/sample_trie_access_traits.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/sample_trie_access_traits.hpp new file mode 100644 index 0000000..0590774 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/sample_trie_access_traits.hpp @@ -0,0 +1,77 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file trie_policy/sample_trie_access_traits.hpp + * Contains a sample probe policy. + */ + +#ifndef PB_DS_SAMPLE_TRIE_E_ACCESS_TRAITS_HPP +#define PB_DS_SAMPLE_TRIE_E_ACCESS_TRAITS_HPP + +namespace __gnu_pbds +{ + /// A sample trie element access traits. + struct sample_trie_access_traits + { + typedef std::size_t size_type; + typedef std::string key_type; + + typedef typename _Alloc::template rebind<key_type> __rebind_k; + typedef typename __rebind_k::other::const_reference key_const_reference; + typedef std::string::const_iterator const_iterator; + + /// Element type. + typedef char e_type; + + enum + { + max_size = 4 + }; + + /// Returns a const_iterator to the first element of r_key. + inline static const_iterator + begin(key_const_reference); + + /// Returns a const_iterator to the after-last element of r_key. + inline static const_iterator + end(key_const_reference); + + /// Maps an element to a position. + inline static size_type + e_pos(e_type); + }; +} +#endif // #ifndef PB_DS_SAMPLE_TRIE_E_ACCESS_TRAITS_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/sample_trie_node_update.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/sample_trie_node_update.hpp new file mode 100644 index 0000000..ea9ed1b --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/sample_trie_node_update.hpp @@ -0,0 +1,64 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file trie_policy/sample_trie_node_update.hpp + * Contains a samle node update functor. + */ + +#ifndef PB_DS_SAMPLE_TRIE_NODE_UPDATOR_HPP +#define PB_DS_SAMPLE_TRIE_NODE_UPDATOR_HPP + +namespace __gnu_pbds +{ + /// A sample node updator. + template<typename Node_CItr, typename Node_Itr, + typename _ATraits, typename _Alloc> + class sample_trie_node_update + { + public: + typedef std::size_t metadata_type; + + protected: + /// Default constructor. + sample_trie_node_update(); + + /// Updates the rank of a node through a node_iterator node_it; + /// end_nd_it is the end node iterator. + inline void + operator()(node_iterator, node_const_iterator) const; + }; +} +#endif // #ifndef PB_DS_SAMPLE_TRIE_NODE_UPDATOR_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/trie_policy_base.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/trie_policy_base.hpp new file mode 100644 index 0000000..3914684 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/trie_policy_base.hpp @@ -0,0 +1,207 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file trie_policy/trie_policy_base.hpp + * Contains an implementation of trie_policy_base. + */ + +#ifndef PB_DS_TRIE_POLICY_BASE_HPP +#define PB_DS_TRIE_POLICY_BASE_HPP + +#include <ext/pb_ds/detail/branch_policy/branch_policy.hpp> + +namespace __gnu_pbds +{ + namespace detail + { + /// Base class for trie policies. + template<typename Node_CItr, typename Node_Itr, + typename _ATraits, typename _Alloc> + class trie_policy_base + : public branch_policy<Node_CItr, Node_Itr, _Alloc> + { + typedef branch_policy<Node_CItr, Node_Itr, _Alloc> base_type; + + public: + typedef _ATraits access_traits; + typedef _Alloc allocator_type; + typedef typename allocator_type::size_type size_type; + typedef null_type metadata_type; + typedef Node_CItr node_const_iterator; + typedef Node_Itr node_iterator; + typedef typename node_const_iterator::value_type const_iterator; + typedef typename node_iterator::value_type iterator; + typedef typename base_type::key_type key_type; + typedef typename base_type::key_const_reference key_const_reference; + + protected: + virtual const_iterator + end() const = 0; + + virtual iterator + end() = 0; + + virtual node_const_iterator + node_begin() const = 0; + + virtual node_iterator + node_begin() = 0; + + virtual node_const_iterator + node_end() const = 0; + + virtual node_iterator + node_end() = 0; + + virtual const access_traits& + get_access_traits() const = 0; + + private: + typedef typename access_traits::const_iterator e_const_iterator; + typedef std::pair<e_const_iterator, e_const_iterator> prefix_range_t; + + protected: + static size_type + common_prefix_len(node_iterator, e_const_iterator, + e_const_iterator, const access_traits&); + + static iterator + leftmost_it(node_iterator); + + static iterator + rightmost_it(node_iterator); + + static bool + less(e_const_iterator, e_const_iterator, e_const_iterator, + e_const_iterator, const access_traits&); + }; + + +#define PB_DS_CLASS_T_DEC \ + template<typename Node_CItr, typename Node_Itr, \ + typename _ATraits, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + trie_policy_base<Node_CItr, Node_Itr, _ATraits, _Alloc> + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::size_type + PB_DS_CLASS_C_DEC:: + common_prefix_len(node_iterator nd_it, e_const_iterator b_r, + e_const_iterator e_r, const access_traits& r_traits) + { + prefix_range_t pref_range = nd_it.valid_prefix(); + + e_const_iterator b_l = pref_range.first; + e_const_iterator e_l = pref_range.second; + + const size_type range_length_l = std::distance(b_l, e_l); + const size_type range_length_r = std::distance(b_r, e_r); + + if (range_length_r < range_length_l) + { + std::swap(b_l, b_r); + std::swap(e_l, e_r); + } + + size_type ret = 0; + while (b_l != e_l) + { + if (r_traits.e_pos(*b_l) != r_traits.e_pos(*b_r)) + return ret; + + ++ret; + ++b_l; + ++b_r; + } + + return ret; + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::iterator + PB_DS_CLASS_C_DEC:: + leftmost_it(node_iterator nd_it) + { + if (nd_it.num_children() == 0) + return *nd_it; + + return leftmost_it(nd_it.get_child(0)); + } + + PB_DS_CLASS_T_DEC + typename PB_DS_CLASS_C_DEC::iterator + PB_DS_CLASS_C_DEC:: + rightmost_it(node_iterator nd_it) + { + const size_type num_children = nd_it.num_children(); + + if (num_children == 0) + return *nd_it; + + return rightmost_it(nd_it.get_child(num_children - 1)); + } + + PB_DS_CLASS_T_DEC + bool + PB_DS_CLASS_C_DEC:: + less(e_const_iterator b_l, e_const_iterator e_l, + e_const_iterator b_r, e_const_iterator e_r, + const access_traits& r_traits) + { + while (b_l != e_l) + { + if (b_r == e_r) + return false; + + size_type l_pos = r_traits.e_pos(*b_l); + size_type r_pos = r_traits.e_pos(*b_r); + if (l_pos != r_pos) + return (l_pos < r_pos); + + ++b_l; + ++b_r; + } + return b_r != e_r; + } + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_TRIE_POLICY_BASE_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/trie_string_access_traits_imp.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/trie_string_access_traits_imp.hpp new file mode 100644 index 0000000..3a57634 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/trie_policy/trie_string_access_traits_imp.hpp @@ -0,0 +1,99 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file trie_policy/trie_string_access_traits_imp.hpp + * Contains a policy for extracting character positions from + * a string for a vector-based PATRICIA tree + */ + +PB_DS_CLASS_T_DEC +detail::integral_constant<int, Reverse> PB_DS_CLASS_C_DEC::s_rev_ind; + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +e_pos(e_type e) +{ + return (static_cast<size_type>(e - min_e_val)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin(key_const_reference r_key) +{ + return (begin_imp(r_key, s_rev_ind)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end(key_const_reference r_key) +{ + return (end_imp(r_key, s_rev_ind)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin_imp(key_const_reference r_key, detail::false_type) +{ + return (r_key.begin()); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin_imp(key_const_reference r_key, detail::true_type) +{ + return (r_key.rbegin()); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end_imp(key_const_reference r_key, detail::false_type) +{ + return (r_key.end()); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end_imp(key_const_reference r_key, detail::true_type) +{ + return (r_key.rend()); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/type_utils.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/type_utils.hpp new file mode 100644 index 0000000..033703c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/type_utils.hpp @@ -0,0 +1,167 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file detail/type_utils.hpp + * Contains utilities for handnling types. All of these classes are based on + * Modern C++ by Andrei Alxandrescu. + */ + +#ifndef PB_DS_TYPE_UTILS_HPP +#define PB_DS_TYPE_UTILS_HPP + +#include <cstddef> +#include <utility> +#include <tr1/type_traits> +#include <ext/type_traits.h> +#include <ext/numeric_traits.h> + +namespace __gnu_pbds +{ + namespace detail + { + using std::tr1::is_same; + using std::tr1::is_const; + using std::tr1::is_pointer; + using std::tr1::is_reference; + using std::tr1::is_fundamental; + using std::tr1::is_member_object_pointer; + using std::tr1::is_member_pointer; + using std::tr1::is_base_of; + using std::tr1::remove_const; + using std::tr1::remove_reference; + + // Need integral_const<bool, true> <-> integral_const<int, 1>, so + // because of this use the following typedefs instead of importing + // std::tr1's. + using std::tr1::integral_constant; + typedef std::tr1::integral_constant<int, 1> true_type; + typedef std::tr1::integral_constant<int, 0> false_type; + + using __gnu_cxx::__conditional_type; + using __gnu_cxx::__numeric_traits; + + template<typename T> + struct is_const_pointer + { + enum + { + value = is_const<T>::value && is_pointer<T>::value + }; + }; + + template<typename T> + struct is_const_reference + { + enum + { + value = is_const<T>::value && is_reference<T>::value + }; + }; + + template<typename T> + struct is_simple + { + enum + { + value = is_fundamental<typename remove_const<T>::type>::value + || is_pointer<typename remove_const<T>::type>::value + || is_member_pointer<T>::value + }; + }; + + template<typename T> + class is_pair + { + private: + template<typename U> + struct is_pair_imp + { + enum + { + value = 0 + }; + }; + + template<typename U, typename V> + struct is_pair_imp<std::pair<U,V> > + { + enum + { + value = 1 + }; + }; + + public: + enum + { + value = is_pair_imp<T>::value + }; + }; + + // Use C++0x's static_assert if possible. +#if __cplusplus >= 201103L +#define PB_DS_STATIC_ASSERT(UNIQUE, E) static_assert(E, #UNIQUE) +#else + template<bool> + struct __static_assert; + + template<> + struct __static_assert<true> + { }; + + template<int> + struct __static_assert_dumclass + { + enum + { + v = 1 + }; + }; + +#define PB_DS_STATIC_ASSERT(UNIQUE, E) \ + typedef __gnu_pbds::detail::__static_assert_dumclass<sizeof(__gnu_pbds::detail::__static_assert<bool(E)>)> UNIQUE##__static_assert_type + +#endif + + template<typename Type> + struct type_to_type + { + typedef Type type; + }; + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/types_traits.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/types_traits.hpp new file mode 100644 index 0000000..6666d91 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/types_traits.hpp @@ -0,0 +1,288 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file detail/types_traits.hpp + * Contains a traits class of types used by containers. + */ + +#ifndef PB_DS_TYPES_TRAITS_HPP +#define PB_DS_TYPES_TRAITS_HPP + +#include <algorithm> +#include <utility> +#include <ext/pb_ds/tag_and_trait.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <utility> + +namespace __gnu_pbds +{ + namespace detail + { + /** + * @addtogroup traits Traits + * @{ + */ + + /// Primary template. + template<typename Key, typename Mapped> + struct no_throw_copies + { + static const bool __simple = is_simple<Key>::value + && is_simple<Mapped>::value; + typedef integral_constant<int, __simple> indicator; + }; + + /// Specialization. + template<typename Key> + struct no_throw_copies<Key, null_type> + { + typedef integral_constant<int, is_simple<Key>::value> indicator; + }; + + + /// Stored value. + template<typename _Tv> + struct stored_value + { + typedef _Tv value_type; + value_type m_value; + }; + + /// Stored hash. + template<typename _Th> + struct stored_hash + { + typedef _Th hash_type; + hash_type m_hash; + }; + + /// Primary template for representation of stored data. + /// Two types of data can be stored: value and hash. + template<typename _Tv, typename _Th> + struct stored_data + : public stored_value<_Tv>, public stored_hash<_Th> + { }; + + /// Specialization for representation of stored data of just value type. + template<typename _Tv> + struct stored_data<_Tv, null_type> + : public stored_value<_Tv> + { }; + + /// Primary template. + template<typename Key, typename Mapped, typename _Alloc, bool Store_Hash> + struct type_base; + + /** + * Specialization of type_base for the case where the hash value + * is not stored alongside each value. + */ + template<typename Key, typename Mapped, typename _Alloc> + struct type_base<Key, Mapped, _Alloc, false> + { + public: + typedef typename _Alloc::size_type size_type; + + private: + typedef typename _Alloc::template rebind<Mapped> __rebind_m; + typedef typename __rebind_m::other __rebind_ma; + typedef std::pair<const Key, Mapped> __value_type; + typedef typename _Alloc::template rebind<__value_type> __rebind_v; + typedef typename __rebind_v::other __rebind_va; + + public: + typedef typename __rebind_ma::value_type mapped_type; + typedef typename __rebind_ma::pointer mapped_pointer; + typedef typename __rebind_ma::const_pointer mapped_const_pointer; + typedef typename __rebind_ma::reference mapped_reference; + typedef typename __rebind_ma::const_reference mapped_const_reference; + + typedef typename __rebind_va::value_type value_type; + typedef typename __rebind_va::pointer pointer; + typedef typename __rebind_va::const_pointer const_pointer; + typedef typename __rebind_va::reference reference; + typedef typename __rebind_va::const_reference const_reference; + + typedef stored_data<value_type, null_type> stored_data_type; + }; + + /** + * Specialization of type_base for the case where the hash value + * is stored alongside each value. + */ + template<typename Key, typename Mapped, typename _Alloc> + struct type_base<Key, Mapped, _Alloc, true> + { + public: + typedef typename _Alloc::size_type size_type; + + private: + typedef typename _Alloc::template rebind<Mapped> __rebind_m; + typedef typename __rebind_m::other __rebind_ma; + typedef std::pair<const Key, Mapped> __value_type; + typedef typename _Alloc::template rebind<__value_type> __rebind_v; + typedef typename __rebind_v::other __rebind_va; + + public: + typedef typename __rebind_ma::value_type mapped_type; + typedef typename __rebind_ma::pointer mapped_pointer; + typedef typename __rebind_ma::const_pointer mapped_const_pointer; + typedef typename __rebind_ma::reference mapped_reference; + typedef typename __rebind_ma::const_reference mapped_const_reference; + + typedef typename __rebind_va::value_type value_type; + typedef typename __rebind_va::pointer pointer; + typedef typename __rebind_va::const_pointer const_pointer; + typedef typename __rebind_va::reference reference; + typedef typename __rebind_va::const_reference const_reference; + + typedef stored_data<value_type, size_type> stored_data_type; + }; + + + /** + * Specialization of type_base for the case where the hash value + * is not stored alongside each value. + */ + template<typename Key, typename _Alloc> + struct type_base<Key, null_type, _Alloc, false> + { + public: + typedef typename _Alloc::size_type size_type; + typedef Key value_type; + + private: + typedef typename _Alloc::template rebind<null_type> __rebind_m; + typedef typename __rebind_m::other __rebind_ma; + typedef typename _Alloc::template rebind<value_type> __rebind_v; + typedef typename __rebind_v::other __rebind_va; + + public: + typedef typename __rebind_ma::value_type mapped_type; + typedef typename __rebind_ma::pointer mapped_pointer; + typedef typename __rebind_ma::const_pointer mapped_const_pointer; + typedef typename __rebind_ma::reference mapped_reference; + typedef typename __rebind_ma::const_reference mapped_const_reference; + + typedef typename __rebind_va::pointer pointer; + typedef typename __rebind_va::const_pointer const_pointer; + typedef typename __rebind_va::reference reference; + typedef typename __rebind_va::const_reference const_reference; + + typedef stored_data<value_type, null_type> stored_data_type; + + static null_type s_null_type; + }; + + template<typename Key, typename _Alloc> + null_type + type_base<Key, null_type, _Alloc, false>::s_null_type; + + + /** + * Specialization of type_base for the case where the hash value + * is stored alongside each value. + */ + template<typename Key, typename _Alloc> + struct type_base<Key, null_type, _Alloc, true> + { + public: + typedef typename _Alloc::size_type size_type; + typedef Key value_type; + + private: + typedef typename _Alloc::template rebind<null_type> __rebind_m; + typedef typename __rebind_m::other __rebind_ma; + typedef typename _Alloc::template rebind<value_type> __rebind_v; + typedef typename __rebind_v::other __rebind_va; + + public: + typedef typename __rebind_ma::value_type mapped_type; + typedef typename __rebind_ma::pointer mapped_pointer; + typedef typename __rebind_ma::const_pointer mapped_const_pointer; + typedef typename __rebind_ma::reference mapped_reference; + typedef typename __rebind_ma::const_reference mapped_const_reference; + + typedef typename __rebind_va::pointer pointer; + typedef typename __rebind_va::const_pointer const_pointer; + typedef typename __rebind_va::reference reference; + typedef typename __rebind_va::const_reference const_reference; + + typedef stored_data<value_type, size_type> stored_data_type; + + static null_type s_null_type; + }; + + template<typename Key, typename _Alloc> + null_type + type_base<Key, null_type, _Alloc, true>::s_null_type; + + + /// Type base dispatch. + template<typename Key, typename Mapped, typename _Alloc, bool Store_Hash> + struct type_dispatch + { + typedef type_base<Key, Mapped, _Alloc, Store_Hash> type; + }; + + /// Traits for abstract types. + template<typename Key, typename Mapped, typename _Alloc, bool Store_Hash> + struct types_traits + : public type_dispatch<Key, Mapped, _Alloc, Store_Hash>::type + { + private: + typedef no_throw_copies<Key, Mapped> __nothrowcopy; + typedef typename _Alloc::template rebind<Key>::other __rebind_a; + + public: + typedef typename _Alloc::size_type size_type; + typedef typename __rebind_a::value_type key_type; + typedef typename __rebind_a::pointer key_pointer; + typedef typename __rebind_a::const_pointer key_const_pointer; + typedef typename __rebind_a::reference key_reference; + typedef typename __rebind_a::const_reference key_const_reference; + typedef std::pair<size_type, size_type> comp_hash; + typedef integral_constant<int, Store_Hash> store_extra; + typedef typename __nothrowcopy::indicator no_throw_indicator; + + store_extra m_store_extra_indicator; + no_throw_indicator m_no_throw_copies_indicator; + }; + //@} + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/const_iterator.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/const_iterator.hpp new file mode 100644 index 0000000..8c02e88 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/const_iterator.hpp @@ -0,0 +1,111 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file unordered_iterator/const_iterator.hpp + * Contains an iterator class used for const ranging over the elements of the + * table. + */ + +/// Const range-type iterator. +class const_iterator_ +: public point_const_iterator_ +{ +public: + /// Category. + typedef std::forward_iterator_tag iterator_category; + + /// Difference type. + typedef typename _Alloc::difference_type difference_type; + + /// Iterator's value type. + typedef value_type_ value_type; + + /// Iterator's pointer type. + typedef pointer_ pointer; + + /// Iterator's const pointer type. + typedef const_pointer_ const_pointer; + + /// Iterator's reference type. + typedef reference_ reference; + + /// Iterator's const reference type. + typedef const_reference_ const_reference; + + /// Default constructor. + const_iterator_() : m_p_tbl(0) + { } + + /// Increments. + const_iterator_& + operator++() + { + m_p_tbl->inc_it_state(base_type::m_p_value, m_pos); + return *this; + } + + /// Increments. + const_iterator_ + operator++(int) + { + const_iterator_ ret =* this; + m_p_tbl->inc_it_state(base_type::m_p_value, m_pos); + return ret; + } + +protected: + typedef point_const_iterator_ base_type; + + /** + * Constructor used by the table to initiate the generalized + * pointer and position (e.g., this is called from within a find() + * of a table. + * */ + const_iterator_(const_pointer_ p_value, PB_DS_GEN_POS pos, + const PB_DS_CLASS_C_DEC* p_tbl) + : point_const_iterator_(p_value), m_p_tbl(p_tbl), m_pos(pos) + { } + + /** + * Pointer to the table object which created the iterator (used for + * incrementing its position. + * */ + const PB_DS_CLASS_C_DEC* m_p_tbl; + + PB_DS_GEN_POS m_pos; + + friend class PB_DS_CLASS_C_DEC; +}; diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/iterator.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/iterator.hpp new file mode 100644 index 0000000..464fbb5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/iterator.hpp @@ -0,0 +1,130 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file iterator.hpp + * Contains an iterator_ class used for ranging over the elements of the + * table. + */ + +/// Range-type iterator. +class iterator_ +: public const_iterator_ +{ +public: + /// Category. + typedef std::forward_iterator_tag iterator_category; + + /// Difference type. + typedef typename _Alloc::difference_type difference_type; + + /// Iterator's value type. + typedef value_type_ value_type; + + /// Iterator's pointer type. + typedef pointer_ pointer; + + /// Iterator's const pointer type. + typedef const_pointer_ const_pointer; + + /// Iterator's reference type. + typedef reference_ reference; + + /// Iterator's const reference type. + typedef const_reference_ const_reference; + + /// Default constructor. + inline + iterator_() + : const_iterator_(0, PB_DS_GEN_POS(), 0) { } + + /// Conversion to a point-type iterator. + inline + operator point_iterator_() + { return point_iterator_(const_cast<pointer>(const_iterator_::m_p_value)); } + + /// Conversion to a point-type iterator. + inline + operator const point_iterator_() const + { return point_iterator_(const_cast<pointer>(const_iterator_::m_p_value)); } + + /// Access. + pointer + operator->() const + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_p_value != 0); + return (const_cast<pointer>(base_type::m_p_value)); + } + + /// Access. + reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_p_value != 0); + return (const_cast<reference>(*base_type::m_p_value)); + } + + /// Increments. + iterator_& + operator++() + { + base_type::m_p_tbl->inc_it_state(base_type::m_p_value, base_type::m_pos); + return *this; + } + + /// Increments. + iterator_ + operator++(int) + { + iterator_ ret =* this; + base_type::m_p_tbl->inc_it_state(base_type::m_p_value, base_type::m_pos); + return ret; + } + +protected: + typedef const_iterator_ base_type; + + /** + * Constructor used by the table to initiate the generalized + * pointer and position (e.g., this is called from within a find() + * of a table. + * */ + inline + iterator_(pointer p_value, PB_DS_GEN_POS pos, PB_DS_CLASS_C_DEC* p_tbl) + : const_iterator_(p_value, pos, p_tbl) + { } + + friend class PB_DS_CLASS_C_DEC; +}; diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/point_const_iterator.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/point_const_iterator.hpp new file mode 100644 index 0000000..4ea6bc1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/point_const_iterator.hpp @@ -0,0 +1,133 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file unordered_iterator/point_const_iterator.hpp + * Contains an iterator class returned by the tables' const find and insert + * methods. + */ + +class point_iterator_; + +/// Const point-type iterator. +class point_const_iterator_ +{ +public: + /// Category. + typedef trivial_iterator_tag iterator_category; + + /// Difference type. + typedef trivial_iterator_difference_type difference_type; + + /// Iterator's value type. + typedef value_type_ value_type; + + /// Iterator's pointer type. + typedef pointer_ pointer; + + /// Iterator's const pointer type. + typedef const_pointer_ const_pointer; + + /// Iterator's reference type. + typedef reference_ reference; + + /// Iterator's const reference type. + typedef const_reference_ const_reference; + + inline + point_const_iterator_(const_pointer p_value) : m_p_value(p_value) + { } + + /// Default constructor. + inline + point_const_iterator_() : m_p_value(0) + { } + + /// Copy constructor. + inline + point_const_iterator_(const point_const_iterator_& other) + : m_p_value(other.m_p_value) + { } + + /// Copy constructor. + inline + point_const_iterator_(const point_iterator_& other) + : m_p_value(other.m_p_value) + { } + + /// Access. + const_pointer + operator->() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_value != 0); + return m_p_value; + } + + /// Access. + const_reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_value != 0); + return *m_p_value; + } + + /// Compares content to a different iterator object. + bool + operator==(const point_iterator_& other) const + { return m_p_value == other.m_p_value; } + + /// Compares content to a different iterator object. + bool + operator==(const point_const_iterator_& other) const + { return m_p_value == other.m_p_value; } + + /// Compares content (negatively) to a different iterator object. + bool + operator!=(const point_iterator_& other) const + { return m_p_value != other.m_p_value; } + + /// Compares content (negatively) to a different iterator object. + bool + operator!=(const point_const_iterator_& other) const + { return m_p_value != other.m_p_value; } + +protected: + const_pointer m_p_value; + + friend class point_iterator_; + + friend class PB_DS_CLASS_C_DEC; +}; + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/point_iterator.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/point_iterator.hpp new file mode 100644 index 0000000..c4d915b --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/unordered_iterator/point_iterator.hpp @@ -0,0 +1,126 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file point_iterator.hpp + * Contains an iterator class returned by the tables' find and insert + * methods. + */ + +/// Find type iterator. +class point_iterator_ +{ +public: + /// Category. + typedef trivial_iterator_tag iterator_category; + + /// Difference type. + typedef trivial_iterator_difference_type difference_type; + + /// Iterator's value type. + typedef value_type_ value_type; + + /// Iterator's pointer type. + typedef pointer_ pointer; + + /// Iterator's const pointer type. + typedef const_pointer_ const_pointer; + + /// Iterator's reference type. + typedef reference_ reference; + + /// Iterator's const reference type. + typedef const_reference_ const_reference; + + /// Default constructor. + inline + point_iterator_() + : m_p_value(0) + { } + + /// Copy constructor. + inline + point_iterator_(const point_iterator_& other) + : m_p_value(other.m_p_value) + { } + + /// Access. + pointer + operator->() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_value != 0); + return (m_p_value); + } + + /// Access. + reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_value != 0); + return (*m_p_value); + } + + /// Compares content to a different iterator object. + bool + operator==(const point_iterator_& other) const + { return m_p_value == other.m_p_value; } + + /// Compares content to a different iterator object. + bool + operator==(const point_const_iterator_& other) const + { return m_p_value == other.m_p_value; } + + /// Compares content to a different iterator object. + bool + operator!=(const point_iterator_& other) const + { return m_p_value != other.m_p_value; } + + /// Compares content (negatively) to a different iterator object. + bool + operator!=(const point_const_iterator_& other) const + { return m_p_value != other.m_p_value; } + + inline + point_iterator_(pointer p_value) : m_p_value(p_value) + { } + +protected: + friend class point_const_iterator_; + + friend class PB_DS_CLASS_C_DEC; + +protected: + pointer m_p_value; +}; diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/exception.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/exception.hpp new file mode 100644 index 0000000..a42b735 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/exception.hpp @@ -0,0 +1,93 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file exception.hpp + * Contains exception classes. + */ + +#ifndef PB_DS_EXCEPTION_HPP +#define PB_DS_EXCEPTION_HPP + +#include <bits/c++config.h> +#include <stdexcept> +#include <cstdlib> + +namespace __gnu_pbds +{ + /** + * @defgroup exceptions-pbds Exceptions + * @ingroup pbds + * @{ + */ + + /// Base class for exceptions. + struct container_error : public std::logic_error + { + container_error() + : std::logic_error(__N("__gnu_pbds::container_error")) { } + }; + + /// An entry cannot be inserted into a container object for logical + /// reasons (not, e.g., if memory is unabvailable, in which case + /// the allocator_type's exception will be thrown). + struct insert_error : public container_error { }; + + /// A join cannot be performed logical reasons (i.e., the ranges of + /// the two container objects being joined overlaps. + struct join_error : public container_error { }; + + /// A container cannot be resized. + struct resize_error : public container_error { }; + + inline void + __throw_container_error() + { _GLIBCXX_THROW_OR_ABORT(container_error()); } + + inline void + __throw_insert_error() + { _GLIBCXX_THROW_OR_ABORT(insert_error()); } + + inline void + __throw_join_error() + { _GLIBCXX_THROW_OR_ABORT(join_error()); } + + inline void + __throw_resize_error() + { _GLIBCXX_THROW_OR_ABORT(resize_error()); } + //@} +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/hash_policy.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/hash_policy.hpp new file mode 100644 index 0000000..c8f9af6 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/hash_policy.hpp @@ -0,0 +1,617 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file hash_policy.hpp + * Contains hash-related policies. + */ + +#ifndef PB_DS_HASH_POLICY_HPP +#define PB_DS_HASH_POLICY_HPP + +#include <bits/c++config.h> +#include <algorithm> +#include <vector> +#include <cmath> +#include <ext/pb_ds/exception.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/hash_fn/mask_based_range_hashing.hpp> +#include <ext/pb_ds/detail/hash_fn/mod_based_range_hashing.hpp> +#include <ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_size_base.hpp> + +namespace __gnu_pbds +{ +#define PB_DS_CLASS_T_DEC template<typename Size_Type> +#define PB_DS_CLASS_C_DEC linear_probe_fn<Size_Type> + + /// A probe sequence policy using fixed increments. + template<typename Size_Type = std::size_t> + class linear_probe_fn + { + public: + typedef Size_Type size_type; + + void + swap(PB_DS_CLASS_C_DEC& other); + + protected: + /// Returns the i-th offset from the hash value. + inline size_type + operator()(size_type i) const; + }; + +#include <ext/pb_ds/detail/hash_fn/linear_probe_fn_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC template<typename Size_Type> +#define PB_DS_CLASS_C_DEC quadratic_probe_fn<Size_Type> + + /// A probe sequence policy using square increments. + template<typename Size_Type = std::size_t> + class quadratic_probe_fn + { + public: + typedef Size_Type size_type; + + void + swap(PB_DS_CLASS_C_DEC& other); + + protected: + /// Returns the i-th offset from the hash value. + inline size_type + operator()(size_type i) const; + }; + +#include <ext/pb_ds/detail/hash_fn/quadratic_probe_fn_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC template<typename Size_Type> +#define PB_DS_CLASS_C_DEC direct_mask_range_hashing<Size_Type> + + /// A mask range-hashing class (uses a bitmask). + template<typename Size_Type = std::size_t> + class direct_mask_range_hashing + : public detail::mask_based_range_hashing<Size_Type> + { + private: + typedef detail::mask_based_range_hashing<Size_Type> mask_based_base; + + public: + typedef Size_Type size_type; + + void + swap(PB_DS_CLASS_C_DEC& other); + + protected: + void + notify_resized(size_type size); + + /// Transforms the __hash value hash into a ranged-hash value + /// (using a bit-mask). + inline size_type + operator()(size_type hash) const; + }; + +#include <ext/pb_ds/detail/hash_fn/direct_mask_range_hashing_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC template<typename Size_Type> +#define PB_DS_CLASS_C_DEC direct_mod_range_hashing<Size_Type> + + /// A mod range-hashing class (uses the modulo function). + template<typename Size_Type = std::size_t> + class direct_mod_range_hashing + : public detail::mod_based_range_hashing<Size_Type> + { + public: + typedef Size_Type size_type; + + void + swap(PB_DS_CLASS_C_DEC& other); + + protected: + void + notify_resized(size_type size); + + /// Transforms the __hash value hash into a ranged-hash value + /// (using a modulo operation). + inline size_type + operator()(size_type hash) const; + + private: + typedef detail::mod_based_range_hashing<size_type> mod_based_base; + }; + +#include <ext/pb_ds/detail/hash_fn/direct_mod_range_hashing_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC template<bool External_Load_Access, typename Size_Type> +#define PB_DS_CLASS_C_DEC hash_load_check_resize_trigger<External_Load_Access, Size_Type> +#define PB_DS_SIZE_BASE_C_DEC detail::hash_load_check_resize_trigger_size_base<Size_Type, External_Load_Access> + + /// A resize trigger policy based on a load check. It keeps the + /// load factor between some load factors load_min and load_max. + template<bool External_Load_Access = false, typename Size_Type = std::size_t> + class hash_load_check_resize_trigger : private PB_DS_SIZE_BASE_C_DEC + { + public: + typedef Size_Type size_type; + + enum + { + /// Specifies whether the load factor can be accessed + /// externally. The two options have different trade-offs in + /// terms of flexibility, genericity, and encapsulation. + external_load_access = External_Load_Access + }; + + /// Default constructor, or constructor taking load_min and + /// load_max load factors between which this policy will keep the + /// actual load. + hash_load_check_resize_trigger(float load_min = 0.125, + float load_max = 0.5); + + void + swap(hash_load_check_resize_trigger& other); + + virtual + ~hash_load_check_resize_trigger(); + + /// Returns a pair of the minimal and maximal loads, respectively. + inline std::pair<float, float> + get_loads() const; + + /// Sets the loads through a pair of the minimal and maximal + /// loads, respectively. + void + set_loads(std::pair<float, float> load_pair); + + protected: + inline void + notify_insert_search_start(); + + inline void + notify_insert_search_collision(); + + inline void + notify_insert_search_end(); + + inline void + notify_find_search_start(); + + inline void + notify_find_search_collision(); + + inline void + notify_find_search_end(); + + inline void + notify_erase_search_start(); + + inline void + notify_erase_search_collision(); + + inline void + notify_erase_search_end(); + + /// Notifies an element was inserted. The total number of entries + /// in the table is num_entries. + inline void + notify_inserted(size_type num_entries); + + inline void + notify_erased(size_type num_entries); + + /// Notifies the table was cleared. + void + notify_cleared(); + + /// Notifies the table was resized as a result of this object's + /// signifying that a resize is needed. + void + notify_resized(size_type new_size); + + void + notify_externally_resized(size_type new_size); + + inline bool + is_resize_needed() const; + + inline bool + is_grow_needed(size_type size, size_type num_entries) const; + + private: + virtual void + do_resize(size_type new_size); + + typedef PB_DS_SIZE_BASE_C_DEC size_base; + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char* file, int line) const; +#endif + + float m_load_min; + float m_load_max; + size_type m_next_shrink_size; + size_type m_next_grow_size; + bool m_resize_needed; + }; + +#include <ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_SIZE_BASE_C_DEC + +#define PB_DS_CLASS_T_DEC template<bool External_Load_Access, typename Size_Type> +#define PB_DS_CLASS_C_DEC cc_hash_max_collision_check_resize_trigger<External_Load_Access, Size_Type> + + /// A resize trigger policy based on collision checks. It keeps the + /// simulated load factor lower than some given load factor. + template<bool External_Load_Access = false, typename Size_Type = std::size_t> + class cc_hash_max_collision_check_resize_trigger + { + public: + typedef Size_Type size_type; + + enum + { + /// Specifies whether the load factor can be accessed + /// externally. The two options have different trade-offs in + /// terms of flexibility, genericity, and encapsulation. + external_load_access = External_Load_Access + }; + + /// Default constructor, or constructor taking load, a __load + /// factor which it will attempt to maintain. + cc_hash_max_collision_check_resize_trigger(float load = 0.5); + + void + swap(PB_DS_CLASS_C_DEC& other); + + /// Returns the current load. + inline float + get_load() const; + + /// Sets the load; does not resize the container. + void + set_load(float load); + + protected: + /// Notifies an insert search started. + inline void + notify_insert_search_start(); + + /// Notifies a search encountered a collision. + inline void + notify_insert_search_collision(); + + /// Notifies a search ended. + inline void + notify_insert_search_end(); + + /// Notifies a find search started. + inline void + notify_find_search_start(); + + /// Notifies a search encountered a collision. + inline void + notify_find_search_collision(); + + /// Notifies a search ended. + inline void + notify_find_search_end(); + + /// Notifies an erase search started. + inline void + notify_erase_search_start(); + + /// Notifies a search encountered a collision. + inline void + notify_erase_search_collision(); + + /// Notifies a search ended. + inline void + notify_erase_search_end(); + + /// Notifies an element was inserted. + inline void + notify_inserted(size_type num_entries); + + /// Notifies an element was erased. + inline void + notify_erased(size_type num_entries); + + /// Notifies the table was cleared. + void + notify_cleared(); + + /// Notifies the table was resized as a result of this object's + /// signifying that a resize is needed. + void + notify_resized(size_type new_size); + + /// Notifies the table was resized externally. + void + notify_externally_resized(size_type new_size); + + /// Queries whether a resize is needed. + inline bool + is_resize_needed() const; + + /// Queries whether a grow is needed. This method is called only + /// if this object indicated is needed. + inline bool + is_grow_needed(size_type size, size_type num_entries) const; + + private: + void + calc_max_num_coll(); + + inline void + calc_resize_needed(); + + float m_load; + size_type m_size; + size_type m_num_col; + size_type m_max_col; + bool m_resize_needed; + }; + +#include <ext/pb_ds/detail/resize_policy/cc_hash_max_collision_check_resize_trigger_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC template<typename Size_Type> +#define PB_DS_CLASS_C_DEC hash_exponential_size_policy<Size_Type> + + /// A size policy whose sequence of sizes form an exponential + /// sequence (typically powers of 2. + template<typename Size_Type = std::size_t> + class hash_exponential_size_policy + { + public: + typedef Size_Type size_type; + + /// Default constructor, or onstructor taking a start_size, or + /// constructor taking a start size and grow_factor. The policy + /// will use the sequence of sizes start_size, start_size* + /// grow_factor, start_size* grow_factor^2, ... + hash_exponential_size_policy(size_type start_size = 8, + size_type grow_factor = 2); + + void + swap(PB_DS_CLASS_C_DEC& other); + + protected: + size_type + get_nearest_larger_size(size_type size) const; + + size_type + get_nearest_smaller_size(size_type size) const; + + private: + size_type m_start_size; + size_type m_grow_factor; + }; + +#include <ext/pb_ds/detail/resize_policy/hash_exponential_size_policy_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC +#define PB_DS_CLASS_C_DEC hash_prime_size_policy + + /// A size policy whose sequence of sizes form a nearly-exponential + /// sequence of primes. + class hash_prime_size_policy + { + public: + /// Size type. + typedef std::size_t size_type; + + /// Default constructor, or onstructor taking a start_size The + /// policy will use the sequence of sizes approximately + /// start_size, start_size* 2, start_size* 2^2, ... + hash_prime_size_policy(size_type start_size = 8); + + inline void + swap(PB_DS_CLASS_C_DEC& other); + + protected: + size_type + get_nearest_larger_size(size_type size) const; + + size_type + get_nearest_smaller_size(size_type size) const; + + private: + size_type m_start_size; + }; + +#include <ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC template<typename Size_Policy, typename Trigger_Policy, bool External_Size_Access, typename Size_Type> + +#define PB_DS_CLASS_C_DEC hash_standard_resize_policy<Size_Policy, Trigger_Policy, External_Size_Access, Size_Type> + + /// A resize policy which delegates operations to size and trigger policies. + template<typename Size_Policy = hash_exponential_size_policy<>, + typename Trigger_Policy = hash_load_check_resize_trigger<>, + bool External_Size_Access = false, + typename Size_Type = std::size_t> + class hash_standard_resize_policy + : public Size_Policy, public Trigger_Policy + { + public: + typedef Size_Type size_type; + typedef Trigger_Policy trigger_policy; + typedef Size_Policy size_policy; + + enum + { + external_size_access = External_Size_Access + }; + + /// Default constructor. + hash_standard_resize_policy(); + + /// constructor taking some policies r_size_policy will be copied + /// by the Size_Policy object of this object. + hash_standard_resize_policy(const Size_Policy& r_size_policy); + + /// constructor taking some policies. r_size_policy will be + /// copied by the Size_Policy object of this + /// object. r_trigger_policy will be copied by the Trigger_Policy + /// object of this object. + hash_standard_resize_policy(const Size_Policy& r_size_policy, + const Trigger_Policy& r_trigger_policy); + + virtual + ~hash_standard_resize_policy(); + + inline void + swap(PB_DS_CLASS_C_DEC& other); + + /// Access to the Size_Policy object used. + Size_Policy& + get_size_policy(); + + /// Const access to the Size_Policy object used. + const Size_Policy& + get_size_policy() const; + + /// Access to the Trigger_Policy object used. + Trigger_Policy& + get_trigger_policy(); + + /// Access to the Trigger_Policy object used. + const Trigger_Policy& + get_trigger_policy() const; + + /// Returns the actual size of the container. + inline size_type + get_actual_size() const; + + /// Resizes the container to suggested_new_size, a suggested size + /// (the actual size will be determined by the Size_Policy + /// object). + void + resize(size_type suggested_new_size); + + protected: + inline void + notify_insert_search_start(); + + inline void + notify_insert_search_collision(); + + inline void + notify_insert_search_end(); + + inline void + notify_find_search_start(); + + inline void + notify_find_search_collision(); + + inline void + notify_find_search_end(); + + inline void + notify_erase_search_start(); + + inline void + notify_erase_search_collision(); + + inline void + notify_erase_search_end(); + + inline void + notify_inserted(size_type num_e); + + inline void + notify_erased(size_type num_e); + + void + notify_cleared(); + + void + notify_resized(size_type new_size); + + inline bool + is_resize_needed() const; + + /// Queries what the new size should be, when the container is + /// resized naturally. The current __size of the container is + /// size, and the number of used entries within the container is + /// num_used_e. + size_type + get_new_size(size_type size, size_type num_used_e) const; + + private: + /// Resizes to new_size. + virtual void + do_resize(size_type new_size); + + typedef Trigger_Policy trigger_policy_base; + + typedef Size_Policy size_policy_base; + + size_type m_size; + }; + +#include <ext/pb_ds/detail/resize_policy/hash_standard_resize_policy_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/list_update_policy.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/list_update_policy.hpp new file mode 100644 index 0000000..1cc8144 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/list_update_policy.hpp @@ -0,0 +1,130 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file list_update_policy.hpp + * Contains policies for list update containers. + */ + +#ifndef PB_DS_LU_POLICY_HPP +#define PB_DS_LU_POLICY_HPP + +#include <bits/c++config.h> +#include <cstdlib> +#include <ext/pb_ds/detail/list_update_policy/lu_counter_metadata.hpp> +#include <ext/pb_ds/tag_and_trait.hpp> + +namespace __gnu_pbds +{ + /** + * A list-update policy that unconditionally moves elements to the + * front of the list. A null type means that each link in a + * list-based container does not actually need metadata. + */ + template<typename _Alloc = std::allocator<char> > + class lu_move_to_front_policy + { + public: + typedef _Alloc allocator_type; + + /// Metadata on which this functor operates. + typedef null_type metadata_type; + + private: + typedef typename _Alloc::template rebind<metadata_type> __rebind_m; + + public: + /// Reference to metadata on which this functor operates. + typedef typename __rebind_m::other::reference metadata_reference; + + /// Creates a metadata object. + metadata_type + operator()() const + { return s_metadata; } + + /// Decides whether a metadata object should be moved to the front + /// of the list. + inline bool + operator()(metadata_reference r_metadata) const + { return true; } + + private: + static null_type s_metadata; + }; + + /** + * A list-update policy that moves elements to the front of the + * list based on the counter algorithm. + */ + template<std::size_t Max_Count = 5, typename _Alloc = std::allocator<char> > + class lu_counter_policy + : private detail::lu_counter_policy_base<typename _Alloc::size_type> + { + public: + typedef _Alloc allocator_type; + typedef typename allocator_type::size_type size_type; + + enum + { + /// When some element is accessed this number of times, it + /// will be moved to the front of the list. + max_count = Max_Count + }; + + /// Metadata on which this functor operates. + typedef detail::lu_counter_metadata<size_type> metadata_type; + + private: + typedef detail::lu_counter_policy_base<size_type> base_type; + typedef typename _Alloc::template rebind<metadata_type> __rebind_m; + + public: + /// Reference to metadata on which this functor operates. + typedef typename __rebind_m::other::reference metadata_reference; + + /// Creates a metadata object. + metadata_type + operator()() const + { return base_type::operator()(max_count); } + + /// Decides whether a metadata object should be moved to the front + /// of the list. + bool + operator()(metadata_reference r_data) const + { return base_type::operator()(r_data, max_count); } + }; +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/priority_queue.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/priority_queue.hpp new file mode 100644 index 0000000..83475bb --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/priority_queue.hpp @@ -0,0 +1,157 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file priority_queue.hpp + * Contains priority_queues. + */ + +#ifndef PB_DS_PRIORITY_QUEUE_HPP +#define PB_DS_PRIORITY_QUEUE_HPP + +#include <bits/c++config.h> +#include <ext/pb_ds/tag_and_trait.hpp> +#include <ext/pb_ds/detail/priority_queue_base_dispatch.hpp> +#include <ext/pb_ds/detail/standard_policies.hpp> + +namespace __gnu_pbds +{ + /** + * @defgroup heap-based Heap-Based + * @ingroup containers-pbds + * @{ + */ + + /** + * @defgroup heap-detail Base and Policy Classes + * @ingroup heap-based + */ + + /** + * A priority queue composed of one specific heap policy. + * + * @tparam _Tv Value type. + * @tparam Cmp_Fn Comparison functor. + * @tparam Tag Instantiating data structure type, + * see container_tag. + * @tparam _Alloc Allocator type. + * + * Base is dispatched at compile time via Tag, from the following + * choices: binary_heap_tag, binomial_heap_tag, pairing_heap_tag, + * rc_binomial_heap_tag, thin_heap_tag + * + * Base choices are: detail::binary_heap, detail::binomial_heap, + * detail::pairing_heap, detail::rc_binomial_heap, + * detail::thin_heap. + */ + template<typename _Tv, + typename Cmp_Fn = std::less<_Tv>, + typename Tag = pairing_heap_tag, + typename _Alloc = std::allocator<char> > + class priority_queue + : public detail::container_base_dispatch<_Tv, Cmp_Fn, _Alloc, Tag>::type + { + public: + typedef _Tv value_type; + typedef Cmp_Fn cmp_fn; + typedef Tag container_category; + typedef _Alloc allocator_type; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + + private: + typedef typename detail::container_base_dispatch<_Tv, Cmp_Fn, _Alloc, + Tag>::type + base_type; + typedef typename _Alloc::template rebind<_Tv> __rebind_v; + typedef typename __rebind_v::other __rebind_va; + + public: + typedef typename __rebind_va::reference reference; + typedef typename __rebind_va::const_reference const_reference; + typedef typename __rebind_va::pointer pointer; + typedef typename __rebind_va::const_pointer const_pointer; + + typedef typename base_type::point_iterator point_iterator; + typedef typename base_type::point_const_iterator point_const_iterator; + typedef typename base_type::iterator iterator; + typedef typename base_type::const_iterator const_iterator; + + priority_queue() { } + + /// Constructor taking some policy objects. r_cmp_fn will be + /// copied by the Cmp_Fn object of the container object. + priority_queue(const cmp_fn& r_cmp_fn) : base_type(r_cmp_fn) { } + + /// Constructor taking __iterators to a range of value_types. The + /// value_types between first_it and last_it will be inserted into + /// the container object. + template<typename It> + priority_queue(It first_it, It last_it) + { base_type::copy_from_range(first_it, last_it); } + + /// Constructor taking __iterators to a range of value_types and + /// some policy objects The value_types between first_it and + /// last_it will be inserted into the container object. r_cmp_fn + /// will be copied by the cmp_fn object of the container object. + template<typename It> + priority_queue(It first_it, It last_it, const cmp_fn& r_cmp_fn) + : base_type(r_cmp_fn) + { base_type::copy_from_range(first_it, last_it); } + + priority_queue(const priority_queue& other) + : base_type((const base_type& )other) { } + + virtual + ~priority_queue() { } + + priority_queue& + operator=(const priority_queue& other) + { + if (this != &other) + { + priority_queue tmp(other); + swap(tmp); + } + return *this; + } + + void + swap(priority_queue& other) + { base_type::swap(other); } + }; +} // namespace __gnu_pbds + //@} heap-based +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/tag_and_trait.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/tag_and_trait.hpp new file mode 100644 index 0000000..ba2fb3d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/tag_and_trait.hpp @@ -0,0 +1,454 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file tag_and_trait.hpp + * Contains tags and traits, e.g., ones describing underlying + * data structures. + */ + +#ifndef PB_DS_TAG_AND_TRAIT_HPP +#define PB_DS_TAG_AND_TRAIT_HPP + +#include <bits/c++config.h> +#include <ext/pb_ds/detail/type_utils.hpp> + +/** + * @namespace __gnu_pbds + * @brief GNU extensions for policy-based data structures for public use. + */ +namespace __gnu_pbds +{ + /** @defgroup pbds Policy-Based Data Structures + * @ingroup extensions + * + * This is a library of policy-based elementary data structures: + * associative containers and priority queues. It is designed for + * high-performance, flexibility, semantic safety, and conformance + * to the corresponding containers in std (except for some points + * where it differs by design). + * + * For details, see: + * http://gcc.gnu.org/onlinedocs/libstdc++/ext/pb_ds/index.html + * + * @{ + */ + + /** + * @defgroup tags Tags + * @{ + */ + /// A trivial iterator tag. Signifies that the iterators has none of + /// std::iterators's movement abilities. + struct trivial_iterator_tag + { }; + + /// Prohibit moving trivial iterators. + typedef void trivial_iterator_difference_type; + + + /** + * @defgroup invalidation_tags Invalidation Guarantees + * @ingroup tags + * @{ + */ + + /** + * Signifies a basic invalidation guarantee that any iterator, + * pointer, or reference to a container object's mapped value type + * is valid as long as the container is not modified. + */ + struct basic_invalidation_guarantee + { }; + + /** + * Signifies an invalidation guarantee that includes all those of + * its base, and additionally, that any point-type iterator, + * pointer, or reference to a container object's mapped value type + * is valid as long as its corresponding entry has not be erased, + * regardless of modifications to the container object. + */ + struct point_invalidation_guarantee : public basic_invalidation_guarantee + { }; + + /** + * Signifies an invalidation guarantee that includes all those of + * its base, and additionally, that any range-type iterator + * (including the returns of begin() and end()) is in the correct + * relative positions to other range-type iterators as long as its + * corresponding entry has not be erased, regardless of + * modifications to the container object. + */ + struct range_invalidation_guarantee : public point_invalidation_guarantee + { }; + //@} + + + /** + * @defgroup ds_tags Data Structure Type + * @ingroup tags + * @{ + */ + /// Base data structure tag. + struct container_tag + { }; + + /// Basic sequence. + struct sequence_tag : public container_tag { }; + + /// Basic string container, inclusive of strings, ropes, etc. + struct string_tag : public sequence_tag { }; + + /// Basic associative-container. + struct associative_tag : public container_tag { }; + + /// Basic hash structure. + struct basic_hash_tag : public associative_tag { }; + + /// Collision-chaining hash. + struct cc_hash_tag : public basic_hash_tag { }; + + /// General-probing hash. + struct gp_hash_tag : public basic_hash_tag { }; + + /// Basic branch structure. + struct basic_branch_tag : public associative_tag { }; + + /// Basic tree structure. + struct tree_tag : public basic_branch_tag { }; + + /// Red-black tree. + struct rb_tree_tag : public tree_tag { }; + + /// Splay tree. + struct splay_tree_tag : public tree_tag { }; + + /// Ordered-vector tree. + struct ov_tree_tag : public tree_tag { }; + + /// Basic trie structure. + struct trie_tag : public basic_branch_tag { }; + + /// PATRICIA trie. + struct pat_trie_tag : public trie_tag { }; + + /// List-update. + struct list_update_tag : public associative_tag { }; + + /// Basic priority-queue. + struct priority_queue_tag : public container_tag { }; + + /// Pairing-heap. + struct pairing_heap_tag : public priority_queue_tag { }; + + /// Binomial-heap. + struct binomial_heap_tag : public priority_queue_tag { }; + + /// Redundant-counter binomial-heap. + struct rc_binomial_heap_tag : public priority_queue_tag { }; + + /// Binary-heap (array-based). + struct binary_heap_tag : public priority_queue_tag { }; + + /// Thin heap. + struct thin_heap_tag : public priority_queue_tag { }; + //@} + //@} + + + /** + * @defgroup traits Traits + * @{ + */ + + /** + * @brief Represents no type, or absence of type, for template tricks. + * + * In a mapped-policy, indicates that an associative container is a set. + * + * In a list-update policy, indicates that each link does not need + * metadata. + * + * In a hash policy, indicates that the combining hash function + * is actually a ranged hash function. + * + * In a probe policy, indicates that the combining probe function + * is actually a ranged probe function. + */ + struct null_type { }; + + /// A null node updator, indicating that no node updates are required. + template<typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4> + struct null_node_update : public null_type + { }; + + + /// Primary template, container traits base. + template<typename _Tag> + struct container_traits_base; + + /// Specialization, cc hash. + template<> + struct container_traits_base<cc_hash_tag> + { + typedef cc_hash_tag container_category; + typedef point_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = false, + erase_can_throw = false, + split_join_can_throw = false, + reverse_iteration = false + }; + }; + + /// Specialization, gp hash. + template<> + struct container_traits_base<gp_hash_tag> + { + typedef gp_hash_tag container_category; + typedef basic_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = false, + erase_can_throw = false, + split_join_can_throw = false, + reverse_iteration = false + }; + }; + + /// Specialization, rb tree. + template<> + struct container_traits_base<rb_tree_tag> + { + typedef rb_tree_tag container_category; + typedef range_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = true, + erase_can_throw = false, + split_join_can_throw = false, + reverse_iteration = true + }; + }; + + /// Specialization, splay tree. + template<> + struct container_traits_base<splay_tree_tag> + { + typedef splay_tree_tag container_category; + typedef range_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = true, + erase_can_throw = false, + split_join_can_throw = false, + reverse_iteration = true + }; + }; + + /// Specialization, ov tree. + template<> + struct container_traits_base<ov_tree_tag> + { + typedef ov_tree_tag container_category; + typedef basic_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = true, + erase_can_throw = true, + split_join_can_throw = true, + reverse_iteration = false + }; + }; + + /// Specialization, pat trie. + template<> + struct container_traits_base<pat_trie_tag> + { + typedef pat_trie_tag container_category; + typedef range_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = true, + erase_can_throw = false, + split_join_can_throw = true, + reverse_iteration = true + }; + }; + + /// Specialization, list update. + template<> + struct container_traits_base<list_update_tag> + { + typedef list_update_tag container_category; + typedef point_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = false, + erase_can_throw = false, + split_join_can_throw = false, + reverse_iteration = false + }; + }; + + /// Specialization, pairing heap. + template<> + struct container_traits_base<pairing_heap_tag> + { + typedef pairing_heap_tag container_category; + typedef point_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = false, + erase_can_throw = false, + split_join_can_throw = false, + reverse_iteration = false + }; + }; + + /// Specialization, thin heap. + template<> + struct container_traits_base<thin_heap_tag> + { + typedef thin_heap_tag container_category; + typedef point_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = false, + erase_can_throw = false, + split_join_can_throw = false, + reverse_iteration = false + }; + }; + + /// Specialization, binomial heap. + template<> + struct container_traits_base<binomial_heap_tag> + { + typedef binomial_heap_tag container_category; + typedef point_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = false, + erase_can_throw = false, + split_join_can_throw = false, + reverse_iteration = false + }; + }; + + /// Specialization, rc binomial heap. + template<> + struct container_traits_base<rc_binomial_heap_tag> + { + typedef rc_binomial_heap_tag container_category; + typedef point_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = false, + erase_can_throw = false, + split_join_can_throw = false, + reverse_iteration = false + }; + }; + + /// Specialization, binary heap. + template<> + struct container_traits_base<binary_heap_tag> + { + typedef binary_heap_tag container_category; + typedef basic_invalidation_guarantee invalidation_guarantee; + + enum + { + order_preserving = false, + erase_can_throw = false, + split_join_can_throw = true, + reverse_iteration = false + }; + }; + + + /// Container traits. + // See Matt Austern for the name, S. Meyers MEFC++ #2, others. + template<typename Cntnr> + struct container_traits + : public container_traits_base<typename Cntnr::container_category> + { + typedef Cntnr container_type; + typedef typename Cntnr::container_category container_category; + typedef container_traits_base<container_category> base_type; + typedef typename base_type::invalidation_guarantee invalidation_guarantee; + + enum + { + /// True only if Cntnr objects guarantee storing keys by order. + order_preserving = base_type::order_preserving, + + /// True only if erasing a key can throw. + erase_can_throw = base_type::erase_can_throw, + + /// True only if split or join operations can throw. + split_join_can_throw = base_type::split_join_can_throw, + + /// True only reverse iterators are supported. + reverse_iteration = base_type::reverse_iteration + }; + }; + //@} + + + namespace detail + { + /// Dispatch mechanism, primary template for associative types. + template<typename Key, typename Mapped, typename _Alloc, typename Tag, + typename Policy_Tl = null_type> + struct container_base_dispatch; + } // namespace detail + //@} +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/tree_policy.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/tree_policy.hpp new file mode 100644 index 0000000..ab421d0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/tree_policy.hpp @@ -0,0 +1,157 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file tree_policy.hpp + * Contains tree-related policies. + */ + +#ifndef PB_DS_TREE_POLICY_HPP +#define PB_DS_TREE_POLICY_HPP + +#include <bits/c++config.h> +#include <iterator> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/branch_policy/branch_policy.hpp> + +namespace __gnu_pbds +{ +#define PB_DS_CLASS_T_DEC \ + template<typename Node_CItr, typename Node_Itr, typename Cmp_Fn, \ + typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + tree_order_statistics_node_update<Node_CItr, Node_Itr, Cmp_Fn, _Alloc> + +#define PB_DS_BRANCH_POLICY_BASE \ + detail::branch_policy<Node_CItr, Node_Itr, _Alloc> + + /// Functor updating ranks of entrees. + template<typename Node_CItr, typename Node_Itr, + typename Cmp_Fn, typename _Alloc> + class tree_order_statistics_node_update : private PB_DS_BRANCH_POLICY_BASE + { + private: + typedef PB_DS_BRANCH_POLICY_BASE base_type; + + public: + typedef Cmp_Fn cmp_fn; + typedef _Alloc allocator_type; + typedef typename allocator_type::size_type size_type; + typedef typename base_type::key_type key_type; + typedef typename base_type::key_const_reference key_const_reference; + + typedef size_type metadata_type; + typedef Node_CItr node_const_iterator; + typedef Node_Itr node_iterator; + typedef typename node_const_iterator::value_type const_iterator; + typedef typename node_iterator::value_type iterator; + + /// Finds an entry by __order. Returns a const_iterator to the + /// entry with the __order order, or a const_iterator to the + /// container object's end if order is at least the size of the + /// container object. + inline const_iterator + find_by_order(size_type) const; + + /// Finds an entry by __order. Returns an iterator to the entry + /// with the __order order, or an iterator to the container + /// object's end if order is at least the size of the container + /// object. + inline iterator + find_by_order(size_type); + + /// Returns the order of a key within a sequence. For exapmle, if + /// r_key is the smallest key, this method will return 0; if r_key + /// is a key between the smallest and next key, this method will + /// return 1; if r_key is a key larger than the largest key, this + /// method will return the size of r_c. + inline size_type + order_of_key(key_const_reference) const; + + private: + /// Const reference to the container's value-type. + typedef typename base_type::const_reference const_reference; + + /// Const pointer to the container's value-type. + typedef typename base_type::const_pointer const_pointer; + + typedef typename _Alloc::template rebind<metadata_type>::other __rebind_m; + + /// Const metadata reference. + typedef typename __rebind_m::const_reference metadata_const_reference; + + /// Metadata reference. + typedef typename __rebind_m::reference metadata_reference; + + /// Returns the node_const_iterator associated with the tree's root node. + virtual node_const_iterator + node_begin() const = 0; + + /// Returns the node_iterator associated with the tree's root node. + virtual node_iterator + node_begin() = 0; + + /// Returns the node_const_iterator associated with a just-after leaf node. + virtual node_const_iterator + node_end() const = 0; + + /// Returns the node_iterator associated with a just-after leaf node. + virtual node_iterator + node_end() = 0; + + /// Access to the cmp_fn object. + virtual cmp_fn& + get_cmp_fn() = 0; + + protected: + /// Updates the rank of a node through a node_iterator node_it; + /// end_nd_it is the end node iterator. + inline void + operator()(node_iterator, node_const_iterator) const; + + virtual + ~tree_order_statistics_node_update(); + }; + +#include <ext/pb_ds/detail/tree_policy/order_statistics_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_BRANCH_POLICY_BASE + +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/trie_policy.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/trie_policy.hpp new file mode 100644 index 0000000..04bddfa --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/trie_policy.hpp @@ -0,0 +1,360 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file trie_policy.hpp + * Contains trie-related policies. + */ + +#ifndef PB_DS_TRIE_POLICY_HPP +#define PB_DS_TRIE_POLICY_HPP + +#include <bits/c++config.h> +#include <string> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/trie_policy/trie_policy_base.hpp> + +namespace __gnu_pbds +{ +#define PB_DS_CLASS_T_DEC \ + template<typename String, typename String::value_type Min_E_Val, \ + typename String::value_type Max_E_Val, bool Reverse, \ + typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + trie_string_access_traits<String, Min_E_Val,Max_E_Val,Reverse,_Alloc> + + /** + * Element access traits for string types. + * + * @tparam String String type. + * @tparam Min_E_Val Minimal element value. + * @tparam Max_E_Val Maximum element value. + * @tparam Reverse Reverse iteration should be used. + * Default: false. + * @tparam _Alloc Allocator type. + */ + template<typename String = std::string, + typename String::value_type Min_E_Val = detail::__numeric_traits<typename String::value_type>::__min, + typename String::value_type Max_E_Val = detail::__numeric_traits<typename String::value_type>::__max, + bool Reverse = false, + typename _Alloc = std::allocator<char> > + struct trie_string_access_traits + { + public: + typedef typename _Alloc::size_type size_type; + typedef String key_type; + typedef typename _Alloc::template rebind<key_type> __rebind_k; + typedef typename __rebind_k::other::const_reference key_const_reference; + + enum + { + reverse = Reverse + }; + + /// Element const iterator type. + typedef typename detail::__conditional_type<Reverse, \ + typename String::const_reverse_iterator, \ + typename String::const_iterator>::__type const_iterator; + + /// Element type. + typedef typename std::iterator_traits<const_iterator>::value_type e_type; + + enum + { + min_e_val = Min_E_Val, + max_e_val = Max_E_Val, + max_size = max_e_val - min_e_val + 1 + }; + PB_DS_STATIC_ASSERT(min_max_size, max_size >= 2); + + /// Returns a const_iterator to the first element of + /// key_const_reference agumnet. + inline static const_iterator + begin(key_const_reference); + + /// Returns a const_iterator to the after-last element of + /// key_const_reference argument. + inline static const_iterator + end(key_const_reference); + + /// Maps an element to a position. + inline static size_type + e_pos(e_type e); + + private: + inline static const_iterator + begin_imp(key_const_reference, detail::false_type); + + inline static const_iterator + begin_imp(key_const_reference, detail::true_type); + + inline static const_iterator + end_imp(key_const_reference, detail::false_type); + + inline static const_iterator + end_imp(key_const_reference, detail::true_type); + + static detail::integral_constant<int, Reverse> s_rev_ind; + }; + +#include <ext/pb_ds/detail/trie_policy/trie_string_access_traits_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_T_DEC \ + template<typename Node_CItr,typename Node_Itr, \ + typename _ATraits, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + trie_prefix_search_node_update<Node_CItr, Node_Itr, \ + _ATraits,_Alloc> + +#define PB_DS_TRIE_POLICY_BASE \ + detail::trie_policy_base<Node_CItr,Node_Itr,_ATraits, _Alloc> + + /// A node updator that allows tries to be searched for the range of + /// values that match a certain prefix. + template<typename Node_CItr, + typename Node_Itr, + typename _ATraits, + typename _Alloc> + class trie_prefix_search_node_update : private PB_DS_TRIE_POLICY_BASE + { + private: + typedef PB_DS_TRIE_POLICY_BASE base_type; + + public: + typedef typename base_type::key_type key_type; + typedef typename base_type::key_const_reference key_const_reference; + + /// Element access traits. + typedef _ATraits access_traits; + + /// Const element iterator. + typedef typename access_traits::const_iterator a_const_iterator; + + /// _Alloc type. + typedef _Alloc allocator_type; + + /// Size type. + typedef typename allocator_type::size_type size_type; + typedef null_type metadata_type; + typedef Node_Itr node_iterator; + typedef Node_CItr node_const_iterator; + typedef typename node_iterator::value_type iterator; + typedef typename node_const_iterator::value_type const_iterator; + + /// Finds the const iterator range corresponding to all values + /// whose prefixes match r_key. + std::pair<const_iterator, const_iterator> + prefix_range(key_const_reference) const; + + /// Finds the iterator range corresponding to all values whose + /// prefixes match r_key. + std::pair<iterator, iterator> + prefix_range(key_const_reference); + + /// Finds the const iterator range corresponding to all values + /// whose prefixes match [b, e). + std::pair<const_iterator, const_iterator> + prefix_range(a_const_iterator, a_const_iterator) const; + + /// Finds the iterator range corresponding to all values whose + /// prefixes match [b, e). + std::pair<iterator, iterator> + prefix_range(a_const_iterator, a_const_iterator); + + protected: + /// Called to update a node's metadata. + inline void + operator()(node_iterator node_it, node_const_iterator end_nd_it) const; + + private: + node_iterator + next_child(node_iterator, a_const_iterator, a_const_iterator, + node_iterator, const access_traits&); + + /// Returns the const iterator associated with the just-after last element. + virtual const_iterator + end() const = 0; + + /// Returns the iterator associated with the just-after last element. + virtual iterator + end() = 0; + + /// Returns the node_const_iterator associated with the trie's root node. + virtual node_const_iterator + node_begin() const = 0; + + /// Returns the node_iterator associated with the trie's root node. + virtual node_iterator + node_begin() = 0; + + /// Returns the node_const_iterator associated with a just-after leaf node. + virtual node_const_iterator + node_end() const = 0; + + /// Returns the node_iterator associated with a just-after leaf node. + virtual node_iterator + node_end() = 0; + + /// Access to the cmp_fn object. + virtual const access_traits& + get_access_traits() const = 0; + }; + +#include <ext/pb_ds/detail/trie_policy/prefix_search_node_update_imp.hpp> + +#undef PB_DS_CLASS_C_DEC + +#define PB_DS_CLASS_C_DEC \ + trie_order_statistics_node_update<Node_CItr, Node_Itr, \ + _ATraits, _Alloc> + + /// Functor updating ranks of entrees. + template<typename Node_CItr, + typename Node_Itr, + typename _ATraits, + typename _Alloc> + class trie_order_statistics_node_update : private PB_DS_TRIE_POLICY_BASE + { + private: + typedef PB_DS_TRIE_POLICY_BASE base_type; + + public: + typedef _ATraits access_traits; + typedef typename access_traits::const_iterator a_const_iterator; + typedef _Alloc allocator_type; + typedef typename allocator_type::size_type size_type; + typedef typename base_type::key_type key_type; + typedef typename base_type::key_const_reference key_const_reference; + + typedef size_type metadata_type; + typedef Node_CItr node_const_iterator; + typedef Node_Itr node_iterator; + typedef typename node_const_iterator::value_type const_iterator; + typedef typename node_iterator::value_type iterator; + + /// Finds an entry by __order. Returns a const_iterator to the + /// entry with the __order order, or a const_iterator to the + /// container object's end if order is at least the size of the + /// container object. + inline const_iterator + find_by_order(size_type) const; + + /// Finds an entry by __order. Returns an iterator to the entry + /// with the __order order, or an iterator to the container + /// object's end if order is at least the size of the container + /// object. + inline iterator + find_by_order(size_type); + + /// Returns the order of a key within a sequence. For exapmle, if + /// r_key is the smallest key, this method will return 0; if r_key + /// is a key between the smallest and next key, this method will + /// return 1; if r_key is a key larger than the largest key, this + /// method will return the size of r_c. + inline size_type + order_of_key(key_const_reference) const; + + /// Returns the order of a prefix within a sequence. For exapmle, + /// if [b, e] is the smallest prefix, this method will return 0; if + /// r_key is a key between the smallest and next key, this method + /// will return 1; if r_key is a key larger than the largest key, + /// this method will return the size of r_c. + inline size_type + order_of_prefix(a_const_iterator, a_const_iterator) const; + + protected: + /// Updates the rank of a node through a node_iterator node_it; + /// end_nd_it is the end node iterator. + inline void + operator()(node_iterator, node_const_iterator) const; + + private: + typedef typename base_type::const_reference const_reference; + typedef typename base_type::const_pointer const_pointer; + + typedef typename _Alloc::template rebind<metadata_type> __rebind_m; + typedef typename __rebind_m::other __rebind_ma; + typedef typename __rebind_ma::const_reference metadata_const_reference; + typedef typename __rebind_ma::reference metadata_reference; + + /// Returns true if the container is empty. + virtual bool + empty() const = 0; + + /// Returns the iterator associated with the trie's first element. + virtual iterator + begin() = 0; + + /// Returns the iterator associated with the trie's + /// just-after-last element. + virtual iterator + end() = 0; + + /// Returns the node_const_iterator associated with the trie's root node. + virtual node_const_iterator + node_begin() const = 0; + + /// Returns the node_iterator associated with the trie's root node. + virtual node_iterator + node_begin() = 0; + + /// Returns the node_const_iterator associated with a just-after + /// leaf node. + virtual node_const_iterator + node_end() const = 0; + + /// Returns the node_iterator associated with a just-after leaf node. + virtual node_iterator + node_end() = 0; + + /// Access to the cmp_fn object. + virtual access_traits& + get_access_traits() = 0; + }; + +#include <ext/pb_ds/detail/trie_policy/order_statistics_imp.hpp> + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_TRIE_POLICY_BASE + +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pod_char_traits.h b/gcc-4.9/libstdc++-v3/include/ext/pod_char_traits.h new file mode 100644 index 0000000..e027585 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pod_char_traits.h @@ -0,0 +1,192 @@ +// POD character, std::char_traits specialization -*- C++ -*- + +// Copyright (C) 2002-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/pod_char_traits.h + * This file is a GNU extension to the Standard C++ Library. + */ + +// Gabriel Dos Reis <gdr@integrable-solutions.net> +// Benjamin Kosnik <bkoz@redhat.com> + +#ifndef _POD_CHAR_TRAITS_H +#define _POD_CHAR_TRAITS_H 1 + +#pragma GCC system_header + +#include <string> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // POD character abstraction. + // NB: The char_type parameter is a subset of int_type, as to allow + // int_type to properly hold the full range of char_type values as + // well as EOF. + /// @brief A POD class that serves as a character abstraction class. + template<typename _Value, typename _Int, typename _St = std::mbstate_t> + struct character + { + typedef _Value value_type; + typedef _Int int_type; + typedef _St state_type; + typedef character<_Value, _Int, _St> char_type; + + value_type value; + + template<typename V2> + static char_type + from(const V2& v) + { + char_type ret = { static_cast<value_type>(v) }; + return ret; + } + + template<typename V2> + static V2 + to(const char_type& c) + { + V2 ret = { static_cast<V2>(c.value) }; + return ret; + } + + }; + + template<typename _Value, typename _Int, typename _St> + inline bool + operator==(const character<_Value, _Int, _St>& lhs, + const character<_Value, _Int, _St>& rhs) + { return lhs.value == rhs.value; } + + template<typename _Value, typename _Int, typename _St> + inline bool + operator<(const character<_Value, _Int, _St>& lhs, + const character<_Value, _Int, _St>& rhs) + { return lhs.value < rhs.value; } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /// char_traits<__gnu_cxx::character> specialization. + template<typename _Value, typename _Int, typename _St> + struct char_traits<__gnu_cxx::character<_Value, _Int, _St> > + { + typedef __gnu_cxx::character<_Value, _Int, _St> char_type; + typedef typename char_type::int_type int_type; + typedef typename char_type::state_type state_type; + typedef fpos<state_type> pos_type; + typedef streamoff off_type; + + static void + assign(char_type& __c1, const char_type& __c2) + { __c1 = __c2; } + + static bool + eq(const char_type& __c1, const char_type& __c2) + { return __c1 == __c2; } + + static bool + lt(const char_type& __c1, const char_type& __c2) + { return __c1 < __c2; } + + static int + compare(const char_type* __s1, const char_type* __s2, size_t __n) + { + for (size_t __i = 0; __i < __n; ++__i) + if (!eq(__s1[__i], __s2[__i])) + return lt(__s1[__i], __s2[__i]) ? -1 : 1; + return 0; + } + + static size_t + length(const char_type* __s) + { + const char_type* __p = __s; + while (__p->value) + ++__p; + return (__p - __s); + } + + static const char_type* + find(const char_type* __s, size_t __n, const char_type& __a) + { + for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p) + if (*__p == __a) + return __p; + return 0; + } + + static char_type* + move(char_type* __s1, const char_type* __s2, size_t __n) + { + return static_cast<char_type*> + (__builtin_memmove(__s1, __s2, __n * sizeof(char_type))); + } + + static char_type* + copy(char_type* __s1, const char_type* __s2, size_t __n) + { + std::copy(__s2, __s2 + __n, __s1); + return __s1; + } + + static char_type* + assign(char_type* __s, size_t __n, char_type __a) + { + std::fill_n(__s, __n, __a); + return __s; + } + + static char_type + to_char_type(const int_type& __i) + { return char_type::template from(__i); } + + static int_type + to_int_type(const char_type& __c) + { return char_type::template to<int_type>(__c); } + + static bool + eq_int_type(const int_type& __c1, const int_type& __c2) + { return __c1 == __c2; } + + static int_type + eof() + { + int_type __r = { -1 }; + return __r; + } + + static int_type + not_eof(const int_type& __c) + { return eq_int_type(__c, eof()) ? int_type() : __c; } + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pointer.h b/gcc-4.9/libstdc++-v3/include/ext/pointer.h new file mode 100644 index 0000000..cfc6b7c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pointer.h @@ -0,0 +1,593 @@ +// Custom pointer adapter and sample storage policies + +// Copyright (C) 2008-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** + * @file ext/pointer.h + * This file is a GNU extension to the Standard C++ Library. + * + * @author Bob Walters + * + * Provides reusable _Pointer_adapter for assisting in the development of + * custom pointer types that can be used with the standard containers via + * the allocator::pointer and allocator::const_pointer typedefs. + */ + +#ifndef _POINTER_H +#define _POINTER_H 1 + +#pragma GCC system_header + +#include <iosfwd> +#include <bits/stl_iterator_base_types.h> +#include <ext/cast.h> +#include <ext/type_traits.h> +#if __cplusplus >= 201103L +# include <bits/move.h> +# include <bits/ptr_traits.h> +#endif + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * @brief A storage policy for use with _Pointer_adapter<> which yields a + * standard pointer. + * + * A _Storage_policy is required to provide 4 things: + * 1) A get() API for returning the stored pointer value. + * 2) An set() API for storing a pointer value. + * 3) An element_type typedef to define the type this points to. + * 4) An operator<() to support pointer comparison. + * 5) An operator==() to support pointer comparison. + */ + template<typename _Tp> + class _Std_pointer_impl + { + public: + // the type this pointer points to. + typedef _Tp element_type; + + // A method to fetch the pointer value as a standard T* value; + inline _Tp* + get() const + { return _M_value; } + + // A method to set the pointer value, from a standard T* value; + inline void + set(element_type* __arg) + { _M_value = __arg; } + + // Comparison of pointers + inline bool + operator<(const _Std_pointer_impl& __rarg) const + { return (_M_value < __rarg._M_value); } + + inline bool + operator==(const _Std_pointer_impl& __rarg) const + { return (_M_value == __rarg._M_value); } + + private: + element_type* _M_value; + }; + + /** + * @brief A storage policy for use with _Pointer_adapter<> which stores + * the pointer's address as an offset value which is relative to + * its own address. + * + * This is intended for pointers within shared memory regions which + * might be mapped at different addresses by different processes. + * For null pointers, a value of 1 is used. (0 is legitimate + * sometimes for nodes in circularly linked lists) This value was + * chosen as the least likely to generate an incorrect null, As + * there is no reason why any normal pointer would point 1 byte into + * its own pointer address. + */ + template<typename _Tp> + class _Relative_pointer_impl + { + public: + typedef _Tp element_type; + + _Tp* + get() const + { + if (_M_diff == 1) + return 0; + else + return reinterpret_cast<_Tp*>(reinterpret_cast<_UIntPtrType>(this) + + _M_diff); + } + + void + set(_Tp* __arg) + { + if (!__arg) + _M_diff = 1; + else + _M_diff = reinterpret_cast<_UIntPtrType>(__arg) + - reinterpret_cast<_UIntPtrType>(this); + } + + // Comparison of pointers + inline bool + operator<(const _Relative_pointer_impl& __rarg) const + { return (reinterpret_cast<_UIntPtrType>(this->get()) + < reinterpret_cast<_UIntPtrType>(__rarg.get())); } + + inline bool + operator==(const _Relative_pointer_impl& __rarg) const + { return (reinterpret_cast<_UIntPtrType>(this->get()) + == reinterpret_cast<_UIntPtrType>(__rarg.get())); } + + private: +#ifdef _GLIBCXX_USE_LONG_LONG + typedef __gnu_cxx::__conditional_type< + (sizeof(unsigned long) >= sizeof(void*)), + unsigned long, unsigned long long>::__type _UIntPtrType; +#else + typedef unsigned long _UIntPtrType; +#endif + _UIntPtrType _M_diff; + }; + + /** + * Relative_pointer_impl needs a specialization for const T because of + * the casting done during pointer arithmetic. + */ + template<typename _Tp> + class _Relative_pointer_impl<const _Tp> + { + public: + typedef const _Tp element_type; + + const _Tp* + get() const + { + if (_M_diff == 1) + return 0; + else + return reinterpret_cast<const _Tp*> + (reinterpret_cast<_UIntPtrType>(this) + _M_diff); + } + + void + set(const _Tp* __arg) + { + if (!__arg) + _M_diff = 1; + else + _M_diff = reinterpret_cast<_UIntPtrType>(__arg) + - reinterpret_cast<_UIntPtrType>(this); + } + + // Comparison of pointers + inline bool + operator<(const _Relative_pointer_impl& __rarg) const + { return (reinterpret_cast<_UIntPtrType>(this->get()) + < reinterpret_cast<_UIntPtrType>(__rarg.get())); } + + inline bool + operator==(const _Relative_pointer_impl& __rarg) const + { return (reinterpret_cast<_UIntPtrType>(this->get()) + == reinterpret_cast<_UIntPtrType>(__rarg.get())); } + + private: +#ifdef _GLIBCXX_USE_LONG_LONG + typedef __gnu_cxx::__conditional_type< + (sizeof(unsigned long) >= sizeof(void*)), + unsigned long, unsigned long long>::__type _UIntPtrType; +#else + typedef unsigned long _UIntPtrType; +#endif + _UIntPtrType _M_diff; + }; + + /** + * The specialization on this type helps resolve the problem of + * reference to void, and eliminates the need to specialize + * _Pointer_adapter for cases of void*, const void*, and so on. + */ + struct _Invalid_type { }; + + template<typename _Tp> + struct _Reference_type + { typedef _Tp& reference; }; + + template<> + struct _Reference_type<void> + { typedef _Invalid_type& reference; }; + + template<> + struct _Reference_type<const void> + { typedef const _Invalid_type& reference; }; + + template<> + struct _Reference_type<volatile void> + { typedef volatile _Invalid_type& reference; }; + + template<> + struct _Reference_type<volatile const void> + { typedef const volatile _Invalid_type& reference; }; + + /** + * This structure accommodates the way in which + * std::iterator_traits<> is normally specialized for const T*, so + * that value_type is still T. + */ + template<typename _Tp> + struct _Unqualified_type + { typedef _Tp type; }; + + template<typename _Tp> + struct _Unqualified_type<const _Tp> + { typedef _Tp type; }; + + /** + * The following provides an 'alternative pointer' that works with + * the containers when specified as the pointer typedef of the + * allocator. + * + * The pointer type used with the containers doesn't have to be this + * class, but it must support the implicit conversions, pointer + * arithmetic, comparison operators, etc. that are supported by this + * class, and avoid raising compile-time ambiguities. Because + * creating a working pointer can be challenging, this pointer + * template was designed to wrapper an easier storage policy type, + * so that it becomes reusable for creating other pointer types. + * + * A key point of this class is also that it allows container + * writers to 'assume' Allocator::pointer is a typedef for a normal + * pointer. This class supports most of the conventions of a true + * pointer, and can, for instance handle implicit conversion to + * const and base class pointer types. The only impositions on + * container writers to support extended pointers are: 1) use the + * Allocator::pointer typedef appropriately for pointer types. 2) + * if you need pointer casting, use the __pointer_cast<> functions + * from ext/cast.h. This allows pointer cast operations to be + * overloaded as necessary by custom pointers. + * + * Note: The const qualifier works with this pointer adapter as + * follows: + * + * _Tp* == _Pointer_adapter<_Std_pointer_impl<_Tp> >; + * const _Tp* == _Pointer_adapter<_Std_pointer_impl<const _Tp> >; + * _Tp* const == const _Pointer_adapter<_Std_pointer_impl<_Tp> >; + * const _Tp* const == const _Pointer_adapter<_Std_pointer_impl<const _Tp> >; + */ + template<typename _Storage_policy> + class _Pointer_adapter : public _Storage_policy + { + public: + typedef typename _Storage_policy::element_type element_type; + + // These are needed for iterator_traits + typedef std::random_access_iterator_tag iterator_category; + typedef typename _Unqualified_type<element_type>::type value_type; + typedef std::ptrdiff_t difference_type; + typedef _Pointer_adapter pointer; + typedef typename _Reference_type<element_type>::reference reference; + + // Reminder: 'const' methods mean that the method is valid when the + // pointer is immutable, and has nothing to do with whether the + // 'pointee' is const. + + // Default Constructor (Convert from element_type*) + _Pointer_adapter(element_type* __arg = 0) + { _Storage_policy::set(__arg); } + + // Copy constructor from _Pointer_adapter of same type. + _Pointer_adapter(const _Pointer_adapter& __arg) + { _Storage_policy::set(__arg.get()); } + + // Convert from _Up* if conversion to element_type* is valid. + template<typename _Up> + _Pointer_adapter(_Up* __arg) + { _Storage_policy::set(__arg); } + + // Conversion from another _Pointer_adapter if _Up if static cast is + // valid. + template<typename _Up> + _Pointer_adapter(const _Pointer_adapter<_Up>& __arg) + { _Storage_policy::set(__arg.get()); } + + // Destructor + ~_Pointer_adapter() { } + + // Assignment operator + _Pointer_adapter& + operator=(const _Pointer_adapter& __arg) + { + _Storage_policy::set(__arg.get()); + return *this; + } + + template<typename _Up> + _Pointer_adapter& + operator=(const _Pointer_adapter<_Up>& __arg) + { + _Storage_policy::set(__arg.get()); + return *this; + } + + template<typename _Up> + _Pointer_adapter& + operator=(_Up* __arg) + { + _Storage_policy::set(__arg); + return *this; + } + + // Operator*, returns element_type& + inline reference + operator*() const + { return *(_Storage_policy::get()); } + + // Operator->, returns element_type* + inline element_type* + operator->() const + { return _Storage_policy::get(); } + + // Operator[], returns a element_type& to the item at that loc. + inline reference + operator[](std::ptrdiff_t __index) const + { return _Storage_policy::get()[__index]; } + + // To allow implicit conversion to "bool", for "if (ptr)..." + private: + typedef element_type*(_Pointer_adapter::*__unspecified_bool_type)() const; + + public: + operator __unspecified_bool_type() const + { + return _Storage_policy::get() == 0 ? 0 : + &_Pointer_adapter::operator->; + } + + // ! operator (for: if (!ptr)...) + inline bool + operator!() const + { return (_Storage_policy::get() == 0); } + + // Pointer differences + inline friend std::ptrdiff_t + operator-(const _Pointer_adapter& __lhs, element_type* __rhs) + { return (__lhs.get() - __rhs); } + + inline friend std::ptrdiff_t + operator-(element_type* __lhs, const _Pointer_adapter& __rhs) + { return (__lhs - __rhs.get()); } + + template<typename _Up> + inline friend std::ptrdiff_t + operator-(const _Pointer_adapter& __lhs, _Up* __rhs) + { return (__lhs.get() - __rhs); } + + template<typename _Up> + inline friend std::ptrdiff_t + operator-(_Up* __lhs, const _Pointer_adapter& __rhs) + { return (__lhs - __rhs.get()); } + + template<typename _Up> + inline std::ptrdiff_t + operator-(const _Pointer_adapter<_Up>& __rhs) const + { return (_Storage_policy::get() - __rhs.get()); } + + // Pointer math + // Note: There is a reason for all this overloading based on different + // integer types. In some libstdc++-v3 test cases, a templated + // operator+ is declared which can match any types. This operator + // tends to "steal" the recognition of _Pointer_adapter's own operator+ + // unless the integer type matches perfectly. + +#define _CXX_POINTER_ARITH_OPERATOR_SET(INT_TYPE) \ + inline friend _Pointer_adapter \ + operator+(const _Pointer_adapter& __lhs, INT_TYPE __offset) \ + { return _Pointer_adapter(__lhs.get() + __offset); } \ +\ + inline friend _Pointer_adapter \ + operator+(INT_TYPE __offset, const _Pointer_adapter& __rhs) \ + { return _Pointer_adapter(__rhs.get() + __offset); } \ +\ + inline friend _Pointer_adapter \ + operator-(const _Pointer_adapter& __lhs, INT_TYPE __offset) \ + { return _Pointer_adapter(__lhs.get() - __offset); } \ +\ + inline _Pointer_adapter& \ + operator+=(INT_TYPE __offset) \ + { \ + _Storage_policy::set(_Storage_policy::get() + __offset); \ + return *this; \ + } \ +\ + inline _Pointer_adapter& \ + operator-=(INT_TYPE __offset) \ + { \ + _Storage_policy::set(_Storage_policy::get() - __offset); \ + return *this; \ + } \ +// END of _CXX_POINTER_ARITH_OPERATOR_SET macro + + // Expand into the various pointer arithmetic operators needed. + _CXX_POINTER_ARITH_OPERATOR_SET(short); + _CXX_POINTER_ARITH_OPERATOR_SET(unsigned short); + _CXX_POINTER_ARITH_OPERATOR_SET(int); + _CXX_POINTER_ARITH_OPERATOR_SET(unsigned int); + _CXX_POINTER_ARITH_OPERATOR_SET(long); + _CXX_POINTER_ARITH_OPERATOR_SET(unsigned long); + + // Mathematical Manipulators + inline _Pointer_adapter& + operator++() + { + _Storage_policy::set(_Storage_policy::get() + 1); + return *this; + } + + inline _Pointer_adapter + operator++(int) + { + _Pointer_adapter tmp(*this); + _Storage_policy::set(_Storage_policy::get() + 1); + return tmp; + } + + inline _Pointer_adapter& + operator--() + { + _Storage_policy::set(_Storage_policy::get() - 1); + return *this; + } + + inline _Pointer_adapter + operator--(int) + { + _Pointer_adapter tmp(*this); + _Storage_policy::set(_Storage_policy::get() - 1); + return tmp; + } + + }; // class _Pointer_adapter + + +#define _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(OPERATOR) \ + template<typename _Tp1, typename _Tp2> \ + inline bool \ + operator OPERATOR(const _Pointer_adapter<_Tp1>& __lhs, _Tp2 __rhs) \ + { return __lhs.get() OPERATOR __rhs; } \ +\ + template<typename _Tp1, typename _Tp2> \ + inline bool \ + operator OPERATOR(_Tp1 __lhs, const _Pointer_adapter<_Tp2>& __rhs) \ + { return __lhs OPERATOR __rhs.get(); } \ +\ + template<typename _Tp1, typename _Tp2> \ + inline bool \ + operator OPERATOR(const _Pointer_adapter<_Tp1>& __lhs, \ + const _Pointer_adapter<_Tp2>& __rhs) \ + { return __lhs.get() OPERATOR __rhs.get(); } \ +\ +// End GCC_CXX_POINTER_COMPARISON_OPERATION_SET Macro + + // Expand into the various comparison operators needed. + _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(==) + _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(!=) + _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(<) + _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(<=) + _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(>) + _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(>=) + + // These are here for expressions like "ptr == 0", "ptr != 0" + template<typename _Tp> + inline bool + operator==(const _Pointer_adapter<_Tp>& __lhs, int __rhs) + { return __lhs.get() == reinterpret_cast<void*>(__rhs); } + + template<typename _Tp> + inline bool + operator==(int __lhs, const _Pointer_adapter<_Tp>& __rhs) + { return __rhs.get() == reinterpret_cast<void*>(__lhs); } + + template<typename _Tp> + inline bool + operator!=(const _Pointer_adapter<_Tp>& __lhs, int __rhs) + { return __lhs.get() != reinterpret_cast<void*>(__rhs); } + + template<typename _Tp> + inline bool + operator!=(int __lhs, const _Pointer_adapter<_Tp>& __rhs) + { return __rhs.get() != reinterpret_cast<void*>(__lhs); } + + /** + * Comparison operators for _Pointer_adapter defer to the base class' + * comparison operators, when possible. + */ + template<typename _Tp> + inline bool + operator==(const _Pointer_adapter<_Tp>& __lhs, + const _Pointer_adapter<_Tp>& __rhs) + { return __lhs._Tp::operator==(__rhs); } + + template<typename _Tp> + inline bool + operator<=(const _Pointer_adapter<_Tp>& __lhs, + const _Pointer_adapter<_Tp>& __rhs) + { return __lhs._Tp::operator<(__rhs) || __lhs._Tp::operator==(__rhs); } + + template<typename _Tp> + inline bool + operator!=(const _Pointer_adapter<_Tp>& __lhs, + const _Pointer_adapter<_Tp>& __rhs) + { return !(__lhs._Tp::operator==(__rhs)); } + + template<typename _Tp> + inline bool + operator>(const _Pointer_adapter<_Tp>& __lhs, + const _Pointer_adapter<_Tp>& __rhs) + { return !(__lhs._Tp::operator<(__rhs) || __lhs._Tp::operator==(__rhs)); } + + template<typename _Tp> + inline bool + operator>=(const _Pointer_adapter<_Tp>& __lhs, + const _Pointer_adapter<_Tp>& __rhs) + { return !(__lhs._Tp::operator<(__rhs)); } + + template<typename _CharT, typename _Traits, typename _StoreT> + inline std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const _Pointer_adapter<_StoreT>& __p) + { return (__os << __p.get()); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#if __cplusplus >= 201103L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template<typename _Storage_policy> + struct pointer_traits<__gnu_cxx::_Pointer_adapter<_Storage_policy>> + { + /// The pointer type + typedef __gnu_cxx::_Pointer_adapter<_Storage_policy> pointer; + /// The type pointed to + typedef typename pointer::element_type element_type; + /// Type used to represent the difference between two pointers + typedef typename pointer::difference_type difference_type; + + template<typename _Up> + using rebind = typename __gnu_cxx::_Pointer_adapter< + typename pointer_traits<_Storage_policy>::template rebind<_Up>>; + + static pointer pointer_to(typename pointer::reference __r) noexcept + { return pointer(std::addressof(__r)); } + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace +#endif + +#endif // _POINTER_H diff --git a/gcc-4.9/libstdc++-v3/include/ext/pool_allocator.h b/gcc-4.9/libstdc++-v3/include/ext/pool_allocator.h new file mode 100644 index 0000000..07bb41e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pool_allocator.h @@ -0,0 +1,280 @@ +// Allocators -*- C++ -*- + +// Copyright (C) 2001-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * Copyright (c) 1996-1997 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/** @file ext/pool_allocator.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _POOL_ALLOCATOR_H +#define _POOL_ALLOCATOR_H 1 + +#include <bits/c++config.h> +#include <cstdlib> +#include <new> +#include <bits/functexcept.h> +#include <ext/atomicity.h> +#include <ext/concurrence.h> +#include <bits/move.h> +#if __cplusplus >= 201103L +#include <type_traits> +#endif + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::size_t; + using std::ptrdiff_t; + + /** + * @brief Base class for __pool_alloc. + * + * Uses various allocators to fulfill underlying requests (and makes as + * few requests as possible when in default high-speed pool mode). + * + * Important implementation properties: + * 0. If globally mandated, then allocate objects from new + * 1. If the clients request an object of size > _S_max_bytes, the resulting + * object will be obtained directly from new + * 2. In all other cases, we allocate an object of size exactly + * _S_round_up(requested_size). Thus the client has enough size + * information that we can return the object to the proper free list + * without permanently losing part of the object. + */ + class __pool_alloc_base + { + protected: + + enum { _S_align = 8 }; + enum { _S_max_bytes = 128 }; + enum { _S_free_list_size = (size_t)_S_max_bytes / (size_t)_S_align }; + + union _Obj + { + union _Obj* _M_free_list_link; + char _M_client_data[1]; // The client sees this. + }; + + static _Obj* volatile _S_free_list[_S_free_list_size]; + + // Chunk allocation state. + static char* _S_start_free; + static char* _S_end_free; + static size_t _S_heap_size; + + size_t + _M_round_up(size_t __bytes) + { return ((__bytes + (size_t)_S_align - 1) & ~((size_t)_S_align - 1)); } + + _GLIBCXX_CONST _Obj* volatile* + _M_get_free_list(size_t __bytes) throw (); + + __mutex& + _M_get_mutex() throw (); + + // Returns an object of size __n, and optionally adds to size __n + // free list. + void* + _M_refill(size_t __n); + + // Allocates a chunk for nobjs of size size. nobjs may be reduced + // if it is inconvenient to allocate the requested number. + char* + _M_allocate_chunk(size_t __n, int& __nobjs); + }; + + + /** + * @brief Allocator using a memory pool with a single lock. + * @ingroup allocators + */ + template<typename _Tp> + class __pool_alloc : private __pool_alloc_base + { + private: + static _Atomic_word _S_force_new; + + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp* pointer; + typedef const _Tp* const_pointer; + typedef _Tp& reference; + typedef const _Tp& const_reference; + typedef _Tp value_type; + + template<typename _Tp1> + struct rebind + { typedef __pool_alloc<_Tp1> other; }; + +#if __cplusplus >= 201103L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2103. propagate_on_container_move_assignment + typedef std::true_type propagate_on_container_move_assignment; +#endif + + __pool_alloc() _GLIBCXX_USE_NOEXCEPT { } + + __pool_alloc(const __pool_alloc&) _GLIBCXX_USE_NOEXCEPT { } + + template<typename _Tp1> + __pool_alloc(const __pool_alloc<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { } + + ~__pool_alloc() _GLIBCXX_USE_NOEXCEPT { } + + pointer + address(reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + const_pointer + address(const_reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + size_type + max_size() const _GLIBCXX_USE_NOEXCEPT + { return size_t(-1) / sizeof(_Tp); } + +#if __cplusplus >= 201103L + template<typename _Up, typename... _Args> + void + construct(_Up* __p, _Args&&... __args) + { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } + + template<typename _Up> + void + destroy(_Up* __p) { __p->~_Up(); } +#else + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 402. wrong new expression in [some_] allocator::construct + void + construct(pointer __p, const _Tp& __val) + { ::new((void *)__p) _Tp(__val); } + + void + destroy(pointer __p) { __p->~_Tp(); } +#endif + + pointer + allocate(size_type __n, const void* = 0); + + void + deallocate(pointer __p, size_type __n); + }; + + template<typename _Tp> + inline bool + operator==(const __pool_alloc<_Tp>&, const __pool_alloc<_Tp>&) + { return true; } + + template<typename _Tp> + inline bool + operator!=(const __pool_alloc<_Tp>&, const __pool_alloc<_Tp>&) + { return false; } + + template<typename _Tp> + _Atomic_word + __pool_alloc<_Tp>::_S_force_new; + + template<typename _Tp> + _Tp* + __pool_alloc<_Tp>::allocate(size_type __n, const void*) + { + pointer __ret = 0; + if (__builtin_expect(__n != 0, true)) + { + if (__n > this->max_size()) + std::__throw_bad_alloc(); + + // If there is a race through here, assume answer from getenv + // will resolve in same direction. Inspired by techniques + // to efficiently support threading found in basic_string.h. + if (_S_force_new == 0) + { + if (std::getenv("GLIBCXX_FORCE_NEW")) + __atomic_add_dispatch(&_S_force_new, 1); + else + __atomic_add_dispatch(&_S_force_new, -1); + } + + const size_t __bytes = __n * sizeof(_Tp); + if (__bytes > size_t(_S_max_bytes) || _S_force_new > 0) + __ret = static_cast<_Tp*>(::operator new(__bytes)); + else + { + _Obj* volatile* __free_list = _M_get_free_list(__bytes); + + __scoped_lock sentry(_M_get_mutex()); + _Obj* __restrict__ __result = *__free_list; + if (__builtin_expect(__result == 0, 0)) + __ret = static_cast<_Tp*>(_M_refill(_M_round_up(__bytes))); + else + { + *__free_list = __result->_M_free_list_link; + __ret = reinterpret_cast<_Tp*>(__result); + } + if (__ret == 0) + std::__throw_bad_alloc(); + } + } + return __ret; + } + + template<typename _Tp> + void + __pool_alloc<_Tp>::deallocate(pointer __p, size_type __n) + { + if (__builtin_expect(__n != 0 && __p != 0, true)) + { + const size_t __bytes = __n * sizeof(_Tp); + if (__bytes > static_cast<size_t>(_S_max_bytes) || _S_force_new > 0) + ::operator delete(__p); + else + { + _Obj* volatile* __free_list = _M_get_free_list(__bytes); + _Obj* __q = reinterpret_cast<_Obj*>(__p); + + __scoped_lock sentry(_M_get_mutex()); + __q ->_M_free_list_link = *__free_list; + *__free_list = __q; + } + } + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/random b/gcc-4.9/libstdc++-v3/include/ext/random new file mode 100644 index 0000000..2c9462f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/random @@ -0,0 +1,3119 @@ +// Random number extensions -*- C++ -*- + +// Copyright (C) 2012-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/random + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _EXT_RANDOM +#define _EXT_RANDOM 1 + +#pragma GCC system_header + +#if __cplusplus < 201103L +# include <bits/c++0x_warning.h> +#else + +#include <random> +#include <array> +#include <ext/cmath> +#ifdef __SSE2__ +# include <x86intrin.h> +#endif + +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + + /* Mersenne twister implementation optimized for vector operations. + * + * Reference: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/ + */ + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + class simd_fast_mersenne_twister_engine + { + static_assert(std::is_unsigned<_UIntType>::value, "template argument " + "substituting _UIntType not an unsigned integral type"); + static_assert(__sr1 < 32, "first right shift too large"); + static_assert(__sr2 < 16, "second right shift too large"); + static_assert(__sl1 < 32, "first left shift too large"); + static_assert(__sl2 < 16, "second left shift too large"); + + public: + typedef _UIntType result_type; + + private: + static constexpr size_t m_w = sizeof(result_type) * 8; + static constexpr size_t _M_nstate = __m / 128 + 1; + static constexpr size_t _M_nstate32 = _M_nstate * 4; + + static_assert(std::is_unsigned<_UIntType>::value, "template argument " + "substituting _UIntType not an unsigned integral type"); + static_assert(__pos1 < _M_nstate, "POS1 not smaller than state size"); + static_assert(16 % sizeof(_UIntType) == 0, + "UIntType size must divide 16"); + + public: + static constexpr size_t state_size = _M_nstate * (16 + / sizeof(result_type)); + static constexpr result_type default_seed = 5489u; + + // constructors and member function + explicit + simd_fast_mersenne_twister_engine(result_type __sd = default_seed) + { seed(__sd); } + + template<typename _Sseq, typename = typename + std::enable_if<!std::is_same<_Sseq, + simd_fast_mersenne_twister_engine>::value> + ::type> + explicit + simd_fast_mersenne_twister_engine(_Sseq& __q) + { seed(__q); } + + void + seed(result_type __sd = default_seed); + + template<typename _Sseq> + typename std::enable_if<std::is_class<_Sseq>::value>::type + seed(_Sseq& __q); + + static constexpr result_type + min() + { return 0; }; + + static constexpr result_type + max() + { return std::numeric_limits<result_type>::max(); } + + void + discard(unsigned long long __z); + + result_type + operator()() + { + if (__builtin_expect(_M_pos >= state_size, 0)) + _M_gen_rand(); + + return _M_stateT[_M_pos++]; + } + + template<typename _UIntType_2, size_t __m_2, + size_t __pos1_2, size_t __sl1_2, size_t __sl2_2, + size_t __sr1_2, size_t __sr2_2, + uint32_t __msk1_2, uint32_t __msk2_2, + uint32_t __msk3_2, uint32_t __msk4_2, + uint32_t __parity1_2, uint32_t __parity2_2, + uint32_t __parity3_2, uint32_t __parity4_2> + friend bool + operator==(const simd_fast_mersenne_twister_engine<_UIntType_2, + __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2, + __msk1_2, __msk2_2, __msk3_2, __msk4_2, + __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __lhs, + const simd_fast_mersenne_twister_engine<_UIntType_2, + __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2, + __msk1_2, __msk2_2, __msk3_2, __msk4_2, + __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __rhs); + + template<typename _UIntType_2, size_t __m_2, + size_t __pos1_2, size_t __sl1_2, size_t __sl2_2, + size_t __sr1_2, size_t __sr2_2, + uint32_t __msk1_2, uint32_t __msk2_2, + uint32_t __msk3_2, uint32_t __msk4_2, + uint32_t __parity1_2, uint32_t __parity2_2, + uint32_t __parity3_2, uint32_t __parity4_2, + typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::simd_fast_mersenne_twister_engine + <_UIntType_2, + __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2, + __msk1_2, __msk2_2, __msk3_2, __msk4_2, + __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __x); + + template<typename _UIntType_2, size_t __m_2, + size_t __pos1_2, size_t __sl1_2, size_t __sl2_2, + size_t __sr1_2, size_t __sr2_2, + uint32_t __msk1_2, uint32_t __msk2_2, + uint32_t __msk3_2, uint32_t __msk4_2, + uint32_t __parity1_2, uint32_t __parity2_2, + uint32_t __parity3_2, uint32_t __parity4_2, + typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType_2, + __m_2, __pos1_2, __sl1_2, __sl2_2, __sr1_2, __sr2_2, + __msk1_2, __msk2_2, __msk3_2, __msk4_2, + __parity1_2, __parity2_2, __parity3_2, __parity4_2>& __x); + + private: + union + { +#ifdef __SSE2__ + __m128i _M_state[_M_nstate]; +#endif + uint32_t _M_state32[_M_nstate32]; + result_type _M_stateT[state_size]; + } __attribute__ ((__aligned__ (16))); + size_t _M_pos; + + void _M_gen_rand(void); + void _M_period_certification(); + }; + + + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + inline bool + operator!=(const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, __msk1, __msk2, __msk3, + __msk4, __parity1, __parity2, __parity3, __parity4>& __lhs, + const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, __msk1, __msk2, __msk3, + __msk4, __parity1, __parity2, __parity3, __parity4>& __rhs) + { return !(__lhs == __rhs); } + + + /* Definitions for the SIMD-oriented Fast Mersenne Twister as defined + * in the C implementation by Daito and Matsumoto, as both a 32-bit + * and 64-bit version. + */ + typedef simd_fast_mersenne_twister_engine<uint32_t, 607, 2, + 15, 3, 13, 3, + 0xfdff37ffU, 0xef7f3f7dU, + 0xff777b7dU, 0x7ff7fb2fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x5986f054U> + sfmt607; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 607, 2, + 15, 3, 13, 3, + 0xfdff37ffU, 0xef7f3f7dU, + 0xff777b7dU, 0x7ff7fb2fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x5986f054U> + sfmt607_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 1279, 7, + 14, 3, 5, 1, + 0xf7fefffdU, 0x7fefcfffU, + 0xaff3ef3fU, 0xb5ffff7fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x20000000U> + sfmt1279; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 1279, 7, + 14, 3, 5, 1, + 0xf7fefffdU, 0x7fefcfffU, + 0xaff3ef3fU, 0xb5ffff7fU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x20000000U> + sfmt1279_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 2281, 12, + 19, 1, 5, 1, + 0xbff7ffbfU, 0xfdfffffeU, + 0xf7ffef7fU, 0xf2f7cbbfU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x41dfa600U> + sfmt2281; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 2281, 12, + 19, 1, 5, 1, + 0xbff7ffbfU, 0xfdfffffeU, + 0xf7ffef7fU, 0xf2f7cbbfU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x41dfa600U> + sfmt2281_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 4253, 17, + 20, 1, 7, 1, + 0x9f7bffffU, 0x9fffff5fU, + 0x3efffffbU, 0xfffff7bbU, + 0xa8000001U, 0xaf5390a3U, + 0xb740b3f8U, 0x6c11486dU> + sfmt4253; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 4253, 17, + 20, 1, 7, 1, + 0x9f7bffffU, 0x9fffff5fU, + 0x3efffffbU, 0xfffff7bbU, + 0xa8000001U, 0xaf5390a3U, + 0xb740b3f8U, 0x6c11486dU> + sfmt4253_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 11213, 68, + 14, 3, 7, 3, + 0xeffff7fbU, 0xffffffefU, + 0xdfdfbfffU, 0x7fffdbfdU, + 0x00000001U, 0x00000000U, + 0xe8148000U, 0xd0c7afa3U> + sfmt11213; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 11213, 68, + 14, 3, 7, 3, + 0xeffff7fbU, 0xffffffefU, + 0xdfdfbfffU, 0x7fffdbfdU, + 0x00000001U, 0x00000000U, + 0xe8148000U, 0xd0c7afa3U> + sfmt11213_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 19937, 122, + 18, 1, 11, 1, + 0xdfffffefU, 0xddfecb7fU, + 0xbffaffffU, 0xbffffff6U, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x13c9e684U> + sfmt19937; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 19937, 122, + 18, 1, 11, 1, + 0xdfffffefU, 0xddfecb7fU, + 0xbffaffffU, 0xbffffff6U, + 0x00000001U, 0x00000000U, + 0x00000000U, 0x13c9e684U> + sfmt19937_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 44497, 330, + 5, 3, 9, 3, + 0xeffffffbU, 0xdfbebfffU, + 0xbfbf7befU, 0x9ffd7bffU, + 0x00000001U, 0x00000000U, + 0xa3ac4000U, 0xecc1327aU> + sfmt44497; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 44497, 330, + 5, 3, 9, 3, + 0xeffffffbU, 0xdfbebfffU, + 0xbfbf7befU, 0x9ffd7bffU, + 0x00000001U, 0x00000000U, + 0xa3ac4000U, 0xecc1327aU> + sfmt44497_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 86243, 366, + 6, 7, 19, 1, + 0xfdbffbffU, 0xbff7ff3fU, + 0xfd77efffU, 0xbf9ff3ffU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0xe9528d85U> + sfmt86243; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 86243, 366, + 6, 7, 19, 1, + 0xfdbffbffU, 0xbff7ff3fU, + 0xfd77efffU, 0xbf9ff3ffU, + 0x00000001U, 0x00000000U, + 0x00000000U, 0xe9528d85U> + sfmt86243_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 132049, 110, + 19, 1, 21, 1, + 0xffffbb5fU, 0xfb6ebf95U, + 0xfffefffaU, 0xcff77fffU, + 0x00000001U, 0x00000000U, + 0xcb520000U, 0xc7e91c7dU> + sfmt132049; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 132049, 110, + 19, 1, 21, 1, + 0xffffbb5fU, 0xfb6ebf95U, + 0xfffefffaU, 0xcff77fffU, + 0x00000001U, 0x00000000U, + 0xcb520000U, 0xc7e91c7dU> + sfmt132049_64; + + + typedef simd_fast_mersenne_twister_engine<uint32_t, 216091, 627, + 11, 3, 10, 1, + 0xbff7bff7U, 0xbfffffffU, + 0xbffffa7fU, 0xffddfbfbU, + 0xf8000001U, 0x89e80709U, + 0x3bd2b64bU, 0x0c64b1e4U> + sfmt216091; + + typedef simd_fast_mersenne_twister_engine<uint64_t, 216091, 627, + 11, 3, 10, 1, + 0xbff7bff7U, 0xbfffffffU, + 0xbffffa7fU, 0xffddfbfbU, + 0xf8000001U, 0x89e80709U, + 0x3bd2b64bU, 0x0c64b1e4U> + sfmt216091_64; + +#endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + + /** + * @brief A beta continuous distribution for random numbers. + * + * The formula for the beta probability density function is: + * @f[ + * p(x|\alpha,\beta) = \frac{1}{B(\alpha,\beta)} + * x^{\alpha - 1} (1 - x)^{\beta - 1} + * @f] + */ + template<typename _RealType = double> + class beta_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef beta_distribution<_RealType> distribution_type; + friend class beta_distribution<_RealType>; + + explicit + param_type(_RealType __alpha_val = _RealType(1), + _RealType __beta_val = _RealType(1)) + : _M_alpha(__alpha_val), _M_beta(__beta_val) + { + _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0)); + _GLIBCXX_DEBUG_ASSERT(_M_beta > _RealType(0)); + } + + _RealType + alpha() const + { return _M_alpha; } + + _RealType + beta() const + { return _M_beta; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_alpha == __p2._M_alpha + && __p1._M_beta == __p2._M_beta); } + + private: + void + _M_initialize(); + + _RealType _M_alpha; + _RealType _M_beta; + }; + + public: + /** + * @brief Constructs a beta distribution with parameters + * @f$\alpha@f$ and @f$\beta@f$. + */ + explicit + beta_distribution(_RealType __alpha_val = _RealType(1), + _RealType __beta_val = _RealType(1)) + : _M_param(__alpha_val, __beta_val) + { } + + explicit + beta_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * @brief Returns the @f$\alpha@f$ of the distribution. + */ + _RealType + alpha() const + { return _M_param.alpha(); } + + /** + * @brief Returns the @f$\beta@f$ of the distribution. + */ + _RealType + beta() const + { return _M_param.beta(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return result_type(1); } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, _M_param); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, _M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template<typename _UniformRandomNumberGenerator> + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two beta distributions have the same + * parameters and the sequences that would be generated + * are equal. + */ + friend bool + operator==(const beta_distribution& __d1, + const beta_distribution& __d2) + { return __d1._M_param == __d2._M_param; } + + /** + * @brief Inserts a %beta_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %beta_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::beta_distribution<_RealType1>& __x); + + /** + * @brief Extracts a %beta_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %beta_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::beta_distribution<_RealType1>& __x); + + private: + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + }; + + /** + * @brief Return true if two beta distributions are different. + */ + template<typename _RealType> + inline bool + operator!=(const __gnu_cxx::beta_distribution<_RealType>& __d1, + const __gnu_cxx::beta_distribution<_RealType>& __d2) + { return !(__d1 == __d2); } + + + /** + * @brief A multi-variate normal continuous distribution for random numbers. + * + * The formula for the normal probability density function is + * @f[ + * p(\overrightarrow{x}|\overrightarrow{\mu },\Sigma) = + * \frac{1}{\sqrt{(2\pi )^k\det(\Sigma))}} + * e^{-\frac{1}{2}(\overrightarrow{x}-\overrightarrow{\mu})^\text{T} + * \Sigma ^{-1}(\overrightarrow{x}-\overrightarrow{\mu})} + * @f] + * + * where @f$\overrightarrow{x}@f$ and @f$\overrightarrow{\mu}@f$ are + * vectors of dimension @f$k@f$ and @f$\Sigma@f$ is the covariance + * matrix (which must be positive-definite). + */ + template<std::size_t _Dimen, typename _RealType = double> + class normal_mv_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + static_assert(_Dimen != 0, "dimension is zero"); + + public: + /** The type of the range of the distribution. */ + typedef std::array<_RealType, _Dimen> result_type; + /** Parameter type. */ + class param_type + { + static constexpr size_t _M_t_size = _Dimen * (_Dimen + 1) / 2; + + public: + typedef normal_mv_distribution<_Dimen, _RealType> distribution_type; + friend class normal_mv_distribution<_Dimen, _RealType>; + + param_type() + { + std::fill(_M_mean.begin(), _M_mean.end(), _RealType(0)); + auto __it = _M_t.begin(); + for (size_t __i = 0; __i < _Dimen; ++__i) + { + std::fill_n(__it, __i, _RealType(0)); + __it += __i; + *__it++ = _RealType(1); + } + } + + template<typename _ForwardIterator1, typename _ForwardIterator2> + param_type(_ForwardIterator1 __meanbegin, + _ForwardIterator1 __meanend, + _ForwardIterator2 __varcovbegin, + _ForwardIterator2 __varcovend) + { + __glibcxx_function_requires(_ForwardIteratorConcept< + _ForwardIterator1>) + __glibcxx_function_requires(_ForwardIteratorConcept< + _ForwardIterator2>) + _GLIBCXX_DEBUG_ASSERT(std::distance(__meanbegin, __meanend) + <= _Dimen); + const auto __dist = std::distance(__varcovbegin, __varcovend); + _GLIBCXX_DEBUG_ASSERT(__dist == _Dimen * _Dimen + || __dist == _Dimen * (_Dimen + 1) / 2 + || __dist == _Dimen); + + if (__dist == _Dimen * _Dimen) + _M_init_full(__meanbegin, __meanend, __varcovbegin, __varcovend); + else if (__dist == _Dimen * (_Dimen + 1) / 2) + _M_init_lower(__meanbegin, __meanend, __varcovbegin, __varcovend); + else + _M_init_diagonal(__meanbegin, __meanend, + __varcovbegin, __varcovend); + } + + param_type(std::initializer_list<_RealType> __mean, + std::initializer_list<_RealType> __varcov) + { + _GLIBCXX_DEBUG_ASSERT(__mean.size() <= _Dimen); + _GLIBCXX_DEBUG_ASSERT(__varcov.size() == _Dimen * _Dimen + || __varcov.size() == _Dimen * (_Dimen + 1) / 2 + || __varcov.size() == _Dimen); + + if (__varcov.size() == _Dimen * _Dimen) + _M_init_full(__mean.begin(), __mean.end(), + __varcov.begin(), __varcov.end()); + else if (__varcov.size() == _Dimen * (_Dimen + 1) / 2) + _M_init_lower(__mean.begin(), __mean.end(), + __varcov.begin(), __varcov.end()); + else + _M_init_diagonal(__mean.begin(), __mean.end(), + __varcov.begin(), __varcov.end()); + } + + std::array<_RealType, _Dimen> + mean() const + { return _M_mean; } + + std::array<_RealType, _M_t_size> + varcov() const + { return _M_t; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_mean == __p2._M_mean && __p1._M_t == __p2._M_t; } + + private: + template <typename _InputIterator1, typename _InputIterator2> + void _M_init_full(_InputIterator1 __meanbegin, + _InputIterator1 __meanend, + _InputIterator2 __varcovbegin, + _InputIterator2 __varcovend); + template <typename _InputIterator1, typename _InputIterator2> + void _M_init_lower(_InputIterator1 __meanbegin, + _InputIterator1 __meanend, + _InputIterator2 __varcovbegin, + _InputIterator2 __varcovend); + template <typename _InputIterator1, typename _InputIterator2> + void _M_init_diagonal(_InputIterator1 __meanbegin, + _InputIterator1 __meanend, + _InputIterator2 __varbegin, + _InputIterator2 __varend); + + std::array<_RealType, _Dimen> _M_mean; + std::array<_RealType, _M_t_size> _M_t; + }; + + public: + normal_mv_distribution() + : _M_param(), _M_nd() + { } + + template<typename _ForwardIterator1, typename _ForwardIterator2> + normal_mv_distribution(_ForwardIterator1 __meanbegin, + _ForwardIterator1 __meanend, + _ForwardIterator2 __varcovbegin, + _ForwardIterator2 __varcovend) + : _M_param(__meanbegin, __meanend, __varcovbegin, __varcovend), + _M_nd() + { } + + normal_mv_distribution(std::initializer_list<_RealType> __mean, + std::initializer_list<_RealType> __varcov) + : _M_param(__mean, __varcov), _M_nd() + { } + + explicit + normal_mv_distribution(const param_type& __p) + : _M_param(__p), _M_nd() + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { _M_nd.reset(); } + + /** + * @brief Returns the mean of the distribution. + */ + result_type + mean() const + { return _M_param.mean(); } + + /** + * @brief Returns the compact form of the variance/covariance + * matrix of the distribution. + */ + std::array<_RealType, _Dimen * (_Dimen + 1) / 2> + varcov() const + { return _M_param.varcov(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { result_type __res; + __res.fill(std::numeric_limits<_RealType>::lowest()); + return __res; } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { result_type __res; + __res.fill(std::numeric_limits<_RealType>::max()); + return __res; } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, _M_param); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { return this->__generate_impl(__f, __t, __urng, _M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { return this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two multi-variant normal distributions have + * the same parameters and the sequences that would + * be generated are equal. + */ + template<size_t _Dimen1, typename _RealType1> + friend bool + operator==(const + __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>& + __d1, + const + __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>& + __d2); + + /** + * @brief Inserts a %normal_mv_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %normal_mv_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<size_t _Dimen1, typename _RealType1, + typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const + __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>& + __x); + + /** + * @brief Extracts a %normal_mv_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %normal_mv_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error + * state. + */ + template<size_t _Dimen1, typename _RealType1, + typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::normal_mv_distribution<_Dimen1, _RealType1>& + __x); + + private: + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + std::normal_distribution<_RealType> _M_nd; + }; + + /** + * @brief Return true if two multi-variate normal distributions are + * different. + */ + template<size_t _Dimen, typename _RealType> + inline bool + operator!=(const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& + __d1, + const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& + __d2) + { return !(__d1 == __d2); } + + + /** + * @brief A Rice continuous distribution for random numbers. + * + * The formula for the Rice probability density function is + * @f[ + * p(x|\nu,\sigma) = \frac{x}{\sigma^2} + * \exp\left(-\frac{x^2+\nu^2}{2\sigma^2}\right) + * I_0\left(\frac{x \nu}{\sigma^2}\right) + * @f] + * where @f$I_0(z)@f$ is the modified Bessel function of the first kind + * of order 0 and @f$\nu >= 0@f$ and @f$\sigma > 0@f$. + * + * <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Distribution Statistics</caption> + * <tr><td>Mean</td><td>@f$\sqrt{\pi/2}L_{1/2}(-\nu^2/2\sigma^2)@f$</td></tr> + * <tr><td>Variance</td><td>@f$2\sigma^2 + \nu^2 + * + (\pi\sigma^2/2)L^2_{1/2}(-\nu^2/2\sigma^2)@f$</td></tr> + * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr> + * </table> + * where @f$L_{1/2}(x)@f$ is the Laguerre polynomial of order 1/2. + */ + template<typename _RealType = double> + class + rice_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef rice_distribution<result_type> distribution_type; + + param_type(result_type __nu_val = result_type(0), + result_type __sigma_val = result_type(1)) + : _M_nu(__nu_val), _M_sigma(__sigma_val) + { + _GLIBCXX_DEBUG_ASSERT(_M_nu >= result_type(0)); + _GLIBCXX_DEBUG_ASSERT(_M_sigma > result_type(0)); + } + + result_type + nu() const + { return _M_nu; } + + result_type + sigma() const + { return _M_sigma; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_nu == __p2._M_nu + && __p1._M_sigma == __p2._M_sigma; } + + private: + void _M_initialize(); + + result_type _M_nu; + result_type _M_sigma; + }; + + /** + * @brief Constructors. + */ + explicit + rice_distribution(result_type __nu_val = result_type(0), + result_type __sigma_val = result_type(1)) + : _M_param(__nu_val, __sigma_val), + _M_ndx(__nu_val, __sigma_val), + _M_ndy(result_type(0), __sigma_val) + { } + + explicit + rice_distribution(const param_type& __p) + : _M_param(__p), + _M_ndx(__p.nu(), __p.sigma()), + _M_ndy(result_type(0), __p.sigma()) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { + _M_ndx.reset(); + _M_ndy.reset(); + } + + /** + * @brief Return the parameters of the distribution. + */ + result_type + nu() const + { return _M_param.nu(); } + + result_type + sigma() const + { return _M_param.sigma(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __x = this->_M_ndx(__urng); + result_type __y = this->_M_ndy(__urng); +#if _GLIBCXX_USE_C99_MATH_TR1 + return std::hypot(__x, __y); +#else + return std::sqrt(__x * __x + __y * __y); +#endif + } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + typename std::normal_distribution<result_type>::param_type + __px(__p.nu(), __p.sigma()), __py(result_type(0), __p.sigma()); + result_type __x = this->_M_ndx(__px, __urng); + result_type __y = this->_M_ndy(__py, __urng); +#if _GLIBCXX_USE_C99_MATH_TR1 + return std::hypot(__x, __y); +#else + return std::sqrt(__x * __x + __y * __y); +#endif + } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, _M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template<typename _UniformRandomNumberGenerator> + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two Rice distributions have + * the same parameters and the sequences that would + * be generated are equal. + */ + friend bool + operator==(const rice_distribution& __d1, + const rice_distribution& __d2) + { return (__d1._M_param == __d2._M_param + && __d1._M_ndx == __d2._M_ndx + && __d1._M_ndy == __d2._M_ndy); } + + /** + * @brief Inserts a %rice_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %rice_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>&, + const rice_distribution<_RealType1>&); + + /** + * @brief Extracts a %rice_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %rice_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>&, + rice_distribution<_RealType1>&); + + private: + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + + std::normal_distribution<result_type> _M_ndx; + std::normal_distribution<result_type> _M_ndy; + }; + + /** + * @brief Return true if two Rice distributions are not equal. + */ + template<typename _RealType1> + inline bool + operator!=(const rice_distribution<_RealType1>& __d1, + const rice_distribution<_RealType1>& __d2) + { return !(__d1 == __d2); } + + + /** + * @brief A Nakagami continuous distribution for random numbers. + * + * The formula for the Nakagami probability density function is + * @f[ + * p(x|\mu,\omega) = \frac{2\mu^\mu}{\Gamma(\mu)\omega^\mu} + * x^{2\mu-1}e^{-\mu x / \omega} + * @f] + * where @f$\Gamma(z)@f$ is the gamma function and @f$\mu >= 0.5@f$ + * and @f$\omega > 0@f$. + */ + template<typename _RealType = double> + class + nakagami_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef nakagami_distribution<result_type> distribution_type; + + param_type(result_type __mu_val = result_type(1), + result_type __omega_val = result_type(1)) + : _M_mu(__mu_val), _M_omega(__omega_val) + { + _GLIBCXX_DEBUG_ASSERT(_M_mu >= result_type(0.5L)); + _GLIBCXX_DEBUG_ASSERT(_M_omega > result_type(0)); + } + + result_type + mu() const + { return _M_mu; } + + result_type + omega() const + { return _M_omega; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_mu == __p2._M_mu + && __p1._M_omega == __p2._M_omega; } + + private: + void _M_initialize(); + + result_type _M_mu; + result_type _M_omega; + }; + + /** + * @brief Constructors. + */ + explicit + nakagami_distribution(result_type __mu_val = result_type(1), + result_type __omega_val = result_type(1)) + : _M_param(__mu_val, __omega_val), + _M_gd(__mu_val, __omega_val / __mu_val) + { } + + explicit + nakagami_distribution(const param_type& __p) + : _M_param(__p), + _M_gd(__p.mu(), __p.omega() / __p.mu()) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { _M_gd.reset(); } + + /** + * @brief Return the parameters of the distribution. + */ + result_type + mu() const + { return _M_param.mu(); } + + result_type + omega() const + { return _M_param.omega(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return std::sqrt(this->_M_gd(__urng)); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + typename std::gamma_distribution<result_type>::param_type + __pg(__p.mu(), __p.omega() / __p.mu()); + return std::sqrt(this->_M_gd(__pg, __urng)); + } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, _M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template<typename _UniformRandomNumberGenerator> + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two Nakagami distributions have + * the same parameters and the sequences that would + * be generated are equal. + */ + friend bool + operator==(const nakagami_distribution& __d1, + const nakagami_distribution& __d2) + { return (__d1._M_param == __d2._M_param + && __d1._M_gd == __d2._M_gd); } + + /** + * @brief Inserts a %nakagami_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %nakagami_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>&, + const nakagami_distribution<_RealType1>&); + + /** + * @brief Extracts a %nakagami_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %nakagami_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>&, + nakagami_distribution<_RealType1>&); + + private: + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + + std::gamma_distribution<result_type> _M_gd; + }; + + /** + * @brief Return true if two Nakagami distributions are not equal. + */ + template<typename _RealType> + inline bool + operator!=(const nakagami_distribution<_RealType>& __d1, + const nakagami_distribution<_RealType>& __d2) + { return !(__d1 == __d2); } + + + /** + * @brief A Pareto continuous distribution for random numbers. + * + * The formula for the Pareto cumulative probability function is + * @f[ + * P(x|\alpha,\mu) = 1 - \left(\frac{\mu}{x}\right)^\alpha + * @f] + * The formula for the Pareto probability density function is + * @f[ + * p(x|\alpha,\mu) = \frac{\alpha + 1}{\mu} + * \left(\frac{\mu}{x}\right)^{\alpha + 1} + * @f] + * where @f$x >= \mu@f$ and @f$\mu > 0@f$, @f$\alpha > 0@f$. + * + * <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Distribution Statistics</caption> + * <tr><td>Mean</td><td>@f$\alpha \mu / (\alpha - 1)@f$ + * for @f$\alpha > 1@f$</td></tr> + * <tr><td>Variance</td><td>@f$\alpha \mu^2 / [(\alpha - 1)^2(\alpha - 2)]@f$ + * for @f$\alpha > 2@f$</td></tr> + * <tr><td>Range</td><td>@f$[\mu, \infty)@f$</td></tr> + * </table> + */ + template<typename _RealType = double> + class + pareto_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef pareto_distribution<result_type> distribution_type; + + param_type(result_type __alpha_val = result_type(1), + result_type __mu_val = result_type(1)) + : _M_alpha(__alpha_val), _M_mu(__mu_val) + { + _GLIBCXX_DEBUG_ASSERT(_M_alpha > result_type(0)); + _GLIBCXX_DEBUG_ASSERT(_M_mu > result_type(0)); + } + + result_type + alpha() const + { return _M_alpha; } + + result_type + mu() const + { return _M_mu; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_alpha == __p2._M_alpha && __p1._M_mu == __p2._M_mu; } + + private: + void _M_initialize(); + + result_type _M_alpha; + result_type _M_mu; + }; + + /** + * @brief Constructors. + */ + explicit + pareto_distribution(result_type __alpha_val = result_type(1), + result_type __mu_val = result_type(1)) + : _M_param(__alpha_val, __mu_val), + _M_ud() + { } + + explicit + pareto_distribution(const param_type& __p) + : _M_param(__p), + _M_ud() + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { + _M_ud.reset(); + } + + /** + * @brief Return the parameters of the distribution. + */ + result_type + alpha() const + { return _M_param.alpha(); } + + result_type + mu() const + { return _M_param.mu(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return this->mu(); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + return this->mu() * std::pow(this->_M_ud(__urng), + -result_type(1) / this->alpha()); + } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + return __p.mu() * std::pow(this->_M_ud(__urng), + -result_type(1) / __p.alpha()); + } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, _M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template<typename _UniformRandomNumberGenerator> + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two Pareto distributions have + * the same parameters and the sequences that would + * be generated are equal. + */ + friend bool + operator==(const pareto_distribution& __d1, + const pareto_distribution& __d2) + { return (__d1._M_param == __d2._M_param + && __d1._M_ud == __d2._M_ud); } + + /** + * @brief Inserts a %pareto_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %pareto_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>&, + const pareto_distribution<_RealType1>&); + + /** + * @brief Extracts a %pareto_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %pareto_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>&, + pareto_distribution<_RealType1>&); + + private: + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + + std::uniform_real_distribution<result_type> _M_ud; + }; + + /** + * @brief Return true if two Pareto distributions are not equal. + */ + template<typename _RealType> + inline bool + operator!=(const pareto_distribution<_RealType>& __d1, + const pareto_distribution<_RealType>& __d2) + { return !(__d1 == __d2); } + + + /** + * @brief A K continuous distribution for random numbers. + * + * The formula for the K probability density function is + * @f[ + * p(x|\lambda, \mu, \nu) = \frac{2}{x} + * \left(\frac{\lambda\nu x}{\mu}\right)^{\frac{\lambda + \nu}{2}} + * \frac{1}{\Gamma(\lambda)\Gamma(\nu)} + * K_{\nu - \lambda}\left(2\sqrt{\frac{\lambda\nu x}{\mu}}\right) + * @f] + * where @f$I_0(z)@f$ is the modified Bessel function of the second kind + * of order @f$\nu - \lambda@f$ and @f$\lambda > 0@f$, @f$\mu > 0@f$ + * and @f$\nu > 0@f$. + * + * <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Distribution Statistics</caption> + * <tr><td>Mean</td><td>@f$\mu@f$</td></tr> + * <tr><td>Variance</td><td>@f$\mu^2\frac{\lambda + \nu + 1}{\lambda\nu}@f$</td></tr> + * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr> + * </table> + */ + template<typename _RealType = double> + class + k_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef k_distribution<result_type> distribution_type; + + param_type(result_type __lambda_val = result_type(1), + result_type __mu_val = result_type(1), + result_type __nu_val = result_type(1)) + : _M_lambda(__lambda_val), _M_mu(__mu_val), _M_nu(__nu_val) + { + _GLIBCXX_DEBUG_ASSERT(_M_lambda > result_type(0)); + _GLIBCXX_DEBUG_ASSERT(_M_mu > result_type(0)); + _GLIBCXX_DEBUG_ASSERT(_M_nu > result_type(0)); + } + + result_type + lambda() const + { return _M_lambda; } + + result_type + mu() const + { return _M_mu; } + + result_type + nu() const + { return _M_nu; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_lambda == __p2._M_lambda + && __p1._M_mu == __p2._M_mu + && __p1._M_nu == __p2._M_nu; } + + private: + void _M_initialize(); + + result_type _M_lambda; + result_type _M_mu; + result_type _M_nu; + }; + + /** + * @brief Constructors. + */ + explicit + k_distribution(result_type __lambda_val = result_type(1), + result_type __mu_val = result_type(1), + result_type __nu_val = result_type(1)) + : _M_param(__lambda_val, __mu_val, __nu_val), + _M_gd1(__lambda_val, result_type(1) / __lambda_val), + _M_gd2(__nu_val, __mu_val / __nu_val) + { } + + explicit + k_distribution(const param_type& __p) + : _M_param(__p), + _M_gd1(__p.lambda(), result_type(1) / __p.lambda()), + _M_gd2(__p.nu(), __p.mu() / __p.nu()) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { + _M_gd1.reset(); + _M_gd2.reset(); + } + + /** + * @brief Return the parameters of the distribution. + */ + result_type + lambda() const + { return _M_param.lambda(); } + + result_type + mu() const + { return _M_param.mu(); } + + result_type + nu() const + { return _M_param.nu(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator&); + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator&, const param_type&); + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, _M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template<typename _UniformRandomNumberGenerator> + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two K distributions have + * the same parameters and the sequences that would + * be generated are equal. + */ + friend bool + operator==(const k_distribution& __d1, + const k_distribution& __d2) + { return (__d1._M_param == __d2._M_param + && __d1._M_gd1 == __d2._M_gd1 + && __d1._M_gd2 == __d2._M_gd2); } + + /** + * @brief Inserts a %k_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %k_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>&, + const k_distribution<_RealType1>&); + + /** + * @brief Extracts a %k_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %k_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>&, + k_distribution<_RealType1>&); + + private: + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + + std::gamma_distribution<result_type> _M_gd1; + std::gamma_distribution<result_type> _M_gd2; + }; + + /** + * @brief Return true if two K distributions are not equal. + */ + template<typename _RealType> + inline bool + operator!=(const k_distribution<_RealType>& __d1, + const k_distribution<_RealType>& __d2) + { return !(__d1 == __d2); } + + + /** + * @brief An arcsine continuous distribution for random numbers. + * + * The formula for the arcsine probability density function is + * @f[ + * p(x|a,b) = \frac{1}{\pi \sqrt{(x - a)(b - x)}} + * @f] + * where @f$x >= a@f$ and @f$x <= b@f$. + * + * <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Distribution Statistics</caption> + * <tr><td>Mean</td><td>@f$ (a + b) / 2 @f$</td></tr> + * <tr><td>Variance</td><td>@f$ (b - a)^2 / 8 @f$</td></tr> + * <tr><td>Range</td><td>@f$[a, b]@f$</td></tr> + * </table> + */ + template<typename _RealType = double> + class + arcsine_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef arcsine_distribution<result_type> distribution_type; + + param_type(result_type __a = result_type(0), + result_type __b = result_type(1)) + : _M_a(__a), _M_b(__b) + { + _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b); + } + + result_type + a() const + { return _M_a; } + + result_type + b() const + { return _M_b; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; } + + private: + void _M_initialize(); + + result_type _M_a; + result_type _M_b; + }; + + /** + * @brief Constructors. + */ + explicit + arcsine_distribution(result_type __a = result_type(0), + result_type __b = result_type(1)) + : _M_param(__a, __b), + _M_ud(-1.5707963267948966192313216916397514L, + +1.5707963267948966192313216916397514L) + { } + + explicit + arcsine_distribution(const param_type& __p) + : _M_param(__p), + _M_ud(-1.5707963267948966192313216916397514L, + +1.5707963267948966192313216916397514L) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { _M_ud.reset(); } + + /** + * @brief Return the parameters of the distribution. + */ + result_type + a() const + { return _M_param.a(); } + + result_type + b() const + { return _M_param.b(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return this->a(); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return this->b(); } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __x = std::sin(this->_M_ud(__urng)); + return (__x * (this->b() - this->a()) + + this->a() + this->b()) / result_type(2); + } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + result_type __x = std::sin(this->_M_ud(__urng)); + return (__x * (__p.b() - __p.a()) + + __p.a() + __p.b()) / result_type(2); + } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, _M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template<typename _UniformRandomNumberGenerator> + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two arcsine distributions have + * the same parameters and the sequences that would + * be generated are equal. + */ + friend bool + operator==(const arcsine_distribution& __d1, + const arcsine_distribution& __d2) + { return (__d1._M_param == __d2._M_param + && __d1._M_ud == __d2._M_ud); } + + /** + * @brief Inserts a %arcsine_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %arcsine_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>&, + const arcsine_distribution<_RealType1>&); + + /** + * @brief Extracts a %arcsine_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %arcsine_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>&, + arcsine_distribution<_RealType1>&); + + private: + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + + std::uniform_real_distribution<result_type> _M_ud; + }; + + /** + * @brief Return true if two arcsine distributions are not equal. + */ + template<typename _RealType> + inline bool + operator!=(const arcsine_distribution<_RealType>& __d1, + const arcsine_distribution<_RealType>& __d2) + { return !(__d1 == __d2); } + + + /** + * @brief A Hoyt continuous distribution for random numbers. + * + * The formula for the Hoyt probability density function is + * @f[ + * p(x|q,\omega) = \frac{(1 + q^2)x}{q\omega} + * \exp\left(-\frac{(1 + q^2)^2 x^2}{4 q^2 \omega}\right) + * I_0\left(\frac{(1 - q^4) x^2}{4 q^2 \omega}\right) + * @f] + * where @f$I_0(z)@f$ is the modified Bessel function of the first kind + * of order 0 and @f$0 < q < 1@f$. + * + * <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Distribution Statistics</caption> + * <tr><td>Mean</td><td>@f$ \sqrt{\frac{2}{\pi}} \sqrt{\frac{\omega}{1 + q^2}} + * E(1 - q^2) @f$</td></tr> + * <tr><td>Variance</td><td>@f$ \omega \left(1 - \frac{2E^2(1 - q^2)} + * {\pi (1 + q^2)}\right) @f$</td></tr> + * <tr><td>Range</td><td>@f$[0, \infty)@f$</td></tr> + * </table> + * where @f$E(x)@f$ is the elliptic function of the second kind. + */ + template<typename _RealType = double> + class + hoyt_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef hoyt_distribution<result_type> distribution_type; + + param_type(result_type __q = result_type(0.5L), + result_type __omega = result_type(1)) + : _M_q(__q), _M_omega(__omega) + { + _GLIBCXX_DEBUG_ASSERT(_M_q > result_type(0)); + _GLIBCXX_DEBUG_ASSERT(_M_q < result_type(1)); + } + + result_type + q() const + { return _M_q; } + + result_type + omega() const + { return _M_omega; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_q == __p2._M_q + && __p1._M_omega == __p2._M_omega; } + + private: + void _M_initialize(); + + result_type _M_q; + result_type _M_omega; + }; + + /** + * @brief Constructors. + */ + explicit + hoyt_distribution(result_type __q = result_type(0.5L), + result_type __omega = result_type(1)) + : _M_param(__q, __omega), + _M_ad(result_type(0.5L) * (result_type(1) + __q * __q), + result_type(0.5L) * (result_type(1) + __q * __q) + / (__q * __q)), + _M_ed(result_type(1)) + { } + + explicit + hoyt_distribution(const param_type& __p) + : _M_param(__p), + _M_ad(result_type(0.5L) * (result_type(1) + __p.q() * __p.q()), + result_type(0.5L) * (result_type(1) + __p.q() * __p.q()) + / (__p.q() * __p.q())), + _M_ed(result_type(1)) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { + _M_ad.reset(); + _M_ed.reset(); + } + + /** + * @brief Return the parameters of the distribution. + */ + result_type + q() const + { return _M_param.q(); } + + result_type + omega() const + { return _M_param.omega(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, _M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template<typename _UniformRandomNumberGenerator> + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two Hoyt distributions have + * the same parameters and the sequences that would + * be generated are equal. + */ + friend bool + operator==(const hoyt_distribution& __d1, + const hoyt_distribution& __d2) + { return (__d1._M_param == __d2._M_param + && __d1._M_ad == __d2._M_ad + && __d1._M_ed == __d2._M_ed); } + + /** + * @brief Inserts a %hoyt_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %hoyt_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>&, + const hoyt_distribution<_RealType1>&); + + /** + * @brief Extracts a %hoyt_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %hoyt_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>&, + hoyt_distribution<_RealType1>&); + + private: + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + + __gnu_cxx::arcsine_distribution<result_type> _M_ad; + std::exponential_distribution<result_type> _M_ed; + }; + + /** + * @brief Return true if two Hoyt distributions are not equal. + */ + template<typename _RealType> + inline bool + operator!=(const hoyt_distribution<_RealType>& __d1, + const hoyt_distribution<_RealType>& __d2) + { return !(__d1 == __d2); } + + + /** + * @brief A triangular distribution for random numbers. + * + * The formula for the triangular probability density function is + * @f[ + * / 0 for x < a + * p(x|a,b,c) = | \frac{2(x-a)}{(c-a)(b-a)} for a <= x <= b + * | \frac{2(c-x)}{(c-a)(c-b)} for b < x <= c + * \ 0 for c < x + * @f] + * + * <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Distribution Statistics</caption> + * <tr><td>Mean</td><td>@f$ \frac{a+b+c}{2} @f$</td></tr> + * <tr><td>Variance</td><td>@f$ \frac{a^2+b^2+c^2-ab-ac-bc} + * {18}@f$</td></tr> + * <tr><td>Range</td><td>@f$[a, c]@f$</td></tr> + * </table> + */ + template<typename _RealType = double> + class triangular_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + friend class triangular_distribution<_RealType>; + + explicit + param_type(_RealType __a = _RealType(0), + _RealType __b = _RealType(0.5), + _RealType __c = _RealType(1)) + : _M_a(__a), _M_b(__b), _M_c(__c) + { + _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b); + _GLIBCXX_DEBUG_ASSERT(_M_b <= _M_c); + _GLIBCXX_DEBUG_ASSERT(_M_a < _M_c); + + _M_r_ab = (_M_b - _M_a) / (_M_c - _M_a); + _M_f_ab_ac = (_M_b - _M_a) * (_M_c - _M_a); + _M_f_bc_ac = (_M_c - _M_b) * (_M_c - _M_a); + } + + _RealType + a() const + { return _M_a; } + + _RealType + b() const + { return _M_b; } + + _RealType + c() const + { return _M_c; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b + && __p1._M_c == __p2._M_c); } + + private: + + _RealType _M_a; + _RealType _M_b; + _RealType _M_c; + _RealType _M_r_ab; + _RealType _M_f_ab_ac; + _RealType _M_f_bc_ac; + }; + + /** + * @brief Constructs a triangle distribution with parameters + * @f$ a @f$, @f$ b @f$ and @f$ c @f$. + */ + explicit + triangular_distribution(result_type __a = result_type(0), + result_type __b = result_type(0.5), + result_type __c = result_type(1)) + : _M_param(__a, __b, __c) + { } + + explicit + triangular_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * @brief Returns the @f$ a @f$ of the distribution. + */ + result_type + a() const + { return _M_param.a(); } + + /** + * @brief Returns the @f$ b @f$ of the distribution. + */ + result_type + b() const + { return _M_param.b(); } + + /** + * @brief Returns the @f$ c @f$ of the distribution. + */ + result_type + c() const + { return _M_param.c(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return _M_param._M_a; } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return _M_param._M_c; } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, _M_param); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + result_type __rnd = __aurng(); + if (__rnd <= __p._M_r_ab) + return __p.a() + std::sqrt(__rnd * __p._M_f_ab_ac); + else + return __p.c() - std::sqrt((result_type(1) - __rnd) + * __p._M_f_bc_ac); + } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, _M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template<typename _UniformRandomNumberGenerator> + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two triangle distributions have the same + * parameters and the sequences that would be generated + * are equal. + */ + friend bool + operator==(const triangular_distribution& __d1, + const triangular_distribution& __d2) + { return __d1._M_param == __d2._M_param; } + + /** + * @brief Inserts a %triangular_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %triangular_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::triangular_distribution<_RealType1>& __x); + + /** + * @brief Extracts a %triangular_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %triangular_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::triangular_distribution<_RealType1>& __x); + + private: + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + }; + + /** + * @brief Return true if two triangle distributions are different. + */ + template<typename _RealType> + inline bool + operator!=(const __gnu_cxx::triangular_distribution<_RealType>& __d1, + const __gnu_cxx::triangular_distribution<_RealType>& __d2) + { return !(__d1 == __d2); } + + + /** + * @brief A von Mises distribution for random numbers. + * + * The formula for the von Mises probability density function is + * @f[ + * p(x|\mu,\kappa) = \frac{e^{\kappa \cos(x-\mu)}} + * {2\pi I_0(\kappa)} + * @f] + * + * The generating functions use the method according to: + * + * D. J. Best and N. I. Fisher, 1979. "Efficient Simulation of the + * von Mises Distribution", Journal of the Royal Statistical Society. + * Series C (Applied Statistics), Vol. 28, No. 2, pp. 152-157. + * + * <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Distribution Statistics</caption> + * <tr><td>Mean</td><td>@f$ \mu @f$</td></tr> + * <tr><td>Variance</td><td>@f$ 1-I_1(\kappa)/I_0(\kappa) @f$</td></tr> + * <tr><td>Range</td><td>@f$[-\pi, \pi]@f$</td></tr> + * </table> + */ + template<typename _RealType = double> + class von_mises_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + friend class von_mises_distribution<_RealType>; + + explicit + param_type(_RealType __mu = _RealType(0), + _RealType __kappa = _RealType(1)) + : _M_mu(__mu), _M_kappa(__kappa) + { + const _RealType __pi = __gnu_cxx::__math_constants<_RealType>::__pi; + _GLIBCXX_DEBUG_ASSERT(_M_mu >= -__pi && _M_mu <= __pi); + _GLIBCXX_DEBUG_ASSERT(_M_kappa >= _RealType(0)); + + auto __tau = std::sqrt(_RealType(4) * _M_kappa * _M_kappa + + _RealType(1)) + _RealType(1); + auto __rho = ((__tau - std::sqrt(_RealType(2) * __tau)) + / (_RealType(2) * _M_kappa)); + _M_r = (_RealType(1) + __rho * __rho) / (_RealType(2) * __rho); + } + + _RealType + mu() const + { return _M_mu; } + + _RealType + kappa() const + { return _M_kappa; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_mu == __p2._M_mu + && __p1._M_kappa == __p2._M_kappa); } + + private: + _RealType _M_mu; + _RealType _M_kappa; + _RealType _M_r; + }; + + /** + * @brief Constructs a von Mises distribution with parameters + * @f$\mu@f$ and @f$\kappa@f$. + */ + explicit + von_mises_distribution(result_type __mu = result_type(0), + result_type __kappa = result_type(1)) + : _M_param(__mu, __kappa) + { } + + explicit + von_mises_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * @brief Returns the @f$ \mu @f$ of the distribution. + */ + result_type + mu() const + { return _M_param.mu(); } + + /** + * @brief Returns the @f$ \kappa @f$ of the distribution. + */ + result_type + kappa() const + { return _M_param.kappa(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { + return -__gnu_cxx::__math_constants<result_type>::__pi; + } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { + return __gnu_cxx::__math_constants<result_type>::__pi; + } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, _M_param); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + const result_type __pi + = __gnu_cxx::__math_constants<result_type>::__pi; + std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + result_type __f; + while (1) + { + result_type __rnd = std::cos(__pi * __aurng()); + __f = (result_type(1) + __p._M_r * __rnd) / (__p._M_r + __rnd); + result_type __c = __p._M_kappa * (__p._M_r - __f); + + result_type __rnd2 = __aurng(); + if (__c * (result_type(2) - __c) > __rnd2) + break; + if (std::log(__c / __rnd2) >= __c - result_type(1)) + break; + } + + result_type __res = std::acos(__f); +#if _GLIBCXX_USE_C99_MATH_TR1 + __res = std::copysign(__res, __aurng() - result_type(0.5)); +#else + if (__aurng() < result_type(0.5)) + __res = -__res; +#endif + __res += __p._M_mu; + if (__res > __pi) + __res -= result_type(2) * __pi; + else if (__res < -__pi) + __res += result_type(2) * __pi; + return __res; + } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, _M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template<typename _UniformRandomNumberGenerator> + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two von Mises distributions have the same + * parameters and the sequences that would be generated + * are equal. + */ + friend bool + operator==(const von_mises_distribution& __d1, + const von_mises_distribution& __d2) + { return __d1._M_param == __d2._M_param; } + + /** + * @brief Inserts a %von_mises_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %von_mises_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::von_mises_distribution<_RealType1>& __x); + + /** + * @brief Extracts a %von_mises_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %von_mises_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::von_mises_distribution<_RealType1>& __x); + + private: + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + }; + + /** + * @brief Return true if two von Mises distributions are different. + */ + template<typename _RealType> + inline bool + operator!=(const __gnu_cxx::von_mises_distribution<_RealType>& __d1, + const __gnu_cxx::von_mises_distribution<_RealType>& __d2) + { return !(__d1 == __d2); } + + + /** + * @brief A discrete hypergeometric random number distribution. + * + * The hypergeometric distribution is a discrete probability distribution + * that describes the probability of @p k successes in @p n draws @a without + * replacement from a finite population of size @p N containing exactly @p K + * successes. + * + * The formula for the hypergeometric probability density function is + * @f[ + * p(k|N,K,n) = \frac{\binom{K}{k} \binom{N-K}{n-k}}{\binom{N}{n}} + * @f] + * where @f$N@f$ is the total population of the distribution, + * @f$K@f$ is the total population of the distribution. + * + * <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Distribution Statistics</caption> + * <tr><td>Mean</td><td>@f$ n\frac{K}{N} @f$</td></tr> + * <tr><td>Variance</td><td>@f$ n\frac{K}{N}\frac{N-K}{N}\frac{N-n}{N-1} + * @f$</td></tr> + * <tr><td>Range</td><td>@f$[max(0, n+K-N), min(K, n)]@f$</td></tr> + * </table> + */ + template<typename _UIntType = unsigned int> + class hypergeometric_distribution + { + static_assert(std::is_unsigned<_UIntType>::value, "template argument " + "substituting _UIntType not an unsigned integral type"); + + public: + /** The type of the range of the distribution. */ + typedef _UIntType result_type; + + /** Parameter type. */ + struct param_type + { + typedef hypergeometric_distribution<_UIntType> distribution_type; + friend class hypergeometric_distribution<_UIntType>; + + explicit + param_type(result_type __N = 10, result_type __K = 5, + result_type __n = 1) + : _M_N{__N}, _M_K{__K}, _M_n{__n} + { + _GLIBCXX_DEBUG_ASSERT(_M_N >= _M_K); + _GLIBCXX_DEBUG_ASSERT(_M_N >= _M_n); + } + + result_type + total_size() const + { return _M_N; } + + result_type + successful_size() const + { return _M_K; } + + result_type + unsuccessful_size() const + { return _M_N - _M_K; } + + result_type + total_draws() const + { return _M_n; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_N == __p2._M_N) + && (__p1._M_K == __p2._M_K) + && (__p1._M_n == __p2._M_n); } + + private: + + result_type _M_N; + result_type _M_K; + result_type _M_n; + }; + + // constructors and member function + explicit + hypergeometric_distribution(result_type __N = 10, result_type __K = 5, + result_type __n = 1) + : _M_param{__N, __K, __n} + { } + + explicit + hypergeometric_distribution(const param_type& __p) + : _M_param{__p} + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * @brief Returns the distribution parameter @p N, + * the total number of items. + */ + result_type + total_size() const + { return this->_M_param.total_size(); } + + /** + * @brief Returns the distribution parameter @p K, + * the total number of successful items. + */ + result_type + successful_size() const + { return this->_M_param.successful_size(); } + + /** + * @brief Returns the total number of unsuccessful items @f$ N - K @f$. + */ + result_type + unsuccessful_size() const + { return this->_M_param.unsuccessful_size(); } + + /** + * @brief Returns the distribution parameter @p n, + * the total number of draws. + */ + result_type + total_draws() const + { return this->_M_param.total_draws(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return this->_M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { this->_M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { + using _IntType = typename std::make_signed<result_type>::type; + return static_cast<result_type>(std::max(static_cast<_IntType>(0), + static_cast<_IntType>(this->total_draws() + - this->unsuccessful_size()))); + } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::min(this->successful_size(), this->total_draws()); } + + /** + * @brief Generating functions. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->_M_param); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, this->_M_param); } + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template<typename _UniformRandomNumberGenerator> + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two hypergeometric distributions have the same + * parameters and the sequences that would be generated + * are equal. + */ + friend bool + operator==(const hypergeometric_distribution& __d1, + const hypergeometric_distribution& __d2) + { return __d1._M_param == __d2._M_param; } + + /** + * @brief Inserts a %hypergeometric_distribution random number + * distribution @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %hypergeometric_distribution random number + * distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _UIntType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::hypergeometric_distribution<_UIntType1>& + __x); + + /** + * @brief Extracts a %hypergeometric_distribution random number + * distribution @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %hypergeometric_distribution random number generator + * distribution. + * + * @returns The input stream with @p __x extracted or in an error + * state. + */ + template<typename _UIntType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::hypergeometric_distribution<_UIntType1>& __x); + + private: + + template<typename _ForwardIterator, + typename _UniformRandomNumberGenerator> + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + }; + + /** + * @brief Return true if two hypergeometric distributions are different. + */ + template<typename _UIntType> + inline bool + operator!=(const __gnu_cxx::hypergeometric_distribution<_UIntType>& __d1, + const __gnu_cxx::hypergeometric_distribution<_UIntType>& __d2) + { return !(__d1 == __d2); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace __gnu_cxx + +#include "ext/opt_random.h" +#include "random.tcc" + +#endif // _GLIBCXX_USE_C99_STDINT_TR1 + +#endif // C++11 + +#endif // _EXT_RANDOM diff --git a/gcc-4.9/libstdc++-v3/include/ext/random.tcc b/gcc-4.9/libstdc++-v3/include/ext/random.tcc new file mode 100644 index 0000000..dd7a14a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/random.tcc @@ -0,0 +1,1420 @@ +// Random number extensions -*- C++ -*- + +// Copyright (C) 2012-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/random.tcc + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{ext/random} + */ + +#ifndef _EXT_RANDOM_TCC +#define _EXT_RANDOM_TCC 1 + +#pragma GCC system_header + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + void simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + seed(_UIntType __seed) + { + _M_state32[0] = static_cast<uint32_t>(__seed); + for (size_t __i = 1; __i < _M_nstate32; ++__i) + _M_state32[__i] = (1812433253UL + * (_M_state32[__i - 1] ^ (_M_state32[__i - 1] >> 30)) + + __i); + _M_pos = state_size; + _M_period_certification(); + } + + + namespace { + + inline uint32_t _Func1(uint32_t __x) + { + return (__x ^ (__x >> 27)) * UINT32_C(1664525); + } + + inline uint32_t _Func2(uint32_t __x) + { + return (__x ^ (__x >> 27)) * UINT32_C(1566083941); + } + + } + + + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + template<typename _Sseq> + typename std::enable_if<std::is_class<_Sseq>::value>::type + simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + seed(_Sseq& __q) + { + size_t __lag; + + if (_M_nstate32 >= 623) + __lag = 11; + else if (_M_nstate32 >= 68) + __lag = 7; + else if (_M_nstate32 >= 39) + __lag = 5; + else + __lag = 3; + const size_t __mid = (_M_nstate32 - __lag) / 2; + + std::fill(_M_state32, _M_state32 + _M_nstate32, UINT32_C(0x8b8b8b8b)); + uint32_t __arr[_M_nstate32]; + __q.generate(__arr + 0, __arr + _M_nstate32); + + uint32_t __r = _Func1(_M_state32[0] ^ _M_state32[__mid] + ^ _M_state32[_M_nstate32 - 1]); + _M_state32[__mid] += __r; + __r += _M_nstate32; + _M_state32[__mid + __lag] += __r; + _M_state32[0] = __r; + + for (size_t __i = 1, __j = 0; __j < _M_nstate32; ++__j) + { + __r = _Func1(_M_state32[__i] + ^ _M_state32[(__i + __mid) % _M_nstate32] + ^ _M_state32[(__i + _M_nstate32 - 1) % _M_nstate32]); + _M_state32[(__i + __mid) % _M_nstate32] += __r; + __r += __arr[__j] + __i; + _M_state32[(__i + __mid + __lag) % _M_nstate32] += __r; + _M_state32[__i] = __r; + __i = (__i + 1) % _M_nstate32; + } + for (size_t __j = 0; __j < _M_nstate32; ++__j) + { + const size_t __i = (__j + 1) % _M_nstate32; + __r = _Func2(_M_state32[__i] + + _M_state32[(__i + __mid) % _M_nstate32] + + _M_state32[(__i + _M_nstate32 - 1) % _M_nstate32]); + _M_state32[(__i + __mid) % _M_nstate32] ^= __r; + __r -= __i; + _M_state32[(__i + __mid + __lag) % _M_nstate32] ^= __r; + _M_state32[__i] = __r; + } + + _M_pos = state_size; + _M_period_certification(); + } + + + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + void simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + _M_period_certification(void) + { + static const uint32_t __parity[4] = { __parity1, __parity2, + __parity3, __parity4 }; + uint32_t __inner = 0; + for (size_t __i = 0; __i < 4; ++__i) + if (__parity[__i] != 0) + __inner ^= _M_state32[__i] & __parity[__i]; + + if (__builtin_parity(__inner) & 1) + return; + for (size_t __i = 0; __i < 4; ++__i) + if (__parity[__i] != 0) + { + _M_state32[__i] ^= 1 << (__builtin_ffs(__parity[__i]) - 1); + return; + } + __builtin_unreachable(); + } + + + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + void simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + discard(unsigned long long __z) + { + while (__z > state_size - _M_pos) + { + __z -= state_size - _M_pos; + + _M_gen_rand(); + } + + _M_pos += __z; + } + + +#ifndef _GLIBCXX_OPT_HAVE_RANDOM_SFMT_GEN_READ + + namespace { + + template<size_t __shift> + inline void __rshift(uint32_t *__out, const uint32_t *__in) + { + uint64_t __th = ((static_cast<uint64_t>(__in[3]) << 32) + | static_cast<uint64_t>(__in[2])); + uint64_t __tl = ((static_cast<uint64_t>(__in[1]) << 32) + | static_cast<uint64_t>(__in[0])); + + uint64_t __oh = __th >> (__shift * 8); + uint64_t __ol = __tl >> (__shift * 8); + __ol |= __th << (64 - __shift * 8); + __out[1] = static_cast<uint32_t>(__ol >> 32); + __out[0] = static_cast<uint32_t>(__ol); + __out[3] = static_cast<uint32_t>(__oh >> 32); + __out[2] = static_cast<uint32_t>(__oh); + } + + + template<size_t __shift> + inline void __lshift(uint32_t *__out, const uint32_t *__in) + { + uint64_t __th = ((static_cast<uint64_t>(__in[3]) << 32) + | static_cast<uint64_t>(__in[2])); + uint64_t __tl = ((static_cast<uint64_t>(__in[1]) << 32) + | static_cast<uint64_t>(__in[0])); + + uint64_t __oh = __th << (__shift * 8); + uint64_t __ol = __tl << (__shift * 8); + __oh |= __tl >> (64 - __shift * 8); + __out[1] = static_cast<uint32_t>(__ol >> 32); + __out[0] = static_cast<uint32_t>(__ol); + __out[3] = static_cast<uint32_t>(__oh >> 32); + __out[2] = static_cast<uint32_t>(__oh); + } + + + template<size_t __sl1, size_t __sl2, size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, uint32_t __msk3, uint32_t __msk4> + inline void __recursion(uint32_t *__r, + const uint32_t *__a, const uint32_t *__b, + const uint32_t *__c, const uint32_t *__d) + { + uint32_t __x[4]; + uint32_t __y[4]; + + __lshift<__sl2>(__x, __a); + __rshift<__sr2>(__y, __c); + __r[0] = (__a[0] ^ __x[0] ^ ((__b[0] >> __sr1) & __msk1) + ^ __y[0] ^ (__d[0] << __sl1)); + __r[1] = (__a[1] ^ __x[1] ^ ((__b[1] >> __sr1) & __msk2) + ^ __y[1] ^ (__d[1] << __sl1)); + __r[2] = (__a[2] ^ __x[2] ^ ((__b[2] >> __sr1) & __msk3) + ^ __y[2] ^ (__d[2] << __sl1)); + __r[3] = (__a[3] ^ __x[3] ^ ((__b[3] >> __sr1) & __msk4) + ^ __y[3] ^ (__d[3] << __sl1)); + } + + } + + + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + void simd_fast_mersenne_twister_engine<_UIntType, __m, + __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, + __parity4>:: + _M_gen_rand(void) + { + const uint32_t *__r1 = &_M_state32[_M_nstate32 - 8]; + const uint32_t *__r2 = &_M_state32[_M_nstate32 - 4]; + static constexpr size_t __pos1_32 = __pos1 * 4; + + size_t __i; + for (__i = 0; __i < _M_nstate32 - __pos1_32; __i += 4) + { + __recursion<__sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4> + (&_M_state32[__i], &_M_state32[__i], + &_M_state32[__i + __pos1_32], __r1, __r2); + __r1 = __r2; + __r2 = &_M_state32[__i]; + } + + for (; __i < _M_nstate32; __i += 4) + { + __recursion<__sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4> + (&_M_state32[__i], &_M_state32[__i], + &_M_state32[__i + __pos1_32 - _M_nstate32], __r1, __r2); + __r1 = __r2; + __r2 = &_M_state32[__i]; + } + + _M_pos = 0; + } + +#endif + +#ifndef _GLIBCXX_OPT_HAVE_RANDOM_SFMT_OPERATOREQUAL + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4> + bool + operator==(const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, __parity4>& __lhs, + const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, __parity4>& __rhs) + { + typedef __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, __parity4> __engine; + return (std::equal(__lhs._M_stateT, + __lhs._M_stateT + __engine::state_size, + __rhs._M_stateT) + && __lhs._M_pos == __rhs._M_pos); + } +#endif + + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, __parity4>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); + __os.fill(__space); + + for (size_t __i = 0; __i < __x._M_nstate32; ++__i) + __os << __x._M_state32[__i] << __space; + __os << __x._M_pos; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + + template<typename _UIntType, size_t __m, + size_t __pos1, size_t __sl1, size_t __sl2, + size_t __sr1, size_t __sr2, + uint32_t __msk1, uint32_t __msk2, + uint32_t __msk3, uint32_t __msk4, + uint32_t __parity1, uint32_t __parity2, + uint32_t __parity3, uint32_t __parity4, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::simd_fast_mersenne_twister_engine<_UIntType, + __m, __pos1, __sl1, __sl2, __sr1, __sr2, + __msk1, __msk2, __msk3, __msk4, + __parity1, __parity2, __parity3, __parity4>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + for (size_t __i = 0; __i < __x._M_nstate32; ++__i) + __is >> __x._M_state32[__i]; + __is >> __x._M_pos; + + __is.flags(__flags); + return __is; + } + +#endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + + /** + * Iteration method due to M.D. J<o:>hnk. + * + * M.D. J<o:>hnk, Erzeugung von betaverteilten und gammaverteilten + * Zufallszahlen, Metrika, Volume 8, 1964 + */ + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename beta_distribution<_RealType>::result_type + beta_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + result_type __x, __y; + do + { + __x = std::exp(std::log(__aurng()) / __param.alpha()); + __y = std::exp(std::log(__aurng()) / __param.beta()); + } + while (__x + __y > result_type(1)); + + return __x / (__x + __y); + } + + template<typename _RealType> + template<typename _OutputIterator, + typename _UniformRandomNumberGenerator> + void + beta_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + while (__f != __t) + { + result_type __x, __y; + do + { + __x = std::exp(std::log(__aurng()) / __param.alpha()); + __y = std::exp(std::log(__aurng()) / __param.beta()); + } + while (__x + __y > result_type(1)); + + *__f++ = __x / (__x + __y); + } + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::beta_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.alpha() << __space << __x.beta(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::beta_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __alpha_val, __beta_val; + __is >> __alpha_val >> __beta_val; + __x.param(typename __gnu_cxx::beta_distribution<_RealType>:: + param_type(__alpha_val, __beta_val)); + + __is.flags(__flags); + return __is; + } + + + template<std::size_t _Dimen, typename _RealType> + template<typename _InputIterator1, typename _InputIterator2> + void + normal_mv_distribution<_Dimen, _RealType>::param_type:: + _M_init_full(_InputIterator1 __meanbegin, _InputIterator1 __meanend, + _InputIterator2 __varcovbegin, _InputIterator2 __varcovend) + { + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) + std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()), + _M_mean.end(), _RealType(0)); + + // Perform the Cholesky decomposition + auto __w = _M_t.begin(); + for (size_t __j = 0; __j < _Dimen; ++__j) + { + _RealType __sum = _RealType(0); + + auto __slitbegin = __w; + auto __cit = _M_t.begin(); + for (size_t __i = 0; __i < __j; ++__i) + { + auto __slit = __slitbegin; + _RealType __s = *__varcovbegin++; + for (size_t __k = 0; __k < __i; ++__k) + __s -= *__slit++ * *__cit++; + + *__w++ = __s /= *__cit++; + __sum += __s * __s; + } + + __sum = *__varcovbegin - __sum; + if (__builtin_expect(__sum <= _RealType(0), 0)) + std::__throw_runtime_error(__N("normal_mv_distribution::" + "param_type::_M_init_full")); + *__w++ = std::sqrt(__sum); + + std::advance(__varcovbegin, _Dimen - __j); + } + } + + template<std::size_t _Dimen, typename _RealType> + template<typename _InputIterator1, typename _InputIterator2> + void + normal_mv_distribution<_Dimen, _RealType>::param_type:: + _M_init_lower(_InputIterator1 __meanbegin, _InputIterator1 __meanend, + _InputIterator2 __varcovbegin, _InputIterator2 __varcovend) + { + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) + std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()), + _M_mean.end(), _RealType(0)); + + // Perform the Cholesky decomposition + auto __w = _M_t.begin(); + for (size_t __j = 0; __j < _Dimen; ++__j) + { + _RealType __sum = _RealType(0); + + auto __slitbegin = __w; + auto __cit = _M_t.begin(); + for (size_t __i = 0; __i < __j; ++__i) + { + auto __slit = __slitbegin; + _RealType __s = *__varcovbegin++; + for (size_t __k = 0; __k < __i; ++__k) + __s -= *__slit++ * *__cit++; + + *__w++ = __s /= *__cit++; + __sum += __s * __s; + } + + __sum = *__varcovbegin++ - __sum; + if (__builtin_expect(__sum <= _RealType(0), 0)) + std::__throw_runtime_error(__N("normal_mv_distribution::" + "param_type::_M_init_full")); + *__w++ = std::sqrt(__sum); + } + } + + template<std::size_t _Dimen, typename _RealType> + template<typename _InputIterator1, typename _InputIterator2> + void + normal_mv_distribution<_Dimen, _RealType>::param_type:: + _M_init_diagonal(_InputIterator1 __meanbegin, _InputIterator1 __meanend, + _InputIterator2 __varbegin, _InputIterator2 __varend) + { + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) + __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) + std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()), + _M_mean.end(), _RealType(0)); + + auto __w = _M_t.begin(); + size_t __step = 0; + while (__varbegin != __varend) + { + std::fill_n(__w, __step, _RealType(0)); + __w += __step++; + if (__builtin_expect(*__varbegin < _RealType(0), 0)) + std::__throw_runtime_error(__N("normal_mv_distribution::" + "param_type::_M_init_diagonal")); + *__w++ = std::sqrt(*__varbegin++); + } + } + + template<std::size_t _Dimen, typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename normal_mv_distribution<_Dimen, _RealType>::result_type + normal_mv_distribution<_Dimen, _RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + result_type __ret; + + _M_nd.__generate(__ret.begin(), __ret.end(), __urng); + + auto __t_it = __param._M_t.crbegin(); + for (size_t __i = _Dimen; __i > 0; --__i) + { + _RealType __sum = _RealType(0); + for (size_t __j = __i; __j > 0; --__j) + __sum += __ret[__j - 1] * *__t_it++; + __ret[__i - 1] = __sum; + } + + return __ret; + } + + template<std::size_t _Dimen, typename _RealType> + template<typename _ForwardIterator, typename _UniformRandomNumberGenerator> + void + normal_mv_distribution<_Dimen, _RealType>:: + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< + _ForwardIterator>) + while (__f != __t) + *__f++ = this->operator()(__urng, __param); + } + + template<size_t _Dimen, typename _RealType> + bool + operator==(const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& + __d1, + const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& + __d2) + { + return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd; + } + + template<size_t _Dimen, typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + auto __mean = __x._M_param.mean(); + for (auto __it : __mean) + __os << __it << __space; + auto __t = __x._M_param.varcov(); + for (auto __it : __t) + __os << __it << __space; + + __os << __x._M_nd; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<size_t _Dimen, typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + std::array<_RealType, _Dimen> __mean; + for (auto& __it : __mean) + __is >> __it; + std::array<_RealType, _Dimen * (_Dimen + 1) / 2> __varcov; + for (auto& __it : __varcov) + __is >> __it; + + __is >> __x._M_nd; + + __x.param(typename normal_mv_distribution<_Dimen, _RealType>:: + param_type(__mean.begin(), __mean.end(), + __varcov.begin(), __varcov.end())); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _OutputIterator, + typename _UniformRandomNumberGenerator> + void + rice_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + while (__f != __t) + { + typename std::normal_distribution<result_type>::param_type + __px(__p.nu(), __p.sigma()), __py(result_type(0), __p.sigma()); + result_type __x = this->_M_ndx(__px, __urng); + result_type __y = this->_M_ndy(__py, __urng); +#if _GLIBCXX_USE_C99_MATH_TR1 + *__f++ = std::hypot(__x, __y); +#else + *__f++ = std::sqrt(__x * __x + __y * __y); +#endif + } + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const rice_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.nu() << __space << __x.sigma(); + __os << __space << __x._M_ndx; + __os << __space << __x._M_ndy; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + rice_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __nu_val, __sigma_val; + __is >> __nu_val >> __sigma_val; + __is >> __x._M_ndx; + __is >> __x._M_ndy; + __x.param(typename rice_distribution<_RealType>:: + param_type(__nu_val, __sigma_val)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _OutputIterator, + typename _UniformRandomNumberGenerator> + void + nakagami_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + typename std::gamma_distribution<result_type>::param_type + __pg(__p.mu(), __p.omega() / __p.mu()); + while (__f != __t) + *__f++ = std::sqrt(this->_M_gd(__pg, __urng)); + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const nakagami_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.mu() << __space << __x.omega(); + __os << __space << __x._M_gd; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + nakagami_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __mu_val, __omega_val; + __is >> __mu_val >> __omega_val; + __is >> __x._M_gd; + __x.param(typename nakagami_distribution<_RealType>:: + param_type(__mu_val, __omega_val)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _OutputIterator, + typename _UniformRandomNumberGenerator> + void + pareto_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + result_type __mu_val = __p.mu(); + result_type __malphinv = -result_type(1) / __p.alpha(); + while (__f != __t) + *__f++ = __mu_val * std::pow(this->_M_ud(__urng), __malphinv); + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const pareto_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.alpha() << __space << __x.mu(); + __os << __space << __x._M_ud; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + pareto_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __alpha_val, __mu_val; + __is >> __alpha_val >> __mu_val; + __is >> __x._M_ud; + __x.param(typename pareto_distribution<_RealType>:: + param_type(__alpha_val, __mu_val)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename k_distribution<_RealType>::result_type + k_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __x = this->_M_gd1(__urng); + result_type __y = this->_M_gd2(__urng); + return std::sqrt(__x * __y); + } + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename k_distribution<_RealType>::result_type + k_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + typename std::gamma_distribution<result_type>::param_type + __p1(__p.lambda(), result_type(1) / __p.lambda()), + __p2(__p.nu(), __p.mu() / __p.nu()); + result_type __x = this->_M_gd1(__p1, __urng); + result_type __y = this->_M_gd2(__p2, __urng); + return std::sqrt(__x * __y); + } + + template<typename _RealType> + template<typename _OutputIterator, + typename _UniformRandomNumberGenerator> + void + k_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + typename std::gamma_distribution<result_type>::param_type + __p1(__p.lambda(), result_type(1) / __p.lambda()), + __p2(__p.nu(), __p.mu() / __p.nu()); + while (__f != __t) + { + result_type __x = this->_M_gd1(__p1, __urng); + result_type __y = this->_M_gd2(__p2, __urng); + *__f++ = std::sqrt(__x * __y); + } + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const k_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.lambda() << __space << __x.mu() << __space << __x.nu(); + __os << __space << __x._M_gd1; + __os << __space << __x._M_gd2; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + k_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __lambda_val, __mu_val, __nu_val; + __is >> __lambda_val >> __mu_val >> __nu_val; + __is >> __x._M_gd1; + __is >> __x._M_gd2; + __x.param(typename k_distribution<_RealType>:: + param_type(__lambda_val, __mu_val, __nu_val)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _OutputIterator, + typename _UniformRandomNumberGenerator> + void + arcsine_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + result_type __dif = __p.b() - __p.a(); + result_type __sum = __p.a() + __p.b(); + while (__f != __t) + { + result_type __x = std::sin(this->_M_ud(__urng)); + *__f++ = (__x * __dif + __sum) / result_type(2); + } + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const arcsine_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.a() << __space << __x.b(); + __os << __space << __x._M_ud; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + arcsine_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __a, __b; + __is >> __a >> __b; + __is >> __x._M_ud; + __x.param(typename arcsine_distribution<_RealType>:: + param_type(__a, __b)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename hoyt_distribution<_RealType>::result_type + hoyt_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __x = this->_M_ad(__urng); + result_type __y = this->_M_ed(__urng); + return (result_type(2) * this->q() + / (result_type(1) + this->q() * this->q())) + * std::sqrt(this->omega() * __x * __y); + } + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename hoyt_distribution<_RealType>::result_type + hoyt_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + result_type __q2 = __p.q() * __p.q(); + result_type __num = result_type(0.5L) * (result_type(1) + __q2); + typename __gnu_cxx::arcsine_distribution<result_type>::param_type + __pa(__num, __num / __q2); + result_type __x = this->_M_ad(__pa, __urng); + result_type __y = this->_M_ed(__urng); + return (result_type(2) * __p.q() / (result_type(1) + __q2)) + * std::sqrt(__p.omega() * __x * __y); + } + + template<typename _RealType> + template<typename _OutputIterator, + typename _UniformRandomNumberGenerator> + void + hoyt_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + result_type __2q = result_type(2) * __p.q(); + result_type __q2 = __p.q() * __p.q(); + result_type __q2p1 = result_type(1) + __q2; + result_type __num = result_type(0.5L) * __q2p1; + result_type __omega = __p.omega(); + typename __gnu_cxx::arcsine_distribution<result_type>::param_type + __pa(__num, __num / __q2); + while (__f != __t) + { + result_type __x = this->_M_ad(__pa, __urng); + result_type __y = this->_M_ed(__urng); + *__f++ = (__2q / __q2p1) * std::sqrt(__omega * __x * __y); + } + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const hoyt_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.q() << __space << __x.omega(); + __os << __space << __x._M_ad; + __os << __space << __x._M_ed; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + hoyt_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __q, __omega; + __is >> __q >> __omega; + __is >> __x._M_ad; + __is >> __x._M_ed; + __x.param(typename hoyt_distribution<_RealType>:: + param_type(__q, __omega)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _OutputIterator, + typename _UniformRandomNumberGenerator> + void + triangular_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + while (__f != __t) + *__f++ = this->operator()(__urng, __param); + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::triangular_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.a() << __space << __x.b() << __space << __x.c(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::triangular_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __a, __b, __c; + __is >> __a >> __b >> __c; + __x.param(typename __gnu_cxx::triangular_distribution<_RealType>:: + param_type(__a, __b, __c)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _OutputIterator, + typename _UniformRandomNumberGenerator> + void + von_mises_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + while (__f != __t) + *__f++ = this->operator()(__urng, __param); + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::von_mises_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.mu() << __space << __x.kappa(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::von_mises_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __mu, __kappa; + __is >> __mu >> __kappa; + __x.param(typename __gnu_cxx::von_mises_distribution<_RealType>:: + param_type(__mu, __kappa)); + + __is.flags(__flags); + return __is; + } + + + template<typename _UIntType> + template<typename _UniformRandomNumberGenerator> + typename hypergeometric_distribution<_UIntType>::result_type + hypergeometric_distribution<_UIntType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + result_type __a = __param.successful_size(); + result_type __b = __param.total_size(); + result_type __k = 0; + + if (__param.total_draws() < __param.total_size() / 2) + { + for (result_type __i = 0; __i < __param.total_draws(); ++__i) + { + if (__b * __aurng() < __a) + { + ++__k; + if (__k == __param.successful_size()) + return __k; + --__a; + } + --__b; + } + return __k; + } + else + { + for (result_type __i = 0; __i < __param.unsuccessful_size(); ++__i) + { + if (__b * __aurng() < __a) + { + ++__k; + if (__k == __param.successful_size()) + return __param.successful_size() - __k; + --__a; + } + --__b; + } + return __param.successful_size() - __k; + } + } + + template<typename _UIntType> + template<typename _OutputIterator, + typename _UniformRandomNumberGenerator> + void + hypergeometric_distribution<_UIntType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + while (__f != __t) + *__f++ = this->operator()(__urng); + } + + template<typename _UIntType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::hypergeometric_distribution<_UIntType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_UIntType>::max_digits10); + + __os << __x.total_size() << __space << __x.successful_size() << __space + << __x.total_draws(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _UIntType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::hypergeometric_distribution<_UIntType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _UIntType __total_size, __successful_size, __total_draws; + __is >> __total_size >> __successful_size >> __total_draws; + __x.param(typename __gnu_cxx::hypergeometric_distribution<_UIntType>:: + param_type(__total_size, __successful_size, __total_draws)); + + __is.flags(__flags); + return __is; + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + + +#endif // _EXT_RANDOM_TCC diff --git a/gcc-4.9/libstdc++-v3/include/ext/rb_tree b/gcc-4.9/libstdc++-v3/include/ext/rb_tree new file mode 100644 index 0000000..e6d4f61 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/rb_tree @@ -0,0 +1,96 @@ +// rb_tree extension -*- C++ -*- + +// Copyright (C) 2002-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * + * Copyright (c) 1994 + * Hewlett-Packard Company + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Hewlett-Packard Company makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * + * Copyright (c) 1996 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/** @file ext/rb_tree + * This file is a GNU extension to the Standard C++ Library (possibly + * containing extensions from the HP/SGI STL subset). + */ + +#ifndef _RB_TREE +#define _RB_TREE 1 + +#pragma GCC system_header + +#include <bits/stl_tree.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::_Rb_tree; + using std::allocator; + + // Class rb_tree is not part of the C++ standard. It is provided for + // compatibility with the HP STL. + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template <class _Key, class _Value, class _KeyOfValue, class _Compare, + class _Alloc = allocator<_Value> > + struct rb_tree + : public _Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc> + { + typedef _Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc> _Base; + typedef typename _Base::allocator_type allocator_type; + + rb_tree(const _Compare& __comp = _Compare(), + const allocator_type& __a = allocator_type()) + : _Base(__comp, __a) { } + + ~rb_tree() { } + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/rc_string_base.h b/gcc-4.9/libstdc++-v3/include/ext/rc_string_base.h new file mode 100644 index 0000000..4c72407 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/rc_string_base.h @@ -0,0 +1,732 @@ +// Reference-counted versatile string base -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/rc_string_base.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{ext/vstring.h} + */ + +#ifndef _RC_STRING_BASE_H +#define _RC_STRING_BASE_H 1 + +#include <ext/atomicity.h> +#include <bits/stl_iterator_base_funcs.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * Documentation? What's that? + * Nathan Myers <ncm@cantrip.org>. + * + * A string looks like this: + * + * @code + * [_Rep] + * _M_length + * [__rc_string_base<char_type>] _M_capacity + * _M_dataplus _M_refcount + * _M_p ----------------> unnamed array of char_type + * @endcode + * + * Where the _M_p points to the first character in the string, and + * you cast it to a pointer-to-_Rep and subtract 1 to get a + * pointer to the header. + * + * This approach has the enormous advantage that a string object + * requires only one allocation. All the ugliness is confined + * within a single pair of inline functions, which each compile to + * a single @a add instruction: _Rep::_M_refdata(), and + * __rc_string_base::_M_rep(); and the allocation function which gets a + * block of raw bytes and with room enough and constructs a _Rep + * object at the front. + * + * The reason you want _M_data pointing to the character array and + * not the _Rep is so that the debugger can see the string + * contents. (Probably we should add a non-inline member to get + * the _Rep for the debugger to use, so users can check the actual + * string length.) + * + * Note that the _Rep object is a POD so that you can have a + * static <em>empty string</em> _Rep object already @a constructed before + * static constructors have run. The reference-count encoding is + * chosen so that a 0 indicates one reference, so you never try to + * destroy the empty-string _Rep object. + * + * All but the last paragraph is considered pretty conventional + * for a C++ string implementation. + */ + template<typename _CharT, typename _Traits, typename _Alloc> + class __rc_string_base + : protected __vstring_utility<_CharT, _Traits, _Alloc> + { + public: + typedef _Traits traits_type; + typedef typename _Traits::char_type value_type; + typedef _Alloc allocator_type; + + typedef __vstring_utility<_CharT, _Traits, _Alloc> _Util_Base; + typedef typename _Util_Base::_CharT_alloc_type _CharT_alloc_type; + typedef typename _CharT_alloc_type::size_type size_type; + + private: + // _Rep: string representation + // Invariants: + // 1. String really contains _M_length + 1 characters: due to 21.3.4 + // must be kept null-terminated. + // 2. _M_capacity >= _M_length + // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT). + // 3. _M_refcount has three states: + // -1: leaked, one reference, no ref-copies allowed, non-const. + // 0: one reference, non-const. + // n>0: n + 1 references, operations require a lock, const. + // 4. All fields == 0 is an empty string, given the extra storage + // beyond-the-end for a null terminator; thus, the shared + // empty string representation needs no constructor. + struct _Rep + { + union + { + struct + { + size_type _M_length; + size_type _M_capacity; + _Atomic_word _M_refcount; + } _M_info; + + // Only for alignment purposes. + _CharT _M_align; + }; + + typedef typename _Alloc::template rebind<_Rep>::other _Rep_alloc_type; + + _CharT* + _M_refdata() throw() + { return reinterpret_cast<_CharT*>(this + 1); } + + _CharT* + _M_refcopy() throw() + { + __atomic_add_dispatch(&_M_info._M_refcount, 1); + return _M_refdata(); + } // XXX MT + + void + _M_set_length(size_type __n) + { + _M_info._M_refcount = 0; // One reference. + _M_info._M_length = __n; + // grrr. (per 21.3.4) + // You cannot leave those LWG people alone for a second. + traits_type::assign(_M_refdata()[__n], _CharT()); + } + + // Create & Destroy + static _Rep* + _S_create(size_type, size_type, const _Alloc&); + + void + _M_destroy(const _Alloc&) throw(); + + _CharT* + _M_clone(const _Alloc&, size_type __res = 0); + }; + + struct _Rep_empty + : public _Rep + { + _CharT _M_terminal; + }; + + static _Rep_empty _S_empty_rep; + + // The maximum number of individual char_type elements of an + // individual string is determined by _S_max_size. This is the + // value that will be returned by max_size(). (Whereas npos + // is the maximum number of bytes the allocator can allocate.) + // If one was to divvy up the theoretical largest size string, + // with a terminating character and m _CharT elements, it'd + // look like this: + // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT) + // + sizeof(_Rep) - 1 + // (NB: last two terms for rounding reasons, see _M_create below) + // Solving for m: + // m = ((npos - 2 * sizeof(_Rep) + 1) / sizeof(_CharT)) - 1 + // In addition, this implementation halves this amount. + enum { _S_max_size = (((static_cast<size_type>(-1) - 2 * sizeof(_Rep) + + 1) / sizeof(_CharT)) - 1) / 2 }; + + // Data Member (private): + mutable typename _Util_Base::template _Alloc_hider<_Alloc> _M_dataplus; + + void + _M_data(_CharT* __p) + { _M_dataplus._M_p = __p; } + + _Rep* + _M_rep() const + { return &((reinterpret_cast<_Rep*>(_M_data()))[-1]); } + + _CharT* + _M_grab(const _Alloc& __alloc) const + { + return (!_M_is_leaked() && _M_get_allocator() == __alloc) + ? _M_rep()->_M_refcopy() : _M_rep()->_M_clone(__alloc); + } + + void + _M_dispose() + { + // Be race-detector-friendly. For more info see bits/c++config. + _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_rep()->_M_info. + _M_refcount); + if (__exchange_and_add_dispatch(&_M_rep()->_M_info._M_refcount, + -1) <= 0) + { + _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_rep()->_M_info. + _M_refcount); + _M_rep()->_M_destroy(_M_get_allocator()); + } + } // XXX MT + + bool + _M_is_leaked() const + { return _M_rep()->_M_info._M_refcount < 0; } + + void + _M_set_sharable() + { _M_rep()->_M_info._M_refcount = 0; } + + void + _M_leak_hard(); + + // _S_construct_aux is used to implement the 21.3.1 para 15 which + // requires special behaviour if _InIterator is an integral type + template<typename _InIterator> + static _CharT* + _S_construct_aux(_InIterator __beg, _InIterator __end, + const _Alloc& __a, std::__false_type) + { + typedef typename iterator_traits<_InIterator>::iterator_category _Tag; + return _S_construct(__beg, __end, __a, _Tag()); + } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 438. Ambiguity in the "do the right thing" clause + template<typename _Integer> + static _CharT* + _S_construct_aux(_Integer __beg, _Integer __end, + const _Alloc& __a, std::__true_type) + { return _S_construct_aux_2(static_cast<size_type>(__beg), + __end, __a); } + + static _CharT* + _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a) + { return _S_construct(__req, __c, __a); } + + template<typename _InIterator> + static _CharT* + _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a) + { + typedef typename std::__is_integer<_InIterator>::__type _Integral; + return _S_construct_aux(__beg, __end, __a, _Integral()); + } + + // For Input Iterators, used in istreambuf_iterators, etc. + template<typename _InIterator> + static _CharT* + _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, + std::input_iterator_tag); + + // For forward_iterators up to random_access_iterators, used for + // string::iterator, _CharT*, etc. + template<typename _FwdIterator> + static _CharT* + _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a, + std::forward_iterator_tag); + + static _CharT* + _S_construct(size_type __req, _CharT __c, const _Alloc& __a); + + public: + size_type + _M_max_size() const + { return size_type(_S_max_size); } + + _CharT* + _M_data() const + { return _M_dataplus._M_p; } + + size_type + _M_length() const + { return _M_rep()->_M_info._M_length; } + + size_type + _M_capacity() const + { return _M_rep()->_M_info._M_capacity; } + + bool + _M_is_shared() const + { return _M_rep()->_M_info._M_refcount > 0; } + + void + _M_set_leaked() + { _M_rep()->_M_info._M_refcount = -1; } + + void + _M_leak() // for use in begin() & non-const op[] + { + if (!_M_is_leaked()) + _M_leak_hard(); + } + + void + _M_set_length(size_type __n) + { _M_rep()->_M_set_length(__n); } + + __rc_string_base() + : _M_dataplus(_S_empty_rep._M_refcopy()) { } + + __rc_string_base(const _Alloc& __a); + + __rc_string_base(const __rc_string_base& __rcs); + +#if __cplusplus >= 201103L + __rc_string_base(__rc_string_base&& __rcs) + : _M_dataplus(__rcs._M_dataplus) + { __rcs._M_data(_S_empty_rep._M_refcopy()); } +#endif + + __rc_string_base(size_type __n, _CharT __c, const _Alloc& __a); + + template<typename _InputIterator> + __rc_string_base(_InputIterator __beg, _InputIterator __end, + const _Alloc& __a); + + ~__rc_string_base() + { _M_dispose(); } + + allocator_type& + _M_get_allocator() + { return _M_dataplus; } + + const allocator_type& + _M_get_allocator() const + { return _M_dataplus; } + + void + _M_swap(__rc_string_base& __rcs); + + void + _M_assign(const __rc_string_base& __rcs); + + void + _M_reserve(size_type __res); + + void + _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, + size_type __len2); + + void + _M_erase(size_type __pos, size_type __n); + + void + _M_clear() + { _M_erase(size_type(0), _M_length()); } + + bool + _M_compare(const __rc_string_base&) const + { return false; } + }; + + template<typename _CharT, typename _Traits, typename _Alloc> + typename __rc_string_base<_CharT, _Traits, _Alloc>::_Rep_empty + __rc_string_base<_CharT, _Traits, _Alloc>::_S_empty_rep; + + template<typename _CharT, typename _Traits, typename _Alloc> + typename __rc_string_base<_CharT, _Traits, _Alloc>::_Rep* + __rc_string_base<_CharT, _Traits, _Alloc>::_Rep:: + _S_create(size_type __capacity, size_type __old_capacity, + const _Alloc& __alloc) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 83. String::npos vs. string::max_size() + if (__capacity > size_type(_S_max_size)) + std::__throw_length_error(__N("__rc_string_base::_Rep::_S_create")); + + // The standard places no restriction on allocating more memory + // than is strictly needed within this layer at the moment or as + // requested by an explicit application call to reserve(). + + // Many malloc implementations perform quite poorly when an + // application attempts to allocate memory in a stepwise fashion + // growing each allocation size by only 1 char. Additionally, + // it makes little sense to allocate less linear memory than the + // natural blocking size of the malloc implementation. + // Unfortunately, we would need a somewhat low-level calculation + // with tuned parameters to get this perfect for any particular + // malloc implementation. Fortunately, generalizations about + // common features seen among implementations seems to suffice. + + // __pagesize need not match the actual VM page size for good + // results in practice, thus we pick a common value on the low + // side. __malloc_header_size is an estimate of the amount of + // overhead per memory allocation (in practice seen N * sizeof + // (void*) where N is 0, 2 or 4). According to folklore, + // picking this value on the high side is better than + // low-balling it (especially when this algorithm is used with + // malloc implementations that allocate memory blocks rounded up + // to a size which is a power of 2). + const size_type __pagesize = 4096; + const size_type __malloc_header_size = 4 * sizeof(void*); + + // The below implements an exponential growth policy, necessary to + // meet amortized linear time requirements of the library: see + // http://gcc.gnu.org/ml/libstdc++/2001-07/msg00085.html. + if (__capacity > __old_capacity && __capacity < 2 * __old_capacity) + { + __capacity = 2 * __old_capacity; + // Never allocate a string bigger than _S_max_size. + if (__capacity > size_type(_S_max_size)) + __capacity = size_type(_S_max_size); + } + + // NB: Need an array of char_type[__capacity], plus a terminating + // null char_type() element, plus enough for the _Rep data structure, + // plus sizeof(_Rep) - 1 to upper round to a size multiple of + // sizeof(_Rep). + // Whew. Seemingly so needy, yet so elemental. + size_type __size = ((__capacity + 1) * sizeof(_CharT) + + 2 * sizeof(_Rep) - 1); + + const size_type __adj_size = __size + __malloc_header_size; + if (__adj_size > __pagesize && __capacity > __old_capacity) + { + const size_type __extra = __pagesize - __adj_size % __pagesize; + __capacity += __extra / sizeof(_CharT); + if (__capacity > size_type(_S_max_size)) + __capacity = size_type(_S_max_size); + __size = (__capacity + 1) * sizeof(_CharT) + 2 * sizeof(_Rep) - 1; + } + + // NB: Might throw, but no worries about a leak, mate: _Rep() + // does not throw. + _Rep* __place = _Rep_alloc_type(__alloc).allocate(__size / sizeof(_Rep)); + _Rep* __p = new (__place) _Rep; + __p->_M_info._M_capacity = __capacity; + return __p; + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __rc_string_base<_CharT, _Traits, _Alloc>::_Rep:: + _M_destroy(const _Alloc& __a) throw () + { + const size_type __size = ((_M_info._M_capacity + 1) * sizeof(_CharT) + + 2 * sizeof(_Rep) - 1); + _Rep_alloc_type(__a).deallocate(this, __size / sizeof(_Rep)); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + _CharT* + __rc_string_base<_CharT, _Traits, _Alloc>::_Rep:: + _M_clone(const _Alloc& __alloc, size_type __res) + { + // Requested capacity of the clone. + const size_type __requested_cap = _M_info._M_length + __res; + _Rep* __r = _Rep::_S_create(__requested_cap, _M_info._M_capacity, + __alloc); + + if (_M_info._M_length) + __rc_string_base::_S_copy(__r->_M_refdata(), _M_refdata(), _M_info._M_length); + + __r->_M_set_length(_M_info._M_length); + return __r->_M_refdata(); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + __rc_string_base<_CharT, _Traits, _Alloc>:: + __rc_string_base(const _Alloc& __a) + : _M_dataplus(__a, _S_construct(size_type(), _CharT(), __a)) { } + + template<typename _CharT, typename _Traits, typename _Alloc> + __rc_string_base<_CharT, _Traits, _Alloc>:: + __rc_string_base(const __rc_string_base& __rcs) + : _M_dataplus(__rcs._M_get_allocator(), + __rcs._M_grab(__rcs._M_get_allocator())) { } + + template<typename _CharT, typename _Traits, typename _Alloc> + __rc_string_base<_CharT, _Traits, _Alloc>:: + __rc_string_base(size_type __n, _CharT __c, const _Alloc& __a) + : _M_dataplus(__a, _S_construct(__n, __c, __a)) { } + + template<typename _CharT, typename _Traits, typename _Alloc> + template<typename _InputIterator> + __rc_string_base<_CharT, _Traits, _Alloc>:: + __rc_string_base(_InputIterator __beg, _InputIterator __end, + const _Alloc& __a) + : _M_dataplus(__a, _S_construct(__beg, __end, __a)) { } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __rc_string_base<_CharT, _Traits, _Alloc>:: + _M_leak_hard() + { + if (_M_is_shared()) + _M_erase(0, 0); + _M_set_leaked(); + } + + // NB: This is the special case for Input Iterators, used in + // istreambuf_iterators, etc. + // Input Iterators have a cost structure very different from + // pointers, calling for a different coding style. + template<typename _CharT, typename _Traits, typename _Alloc> + template<typename _InIterator> + _CharT* + __rc_string_base<_CharT, _Traits, _Alloc>:: + _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, + std::input_iterator_tag) + { + if (__beg == __end && __a == _Alloc()) + return _S_empty_rep._M_refcopy(); + + // Avoid reallocation for common case. + _CharT __buf[128]; + size_type __len = 0; + while (__beg != __end && __len < sizeof(__buf) / sizeof(_CharT)) + { + __buf[__len++] = *__beg; + ++__beg; + } + _Rep* __r = _Rep::_S_create(__len, size_type(0), __a); + _S_copy(__r->_M_refdata(), __buf, __len); + __try + { + while (__beg != __end) + { + if (__len == __r->_M_info._M_capacity) + { + // Allocate more space. + _Rep* __another = _Rep::_S_create(__len + 1, __len, __a); + _S_copy(__another->_M_refdata(), __r->_M_refdata(), __len); + __r->_M_destroy(__a); + __r = __another; + } + __r->_M_refdata()[__len++] = *__beg; + ++__beg; + } + } + __catch(...) + { + __r->_M_destroy(__a); + __throw_exception_again; + } + __r->_M_set_length(__len); + return __r->_M_refdata(); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + template<typename _InIterator> + _CharT* + __rc_string_base<_CharT, _Traits, _Alloc>:: + _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, + std::forward_iterator_tag) + { + if (__beg == __end && __a == _Alloc()) + return _S_empty_rep._M_refcopy(); + + // NB: Not required, but considered best practice. + if (__is_null_pointer(__beg) && __beg != __end) + std::__throw_logic_error(__N("__rc_string_base::" + "_S_construct null not valid")); + + const size_type __dnew = static_cast<size_type>(std::distance(__beg, + __end)); + // Check for out_of_range and length_error exceptions. + _Rep* __r = _Rep::_S_create(__dnew, size_type(0), __a); + __try + { __rc_string_base::_S_copy_chars(__r->_M_refdata(), __beg, __end); } + __catch(...) + { + __r->_M_destroy(__a); + __throw_exception_again; + } + __r->_M_set_length(__dnew); + return __r->_M_refdata(); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + _CharT* + __rc_string_base<_CharT, _Traits, _Alloc>:: + _S_construct(size_type __n, _CharT __c, const _Alloc& __a) + { + if (__n == 0 && __a == _Alloc()) + return _S_empty_rep._M_refcopy(); + + // Check for out_of_range and length_error exceptions. + _Rep* __r = _Rep::_S_create(__n, size_type(0), __a); + if (__n) + __rc_string_base::_S_assign(__r->_M_refdata(), __n, __c); + + __r->_M_set_length(__n); + return __r->_M_refdata(); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __rc_string_base<_CharT, _Traits, _Alloc>:: + _M_swap(__rc_string_base& __rcs) + { + if (_M_is_leaked()) + _M_set_sharable(); + if (__rcs._M_is_leaked()) + __rcs._M_set_sharable(); + + _CharT* __tmp = _M_data(); + _M_data(__rcs._M_data()); + __rcs._M_data(__tmp); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<allocator_type>::_S_do_it(_M_get_allocator(), + __rcs._M_get_allocator()); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __rc_string_base<_CharT, _Traits, _Alloc>:: + _M_assign(const __rc_string_base& __rcs) + { + if (_M_rep() != __rcs._M_rep()) + { + _CharT* __tmp = __rcs._M_grab(_M_get_allocator()); + _M_dispose(); + _M_data(__tmp); + } + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __rc_string_base<_CharT, _Traits, _Alloc>:: + _M_reserve(size_type __res) + { + // Make sure we don't shrink below the current size. + if (__res < _M_length()) + __res = _M_length(); + + if (__res != _M_capacity() || _M_is_shared()) + { + _CharT* __tmp = _M_rep()->_M_clone(_M_get_allocator(), + __res - _M_length()); + _M_dispose(); + _M_data(__tmp); + } + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __rc_string_base<_CharT, _Traits, _Alloc>:: + _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, + size_type __len2) + { + const size_type __how_much = _M_length() - __pos - __len1; + + _Rep* __r = _Rep::_S_create(_M_length() + __len2 - __len1, + _M_capacity(), _M_get_allocator()); + + if (__pos) + this->_S_copy(__r->_M_refdata(), _M_data(), __pos); + if (__s && __len2) + this->_S_copy(__r->_M_refdata() + __pos, __s, __len2); + if (__how_much) + this->_S_copy(__r->_M_refdata() + __pos + __len2, + _M_data() + __pos + __len1, __how_much); + + _M_dispose(); + _M_data(__r->_M_refdata()); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __rc_string_base<_CharT, _Traits, _Alloc>:: + _M_erase(size_type __pos, size_type __n) + { + const size_type __new_size = _M_length() - __n; + const size_type __how_much = _M_length() - __pos - __n; + + if (_M_is_shared()) + { + // Must reallocate. + _Rep* __r = _Rep::_S_create(__new_size, _M_capacity(), + _M_get_allocator()); + + if (__pos) + this->_S_copy(__r->_M_refdata(), _M_data(), __pos); + if (__how_much) + this->_S_copy(__r->_M_refdata() + __pos, + _M_data() + __pos + __n, __how_much); + + _M_dispose(); + _M_data(__r->_M_refdata()); + } + else if (__how_much && __n) + { + // Work in-place. + this->_S_move(_M_data() + __pos, + _M_data() + __pos + __n, __how_much); + } + + _M_rep()->_M_set_length(__new_size); + } + + template<> + inline bool + __rc_string_base<char, std::char_traits<char>, + std::allocator<char> >:: + _M_compare(const __rc_string_base& __rcs) const + { + if (_M_rep() == __rcs._M_rep()) + return true; + return false; + } + +#ifdef _GLIBCXX_USE_WCHAR_T + template<> + inline bool + __rc_string_base<wchar_t, std::char_traits<wchar_t>, + std::allocator<wchar_t> >:: + _M_compare(const __rc_string_base& __rcs) const + { + if (_M_rep() == __rcs._M_rep()) + return true; + return false; + } +#endif + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif /* _RC_STRING_BASE_H */ diff --git a/gcc-4.9/libstdc++-v3/include/ext/rope b/gcc-4.9/libstdc++-v3/include/ext/rope new file mode 100644 index 0000000..df3d4bb --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/rope @@ -0,0 +1,2976 @@ +// SGI's rope class -*- C++ -*- + +// Copyright (C) 2001-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * Copyright (c) 1997 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/** @file ext/rope + * This file is a GNU extension to the Standard C++ Library (possibly + * containing extensions from the HP/SGI STL subset). + */ + +#ifndef _ROPE +#define _ROPE 1 + +#pragma GCC system_header + +#include <algorithm> +#include <iosfwd> +#include <bits/stl_construct.h> +#include <bits/stl_uninitialized.h> +#include <bits/stl_function.h> +#include <bits/stl_numeric.h> +#include <bits/allocator.h> +#include <bits/gthr.h> +#include <tr1/functional> + +# ifdef __GC +# define __GC_CONST const +# else +# define __GC_CONST // constant except for deallocation +# endif + +#include <ext/memory> // For uninitialized_copy_n + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ + namespace __detail + { + enum { _S_max_rope_depth = 45 }; + enum _Tag {_S_leaf, _S_concat, _S_substringfn, _S_function}; + } // namespace __detail + + using std::size_t; + using std::ptrdiff_t; + using std::allocator; + using std::_Destroy; + +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // See libstdc++/36832. + template<typename _ForwardIterator, typename _Allocator> + void + _Destroy_const(_ForwardIterator __first, + _ForwardIterator __last, _Allocator __alloc) + { + for (; __first != __last; ++__first) + __alloc.destroy(&*__first); + } + + template<typename _ForwardIterator, typename _Tp> + inline void + _Destroy_const(_ForwardIterator __first, + _ForwardIterator __last, allocator<_Tp>) + { _Destroy(__first, __last); } + + // The _S_eos function is used for those functions that + // convert to/from C-like strings to detect the end of the string. + + // The end-of-C-string character. + // This is what the draft standard says it should be. + template <class _CharT> + inline _CharT + _S_eos(_CharT*) + { return _CharT(); } + + // Test for basic character types. + // For basic character types leaves having a trailing eos. + template <class _CharT> + inline bool + _S_is_basic_char_type(_CharT*) + { return false; } + + template <class _CharT> + inline bool + _S_is_one_byte_char_type(_CharT*) + { return false; } + + inline bool + _S_is_basic_char_type(char*) + { return true; } + + inline bool + _S_is_one_byte_char_type(char*) + { return true; } + + inline bool + _S_is_basic_char_type(wchar_t*) + { return true; } + + // Store an eos iff _CharT is a basic character type. + // Do not reference _S_eos if it isn't. + template <class _CharT> + inline void + _S_cond_store_eos(_CharT&) { } + + inline void + _S_cond_store_eos(char& __c) + { __c = 0; } + + inline void + _S_cond_store_eos(wchar_t& __c) + { __c = 0; } + + // char_producers are logically functions that generate a section of + // a string. These can be converted to ropes. The resulting rope + // invokes the char_producer on demand. This allows, for example, + // files to be viewed as ropes without reading the entire file. + template <class _CharT> + class char_producer + { + public: + virtual ~char_producer() { }; + + virtual void + operator()(size_t __start_pos, size_t __len, + _CharT* __buffer) = 0; + // Buffer should really be an arbitrary output iterator. + // That way we could flatten directly into an ostream, etc. + // This is thoroughly impossible, since iterator types don't + // have runtime descriptions. + }; + + // Sequence buffers: + // + // Sequence must provide an append operation that appends an + // array to the sequence. Sequence buffers are useful only if + // appending an entire array is cheaper than appending element by element. + // This is true for many string representations. + // This should perhaps inherit from ostream<sequence::value_type> + // and be implemented correspondingly, so that they can be used + // for formatted. For the sake of portability, we don't do this yet. + // + // For now, sequence buffers behave as output iterators. But they also + // behave a little like basic_ostringstream<sequence::value_type> and a + // little like containers. + + template<class _Sequence, size_t _Buf_sz = 100> + class sequence_buffer + : public std::iterator<std::output_iterator_tag, void, void, void, void> + { + public: + typedef typename _Sequence::value_type value_type; + protected: + _Sequence* _M_prefix; + value_type _M_buffer[_Buf_sz]; + size_t _M_buf_count; + public: + + void + flush() + { + _M_prefix->append(_M_buffer, _M_buffer + _M_buf_count); + _M_buf_count = 0; + } + + ~sequence_buffer() + { flush(); } + + sequence_buffer() + : _M_prefix(0), _M_buf_count(0) { } + + sequence_buffer(const sequence_buffer& __x) + { + _M_prefix = __x._M_prefix; + _M_buf_count = __x._M_buf_count; + std::copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer); + } + + sequence_buffer(sequence_buffer& __x) + { + __x.flush(); + _M_prefix = __x._M_prefix; + _M_buf_count = 0; + } + + sequence_buffer(_Sequence& __s) + : _M_prefix(&__s), _M_buf_count(0) { } + + sequence_buffer& + operator=(sequence_buffer& __x) + { + __x.flush(); + _M_prefix = __x._M_prefix; + _M_buf_count = 0; + return *this; + } + + sequence_buffer& + operator=(const sequence_buffer& __x) + { + _M_prefix = __x._M_prefix; + _M_buf_count = __x._M_buf_count; + std::copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer); + return *this; + } + + void + push_back(value_type __x) + { + if (_M_buf_count < _Buf_sz) + { + _M_buffer[_M_buf_count] = __x; + ++_M_buf_count; + } + else + { + flush(); + _M_buffer[0] = __x; + _M_buf_count = 1; + } + } + + void + append(value_type* __s, size_t __len) + { + if (__len + _M_buf_count <= _Buf_sz) + { + size_t __i = _M_buf_count; + for (size_t __j = 0; __j < __len; __i++, __j++) + _M_buffer[__i] = __s[__j]; + _M_buf_count += __len; + } + else if (0 == _M_buf_count) + _M_prefix->append(__s, __s + __len); + else + { + flush(); + append(__s, __len); + } + } + + sequence_buffer& + write(value_type* __s, size_t __len) + { + append(__s, __len); + return *this; + } + + sequence_buffer& + put(value_type __x) + { + push_back(__x); + return *this; + } + + sequence_buffer& + operator=(const value_type& __rhs) + { + push_back(__rhs); + return *this; + } + + sequence_buffer& + operator*() + { return *this; } + + sequence_buffer& + operator++() + { return *this; } + + sequence_buffer + operator++(int) + { return *this; } + }; + + // The following should be treated as private, at least for now. + template<class _CharT> + class _Rope_char_consumer + { + public: + // If we had member templates, these should not be virtual. + // For now we need to use run-time parametrization where + // compile-time would do. Hence this should all be private + // for now. + // The symmetry with char_producer is accidental and temporary. + virtual ~_Rope_char_consumer() { }; + + virtual bool + operator()(const _CharT* __buffer, size_t __len) = 0; + }; + + // First a lot of forward declarations. The standard seems to require + // much stricter "declaration before use" than many of the implementations + // that preceded it. + template<class _CharT, class _Alloc = allocator<_CharT> > + class rope; + + template<class _CharT, class _Alloc> + struct _Rope_RopeConcatenation; + + template<class _CharT, class _Alloc> + struct _Rope_RopeLeaf; + + template<class _CharT, class _Alloc> + struct _Rope_RopeFunction; + + template<class _CharT, class _Alloc> + struct _Rope_RopeSubstring; + + template<class _CharT, class _Alloc> + class _Rope_iterator; + + template<class _CharT, class _Alloc> + class _Rope_const_iterator; + + template<class _CharT, class _Alloc> + class _Rope_char_ref_proxy; + + template<class _CharT, class _Alloc> + class _Rope_char_ptr_proxy; + + template<class _CharT, class _Alloc> + bool + operator==(const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x, + const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y); + + template<class _CharT, class _Alloc> + _Rope_const_iterator<_CharT, _Alloc> + operator-(const _Rope_const_iterator<_CharT, _Alloc>& __x, + ptrdiff_t __n); + + template<class _CharT, class _Alloc> + _Rope_const_iterator<_CharT, _Alloc> + operator+(const _Rope_const_iterator<_CharT, _Alloc>& __x, + ptrdiff_t __n); + + template<class _CharT, class _Alloc> + _Rope_const_iterator<_CharT, _Alloc> + operator+(ptrdiff_t __n, + const _Rope_const_iterator<_CharT, _Alloc>& __x); + + template<class _CharT, class _Alloc> + bool + operator==(const _Rope_const_iterator<_CharT, _Alloc>& __x, + const _Rope_const_iterator<_CharT, _Alloc>& __y); + + template<class _CharT, class _Alloc> + bool + operator<(const _Rope_const_iterator<_CharT, _Alloc>& __x, + const _Rope_const_iterator<_CharT, _Alloc>& __y); + + template<class _CharT, class _Alloc> + ptrdiff_t + operator-(const _Rope_const_iterator<_CharT, _Alloc>& __x, + const _Rope_const_iterator<_CharT, _Alloc>& __y); + + template<class _CharT, class _Alloc> + _Rope_iterator<_CharT, _Alloc> + operator-(const _Rope_iterator<_CharT, _Alloc>& __x, ptrdiff_t __n); + + template<class _CharT, class _Alloc> + _Rope_iterator<_CharT, _Alloc> + operator+(const _Rope_iterator<_CharT, _Alloc>& __x, ptrdiff_t __n); + + template<class _CharT, class _Alloc> + _Rope_iterator<_CharT, _Alloc> + operator+(ptrdiff_t __n, const _Rope_iterator<_CharT, _Alloc>& __x); + + template<class _CharT, class _Alloc> + bool + operator==(const _Rope_iterator<_CharT, _Alloc>& __x, + const _Rope_iterator<_CharT, _Alloc>& __y); + + template<class _CharT, class _Alloc> + bool + operator<(const _Rope_iterator<_CharT, _Alloc>& __x, + const _Rope_iterator<_CharT, _Alloc>& __y); + + template<class _CharT, class _Alloc> + ptrdiff_t + operator-(const _Rope_iterator<_CharT, _Alloc>& __x, + const _Rope_iterator<_CharT, _Alloc>& __y); + + template<class _CharT, class _Alloc> + rope<_CharT, _Alloc> + operator+(const rope<_CharT, _Alloc>& __left, + const rope<_CharT, _Alloc>& __right); + + template<class _CharT, class _Alloc> + rope<_CharT, _Alloc> + operator+(const rope<_CharT, _Alloc>& __left, const _CharT* __right); + + template<class _CharT, class _Alloc> + rope<_CharT, _Alloc> + operator+(const rope<_CharT, _Alloc>& __left, _CharT __right); + + // Some helpers, so we can use power on ropes. + // See below for why this isn't local to the implementation. + + // This uses a nonstandard refcount convention. + // The result has refcount 0. + template<class _CharT, class _Alloc> + struct _Rope_Concat_fn + : public std::binary_function<rope<_CharT, _Alloc>, rope<_CharT, _Alloc>, + rope<_CharT, _Alloc> > + { + rope<_CharT, _Alloc> + operator()(const rope<_CharT, _Alloc>& __x, + const rope<_CharT, _Alloc>& __y) + { return __x + __y; } + }; + + template <class _CharT, class _Alloc> + inline rope<_CharT, _Alloc> + identity_element(_Rope_Concat_fn<_CharT, _Alloc>) + { return rope<_CharT, _Alloc>(); } + + // Class _Refcount_Base provides a type, _RC_t, a data member, + // _M_ref_count, and member functions _M_incr and _M_decr, which perform + // atomic preincrement/predecrement. The constructor initializes + // _M_ref_count. + struct _Refcount_Base + { + // The type _RC_t + typedef size_t _RC_t; + + // The data member _M_ref_count + volatile _RC_t _M_ref_count; + + // Constructor +#ifdef __GTHREAD_MUTEX_INIT + __gthread_mutex_t _M_ref_count_lock = __GTHREAD_MUTEX_INIT; +#else + __gthread_mutex_t _M_ref_count_lock; +#endif + + _Refcount_Base(_RC_t __n) : _M_ref_count(__n) + { +#ifndef __GTHREAD_MUTEX_INIT +#ifdef __GTHREAD_MUTEX_INIT_FUNCTION + __GTHREAD_MUTEX_INIT_FUNCTION (&_M_ref_count_lock); +#else +#error __GTHREAD_MUTEX_INIT or __GTHREAD_MUTEX_INIT_FUNCTION should be defined by gthr.h abstraction layer, report problem to libstdc++@gcc.gnu.org. +#endif +#endif + } + +#ifndef __GTHREAD_MUTEX_INIT + ~_Refcount_Base() + { __gthread_mutex_destroy(&_M_ref_count_lock); } +#endif + + void + _M_incr() + { + __gthread_mutex_lock(&_M_ref_count_lock); + ++_M_ref_count; + __gthread_mutex_unlock(&_M_ref_count_lock); + } + + _RC_t + _M_decr() + { + __gthread_mutex_lock(&_M_ref_count_lock); + volatile _RC_t __tmp = --_M_ref_count; + __gthread_mutex_unlock(&_M_ref_count_lock); + return __tmp; + } + }; + + // + // What follows should really be local to rope. Unfortunately, + // that doesn't work, since it makes it impossible to define generic + // equality on rope iterators. According to the draft standard, the + // template parameters for such an equality operator cannot be inferred + // from the occurrence of a member class as a parameter. + // (SGI compilers in fact allow this, but the __result wouldn't be + // portable.) + // Similarly, some of the static member functions are member functions + // only to avoid polluting the global namespace, and to circumvent + // restrictions on type inference for template functions. + // + + // + // The internal data structure for representing a rope. This is + // private to the implementation. A rope is really just a pointer + // to one of these. + // + // A few basic functions for manipulating this data structure + // are members of _RopeRep. Most of the more complex algorithms + // are implemented as rope members. + // + // Some of the static member functions of _RopeRep have identically + // named functions in rope that simply invoke the _RopeRep versions. + +#define __ROPE_DEFINE_ALLOCS(__a) \ + __ROPE_DEFINE_ALLOC(_CharT,_Data) /* character data */ \ + typedef _Rope_RopeConcatenation<_CharT,__a> __C; \ + __ROPE_DEFINE_ALLOC(__C,_C) \ + typedef _Rope_RopeLeaf<_CharT,__a> __L; \ + __ROPE_DEFINE_ALLOC(__L,_L) \ + typedef _Rope_RopeFunction<_CharT,__a> __F; \ + __ROPE_DEFINE_ALLOC(__F,_F) \ + typedef _Rope_RopeSubstring<_CharT,__a> __S; \ + __ROPE_DEFINE_ALLOC(__S,_S) + + // Internal rope nodes potentially store a copy of the allocator + // instance used to allocate them. This is mostly redundant. + // But the alternative would be to pass allocator instances around + // in some form to nearly all internal functions, since any pointer + // assignment may result in a zero reference count and thus require + // deallocation. + +#define __STATIC_IF_SGI_ALLOC /* not static */ + + template <class _CharT, class _Alloc> + struct _Rope_rep_base + : public _Alloc + { + typedef _Alloc allocator_type; + + allocator_type + get_allocator() const + { return *static_cast<const _Alloc*>(this); } + + allocator_type& + _M_get_allocator() + { return *static_cast<_Alloc*>(this); } + + const allocator_type& + _M_get_allocator() const + { return *static_cast<const _Alloc*>(this); } + + _Rope_rep_base(size_t __size, const allocator_type&) + : _M_size(__size) { } + + size_t _M_size; + +# define __ROPE_DEFINE_ALLOC(_Tp, __name) \ + typedef typename \ + _Alloc::template rebind<_Tp>::other __name##Alloc; \ + static _Tp* __name##_allocate(size_t __n) \ + { return __name##Alloc().allocate(__n); } \ + static void __name##_deallocate(_Tp *__p, size_t __n) \ + { __name##Alloc().deallocate(__p, __n); } + __ROPE_DEFINE_ALLOCS(_Alloc) +# undef __ROPE_DEFINE_ALLOC + }; + + template<class _CharT, class _Alloc> + struct _Rope_RopeRep + : public _Rope_rep_base<_CharT, _Alloc> +# ifndef __GC + , _Refcount_Base +# endif + { + public: + __detail::_Tag _M_tag:8; + bool _M_is_balanced:8; + unsigned char _M_depth; + __GC_CONST _CharT* _M_c_string; +#ifdef __GTHREAD_MUTEX_INIT + __gthread_mutex_t _M_c_string_lock = __GTHREAD_MUTEX_INIT; +#else + __gthread_mutex_t _M_c_string_lock; +#endif + /* Flattened version of string, if needed. */ + /* typically 0. */ + /* If it's not 0, then the memory is owned */ + /* by this node. */ + /* In the case of a leaf, this may point to */ + /* the same memory as the data field. */ + typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type + allocator_type; + + using _Rope_rep_base<_CharT, _Alloc>::get_allocator; + using _Rope_rep_base<_CharT, _Alloc>::_M_get_allocator; + + _Rope_RopeRep(__detail::_Tag __t, int __d, bool __b, size_t __size, + const allocator_type& __a) + : _Rope_rep_base<_CharT, _Alloc>(__size, __a), +#ifndef __GC + _Refcount_Base(1), +#endif + _M_tag(__t), _M_is_balanced(__b), _M_depth(__d), _M_c_string(0) +#ifdef __GTHREAD_MUTEX_INIT + { } +#else + { __GTHREAD_MUTEX_INIT_FUNCTION (&_M_c_string_lock); } + ~_Rope_RopeRep() + { __gthread_mutex_destroy (&_M_c_string_lock); } +#endif +#ifdef __GC + void + _M_incr () { } +#endif + static void + _S_free_string(__GC_CONST _CharT*, size_t __len, + allocator_type& __a); +#define __STL_FREE_STRING(__s, __l, __a) _S_free_string(__s, __l, __a); + // Deallocate data section of a leaf. + // This shouldn't be a member function. + // But its hard to do anything else at the + // moment, because it's templatized w.r.t. + // an allocator. + // Does nothing if __GC is defined. +#ifndef __GC + void _M_free_c_string(); + void _M_free_tree(); + // Deallocate t. Assumes t is not 0. + void + _M_unref_nonnil() + { + if (0 == _M_decr()) + _M_free_tree(); + } + + void + _M_ref_nonnil() + { _M_incr(); } + + static void + _S_unref(_Rope_RopeRep* __t) + { + if (0 != __t) + __t->_M_unref_nonnil(); + } + + static void + _S_ref(_Rope_RopeRep* __t) + { + if (0 != __t) + __t->_M_incr(); + } + + static void + _S_free_if_unref(_Rope_RopeRep* __t) + { + if (0 != __t && 0 == __t->_M_ref_count) + __t->_M_free_tree(); + } +# else /* __GC */ + void _M_unref_nonnil() { } + void _M_ref_nonnil() { } + static void _S_unref(_Rope_RopeRep*) { } + static void _S_ref(_Rope_RopeRep*) { } + static void _S_free_if_unref(_Rope_RopeRep*) { } +# endif +protected: + _Rope_RopeRep& + operator=(const _Rope_RopeRep&); + + _Rope_RopeRep(const _Rope_RopeRep&); + }; + + template<class _CharT, class _Alloc> + struct _Rope_RopeLeaf + : public _Rope_RopeRep<_CharT, _Alloc> + { + public: + // Apparently needed by VC++ + // The data fields of leaves are allocated with some + // extra space, to accommodate future growth and for basic + // character types, to hold a trailing eos character. + enum { _S_alloc_granularity = 8 }; + + static size_t + _S_rounded_up_size(size_t __n) + { + size_t __size_with_eos; + + if (_S_is_basic_char_type((_CharT*)0)) + __size_with_eos = __n + 1; + else + __size_with_eos = __n; +#ifdef __GC + return __size_with_eos; +#else + // Allow slop for in-place expansion. + return ((__size_with_eos + size_t(_S_alloc_granularity) - 1) + &~ (size_t(_S_alloc_granularity) - 1)); +#endif + } + __GC_CONST _CharT* _M_data; /* Not necessarily 0 terminated. */ + /* The allocated size is */ + /* _S_rounded_up_size(size), except */ + /* in the GC case, in which it */ + /* doesn't matter. */ + typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type + allocator_type; + + _Rope_RopeLeaf(__GC_CONST _CharT* __d, size_t __size, + const allocator_type& __a) + : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_leaf, 0, true, + __size, __a), _M_data(__d) + { + if (_S_is_basic_char_type((_CharT *)0)) + { + // already eos terminated. + this->_M_c_string = __d; + } + } + // The constructor assumes that d has been allocated with + // the proper allocator and the properly padded size. + // In contrast, the destructor deallocates the data: +#ifndef __GC + ~_Rope_RopeLeaf() throw() + { + if (_M_data != this->_M_c_string) + this->_M_free_c_string(); + + this->__STL_FREE_STRING(_M_data, this->_M_size, this->_M_get_allocator()); + } +#endif +protected: + _Rope_RopeLeaf& + operator=(const _Rope_RopeLeaf&); + + _Rope_RopeLeaf(const _Rope_RopeLeaf&); + }; + + template<class _CharT, class _Alloc> + struct _Rope_RopeConcatenation + : public _Rope_RopeRep<_CharT, _Alloc> + { + public: + _Rope_RopeRep<_CharT, _Alloc>* _M_left; + _Rope_RopeRep<_CharT, _Alloc>* _M_right; + + typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type + allocator_type; + + _Rope_RopeConcatenation(_Rope_RopeRep<_CharT, _Alloc>* __l, + _Rope_RopeRep<_CharT, _Alloc>* __r, + const allocator_type& __a) + : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_concat, + std::max(__l->_M_depth, + __r->_M_depth) + 1, + false, + __l->_M_size + __r->_M_size, __a), + _M_left(__l), _M_right(__r) + { } +#ifndef __GC + ~_Rope_RopeConcatenation() throw() + { + this->_M_free_c_string(); + _M_left->_M_unref_nonnil(); + _M_right->_M_unref_nonnil(); + } +#endif +protected: + _Rope_RopeConcatenation& + operator=(const _Rope_RopeConcatenation&); + + _Rope_RopeConcatenation(const _Rope_RopeConcatenation&); + }; + + template<class _CharT, class _Alloc> + struct _Rope_RopeFunction + : public _Rope_RopeRep<_CharT, _Alloc> + { + public: + char_producer<_CharT>* _M_fn; +#ifndef __GC + bool _M_delete_when_done; // Char_producer is owned by the + // rope and should be explicitly + // deleted when the rope becomes + // inaccessible. +#else + // In the GC case, we either register the rope for + // finalization, or not. Thus the field is unnecessary; + // the information is stored in the collector data structures. + // We do need a finalization procedure to be invoked by the + // collector. + static void + _S_fn_finalization_proc(void * __tree, void *) + { delete ((_Rope_RopeFunction *)__tree) -> _M_fn; } +#endif + typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type + allocator_type; + + _Rope_RopeFunction(char_producer<_CharT>* __f, size_t __size, + bool __d, const allocator_type& __a) + : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_function, 0, true, __size, __a) + , _M_fn(__f) +#ifndef __GC + , _M_delete_when_done(__d) +#endif + { +#ifdef __GC + if (__d) + { + GC_REGISTER_FINALIZER(this, _Rope_RopeFunction:: + _S_fn_finalization_proc, 0, 0, 0); + } +#endif + } +#ifndef __GC + ~_Rope_RopeFunction() throw() + { + this->_M_free_c_string(); + if (_M_delete_when_done) + delete _M_fn; + } +# endif + protected: + _Rope_RopeFunction& + operator=(const _Rope_RopeFunction&); + + _Rope_RopeFunction(const _Rope_RopeFunction&); + }; + // Substring results are usually represented using just + // concatenation nodes. But in the case of very long flat ropes + // or ropes with a functional representation that isn't practical. + // In that case, we represent the __result as a special case of + // RopeFunction, whose char_producer points back to the rope itself. + // In all cases except repeated substring operations and + // deallocation, we treat the __result as a RopeFunction. + template<class _CharT, class _Alloc> + struct _Rope_RopeSubstring + : public _Rope_RopeFunction<_CharT, _Alloc>, + public char_producer<_CharT> + { + public: + // XXX this whole class should be rewritten. + _Rope_RopeRep<_CharT,_Alloc>* _M_base; // not 0 + size_t _M_start; + + virtual void + operator()(size_t __start_pos, size_t __req_len, + _CharT* __buffer) + { + switch(_M_base->_M_tag) + { + case __detail::_S_function: + case __detail::_S_substringfn: + { + char_producer<_CharT>* __fn = + ((_Rope_RopeFunction<_CharT,_Alloc>*)_M_base)->_M_fn; + (*__fn)(__start_pos + _M_start, __req_len, __buffer); + } + break; + case __detail::_S_leaf: + { + __GC_CONST _CharT* __s = + ((_Rope_RopeLeaf<_CharT,_Alloc>*)_M_base)->_M_data; + uninitialized_copy_n(__s + __start_pos + _M_start, __req_len, + __buffer); + } + break; + default: + break; + } + } + + typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type + allocator_type; + + _Rope_RopeSubstring(_Rope_RopeRep<_CharT, _Alloc>* __b, size_t __s, + size_t __l, const allocator_type& __a) + : _Rope_RopeFunction<_CharT, _Alloc>(this, __l, false, __a), + char_producer<_CharT>(), _M_base(__b), _M_start(__s) + { +#ifndef __GC + _M_base->_M_ref_nonnil(); +#endif + this->_M_tag = __detail::_S_substringfn; + } + virtual ~_Rope_RopeSubstring() throw() + { +#ifndef __GC + _M_base->_M_unref_nonnil(); + // _M_free_c_string(); -- done by parent class +#endif + } + }; + + // Self-destructing pointers to Rope_rep. + // These are not conventional smart pointers. Their + // only purpose in life is to ensure that unref is called + // on the pointer either at normal exit or if an exception + // is raised. It is the caller's responsibility to + // adjust reference counts when these pointers are initialized + // or assigned to. (This convention significantly reduces + // the number of potentially expensive reference count + // updates.) +#ifndef __GC + template<class _CharT, class _Alloc> + struct _Rope_self_destruct_ptr + { + _Rope_RopeRep<_CharT, _Alloc>* _M_ptr; + + ~_Rope_self_destruct_ptr() + { _Rope_RopeRep<_CharT, _Alloc>::_S_unref(_M_ptr); } +#ifdef __EXCEPTIONS + _Rope_self_destruct_ptr() : _M_ptr(0) { }; +#else + _Rope_self_destruct_ptr() { }; +#endif + _Rope_self_destruct_ptr(_Rope_RopeRep<_CharT, _Alloc>* __p) + : _M_ptr(__p) { } + + _Rope_RopeRep<_CharT, _Alloc>& + operator*() + { return *_M_ptr; } + + _Rope_RopeRep<_CharT, _Alloc>* + operator->() + { return _M_ptr; } + + operator _Rope_RopeRep<_CharT, _Alloc>*() + { return _M_ptr; } + + _Rope_self_destruct_ptr& + operator=(_Rope_RopeRep<_CharT, _Alloc>* __x) + { _M_ptr = __x; return *this; } + }; +#endif + + // Dereferencing a nonconst iterator has to return something + // that behaves almost like a reference. It's not possible to + // return an actual reference since assignment requires extra + // work. And we would get into the same problems as with the + // CD2 version of basic_string. + template<class _CharT, class _Alloc> + class _Rope_char_ref_proxy + { + friend class rope<_CharT, _Alloc>; + friend class _Rope_iterator<_CharT, _Alloc>; + friend class _Rope_char_ptr_proxy<_CharT, _Alloc>; +#ifdef __GC + typedef _Rope_RopeRep<_CharT, _Alloc>* _Self_destruct_ptr; +#else + typedef _Rope_self_destruct_ptr<_CharT, _Alloc> _Self_destruct_ptr; +#endif + typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep; + typedef rope<_CharT, _Alloc> _My_rope; + size_t _M_pos; + _CharT _M_current; + bool _M_current_valid; + _My_rope* _M_root; // The whole rope. + public: + _Rope_char_ref_proxy(_My_rope* __r, size_t __p) + : _M_pos(__p), _M_current(), _M_current_valid(false), _M_root(__r) { } + + _Rope_char_ref_proxy(const _Rope_char_ref_proxy& __x) + : _M_pos(__x._M_pos), _M_current(__x._M_current), + _M_current_valid(false), _M_root(__x._M_root) { } + + // Don't preserve cache if the reference can outlive the + // expression. We claim that's not possible without calling + // a copy constructor or generating reference to a proxy + // reference. We declare the latter to have undefined semantics. + _Rope_char_ref_proxy(_My_rope* __r, size_t __p, _CharT __c) + : _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) { } + + inline operator _CharT () const; + + _Rope_char_ref_proxy& + operator=(_CharT __c); + + _Rope_char_ptr_proxy<_CharT, _Alloc> operator&() const; + + _Rope_char_ref_proxy& + operator=(const _Rope_char_ref_proxy& __c) + { return operator=((_CharT)__c); } + }; + + template<class _CharT, class __Alloc> + inline void + swap(_Rope_char_ref_proxy <_CharT, __Alloc > __a, + _Rope_char_ref_proxy <_CharT, __Alloc > __b) + { + _CharT __tmp = __a; + __a = __b; + __b = __tmp; + } + + template<class _CharT, class _Alloc> + class _Rope_char_ptr_proxy + { + // XXX this class should be rewritten. + friend class _Rope_char_ref_proxy<_CharT, _Alloc>; + size_t _M_pos; + rope<_CharT,_Alloc>* _M_root; // The whole rope. + public: + _Rope_char_ptr_proxy(const _Rope_char_ref_proxy<_CharT,_Alloc>& __x) + : _M_pos(__x._M_pos), _M_root(__x._M_root) { } + + _Rope_char_ptr_proxy(const _Rope_char_ptr_proxy& __x) + : _M_pos(__x._M_pos), _M_root(__x._M_root) { } + + _Rope_char_ptr_proxy() { } + + _Rope_char_ptr_proxy(_CharT* __x) + : _M_root(0), _M_pos(0) { } + + _Rope_char_ptr_proxy& + operator=(const _Rope_char_ptr_proxy& __x) + { + _M_pos = __x._M_pos; + _M_root = __x._M_root; + return *this; + } + + template<class _CharT2, class _Alloc2> + friend bool + operator==(const _Rope_char_ptr_proxy<_CharT2, _Alloc2>& __x, + const _Rope_char_ptr_proxy<_CharT2, _Alloc2>& __y); + + _Rope_char_ref_proxy<_CharT, _Alloc> operator*() const + { return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root, _M_pos); } + }; + + // Rope iterators: + // Unlike in the C version, we cache only part of the stack + // for rope iterators, since they must be efficiently copyable. + // When we run out of cache, we have to reconstruct the iterator + // value. + // Pointers from iterators are not included in reference counts. + // Iterators are assumed to be thread private. Ropes can + // be shared. + + template<class _CharT, class _Alloc> + class _Rope_iterator_base + : public std::iterator<std::random_access_iterator_tag, _CharT> + { + friend class rope<_CharT, _Alloc>; + public: + typedef _Alloc _allocator_type; // used in _Rope_rotate, VC++ workaround + typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep; + // Borland doesn't want this to be protected. + protected: + enum { _S_path_cache_len = 4 }; // Must be <= 9. + enum { _S_iterator_buf_len = 15 }; + size_t _M_current_pos; + _RopeRep* _M_root; // The whole rope. + size_t _M_leaf_pos; // Starting position for current leaf + __GC_CONST _CharT* _M_buf_start; + // Buffer possibly + // containing current char. + __GC_CONST _CharT* _M_buf_ptr; + // Pointer to current char in buffer. + // != 0 ==> buffer valid. + __GC_CONST _CharT* _M_buf_end; + // One past __last valid char in buffer. + // What follows is the path cache. We go out of our + // way to make this compact. + // Path_end contains the bottom section of the path from + // the root to the current leaf. + const _RopeRep* _M_path_end[_S_path_cache_len]; + int _M_leaf_index; // Last valid __pos in path_end; + // _M_path_end[0] ... _M_path_end[leaf_index-1] + // point to concatenation nodes. + unsigned char _M_path_directions; + // (path_directions >> __i) & 1 is 1 + // iff we got from _M_path_end[leaf_index - __i - 1] + // to _M_path_end[leaf_index - __i] by going to the + // __right. Assumes path_cache_len <= 9. + _CharT _M_tmp_buf[_S_iterator_buf_len]; + // Short buffer for surrounding chars. + // This is useful primarily for + // RopeFunctions. We put the buffer + // here to avoid locking in the + // multithreaded case. + // The cached path is generally assumed to be valid + // only if the buffer is valid. + static void _S_setbuf(_Rope_iterator_base& __x); + // Set buffer contents given + // path cache. + static void _S_setcache(_Rope_iterator_base& __x); + // Set buffer contents and + // path cache. + static void _S_setcache_for_incr(_Rope_iterator_base& __x); + // As above, but assumes path + // cache is valid for previous posn. + _Rope_iterator_base() { } + + _Rope_iterator_base(_RopeRep* __root, size_t __pos) + : _M_current_pos(__pos), _M_root(__root), _M_buf_ptr(0) { } + + void _M_incr(size_t __n); + void _M_decr(size_t __n); + public: + size_t + index() const + { return _M_current_pos; } + + _Rope_iterator_base(const _Rope_iterator_base& __x) + { + if (0 != __x._M_buf_ptr) + *this = __x; + else + { + _M_current_pos = __x._M_current_pos; + _M_root = __x._M_root; + _M_buf_ptr = 0; + } + } + }; + + template<class _CharT, class _Alloc> + class _Rope_iterator; + + template<class _CharT, class _Alloc> + class _Rope_const_iterator + : public _Rope_iterator_base<_CharT, _Alloc> + { + friend class rope<_CharT, _Alloc>; + protected: + typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep; + // The one from the base class may not be directly visible. + _Rope_const_iterator(const _RopeRep* __root, size_t __pos) + : _Rope_iterator_base<_CharT, _Alloc>(const_cast<_RopeRep*>(__root), + __pos) + // Only nonconst iterators modify root ref count + { } + public: + typedef _CharT reference; // Really a value. Returning a reference + // Would be a mess, since it would have + // to be included in refcount. + typedef const _CharT* pointer; + + public: + _Rope_const_iterator() { }; + + _Rope_const_iterator(const _Rope_const_iterator& __x) + : _Rope_iterator_base<_CharT,_Alloc>(__x) { } + + _Rope_const_iterator(const _Rope_iterator<_CharT,_Alloc>& __x); + + _Rope_const_iterator(const rope<_CharT, _Alloc>& __r, size_t __pos) + : _Rope_iterator_base<_CharT,_Alloc>(__r._M_tree_ptr, __pos) { } + + _Rope_const_iterator& + operator=(const _Rope_const_iterator& __x) + { + if (0 != __x._M_buf_ptr) + *(static_cast<_Rope_iterator_base<_CharT, _Alloc>*>(this)) = __x; + else + { + this->_M_current_pos = __x._M_current_pos; + this->_M_root = __x._M_root; + this->_M_buf_ptr = 0; + } + return(*this); + } + + reference + operator*() + { + if (0 == this->_M_buf_ptr) + this->_S_setcache(*this); + return *this->_M_buf_ptr; + } + + // Without this const version, Rope iterators do not meet the + // requirements of an Input Iterator. + reference + operator*() const + { + return *const_cast<_Rope_const_iterator&>(*this); + } + + _Rope_const_iterator& + operator++() + { + __GC_CONST _CharT* __next; + if (0 != this->_M_buf_ptr + && (__next = this->_M_buf_ptr + 1) < this->_M_buf_end) + { + this->_M_buf_ptr = __next; + ++this->_M_current_pos; + } + else + this->_M_incr(1); + return *this; + } + + _Rope_const_iterator& + operator+=(ptrdiff_t __n) + { + if (__n >= 0) + this->_M_incr(__n); + else + this->_M_decr(-__n); + return *this; + } + + _Rope_const_iterator& + operator--() + { + this->_M_decr(1); + return *this; + } + + _Rope_const_iterator& + operator-=(ptrdiff_t __n) + { + if (__n >= 0) + this->_M_decr(__n); + else + this->_M_incr(-__n); + return *this; + } + + _Rope_const_iterator + operator++(int) + { + size_t __old_pos = this->_M_current_pos; + this->_M_incr(1); + return _Rope_const_iterator<_CharT,_Alloc>(this->_M_root, __old_pos); + // This makes a subsequent dereference expensive. + // Perhaps we should instead copy the iterator + // if it has a valid cache? + } + + _Rope_const_iterator + operator--(int) + { + size_t __old_pos = this->_M_current_pos; + this->_M_decr(1); + return _Rope_const_iterator<_CharT,_Alloc>(this->_M_root, __old_pos); + } + + template<class _CharT2, class _Alloc2> + friend _Rope_const_iterator<_CharT2, _Alloc2> + operator-(const _Rope_const_iterator<_CharT2, _Alloc2>& __x, + ptrdiff_t __n); + + template<class _CharT2, class _Alloc2> + friend _Rope_const_iterator<_CharT2, _Alloc2> + operator+(const _Rope_const_iterator<_CharT2, _Alloc2>& __x, + ptrdiff_t __n); + + template<class _CharT2, class _Alloc2> + friend _Rope_const_iterator<_CharT2, _Alloc2> + operator+(ptrdiff_t __n, + const _Rope_const_iterator<_CharT2, _Alloc2>& __x); + + reference + operator[](size_t __n) + { return rope<_CharT, _Alloc>::_S_fetch(this->_M_root, + this->_M_current_pos + __n); } + + template<class _CharT2, class _Alloc2> + friend bool + operator==(const _Rope_const_iterator<_CharT2, _Alloc2>& __x, + const _Rope_const_iterator<_CharT2, _Alloc2>& __y); + + template<class _CharT2, class _Alloc2> + friend bool + operator<(const _Rope_const_iterator<_CharT2, _Alloc2>& __x, + const _Rope_const_iterator<_CharT2, _Alloc2>& __y); + + template<class _CharT2, class _Alloc2> + friend ptrdiff_t + operator-(const _Rope_const_iterator<_CharT2, _Alloc2>& __x, + const _Rope_const_iterator<_CharT2, _Alloc2>& __y); + }; + + template<class _CharT, class _Alloc> + class _Rope_iterator + : public _Rope_iterator_base<_CharT, _Alloc> + { + friend class rope<_CharT, _Alloc>; + protected: + typedef typename _Rope_iterator_base<_CharT, _Alloc>::_RopeRep _RopeRep; + rope<_CharT, _Alloc>* _M_root_rope; + + // root is treated as a cached version of this, and is used to + // detect changes to the underlying rope. + + // Root is included in the reference count. This is necessary + // so that we can detect changes reliably. Unfortunately, it + // requires careful bookkeeping for the nonGC case. + _Rope_iterator(rope<_CharT, _Alloc>* __r, size_t __pos) + : _Rope_iterator_base<_CharT, _Alloc>(__r->_M_tree_ptr, __pos), + _M_root_rope(__r) + { _RopeRep::_S_ref(this->_M_root); + if (!(__r -> empty())) + this->_S_setcache(*this); + } + + void _M_check(); + public: + typedef _Rope_char_ref_proxy<_CharT, _Alloc> reference; + typedef _Rope_char_ref_proxy<_CharT, _Alloc>* pointer; + + rope<_CharT, _Alloc>& + container() + { return *_M_root_rope; } + + _Rope_iterator() + { + this->_M_root = 0; // Needed for reference counting. + }; + + _Rope_iterator(const _Rope_iterator& __x) + : _Rope_iterator_base<_CharT, _Alloc>(__x) + { + _M_root_rope = __x._M_root_rope; + _RopeRep::_S_ref(this->_M_root); + } + + _Rope_iterator(rope<_CharT, _Alloc>& __r, size_t __pos); + + ~_Rope_iterator() + { _RopeRep::_S_unref(this->_M_root); } + + _Rope_iterator& + operator=(const _Rope_iterator& __x) + { + _RopeRep* __old = this->_M_root; + + _RopeRep::_S_ref(__x._M_root); + if (0 != __x._M_buf_ptr) + { + _M_root_rope = __x._M_root_rope; + *(static_cast<_Rope_iterator_base<_CharT, _Alloc>*>(this)) = __x; + } + else + { + this->_M_current_pos = __x._M_current_pos; + this->_M_root = __x._M_root; + _M_root_rope = __x._M_root_rope; + this->_M_buf_ptr = 0; + } + _RopeRep::_S_unref(__old); + return(*this); + } + + reference + operator*() + { + _M_check(); + if (0 == this->_M_buf_ptr) + return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope, + this->_M_current_pos); + else + return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope, + this->_M_current_pos, + *this->_M_buf_ptr); + } + + // See above comment. + reference + operator*() const + { + return *const_cast<_Rope_iterator&>(*this); + } + + _Rope_iterator& + operator++() + { + this->_M_incr(1); + return *this; + } + + _Rope_iterator& + operator+=(ptrdiff_t __n) + { + if (__n >= 0) + this->_M_incr(__n); + else + this->_M_decr(-__n); + return *this; + } + + _Rope_iterator& + operator--() + { + this->_M_decr(1); + return *this; + } + + _Rope_iterator& + operator-=(ptrdiff_t __n) + { + if (__n >= 0) + this->_M_decr(__n); + else + this->_M_incr(-__n); + return *this; + } + + _Rope_iterator + operator++(int) + { + size_t __old_pos = this->_M_current_pos; + this->_M_incr(1); + return _Rope_iterator<_CharT,_Alloc>(_M_root_rope, __old_pos); + } + + _Rope_iterator + operator--(int) + { + size_t __old_pos = this->_M_current_pos; + this->_M_decr(1); + return _Rope_iterator<_CharT,_Alloc>(_M_root_rope, __old_pos); + } + + reference + operator[](ptrdiff_t __n) + { return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope, + this->_M_current_pos + + __n); } + + template<class _CharT2, class _Alloc2> + friend bool + operator==(const _Rope_iterator<_CharT2, _Alloc2>& __x, + const _Rope_iterator<_CharT2, _Alloc2>& __y); + + template<class _CharT2, class _Alloc2> + friend bool + operator<(const _Rope_iterator<_CharT2, _Alloc2>& __x, + const _Rope_iterator<_CharT2, _Alloc2>& __y); + + template<class _CharT2, class _Alloc2> + friend ptrdiff_t + operator-(const _Rope_iterator<_CharT2, _Alloc2>& __x, + const _Rope_iterator<_CharT2, _Alloc2>& __y); + + template<class _CharT2, class _Alloc2> + friend _Rope_iterator<_CharT2, _Alloc2> + operator-(const _Rope_iterator<_CharT2, _Alloc2>& __x, ptrdiff_t __n); + + template<class _CharT2, class _Alloc2> + friend _Rope_iterator<_CharT2, _Alloc2> + operator+(const _Rope_iterator<_CharT2, _Alloc2>& __x, ptrdiff_t __n); + + template<class _CharT2, class _Alloc2> + friend _Rope_iterator<_CharT2, _Alloc2> + operator+(ptrdiff_t __n, const _Rope_iterator<_CharT2, _Alloc2>& __x); + }; + + + template <class _CharT, class _Alloc> + struct _Rope_base + : public _Alloc + { + typedef _Alloc allocator_type; + + allocator_type + get_allocator() const + { return *static_cast<const _Alloc*>(this); } + + allocator_type& + _M_get_allocator() + { return *static_cast<_Alloc*>(this); } + + const allocator_type& + _M_get_allocator() const + { return *static_cast<const _Alloc*>(this); } + + typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep; + // The one in _Base may not be visible due to template rules. + + _Rope_base(_RopeRep* __t, const allocator_type&) + : _M_tree_ptr(__t) { } + + _Rope_base(const allocator_type&) { } + + // The only data member of a rope: + _RopeRep *_M_tree_ptr; + +#define __ROPE_DEFINE_ALLOC(_Tp, __name) \ + typedef typename \ + _Alloc::template rebind<_Tp>::other __name##Alloc; \ + static _Tp* __name##_allocate(size_t __n) \ + { return __name##Alloc().allocate(__n); } \ + static void __name##_deallocate(_Tp *__p, size_t __n) \ + { __name##Alloc().deallocate(__p, __n); } + __ROPE_DEFINE_ALLOCS(_Alloc) +#undef __ROPE_DEFINE_ALLOC + + protected: + _Rope_base& + operator=(const _Rope_base&); + + _Rope_base(const _Rope_base&); + }; + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template <class _CharT, class _Alloc> + class rope : public _Rope_base<_CharT, _Alloc> + { + public: + typedef _CharT value_type; + typedef ptrdiff_t difference_type; + typedef size_t size_type; + typedef _CharT const_reference; + typedef const _CharT* const_pointer; + typedef _Rope_iterator<_CharT, _Alloc> iterator; + typedef _Rope_const_iterator<_CharT, _Alloc> const_iterator; + typedef _Rope_char_ref_proxy<_CharT, _Alloc> reference; + typedef _Rope_char_ptr_proxy<_CharT, _Alloc> pointer; + + friend class _Rope_iterator<_CharT, _Alloc>; + friend class _Rope_const_iterator<_CharT, _Alloc>; + friend struct _Rope_RopeRep<_CharT, _Alloc>; + friend class _Rope_iterator_base<_CharT, _Alloc>; + friend class _Rope_char_ptr_proxy<_CharT, _Alloc>; + friend class _Rope_char_ref_proxy<_CharT, _Alloc>; + friend struct _Rope_RopeSubstring<_CharT, _Alloc>; + + protected: + typedef _Rope_base<_CharT, _Alloc> _Base; + typedef typename _Base::allocator_type allocator_type; + using _Base::_M_tree_ptr; + using _Base::get_allocator; + using _Base::_M_get_allocator; + typedef __GC_CONST _CharT* _Cstrptr; + + static _CharT _S_empty_c_str[1]; + + static bool + _S_is0(_CharT __c) + { return __c == _S_eos((_CharT*)0); } + + enum { _S_copy_max = 23 }; + // For strings shorter than _S_copy_max, we copy to + // concatenate. + + typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep; + typedef _Rope_RopeConcatenation<_CharT, _Alloc> _RopeConcatenation; + typedef _Rope_RopeLeaf<_CharT, _Alloc> _RopeLeaf; + typedef _Rope_RopeFunction<_CharT, _Alloc> _RopeFunction; + typedef _Rope_RopeSubstring<_CharT, _Alloc> _RopeSubstring; + + // Retrieve a character at the indicated position. + static _CharT _S_fetch(_RopeRep* __r, size_type __pos); + +#ifndef __GC + // Obtain a pointer to the character at the indicated position. + // The pointer can be used to change the character. + // If such a pointer cannot be produced, as is frequently the + // case, 0 is returned instead. + // (Returns nonzero only if all nodes in the path have a refcount + // of 1.) + static _CharT* _S_fetch_ptr(_RopeRep* __r, size_type __pos); +#endif + + static bool + _S_apply_to_pieces(// should be template parameter + _Rope_char_consumer<_CharT>& __c, + const _RopeRep* __r, + size_t __begin, size_t __end); + // begin and end are assumed to be in range. + +#ifndef __GC + static void + _S_unref(_RopeRep* __t) + { _RopeRep::_S_unref(__t); } + + static void + _S_ref(_RopeRep* __t) + { _RopeRep::_S_ref(__t); } + +#else /* __GC */ + static void _S_unref(_RopeRep*) { } + static void _S_ref(_RopeRep*) { } +#endif + +#ifdef __GC + typedef _Rope_RopeRep<_CharT, _Alloc>* _Self_destruct_ptr; +#else + typedef _Rope_self_destruct_ptr<_CharT, _Alloc> _Self_destruct_ptr; +#endif + + // _Result is counted in refcount. + static _RopeRep* _S_substring(_RopeRep* __base, + size_t __start, size_t __endp1); + + static _RopeRep* _S_concat_char_iter(_RopeRep* __r, + const _CharT* __iter, size_t __slen); + // Concatenate rope and char ptr, copying __s. + // Should really take an arbitrary iterator. + // Result is counted in refcount. + static _RopeRep* _S_destr_concat_char_iter(_RopeRep* __r, + const _CharT* __iter, + size_t __slen) + // As above, but one reference to __r is about to be + // destroyed. Thus the pieces may be recycled if all + // relevant reference counts are 1. +#ifdef __GC + // We can't really do anything since refcounts are unavailable. + { return _S_concat_char_iter(__r, __iter, __slen); } +#else + ; +#endif + + static _RopeRep* _S_concat(_RopeRep* __left, _RopeRep* __right); + // General concatenation on _RopeRep. _Result + // has refcount of 1. Adjusts argument refcounts. + + public: + void + apply_to_pieces(size_t __begin, size_t __end, + _Rope_char_consumer<_CharT>& __c) const + { _S_apply_to_pieces(__c, this->_M_tree_ptr, __begin, __end); } + + protected: + + static size_t + _S_rounded_up_size(size_t __n) + { return _RopeLeaf::_S_rounded_up_size(__n); } + + static size_t + _S_allocated_capacity(size_t __n) + { + if (_S_is_basic_char_type((_CharT*)0)) + return _S_rounded_up_size(__n) - 1; + else + return _S_rounded_up_size(__n); + + } + + // Allocate and construct a RopeLeaf using the supplied allocator + // Takes ownership of s instead of copying. + static _RopeLeaf* + _S_new_RopeLeaf(__GC_CONST _CharT *__s, + size_t __size, allocator_type& __a) + { + _RopeLeaf* __space = typename _Base::_LAlloc(__a).allocate(1); + return new(__space) _RopeLeaf(__s, __size, __a); + } + + static _RopeConcatenation* + _S_new_RopeConcatenation(_RopeRep* __left, _RopeRep* __right, + allocator_type& __a) + { + _RopeConcatenation* __space = typename _Base::_CAlloc(__a).allocate(1); + return new(__space) _RopeConcatenation(__left, __right, __a); + } + + static _RopeFunction* + _S_new_RopeFunction(char_producer<_CharT>* __f, + size_t __size, bool __d, allocator_type& __a) + { + _RopeFunction* __space = typename _Base::_FAlloc(__a).allocate(1); + return new(__space) _RopeFunction(__f, __size, __d, __a); + } + + static _RopeSubstring* + _S_new_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s, + size_t __l, allocator_type& __a) + { + _RopeSubstring* __space = typename _Base::_SAlloc(__a).allocate(1); + return new(__space) _RopeSubstring(__b, __s, __l, __a); + } + + static _RopeLeaf* + _S_RopeLeaf_from_unowned_char_ptr(const _CharT *__s, + size_t __size, allocator_type& __a) +#define __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __size, __a) \ + _S_RopeLeaf_from_unowned_char_ptr(__s, __size, __a) + { + if (0 == __size) + return 0; + _CharT* __buf = __a.allocate(_S_rounded_up_size(__size)); + + __uninitialized_copy_n_a(__s, __size, __buf, __a); + _S_cond_store_eos(__buf[__size]); + __try + { return _S_new_RopeLeaf(__buf, __size, __a); } + __catch(...) + { + _RopeRep::__STL_FREE_STRING(__buf, __size, __a); + __throw_exception_again; + } + } + + // Concatenation of nonempty strings. + // Always builds a concatenation node. + // Rebalances if the result is too deep. + // Result has refcount 1. + // Does not increment left and right ref counts even though + // they are referenced. + static _RopeRep* + _S_tree_concat(_RopeRep* __left, _RopeRep* __right); + + // Concatenation helper functions + static _RopeLeaf* + _S_leaf_concat_char_iter(_RopeLeaf* __r, + const _CharT* __iter, size_t __slen); + // Concatenate by copying leaf. + // should take an arbitrary iterator + // result has refcount 1. +#ifndef __GC + static _RopeLeaf* + _S_destr_leaf_concat_char_iter(_RopeLeaf* __r, + const _CharT* __iter, size_t __slen); + // A version that potentially clobbers __r if __r->_M_ref_count == 1. +#endif + + private: + + static size_t _S_char_ptr_len(const _CharT* __s); + // slightly generalized strlen + + rope(_RopeRep* __t, const allocator_type& __a = allocator_type()) + : _Base(__t, __a) { } + + + // Copy __r to the _CharT buffer. + // Returns __buffer + __r->_M_size. + // Assumes that buffer is uninitialized. + static _CharT* _S_flatten(_RopeRep* __r, _CharT* __buffer); + + // Again, with explicit starting position and length. + // Assumes that buffer is uninitialized. + static _CharT* _S_flatten(_RopeRep* __r, + size_t __start, size_t __len, + _CharT* __buffer); + + static const unsigned long + _S_min_len[__detail::_S_max_rope_depth + 1]; + + static bool + _S_is_balanced(_RopeRep* __r) + { return (__r->_M_size >= _S_min_len[__r->_M_depth]); } + + static bool + _S_is_almost_balanced(_RopeRep* __r) + { return (__r->_M_depth == 0 + || __r->_M_size >= _S_min_len[__r->_M_depth - 1]); } + + static bool + _S_is_roughly_balanced(_RopeRep* __r) + { return (__r->_M_depth <= 1 + || __r->_M_size >= _S_min_len[__r->_M_depth - 2]); } + + // Assumes the result is not empty. + static _RopeRep* + _S_concat_and_set_balanced(_RopeRep* __left, _RopeRep* __right) + { + _RopeRep* __result = _S_concat(__left, __right); + if (_S_is_balanced(__result)) + __result->_M_is_balanced = true; + return __result; + } + + // The basic rebalancing operation. Logically copies the + // rope. The result has refcount of 1. The client will + // usually decrement the reference count of __r. + // The result is within height 2 of balanced by the above + // definition. + static _RopeRep* _S_balance(_RopeRep* __r); + + // Add all unbalanced subtrees to the forest of balanced trees. + // Used only by balance. + static void _S_add_to_forest(_RopeRep*__r, _RopeRep** __forest); + + // Add __r to forest, assuming __r is already balanced. + static void _S_add_leaf_to_forest(_RopeRep* __r, _RopeRep** __forest); + + // Print to stdout, exposing structure + static void _S_dump(_RopeRep* __r, int __indent = 0); + + // Return -1, 0, or 1 if __x < __y, __x == __y, or __x > __y resp. + static int _S_compare(const _RopeRep* __x, const _RopeRep* __y); + + public: + bool + empty() const + { return 0 == this->_M_tree_ptr; } + + // Comparison member function. This is public only for those + // clients that need a ternary comparison. Others + // should use the comparison operators below. + int + compare(const rope& __y) const + { return _S_compare(this->_M_tree_ptr, __y._M_tree_ptr); } + + rope(const _CharT* __s, const allocator_type& __a = allocator_type()) + : _Base(__a) + { + this->_M_tree_ptr = + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, _S_char_ptr_len(__s), + _M_get_allocator()); + } + + rope(const _CharT* __s, size_t __len, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { + this->_M_tree_ptr = + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __len, _M_get_allocator()); + } + + // Should perhaps be templatized with respect to the iterator type + // and use Sequence_buffer. (It should perhaps use sequence_buffer + // even now.) + rope(const _CharT* __s, const _CharT* __e, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { + this->_M_tree_ptr = + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __e - __s, _M_get_allocator()); + } + + rope(const const_iterator& __s, const const_iterator& __e, + const allocator_type& __a = allocator_type()) + : _Base(_S_substring(__s._M_root, __s._M_current_pos, + __e._M_current_pos), __a) + { } + + rope(const iterator& __s, const iterator& __e, + const allocator_type& __a = allocator_type()) + : _Base(_S_substring(__s._M_root, __s._M_current_pos, + __e._M_current_pos), __a) + { } + + rope(_CharT __c, const allocator_type& __a = allocator_type()) + : _Base(__a) + { + _CharT* __buf = this->_Data_allocate(_S_rounded_up_size(1)); + + _M_get_allocator().construct(__buf, __c); + __try + { + this->_M_tree_ptr = _S_new_RopeLeaf(__buf, 1, + _M_get_allocator()); + } + __catch(...) + { + _RopeRep::__STL_FREE_STRING(__buf, 1, _M_get_allocator()); + __throw_exception_again; + } + } + + rope(size_t __n, _CharT __c, + const allocator_type& __a = allocator_type()); + + rope(const allocator_type& __a = allocator_type()) + : _Base(0, __a) { } + + // Construct a rope from a function that can compute its members + rope(char_producer<_CharT> *__fn, size_t __len, bool __delete_fn, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { + this->_M_tree_ptr = (0 == __len) ? + 0 : _S_new_RopeFunction(__fn, __len, __delete_fn, __a); + } + + rope(const rope& __x, const allocator_type& __a = allocator_type()) + : _Base(__x._M_tree_ptr, __a) + { _S_ref(this->_M_tree_ptr); } + + ~rope() throw() + { _S_unref(this->_M_tree_ptr); } + + rope& + operator=(const rope& __x) + { + _RopeRep* __old = this->_M_tree_ptr; + this->_M_tree_ptr = __x._M_tree_ptr; + _S_ref(this->_M_tree_ptr); + _S_unref(__old); + return *this; + } + + void + clear() + { + _S_unref(this->_M_tree_ptr); + this->_M_tree_ptr = 0; + } + + void + push_back(_CharT __x) + { + _RopeRep* __old = this->_M_tree_ptr; + this->_M_tree_ptr + = _S_destr_concat_char_iter(this->_M_tree_ptr, &__x, 1); + _S_unref(__old); + } + + void + pop_back() + { + _RopeRep* __old = this->_M_tree_ptr; + this->_M_tree_ptr = _S_substring(this->_M_tree_ptr, + 0, this->_M_tree_ptr->_M_size - 1); + _S_unref(__old); + } + + _CharT + back() const + { return _S_fetch(this->_M_tree_ptr, this->_M_tree_ptr->_M_size - 1); } + + void + push_front(_CharT __x) + { + _RopeRep* __old = this->_M_tree_ptr; + _RopeRep* __left = + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(&__x, 1, _M_get_allocator()); + __try + { + this->_M_tree_ptr = _S_concat(__left, this->_M_tree_ptr); + _S_unref(__old); + _S_unref(__left); + } + __catch(...) + { + _S_unref(__left); + __throw_exception_again; + } + } + + void + pop_front() + { + _RopeRep* __old = this->_M_tree_ptr; + this->_M_tree_ptr + = _S_substring(this->_M_tree_ptr, 1, this->_M_tree_ptr->_M_size); + _S_unref(__old); + } + + _CharT + front() const + { return _S_fetch(this->_M_tree_ptr, 0); } + + void + balance() + { + _RopeRep* __old = this->_M_tree_ptr; + this->_M_tree_ptr = _S_balance(this->_M_tree_ptr); + _S_unref(__old); + } + + void + copy(_CharT* __buffer) const + { + _Destroy_const(__buffer, __buffer + size(), _M_get_allocator()); + _S_flatten(this->_M_tree_ptr, __buffer); + } + + // This is the copy function from the standard, but + // with the arguments reordered to make it consistent with the + // rest of the interface. + // Note that this guaranteed not to compile if the draft standard + // order is assumed. + size_type + copy(size_type __pos, size_type __n, _CharT* __buffer) const + { + size_t __size = size(); + size_t __len = (__pos + __n > __size? __size - __pos : __n); + + _Destroy_const(__buffer, __buffer + __len, _M_get_allocator()); + _S_flatten(this->_M_tree_ptr, __pos, __len, __buffer); + return __len; + } + + // Print to stdout, exposing structure. May be useful for + // performance debugging. + void + dump() + { _S_dump(this->_M_tree_ptr); } + + // Convert to 0 terminated string in new allocated memory. + // Embedded 0s in the input do not terminate the copy. + const _CharT* c_str() const; + + // As above, but also use the flattened representation as + // the new rope representation. + const _CharT* replace_with_c_str(); + + // Reclaim memory for the c_str generated flattened string. + // Intentionally undocumented, since it's hard to say when this + // is safe for multiple threads. + void + delete_c_str () + { + if (0 == this->_M_tree_ptr) + return; + if (__detail::_S_leaf == this->_M_tree_ptr->_M_tag && + ((_RopeLeaf*)this->_M_tree_ptr)->_M_data == + this->_M_tree_ptr->_M_c_string) + { + // Representation shared + return; + } +#ifndef __GC + this->_M_tree_ptr->_M_free_c_string(); +#endif + this->_M_tree_ptr->_M_c_string = 0; + } + + _CharT + operator[] (size_type __pos) const + { return _S_fetch(this->_M_tree_ptr, __pos); } + + _CharT + at(size_type __pos) const + { + // if (__pos >= size()) throw out_of_range; // XXX + return (*this)[__pos]; + } + + const_iterator + begin() const + { return(const_iterator(this->_M_tree_ptr, 0)); } + + // An easy way to get a const iterator from a non-const container. + const_iterator + const_begin() const + { return(const_iterator(this->_M_tree_ptr, 0)); } + + const_iterator + end() const + { return(const_iterator(this->_M_tree_ptr, size())); } + + const_iterator + const_end() const + { return(const_iterator(this->_M_tree_ptr, size())); } + + size_type + size() const + { return(0 == this->_M_tree_ptr? 0 : this->_M_tree_ptr->_M_size); } + + size_type + length() const + { return size(); } + + size_type + max_size() const + { + return _S_min_len[int(__detail::_S_max_rope_depth) - 1] - 1; + // Guarantees that the result can be sufficiently + // balanced. Longer ropes will probably still work, + // but it's harder to make guarantees. + } + + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + const_reverse_iterator + rbegin() const + { return const_reverse_iterator(end()); } + + const_reverse_iterator + const_rbegin() const + { return const_reverse_iterator(end()); } + + const_reverse_iterator + rend() const + { return const_reverse_iterator(begin()); } + + const_reverse_iterator + const_rend() const + { return const_reverse_iterator(begin()); } + + template<class _CharT2, class _Alloc2> + friend rope<_CharT2, _Alloc2> + operator+(const rope<_CharT2, _Alloc2>& __left, + const rope<_CharT2, _Alloc2>& __right); + + template<class _CharT2, class _Alloc2> + friend rope<_CharT2, _Alloc2> + operator+(const rope<_CharT2, _Alloc2>& __left, const _CharT2* __right); + + template<class _CharT2, class _Alloc2> + friend rope<_CharT2, _Alloc2> + operator+(const rope<_CharT2, _Alloc2>& __left, _CharT2 __right); + + // The symmetric cases are intentionally omitted, since they're + // presumed to be less common, and we don't handle them as well. + + // The following should really be templatized. The first + // argument should be an input iterator or forward iterator with + // value_type _CharT. + rope& + append(const _CharT* __iter, size_t __n) + { + _RopeRep* __result = + _S_destr_concat_char_iter(this->_M_tree_ptr, __iter, __n); + _S_unref(this->_M_tree_ptr); + this->_M_tree_ptr = __result; + return *this; + } + + rope& + append(const _CharT* __c_string) + { + size_t __len = _S_char_ptr_len(__c_string); + append(__c_string, __len); + return(*this); + } + + rope& + append(const _CharT* __s, const _CharT* __e) + { + _RopeRep* __result = + _S_destr_concat_char_iter(this->_M_tree_ptr, __s, __e - __s); + _S_unref(this->_M_tree_ptr); + this->_M_tree_ptr = __result; + return *this; + } + + rope& + append(const_iterator __s, const_iterator __e) + { + _Self_destruct_ptr __appendee(_S_substring(__s._M_root, + __s._M_current_pos, + __e._M_current_pos)); + _RopeRep* __result = _S_concat(this->_M_tree_ptr, + (_RopeRep*)__appendee); + _S_unref(this->_M_tree_ptr); + this->_M_tree_ptr = __result; + return *this; + } + + rope& + append(_CharT __c) + { + _RopeRep* __result = + _S_destr_concat_char_iter(this->_M_tree_ptr, &__c, 1); + _S_unref(this->_M_tree_ptr); + this->_M_tree_ptr = __result; + return *this; + } + + rope& + append() + { return append(_CharT()); } // XXX why? + + rope& + append(const rope& __y) + { + _RopeRep* __result = _S_concat(this->_M_tree_ptr, __y._M_tree_ptr); + _S_unref(this->_M_tree_ptr); + this->_M_tree_ptr = __result; + return *this; + } + + rope& + append(size_t __n, _CharT __c) + { + rope<_CharT,_Alloc> __last(__n, __c); + return append(__last); + } + + void + swap(rope& __b) + { + _RopeRep* __tmp = this->_M_tree_ptr; + this->_M_tree_ptr = __b._M_tree_ptr; + __b._M_tree_ptr = __tmp; + } + + protected: + // Result is included in refcount. + static _RopeRep* + replace(_RopeRep* __old, size_t __pos1, + size_t __pos2, _RopeRep* __r) + { + if (0 == __old) + { + _S_ref(__r); + return __r; + } + _Self_destruct_ptr __left(_S_substring(__old, 0, __pos1)); + _Self_destruct_ptr __right(_S_substring(__old, __pos2, __old->_M_size)); + _RopeRep* __result; + + if (0 == __r) + __result = _S_concat(__left, __right); + else + { + _Self_destruct_ptr __left_result(_S_concat(__left, __r)); + __result = _S_concat(__left_result, __right); + } + return __result; + } + + public: + void + insert(size_t __p, const rope& __r) + { + _RopeRep* __result = + replace(this->_M_tree_ptr, __p, __p, __r._M_tree_ptr); + _S_unref(this->_M_tree_ptr); + this->_M_tree_ptr = __result; + } + + void + insert(size_t __p, size_t __n, _CharT __c) + { + rope<_CharT,_Alloc> __r(__n,__c); + insert(__p, __r); + } + + void + insert(size_t __p, const _CharT* __i, size_t __n) + { + _Self_destruct_ptr __left(_S_substring(this->_M_tree_ptr, 0, __p)); + _Self_destruct_ptr __right(_S_substring(this->_M_tree_ptr, + __p, size())); + _Self_destruct_ptr __left_result(_S_concat_char_iter(__left, __i, __n)); + // _S_ destr_concat_char_iter should be safe here. + // But as it stands it's probably not a win, since __left + // is likely to have additional references. + _RopeRep* __result = _S_concat(__left_result, __right); + _S_unref(this->_M_tree_ptr); + this->_M_tree_ptr = __result; + } + + void + insert(size_t __p, const _CharT* __c_string) + { insert(__p, __c_string, _S_char_ptr_len(__c_string)); } + + void + insert(size_t __p, _CharT __c) + { insert(__p, &__c, 1); } + + void + insert(size_t __p) + { + _CharT __c = _CharT(); + insert(__p, &__c, 1); + } + + void + insert(size_t __p, const _CharT* __i, const _CharT* __j) + { + rope __r(__i, __j); + insert(__p, __r); + } + + void + insert(size_t __p, const const_iterator& __i, + const const_iterator& __j) + { + rope __r(__i, __j); + insert(__p, __r); + } + + void + insert(size_t __p, const iterator& __i, + const iterator& __j) + { + rope __r(__i, __j); + insert(__p, __r); + } + + // (position, length) versions of replace operations: + + void + replace(size_t __p, size_t __n, const rope& __r) + { + _RopeRep* __result = + replace(this->_M_tree_ptr, __p, __p + __n, __r._M_tree_ptr); + _S_unref(this->_M_tree_ptr); + this->_M_tree_ptr = __result; + } + + void + replace(size_t __p, size_t __n, + const _CharT* __i, size_t __i_len) + { + rope __r(__i, __i_len); + replace(__p, __n, __r); + } + + void + replace(size_t __p, size_t __n, _CharT __c) + { + rope __r(__c); + replace(__p, __n, __r); + } + + void + replace(size_t __p, size_t __n, const _CharT* __c_string) + { + rope __r(__c_string); + replace(__p, __n, __r); + } + + void + replace(size_t __p, size_t __n, + const _CharT* __i, const _CharT* __j) + { + rope __r(__i, __j); + replace(__p, __n, __r); + } + + void + replace(size_t __p, size_t __n, + const const_iterator& __i, const const_iterator& __j) + { + rope __r(__i, __j); + replace(__p, __n, __r); + } + + void + replace(size_t __p, size_t __n, + const iterator& __i, const iterator& __j) + { + rope __r(__i, __j); + replace(__p, __n, __r); + } + + // Single character variants: + void + replace(size_t __p, _CharT __c) + { + iterator __i(this, __p); + *__i = __c; + } + + void + replace(size_t __p, const rope& __r) + { replace(__p, 1, __r); } + + void + replace(size_t __p, const _CharT* __i, size_t __i_len) + { replace(__p, 1, __i, __i_len); } + + void + replace(size_t __p, const _CharT* __c_string) + { replace(__p, 1, __c_string); } + + void + replace(size_t __p, const _CharT* __i, const _CharT* __j) + { replace(__p, 1, __i, __j); } + + void + replace(size_t __p, const const_iterator& __i, + const const_iterator& __j) + { replace(__p, 1, __i, __j); } + + void + replace(size_t __p, const iterator& __i, + const iterator& __j) + { replace(__p, 1, __i, __j); } + + // Erase, (position, size) variant. + void + erase(size_t __p, size_t __n) + { + _RopeRep* __result = replace(this->_M_tree_ptr, __p, + __p + __n, 0); + _S_unref(this->_M_tree_ptr); + this->_M_tree_ptr = __result; + } + + // Erase, single character + void + erase(size_t __p) + { erase(__p, __p + 1); } + + // Insert, iterator variants. + iterator + insert(const iterator& __p, const rope& __r) + { + insert(__p.index(), __r); + return __p; + } + + iterator + insert(const iterator& __p, size_t __n, _CharT __c) + { + insert(__p.index(), __n, __c); + return __p; + } + + iterator insert(const iterator& __p, _CharT __c) + { + insert(__p.index(), __c); + return __p; + } + + iterator + insert(const iterator& __p ) + { + insert(__p.index()); + return __p; + } + + iterator + insert(const iterator& __p, const _CharT* c_string) + { + insert(__p.index(), c_string); + return __p; + } + + iterator + insert(const iterator& __p, const _CharT* __i, size_t __n) + { + insert(__p.index(), __i, __n); + return __p; + } + + iterator + insert(const iterator& __p, const _CharT* __i, + const _CharT* __j) + { + insert(__p.index(), __i, __j); + return __p; + } + + iterator + insert(const iterator& __p, + const const_iterator& __i, const const_iterator& __j) + { + insert(__p.index(), __i, __j); + return __p; + } + + iterator + insert(const iterator& __p, + const iterator& __i, const iterator& __j) + { + insert(__p.index(), __i, __j); + return __p; + } + + // Replace, range variants. + void + replace(const iterator& __p, const iterator& __q, const rope& __r) + { replace(__p.index(), __q.index() - __p.index(), __r); } + + void + replace(const iterator& __p, const iterator& __q, _CharT __c) + { replace(__p.index(), __q.index() - __p.index(), __c); } + + void + replace(const iterator& __p, const iterator& __q, + const _CharT* __c_string) + { replace(__p.index(), __q.index() - __p.index(), __c_string); } + + void + replace(const iterator& __p, const iterator& __q, + const _CharT* __i, size_t __n) + { replace(__p.index(), __q.index() - __p.index(), __i, __n); } + + void + replace(const iterator& __p, const iterator& __q, + const _CharT* __i, const _CharT* __j) + { replace(__p.index(), __q.index() - __p.index(), __i, __j); } + + void + replace(const iterator& __p, const iterator& __q, + const const_iterator& __i, const const_iterator& __j) + { replace(__p.index(), __q.index() - __p.index(), __i, __j); } + + void + replace(const iterator& __p, const iterator& __q, + const iterator& __i, const iterator& __j) + { replace(__p.index(), __q.index() - __p.index(), __i, __j); } + + // Replace, iterator variants. + void + replace(const iterator& __p, const rope& __r) + { replace(__p.index(), __r); } + + void + replace(const iterator& __p, _CharT __c) + { replace(__p.index(), __c); } + + void + replace(const iterator& __p, const _CharT* __c_string) + { replace(__p.index(), __c_string); } + + void + replace(const iterator& __p, const _CharT* __i, size_t __n) + { replace(__p.index(), __i, __n); } + + void + replace(const iterator& __p, const _CharT* __i, const _CharT* __j) + { replace(__p.index(), __i, __j); } + + void + replace(const iterator& __p, const_iterator __i, const_iterator __j) + { replace(__p.index(), __i, __j); } + + void + replace(const iterator& __p, iterator __i, iterator __j) + { replace(__p.index(), __i, __j); } + + // Iterator and range variants of erase + iterator + erase(const iterator& __p, const iterator& __q) + { + size_t __p_index = __p.index(); + erase(__p_index, __q.index() - __p_index); + return iterator(this, __p_index); + } + + iterator + erase(const iterator& __p) + { + size_t __p_index = __p.index(); + erase(__p_index, 1); + return iterator(this, __p_index); + } + + rope + substr(size_t __start, size_t __len = 1) const + { + return rope<_CharT, _Alloc>(_S_substring(this->_M_tree_ptr, + __start, + __start + __len)); + } + + rope + substr(iterator __start, iterator __end) const + { + return rope<_CharT, _Alloc>(_S_substring(this->_M_tree_ptr, + __start.index(), + __end.index())); + } + + rope + substr(iterator __start) const + { + size_t __pos = __start.index(); + return rope<_CharT, _Alloc>(_S_substring(this->_M_tree_ptr, + __pos, __pos + 1)); + } + + rope + substr(const_iterator __start, const_iterator __end) const + { + // This might eventually take advantage of the cache in the + // iterator. + return rope<_CharT, _Alloc>(_S_substring(this->_M_tree_ptr, + __start.index(), + __end.index())); + } + + rope<_CharT, _Alloc> + substr(const_iterator __start) + { + size_t __pos = __start.index(); + return rope<_CharT, _Alloc>(_S_substring(this->_M_tree_ptr, + __pos, __pos + 1)); + } + + static const size_type npos; + + size_type find(_CharT __c, size_type __pos = 0) const; + + size_type + find(const _CharT* __s, size_type __pos = 0) const + { + size_type __result_pos; + const_iterator __result = + std::search(const_begin() + __pos, const_end(), + __s, __s + _S_char_ptr_len(__s)); + __result_pos = __result.index(); +#ifndef __STL_OLD_ROPE_SEMANTICS + if (__result_pos == size()) + __result_pos = npos; +#endif + return __result_pos; + } + + iterator + mutable_begin() + { return(iterator(this, 0)); } + + iterator + mutable_end() + { return(iterator(this, size())); } + + typedef std::reverse_iterator<iterator> reverse_iterator; + + reverse_iterator + mutable_rbegin() + { return reverse_iterator(mutable_end()); } + + reverse_iterator + mutable_rend() + { return reverse_iterator(mutable_begin()); } + + reference + mutable_reference_at(size_type __pos) + { return reference(this, __pos); } + +#ifdef __STD_STUFF + reference + operator[] (size_type __pos) + { return _char_ref_proxy(this, __pos); } + + reference + at(size_type __pos) + { + // if (__pos >= size()) throw out_of_range; // XXX + return (*this)[__pos]; + } + + void resize(size_type __n, _CharT __c) { } + void resize(size_type __n) { } + void reserve(size_type __res_arg = 0) { } + + size_type + capacity() const + { return max_size(); } + + // Stuff below this line is dangerous because it's error prone. + // I would really like to get rid of it. + // copy function with funny arg ordering. + size_type + copy(_CharT* __buffer, size_type __n, + size_type __pos = 0) const + { return copy(__pos, __n, __buffer); } + + iterator + end() + { return mutable_end(); } + + iterator + begin() + { return mutable_begin(); } + + reverse_iterator + rend() + { return mutable_rend(); } + + reverse_iterator + rbegin() + { return mutable_rbegin(); } + +#else + const_iterator + end() + { return const_end(); } + + const_iterator + begin() + { return const_begin(); } + + const_reverse_iterator + rend() + { return const_rend(); } + + const_reverse_iterator + rbegin() + { return const_rbegin(); } + +#endif + }; + + template <class _CharT, class _Alloc> + const typename rope<_CharT, _Alloc>::size_type + rope<_CharT, _Alloc>::npos = (size_type)(-1); + + template <class _CharT, class _Alloc> + inline bool operator==(const _Rope_const_iterator<_CharT, _Alloc>& __x, + const _Rope_const_iterator<_CharT, _Alloc>& __y) + { return (__x._M_current_pos == __y._M_current_pos + && __x._M_root == __y._M_root); } + + template <class _CharT, class _Alloc> + inline bool operator<(const _Rope_const_iterator<_CharT, _Alloc>& __x, + const _Rope_const_iterator<_CharT, _Alloc>& __y) + { return (__x._M_current_pos < __y._M_current_pos); } + + template <class _CharT, class _Alloc> + inline bool operator!=(const _Rope_const_iterator<_CharT, _Alloc>& __x, + const _Rope_const_iterator<_CharT, _Alloc>& __y) + { return !(__x == __y); } + + template <class _CharT, class _Alloc> + inline bool operator>(const _Rope_const_iterator<_CharT, _Alloc>& __x, + const _Rope_const_iterator<_CharT, _Alloc>& __y) + { return __y < __x; } + + template <class _CharT, class _Alloc> + inline bool + operator<=(const _Rope_const_iterator<_CharT, _Alloc>& __x, + const _Rope_const_iterator<_CharT, _Alloc>& __y) + { return !(__y < __x); } + + template <class _CharT, class _Alloc> + inline bool + operator>=(const _Rope_const_iterator<_CharT, _Alloc>& __x, + const _Rope_const_iterator<_CharT, _Alloc>& __y) + { return !(__x < __y); } + + template <class _CharT, class _Alloc> + inline ptrdiff_t + operator-(const _Rope_const_iterator<_CharT, _Alloc>& __x, + const _Rope_const_iterator<_CharT, _Alloc>& __y) + { return (ptrdiff_t)__x._M_current_pos - (ptrdiff_t)__y._M_current_pos; } + + template <class _CharT, class _Alloc> + inline _Rope_const_iterator<_CharT, _Alloc> + operator-(const _Rope_const_iterator<_CharT, _Alloc>& __x, ptrdiff_t __n) + { return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root, + __x._M_current_pos - __n); } + + template <class _CharT, class _Alloc> + inline _Rope_const_iterator<_CharT, _Alloc> + operator+(const _Rope_const_iterator<_CharT, _Alloc>& __x, ptrdiff_t __n) + { return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root, + __x._M_current_pos + __n); } + + template <class _CharT, class _Alloc> + inline _Rope_const_iterator<_CharT, _Alloc> + operator+(ptrdiff_t __n, const _Rope_const_iterator<_CharT, _Alloc>& __x) + { return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root, + __x._M_current_pos + __n); } + + template <class _CharT, class _Alloc> + inline bool + operator==(const _Rope_iterator<_CharT, _Alloc>& __x, + const _Rope_iterator<_CharT, _Alloc>& __y) + {return (__x._M_current_pos == __y._M_current_pos + && __x._M_root_rope == __y._M_root_rope); } + + template <class _CharT, class _Alloc> + inline bool + operator<(const _Rope_iterator<_CharT, _Alloc>& __x, + const _Rope_iterator<_CharT, _Alloc>& __y) + { return (__x._M_current_pos < __y._M_current_pos); } + + template <class _CharT, class _Alloc> + inline bool + operator!=(const _Rope_iterator<_CharT, _Alloc>& __x, + const _Rope_iterator<_CharT, _Alloc>& __y) + { return !(__x == __y); } + + template <class _CharT, class _Alloc> + inline bool + operator>(const _Rope_iterator<_CharT, _Alloc>& __x, + const _Rope_iterator<_CharT, _Alloc>& __y) + { return __y < __x; } + + template <class _CharT, class _Alloc> + inline bool + operator<=(const _Rope_iterator<_CharT, _Alloc>& __x, + const _Rope_iterator<_CharT, _Alloc>& __y) + { return !(__y < __x); } + + template <class _CharT, class _Alloc> + inline bool + operator>=(const _Rope_iterator<_CharT, _Alloc>& __x, + const _Rope_iterator<_CharT, _Alloc>& __y) + { return !(__x < __y); } + + template <class _CharT, class _Alloc> + inline ptrdiff_t + operator-(const _Rope_iterator<_CharT, _Alloc>& __x, + const _Rope_iterator<_CharT, _Alloc>& __y) + { return ((ptrdiff_t)__x._M_current_pos + - (ptrdiff_t)__y._M_current_pos); } + + template <class _CharT, class _Alloc> + inline _Rope_iterator<_CharT, _Alloc> + operator-(const _Rope_iterator<_CharT, _Alloc>& __x, + ptrdiff_t __n) + { return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope, + __x._M_current_pos - __n); } + + template <class _CharT, class _Alloc> + inline _Rope_iterator<_CharT, _Alloc> + operator+(const _Rope_iterator<_CharT, _Alloc>& __x, ptrdiff_t __n) + { return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope, + __x._M_current_pos + __n); } + + template <class _CharT, class _Alloc> + inline _Rope_iterator<_CharT, _Alloc> + operator+(ptrdiff_t __n, const _Rope_iterator<_CharT, _Alloc>& __x) + { return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope, + __x._M_current_pos + __n); } + + template <class _CharT, class _Alloc> + inline rope<_CharT, _Alloc> + operator+(const rope<_CharT, _Alloc>& __left, + const rope<_CharT, _Alloc>& __right) + { + // Inlining this should make it possible to keep __left and + // __right in registers. + typedef rope<_CharT, _Alloc> rope_type; + return rope_type(rope_type::_S_concat(__left._M_tree_ptr, + __right._M_tree_ptr)); + } + + template <class _CharT, class _Alloc> + inline rope<_CharT, _Alloc>& + operator+=(rope<_CharT, _Alloc>& __left, + const rope<_CharT, _Alloc>& __right) + { + __left.append(__right); + return __left; + } + + template <class _CharT, class _Alloc> + inline rope<_CharT, _Alloc> + operator+(const rope<_CharT, _Alloc>& __left, + const _CharT* __right) + { + typedef rope<_CharT, _Alloc> rope_type; + size_t __rlen = rope_type::_S_char_ptr_len(__right); + return rope_type(rope_type::_S_concat_char_iter(__left._M_tree_ptr, + __right, __rlen)); + } + + template <class _CharT, class _Alloc> + inline rope<_CharT, _Alloc>& + operator+=(rope<_CharT, _Alloc>& __left, + const _CharT* __right) + { + __left.append(__right); + return __left; + } + + template <class _CharT, class _Alloc> + inline rope<_CharT, _Alloc> + operator+(const rope<_CharT, _Alloc>& __left, _CharT __right) + { + typedef rope<_CharT, _Alloc> rope_type; + return rope_type(rope_type::_S_concat_char_iter(__left._M_tree_ptr, + &__right, 1)); + } + + template <class _CharT, class _Alloc> + inline rope<_CharT, _Alloc>& + operator+=(rope<_CharT, _Alloc>& __left, _CharT __right) + { + __left.append(__right); + return __left; + } + + template <class _CharT, class _Alloc> + bool + operator<(const rope<_CharT, _Alloc>& __left, + const rope<_CharT, _Alloc>& __right) + { return __left.compare(__right) < 0; } + + template <class _CharT, class _Alloc> + bool + operator==(const rope<_CharT, _Alloc>& __left, + const rope<_CharT, _Alloc>& __right) + { return __left.compare(__right) == 0; } + + template <class _CharT, class _Alloc> + inline bool + operator==(const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x, + const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y) + { return (__x._M_pos == __y._M_pos && __x._M_root == __y._M_root); } + + template <class _CharT, class _Alloc> + inline bool + operator!=(const rope<_CharT, _Alloc>& __x, + const rope<_CharT, _Alloc>& __y) + { return !(__x == __y); } + + template <class _CharT, class _Alloc> + inline bool + operator>(const rope<_CharT, _Alloc>& __x, + const rope<_CharT, _Alloc>& __y) + { return __y < __x; } + + template <class _CharT, class _Alloc> + inline bool + operator<=(const rope<_CharT, _Alloc>& __x, + const rope<_CharT, _Alloc>& __y) + { return !(__y < __x); } + + template <class _CharT, class _Alloc> + inline bool + operator>=(const rope<_CharT, _Alloc>& __x, + const rope<_CharT, _Alloc>& __y) + { return !(__x < __y); } + + template <class _CharT, class _Alloc> + inline bool + operator!=(const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x, + const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y) + { return !(__x == __y); } + + template<class _CharT, class _Traits, class _Alloc> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __o, + const rope<_CharT, _Alloc>& __r); + + typedef rope<char> crope; + typedef rope<wchar_t> wrope; + + inline crope::reference + __mutable_reference_at(crope& __c, size_t __i) + { return __c.mutable_reference_at(__i); } + + inline wrope::reference + __mutable_reference_at(wrope& __c, size_t __i) + { return __c.mutable_reference_at(__i); } + + template <class _CharT, class _Alloc> + inline void + swap(rope<_CharT, _Alloc>& __x, rope<_CharT, _Alloc>& __y) + { __x.swap(__y); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + + +namespace std _GLIBCXX_VISIBILITY(default) +{ +namespace tr1 +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template<> + struct hash<__gnu_cxx::crope> + { + size_t + operator()(const __gnu_cxx::crope& __str) const + { + size_t __size = __str.size(); + if (0 == __size) + return 0; + return 13 * __str[0] + 5 * __str[__size - 1] + __size; + } + }; + + + template<> + struct hash<__gnu_cxx::wrope> + { + size_t + operator()(const __gnu_cxx::wrope& __str) const + { + size_t __size = __str.size(); + if (0 == __size) + return 0; + return 13 * __str[0] + 5 * __str[__size - 1] + __size; + } + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace tr1 +} // namespace std + +# include <ext/ropeimpl.h> + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/ropeimpl.h b/gcc-4.9/libstdc++-v3/include/ext/ropeimpl.h new file mode 100644 index 0000000..8363e74 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/ropeimpl.h @@ -0,0 +1,1703 @@ +// SGI's rope class implementation -*- C++ -*- + +// Copyright (C) 2001-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * Copyright (c) 1997 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/** @file ropeimpl.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{ext/rope} + */ + +#include <cstdio> +#include <ostream> +#include <bits/functexcept.h> + +#include <ext/algorithm> // For copy_n and lexicographical_compare_3way +#include <ext/memory> // For uninitialized_copy_n +#include <ext/numeric> // For power + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::size_t; + using std::printf; + using std::basic_ostream; + using std::__throw_length_error; + using std::_Destroy; + using std::__uninitialized_fill_n_a; + + // Set buf_start, buf_end, and buf_ptr appropriately, filling tmp_buf + // if necessary. Assumes _M_path_end[leaf_index] and leaf_pos are correct. + // Results in a valid buf_ptr if the iterator can be legitimately + // dereferenced. + template <class _CharT, class _Alloc> + void + _Rope_iterator_base<_CharT, _Alloc>:: + _S_setbuf(_Rope_iterator_base<_CharT, _Alloc>& __x) + { + const _RopeRep* __leaf = __x._M_path_end[__x._M_leaf_index]; + size_t __leaf_pos = __x._M_leaf_pos; + size_t __pos = __x._M_current_pos; + + switch(__leaf->_M_tag) + { + case __detail::_S_leaf: + __x._M_buf_start = ((_Rope_RopeLeaf<_CharT, _Alloc>*)__leaf)->_M_data; + __x._M_buf_ptr = __x._M_buf_start + (__pos - __leaf_pos); + __x._M_buf_end = __x._M_buf_start + __leaf->_M_size; + break; + case __detail::_S_function: + case __detail::_S_substringfn: + { + size_t __len = _S_iterator_buf_len; + size_t __buf_start_pos = __leaf_pos; + size_t __leaf_end = __leaf_pos + __leaf->_M_size; + char_producer<_CharT>* __fn = ((_Rope_RopeFunction<_CharT, + _Alloc>*)__leaf)->_M_fn; + if (__buf_start_pos + __len <= __pos) + { + __buf_start_pos = __pos - __len / 4; + if (__buf_start_pos + __len > __leaf_end) + __buf_start_pos = __leaf_end - __len; + } + if (__buf_start_pos + __len > __leaf_end) + __len = __leaf_end - __buf_start_pos; + (*__fn)(__buf_start_pos - __leaf_pos, __len, __x._M_tmp_buf); + __x._M_buf_ptr = __x._M_tmp_buf + (__pos - __buf_start_pos); + __x._M_buf_start = __x._M_tmp_buf; + __x._M_buf_end = __x._M_tmp_buf + __len; + } + break; + default: + break; + } + } + + // Set path and buffer inside a rope iterator. We assume that + // pos and root are already set. + template <class _CharT, class _Alloc> + void + _Rope_iterator_base<_CharT, _Alloc>:: + _S_setcache(_Rope_iterator_base<_CharT, _Alloc>& __x) + { + const _RopeRep* __path[int(__detail::_S_max_rope_depth) + 1]; + const _RopeRep* __curr_rope; + int __curr_depth = -1; /* index into path */ + size_t __curr_start_pos = 0; + size_t __pos = __x._M_current_pos; + unsigned char __dirns = 0; // Bit vector marking right turns in the path + + if (__pos >= __x._M_root->_M_size) + { + __x._M_buf_ptr = 0; + return; + } + __curr_rope = __x._M_root; + if (0 != __curr_rope->_M_c_string) + { + /* Treat the root as a leaf. */ + __x._M_buf_start = __curr_rope->_M_c_string; + __x._M_buf_end = __curr_rope->_M_c_string + __curr_rope->_M_size; + __x._M_buf_ptr = __curr_rope->_M_c_string + __pos; + __x._M_path_end[0] = __curr_rope; + __x._M_leaf_index = 0; + __x._M_leaf_pos = 0; + return; + } + for(;;) + { + ++__curr_depth; + __path[__curr_depth] = __curr_rope; + switch(__curr_rope->_M_tag) + { + case __detail::_S_leaf: + case __detail::_S_function: + case __detail::_S_substringfn: + __x._M_leaf_pos = __curr_start_pos; + goto done; + case __detail::_S_concat: + { + _Rope_RopeConcatenation<_CharT, _Alloc>* __c = + (_Rope_RopeConcatenation<_CharT, _Alloc>*)__curr_rope; + _RopeRep* __left = __c->_M_left; + size_t __left_len = __left->_M_size; + + __dirns <<= 1; + if (__pos >= __curr_start_pos + __left_len) + { + __dirns |= 1; + __curr_rope = __c->_M_right; + __curr_start_pos += __left_len; + } + else + __curr_rope = __left; + } + break; + } + } + done: + // Copy last section of path into _M_path_end. + { + int __i = -1; + int __j = __curr_depth + 1 - int(_S_path_cache_len); + + if (__j < 0) __j = 0; + while (__j <= __curr_depth) + __x._M_path_end[++__i] = __path[__j++]; + __x._M_leaf_index = __i; + } + __x._M_path_directions = __dirns; + _S_setbuf(__x); + } + + // Specialized version of the above. Assumes that + // the path cache is valid for the previous position. + template <class _CharT, class _Alloc> + void + _Rope_iterator_base<_CharT, _Alloc>:: + _S_setcache_for_incr(_Rope_iterator_base<_CharT, _Alloc>& __x) + { + int __current_index = __x._M_leaf_index; + const _RopeRep* __current_node = __x._M_path_end[__current_index]; + size_t __len = __current_node->_M_size; + size_t __node_start_pos = __x._M_leaf_pos; + unsigned char __dirns = __x._M_path_directions; + _Rope_RopeConcatenation<_CharT, _Alloc>* __c; + + if (__x._M_current_pos - __node_start_pos < __len) + { + /* More stuff in this leaf, we just didn't cache it. */ + _S_setbuf(__x); + return; + } + // node_start_pos is starting position of last_node. + while (--__current_index >= 0) + { + if (!(__dirns & 1) /* Path turned left */) + break; + __current_node = __x._M_path_end[__current_index]; + __c = (_Rope_RopeConcatenation<_CharT, _Alloc>*)__current_node; + // Otherwise we were in the right child. Thus we should pop + // the concatenation node. + __node_start_pos -= __c->_M_left->_M_size; + __dirns >>= 1; + } + if (__current_index < 0) + { + // We underflowed the cache. Punt. + _S_setcache(__x); + return; + } + __current_node = __x._M_path_end[__current_index]; + __c = (_Rope_RopeConcatenation<_CharT, _Alloc>*)__current_node; + // current_node is a concatenation node. We are positioned on the first + // character in its right child. + // node_start_pos is starting position of current_node. + __node_start_pos += __c->_M_left->_M_size; + __current_node = __c->_M_right; + __x._M_path_end[++__current_index] = __current_node; + __dirns |= 1; + while (__detail::_S_concat == __current_node->_M_tag) + { + ++__current_index; + if (int(_S_path_cache_len) == __current_index) + { + int __i; + for (__i = 0; __i < int(_S_path_cache_len) - 1; __i++) + __x._M_path_end[__i] = __x._M_path_end[__i+1]; + --__current_index; + } + __current_node = + ((_Rope_RopeConcatenation<_CharT, _Alloc>*)__current_node)->_M_left; + __x._M_path_end[__current_index] = __current_node; + __dirns <<= 1; + // node_start_pos is unchanged. + } + __x._M_leaf_index = __current_index; + __x._M_leaf_pos = __node_start_pos; + __x._M_path_directions = __dirns; + _S_setbuf(__x); + } + + template <class _CharT, class _Alloc> + void + _Rope_iterator_base<_CharT, _Alloc>:: + _M_incr(size_t __n) + { + _M_current_pos += __n; + if (0 != _M_buf_ptr) + { + size_t __chars_left = _M_buf_end - _M_buf_ptr; + if (__chars_left > __n) + _M_buf_ptr += __n; + else if (__chars_left == __n) + { + _M_buf_ptr += __n; + _S_setcache_for_incr(*this); + } + else + _M_buf_ptr = 0; + } + } + + template <class _CharT, class _Alloc> + void + _Rope_iterator_base<_CharT, _Alloc>:: + _M_decr(size_t __n) + { + if (0 != _M_buf_ptr) + { + size_t __chars_left = _M_buf_ptr - _M_buf_start; + if (__chars_left >= __n) + _M_buf_ptr -= __n; + else + _M_buf_ptr = 0; + } + _M_current_pos -= __n; + } + + template <class _CharT, class _Alloc> + void + _Rope_iterator<_CharT, _Alloc>:: + _M_check() + { + if (_M_root_rope->_M_tree_ptr != this->_M_root) + { + // _Rope was modified. Get things fixed up. + _RopeRep::_S_unref(this->_M_root); + this->_M_root = _M_root_rope->_M_tree_ptr; + _RopeRep::_S_ref(this->_M_root); + this->_M_buf_ptr = 0; + } + } + + template <class _CharT, class _Alloc> + inline + _Rope_const_iterator<_CharT, _Alloc>:: + _Rope_const_iterator(const _Rope_iterator<_CharT, _Alloc>& __x) + : _Rope_iterator_base<_CharT, _Alloc>(__x) + { } + + template <class _CharT, class _Alloc> + inline + _Rope_iterator<_CharT, _Alloc>:: + _Rope_iterator(rope<_CharT, _Alloc>& __r, size_t __pos) + : _Rope_iterator_base<_CharT,_Alloc>(__r._M_tree_ptr, __pos), + _M_root_rope(&__r) + { _RopeRep::_S_ref(this->_M_root); } + + template <class _CharT, class _Alloc> + inline size_t + rope<_CharT, _Alloc>:: + _S_char_ptr_len(const _CharT* __s) + { + const _CharT* __p = __s; + + while (!_S_is0(*__p)) + ++__p; + return (__p - __s); + } + + +#ifndef __GC + + template <class _CharT, class _Alloc> + inline void + _Rope_RopeRep<_CharT, _Alloc>:: + _M_free_c_string() + { + _CharT* __cstr = _M_c_string; + if (0 != __cstr) + { + size_t __size = this->_M_size + 1; + _Destroy(__cstr, __cstr + __size, _M_get_allocator()); + this->_Data_deallocate(__cstr, __size); + } + } + + template <class _CharT, class _Alloc> + inline void + _Rope_RopeRep<_CharT, _Alloc>:: + _S_free_string(_CharT* __s, size_t __n, allocator_type& __a) + { + if (!_S_is_basic_char_type((_CharT*)0)) + _Destroy(__s, __s + __n, __a); + + // This has to be a static member, so this gets a bit messy + __a.deallocate(__s, + _Rope_RopeLeaf<_CharT, _Alloc>::_S_rounded_up_size(__n)); + } + + // There are several reasons for not doing this with virtual destructors + // and a class specific delete operator: + // - A class specific delete operator can't easily get access to + // allocator instances if we need them. + // - Any virtual function would need a 4 or byte vtable pointer; + // this only requires a one byte tag per object. + template <class _CharT, class _Alloc> + void + _Rope_RopeRep<_CharT, _Alloc>:: + _M_free_tree() + { + switch(_M_tag) + { + case __detail::_S_leaf: + { + _Rope_RopeLeaf<_CharT, _Alloc>* __l + = (_Rope_RopeLeaf<_CharT, _Alloc>*)this; + __l->_Rope_RopeLeaf<_CharT, _Alloc>::~_Rope_RopeLeaf(); + this->_L_deallocate(__l, 1); + break; + } + case __detail::_S_concat: + { + _Rope_RopeConcatenation<_CharT,_Alloc>* __c + = (_Rope_RopeConcatenation<_CharT, _Alloc>*)this; + __c->_Rope_RopeConcatenation<_CharT, _Alloc>:: + ~_Rope_RopeConcatenation(); + this->_C_deallocate(__c, 1); + break; + } + case __detail::_S_function: + { + _Rope_RopeFunction<_CharT, _Alloc>* __f + = (_Rope_RopeFunction<_CharT, _Alloc>*)this; + __f->_Rope_RopeFunction<_CharT, _Alloc>::~_Rope_RopeFunction(); + this->_F_deallocate(__f, 1); + break; + } + case __detail::_S_substringfn: + { + _Rope_RopeSubstring<_CharT, _Alloc>* __ss = + (_Rope_RopeSubstring<_CharT, _Alloc>*)this; + __ss->_Rope_RopeSubstring<_CharT, _Alloc>:: + ~_Rope_RopeSubstring(); + this->_S_deallocate(__ss, 1); + break; + } + } + } +#else + + template <class _CharT, class _Alloc> + inline void + _Rope_RopeRep<_CharT, _Alloc>:: + _S_free_string(const _CharT*, size_t, allocator_type) + { } + +#endif + + // Concatenate a C string onto a leaf rope by copying the rope data. + // Used for short ropes. + template <class _CharT, class _Alloc> + typename rope<_CharT, _Alloc>::_RopeLeaf* + rope<_CharT, _Alloc>:: + _S_leaf_concat_char_iter(_RopeLeaf* __r, const _CharT* __iter, size_t __len) + { + size_t __old_len = __r->_M_size; + _CharT* __new_data = (_CharT*) + rope::_Data_allocate(_S_rounded_up_size(__old_len + __len)); + _RopeLeaf* __result; + + uninitialized_copy_n(__r->_M_data, __old_len, __new_data); + uninitialized_copy_n(__iter, __len, __new_data + __old_len); + _S_cond_store_eos(__new_data[__old_len + __len]); + __try + { + __result = _S_new_RopeLeaf(__new_data, __old_len + __len, + __r->_M_get_allocator()); + } + __catch(...) + { + _RopeRep::__STL_FREE_STRING(__new_data, __old_len + __len, + __r->_M_get_allocator()); + __throw_exception_again; + } + return __result; + } + +#ifndef __GC + // As above, but it's OK to clobber original if refcount is 1 + template <class _CharT, class _Alloc> + typename rope<_CharT,_Alloc>::_RopeLeaf* + rope<_CharT, _Alloc>:: + _S_destr_leaf_concat_char_iter(_RopeLeaf* __r, const _CharT* __iter, + size_t __len) + { + if (__r->_M_ref_count > 1) + return _S_leaf_concat_char_iter(__r, __iter, __len); + size_t __old_len = __r->_M_size; + if (_S_allocated_capacity(__old_len) >= __old_len + __len) + { + // The space has been partially initialized for the standard + // character types. But that doesn't matter for those types. + uninitialized_copy_n(__iter, __len, __r->_M_data + __old_len); + if (_S_is_basic_char_type((_CharT*)0)) + _S_cond_store_eos(__r->_M_data[__old_len + __len]); + else if (__r->_M_c_string != __r->_M_data && 0 != __r->_M_c_string) + { + __r->_M_free_c_string(); + __r->_M_c_string = 0; + } + __r->_M_size = __old_len + __len; + __r->_M_ref_count = 2; + return __r; + } + else + { + _RopeLeaf* __result = _S_leaf_concat_char_iter(__r, __iter, __len); + return __result; + } + } +#endif + + // Assumes left and right are not 0. + // Does not increment (nor decrement on exception) child reference counts. + // Result has ref count 1. + template <class _CharT, class _Alloc> + typename rope<_CharT, _Alloc>::_RopeRep* + rope<_CharT, _Alloc>:: + _S_tree_concat(_RopeRep* __left, _RopeRep* __right) + { + _RopeConcatenation* __result = _S_new_RopeConcatenation(__left, __right, + __left-> + _M_get_allocator()); + size_t __depth = __result->_M_depth; + + if (__depth > 20 + && (__result->_M_size < 1000 + || __depth > size_t(__detail::_S_max_rope_depth))) + { + _RopeRep* __balanced; + + __try + { + __balanced = _S_balance(__result); + __result->_M_unref_nonnil(); + } + __catch(...) + { + rope::_C_deallocate(__result,1); + __throw_exception_again; + } + // In case of exception, we need to deallocate + // otherwise dangling result node. But caller + // still owns its children. Thus unref is + // inappropriate. + return __balanced; + } + else + return __result; + } + + template <class _CharT, class _Alloc> + typename rope<_CharT, _Alloc>::_RopeRep* + rope<_CharT, _Alloc>:: + _S_concat_char_iter(_RopeRep* __r, const _CharT*__s, size_t __slen) + { + _RopeRep* __result; + if (0 == __slen) + { + _S_ref(__r); + return __r; + } + if (0 == __r) + return __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, + __r->_M_get_allocator()); + if (__r->_M_tag == __detail::_S_leaf + && __r->_M_size + __slen <= size_t(_S_copy_max)) + { + __result = _S_leaf_concat_char_iter((_RopeLeaf*)__r, __s, __slen); + return __result; + } + if (__detail::_S_concat == __r->_M_tag + && __detail::_S_leaf == ((_RopeConcatenation*) __r)->_M_right->_M_tag) + { + _RopeLeaf* __right = + (_RopeLeaf* )(((_RopeConcatenation* )__r)->_M_right); + if (__right->_M_size + __slen <= size_t(_S_copy_max)) + { + _RopeRep* __left = ((_RopeConcatenation*)__r)->_M_left; + _RopeRep* __nright = + _S_leaf_concat_char_iter((_RopeLeaf*)__right, __s, __slen); + __left->_M_ref_nonnil(); + __try + { __result = _S_tree_concat(__left, __nright); } + __catch(...) + { + _S_unref(__left); + _S_unref(__nright); + __throw_exception_again; + } + return __result; + } + } + _RopeRep* __nright = + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, __r->_M_get_allocator()); + __try + { + __r->_M_ref_nonnil(); + __result = _S_tree_concat(__r, __nright); + } + __catch(...) + { + _S_unref(__r); + _S_unref(__nright); + __throw_exception_again; + } + return __result; + } + +#ifndef __GC + template <class _CharT, class _Alloc> + typename rope<_CharT,_Alloc>::_RopeRep* + rope<_CharT,_Alloc>:: + _S_destr_concat_char_iter(_RopeRep* __r, const _CharT* __s, size_t __slen) + { + _RopeRep* __result; + if (0 == __r) + return __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, + __r->_M_get_allocator()); + size_t __count = __r->_M_ref_count; + size_t __orig_size = __r->_M_size; + if (__count > 1) + return _S_concat_char_iter(__r, __s, __slen); + if (0 == __slen) + { + __r->_M_ref_count = 2; // One more than before + return __r; + } + if (__orig_size + __slen <= size_t(_S_copy_max) + && __detail::_S_leaf == __r->_M_tag) + { + __result = _S_destr_leaf_concat_char_iter((_RopeLeaf*)__r, __s, + __slen); + return __result; + } + if (__detail::_S_concat == __r->_M_tag) + { + _RopeLeaf* __right = (_RopeLeaf*)(((_RopeConcatenation*) + __r)->_M_right); + if (__detail::_S_leaf == __right->_M_tag + && __right->_M_size + __slen <= size_t(_S_copy_max)) + { + _RopeRep* __new_right = + _S_destr_leaf_concat_char_iter(__right, __s, __slen); + if (__right == __new_right) + __new_right->_M_ref_count = 1; + else + __right->_M_unref_nonnil(); + __r->_M_ref_count = 2; // One more than before. + ((_RopeConcatenation*)__r)->_M_right = __new_right; + __r->_M_size = __orig_size + __slen; + if (0 != __r->_M_c_string) + { + __r->_M_free_c_string(); + __r->_M_c_string = 0; + } + return __r; + } + } + _RopeRep* __right = + __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __slen, __r->_M_get_allocator()); + __r->_M_ref_nonnil(); + __try + { __result = _S_tree_concat(__r, __right); } + __catch(...) + { + _S_unref(__r); + _S_unref(__right); + __throw_exception_again; + } + return __result; + } +#endif /* !__GC */ + + template <class _CharT, class _Alloc> + typename rope<_CharT, _Alloc>::_RopeRep* + rope<_CharT, _Alloc>:: + _S_concat(_RopeRep* __left, _RopeRep* __right) + { + if (0 == __left) + { + _S_ref(__right); + return __right; + } + if (0 == __right) + { + __left->_M_ref_nonnil(); + return __left; + } + if (__detail::_S_leaf == __right->_M_tag) + { + if (__detail::_S_leaf == __left->_M_tag) + { + if (__right->_M_size + __left->_M_size <= size_t(_S_copy_max)) + return _S_leaf_concat_char_iter((_RopeLeaf*)__left, + ((_RopeLeaf*)__right)->_M_data, + __right->_M_size); + } + else if (__detail::_S_concat == __left->_M_tag + && __detail::_S_leaf == ((_RopeConcatenation*) + __left)->_M_right->_M_tag) + { + _RopeLeaf* __leftright = + (_RopeLeaf*)(((_RopeConcatenation*)__left)->_M_right); + if (__leftright->_M_size + + __right->_M_size <= size_t(_S_copy_max)) + { + _RopeRep* __leftleft = ((_RopeConcatenation*)__left)->_M_left; + _RopeRep* __rest = _S_leaf_concat_char_iter(__leftright, + ((_RopeLeaf*) + __right)-> + _M_data, + __right->_M_size); + __leftleft->_M_ref_nonnil(); + __try + { return(_S_tree_concat(__leftleft, __rest)); } + __catch(...) + { + _S_unref(__leftleft); + _S_unref(__rest); + __throw_exception_again; + } + } + } + } + __left->_M_ref_nonnil(); + __right->_M_ref_nonnil(); + __try + { return(_S_tree_concat(__left, __right)); } + __catch(...) + { + _S_unref(__left); + _S_unref(__right); + __throw_exception_again; + } + } + + template <class _CharT, class _Alloc> + typename rope<_CharT, _Alloc>::_RopeRep* + rope<_CharT, _Alloc>:: + _S_substring(_RopeRep* __base, size_t __start, size_t __endp1) + { + if (0 == __base) + return 0; + size_t __len = __base->_M_size; + size_t __adj_endp1; + const size_t __lazy_threshold = 128; + + if (__endp1 >= __len) + { + if (0 == __start) + { + __base->_M_ref_nonnil(); + return __base; + } + else + __adj_endp1 = __len; + + } + else + __adj_endp1 = __endp1; + + switch(__base->_M_tag) + { + case __detail::_S_concat: + { + _RopeConcatenation* __c = (_RopeConcatenation*)__base; + _RopeRep* __left = __c->_M_left; + _RopeRep* __right = __c->_M_right; + size_t __left_len = __left->_M_size; + _RopeRep* __result; + + if (__adj_endp1 <= __left_len) + return _S_substring(__left, __start, __endp1); + else if (__start >= __left_len) + return _S_substring(__right, __start - __left_len, + __adj_endp1 - __left_len); + _Self_destruct_ptr __left_result(_S_substring(__left, + __start, + __left_len)); + _Self_destruct_ptr __right_result(_S_substring(__right, 0, + __endp1 + - __left_len)); + __result = _S_concat(__left_result, __right_result); + return __result; + } + case __detail::_S_leaf: + { + _RopeLeaf* __l = (_RopeLeaf*)__base; + _RopeLeaf* __result; + size_t __result_len; + if (__start >= __adj_endp1) + return 0; + __result_len = __adj_endp1 - __start; + if (__result_len > __lazy_threshold) + goto lazy; +#ifdef __GC + const _CharT* __section = __l->_M_data + __start; + __result = _S_new_RopeLeaf(__section, __result_len, + __base->_M_get_allocator()); + __result->_M_c_string = 0; // Not eos terminated. +#else + // We should sometimes create substring node instead. + __result = __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__l->_M_data + __start, + __result_len, + __base-> + _M_get_allocator()); +#endif + return __result; + } + case __detail::_S_substringfn: + // Avoid introducing multiple layers of substring nodes. + { + _RopeSubstring* __old = (_RopeSubstring*)__base; + size_t __result_len; + if (__start >= __adj_endp1) + return 0; + __result_len = __adj_endp1 - __start; + if (__result_len > __lazy_threshold) + { + _RopeSubstring* __result = + _S_new_RopeSubstring(__old->_M_base, + __start + __old->_M_start, + __adj_endp1 - __start, + __base->_M_get_allocator()); + return __result; + + } // *** else fall through: *** + } + case __detail::_S_function: + { + _RopeFunction* __f = (_RopeFunction*)__base; + _CharT* __section; + size_t __result_len; + if (__start >= __adj_endp1) + return 0; + __result_len = __adj_endp1 - __start; + + if (__result_len > __lazy_threshold) + goto lazy; + __section = (_CharT*) + rope::_Data_allocate(_S_rounded_up_size(__result_len)); + __try + { (*(__f->_M_fn))(__start, __result_len, __section); } + __catch(...) + { + _RopeRep::__STL_FREE_STRING(__section, __result_len, + __base->_M_get_allocator()); + __throw_exception_again; + } + _S_cond_store_eos(__section[__result_len]); + return _S_new_RopeLeaf(__section, __result_len, + __base->_M_get_allocator()); + } + } + lazy: + { + // Create substring node. + return _S_new_RopeSubstring(__base, __start, __adj_endp1 - __start, + __base->_M_get_allocator()); + } + } + + template<class _CharT> + class _Rope_flatten_char_consumer + : public _Rope_char_consumer<_CharT> + { + private: + _CharT* _M_buf_ptr; + public: + + _Rope_flatten_char_consumer(_CharT* __buffer) + { _M_buf_ptr = __buffer; }; + + ~_Rope_flatten_char_consumer() {} + + bool + operator()(const _CharT* __leaf, size_t __n) + { + uninitialized_copy_n(__leaf, __n, _M_buf_ptr); + _M_buf_ptr += __n; + return true; + } + }; + + template<class _CharT> + class _Rope_find_char_char_consumer + : public _Rope_char_consumer<_CharT> + { + private: + _CharT _M_pattern; + public: + size_t _M_count; // Number of nonmatching characters + + _Rope_find_char_char_consumer(_CharT __p) + : _M_pattern(__p), _M_count(0) {} + + ~_Rope_find_char_char_consumer() {} + + bool + operator()(const _CharT* __leaf, size_t __n) + { + size_t __i; + for (__i = 0; __i < __n; __i++) + { + if (__leaf[__i] == _M_pattern) + { + _M_count += __i; + return false; + } + } + _M_count += __n; return true; + } + }; + + template<class _CharT, class _Traits> + // Here _CharT is both the stream and rope character type. + class _Rope_insert_char_consumer + : public _Rope_char_consumer<_CharT> + { + private: + typedef basic_ostream<_CharT,_Traits> _Insert_ostream; + _Insert_ostream& _M_o; + public: + _Rope_insert_char_consumer(_Insert_ostream& __writer) + : _M_o(__writer) {}; + ~_Rope_insert_char_consumer() { }; + // Caller is presumed to own the ostream + bool operator() (const _CharT* __leaf, size_t __n); + // Returns true to continue traversal. + }; + + template<class _CharT, class _Traits> + bool + _Rope_insert_char_consumer<_CharT, _Traits>:: + operator()(const _CharT* __leaf, size_t __n) + { + size_t __i; + // We assume that formatting is set up correctly for each element. + for (__i = 0; __i < __n; __i++) + _M_o.put(__leaf[__i]); + return true; + } + + template <class _CharT, class _Alloc> + bool + rope<_CharT, _Alloc>:: + _S_apply_to_pieces(_Rope_char_consumer<_CharT>& __c, + const _RopeRep* __r, size_t __begin, size_t __end) + { + if (0 == __r) + return true; + switch(__r->_M_tag) + { + case __detail::_S_concat: + { + _RopeConcatenation* __conc = (_RopeConcatenation*)__r; + _RopeRep* __left = __conc->_M_left; + size_t __left_len = __left->_M_size; + if (__begin < __left_len) + { + size_t __left_end = std::min(__left_len, __end); + if (!_S_apply_to_pieces(__c, __left, __begin, __left_end)) + return false; + } + if (__end > __left_len) + { + _RopeRep* __right = __conc->_M_right; + size_t __right_start = std::max(__left_len, __begin); + if (!_S_apply_to_pieces(__c, __right, + __right_start - __left_len, + __end - __left_len)) + return false; + } + } + return true; + case __detail::_S_leaf: + { + _RopeLeaf* __l = (_RopeLeaf*)__r; + return __c(__l->_M_data + __begin, __end - __begin); + } + case __detail::_S_function: + case __detail::_S_substringfn: + { + _RopeFunction* __f = (_RopeFunction*)__r; + size_t __len = __end - __begin; + bool __result; + _CharT* __buffer = + (_CharT*)_Alloc().allocate(__len * sizeof(_CharT)); + __try + { + (*(__f->_M_fn))(__begin, __len, __buffer); + __result = __c(__buffer, __len); + _Alloc().deallocate(__buffer, __len * sizeof(_CharT)); + } + __catch(...) + { + _Alloc().deallocate(__buffer, __len * sizeof(_CharT)); + __throw_exception_again; + } + return __result; + } + default: + return false; + } + } + + template<class _CharT, class _Traits> + inline void + _Rope_fill(basic_ostream<_CharT, _Traits>& __o, size_t __n) + { + char __f = __o.fill(); + size_t __i; + + for (__i = 0; __i < __n; __i++) + __o.put(__f); + } + + + template <class _CharT> + inline bool + _Rope_is_simple(_CharT*) + { return false; } + + inline bool + _Rope_is_simple(char*) + { return true; } + + inline bool + _Rope_is_simple(wchar_t*) + { return true; } + + template<class _CharT, class _Traits, class _Alloc> + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __o, + const rope<_CharT, _Alloc>& __r) + { + size_t __w = __o.width(); + bool __left = bool(__o.flags() & std::ios::left); + size_t __pad_len; + size_t __rope_len = __r.size(); + _Rope_insert_char_consumer<_CharT, _Traits> __c(__o); + bool __is_simple = _Rope_is_simple((_CharT*)0); + + if (__rope_len < __w) + __pad_len = __w - __rope_len; + else + __pad_len = 0; + + if (!__is_simple) + __o.width(__w / __rope_len); + __try + { + if (__is_simple && !__left && __pad_len > 0) + _Rope_fill(__o, __pad_len); + __r.apply_to_pieces(0, __r.size(), __c); + if (__is_simple && __left && __pad_len > 0) + _Rope_fill(__o, __pad_len); + if (!__is_simple) + __o.width(__w); + } + __catch(...) + { + if (!__is_simple) + __o.width(__w); + __throw_exception_again; + } + return __o; + } + + template <class _CharT, class _Alloc> + _CharT* + rope<_CharT, _Alloc>:: + _S_flatten(_RopeRep* __r, size_t __start, size_t __len, + _CharT* __buffer) + { + _Rope_flatten_char_consumer<_CharT> __c(__buffer); + _S_apply_to_pieces(__c, __r, __start, __start + __len); + return(__buffer + __len); + } + + template <class _CharT, class _Alloc> + size_t + rope<_CharT, _Alloc>:: + find(_CharT __pattern, size_t __start) const + { + _Rope_find_char_char_consumer<_CharT> __c(__pattern); + _S_apply_to_pieces(__c, this->_M_tree_ptr, __start, size()); + size_type __result_pos = __start + __c._M_count; +#ifndef __STL_OLD_ROPE_SEMANTICS + if (__result_pos == size()) + __result_pos = npos; +#endif + return __result_pos; + } + + template <class _CharT, class _Alloc> + _CharT* + rope<_CharT, _Alloc>:: + _S_flatten(_RopeRep* __r, _CharT* __buffer) + { + if (0 == __r) + return __buffer; + switch(__r->_M_tag) + { + case __detail::_S_concat: + { + _RopeConcatenation* __c = (_RopeConcatenation*)__r; + _RopeRep* __left = __c->_M_left; + _RopeRep* __right = __c->_M_right; + _CharT* __rest = _S_flatten(__left, __buffer); + return _S_flatten(__right, __rest); + } + case __detail::_S_leaf: + { + _RopeLeaf* __l = (_RopeLeaf*)__r; + return copy_n(__l->_M_data, __l->_M_size, __buffer).second; + } + case __detail::_S_function: + case __detail::_S_substringfn: + // We don't yet do anything with substring nodes. + // This needs to be fixed before ropefiles will work well. + { + _RopeFunction* __f = (_RopeFunction*)__r; + (*(__f->_M_fn))(0, __f->_M_size, __buffer); + return __buffer + __f->_M_size; + } + default: + return 0; + } + } + + // This needs work for _CharT != char + template <class _CharT, class _Alloc> + void + rope<_CharT, _Alloc>:: + _S_dump(_RopeRep* __r, int __indent) + { + for (int __i = 0; __i < __indent; __i++) + putchar(' '); + if (0 == __r) + { + printf("NULL\n"); + return; + } + if (_S_concat == __r->_M_tag) + { + _RopeConcatenation* __c = (_RopeConcatenation*)__r; + _RopeRep* __left = __c->_M_left; + _RopeRep* __right = __c->_M_right; + +#ifdef __GC + printf("Concatenation %p (depth = %d, len = %ld, %s balanced)\n", + __r, __r->_M_depth, __r->_M_size, + __r->_M_is_balanced? "" : "not"); +#else + printf("Concatenation %p (rc = %ld, depth = %d, " + "len = %ld, %s balanced)\n", + __r, __r->_M_ref_count, __r->_M_depth, __r->_M_size, + __r->_M_is_balanced? "" : "not"); +#endif + _S_dump(__left, __indent + 2); + _S_dump(__right, __indent + 2); + return; + } + else + { + char* __kind; + + switch (__r->_M_tag) + { + case __detail::_S_leaf: + __kind = "Leaf"; + break; + case __detail::_S_function: + __kind = "Function"; + break; + case __detail::_S_substringfn: + __kind = "Function representing substring"; + break; + default: + __kind = "(corrupted kind field!)"; + } +#ifdef __GC + printf("%s %p (depth = %d, len = %ld) ", + __kind, __r, __r->_M_depth, __r->_M_size); +#else + printf("%s %p (rc = %ld, depth = %d, len = %ld) ", + __kind, __r, __r->_M_ref_count, __r->_M_depth, __r->_M_size); +#endif + if (_S_is_one_byte_char_type((_CharT*)0)) + { + const int __max_len = 40; + _Self_destruct_ptr __prefix(_S_substring(__r, 0, __max_len)); + _CharT __buffer[__max_len + 1]; + bool __too_big = __r->_M_size > __prefix->_M_size; + + _S_flatten(__prefix, __buffer); + __buffer[__prefix->_M_size] = _S_eos((_CharT*)0); + printf("%s%s\n", (char*)__buffer, + __too_big? "...\n" : "\n"); + } + else + printf("\n"); + } + } + + template <class _CharT, class _Alloc> + const unsigned long + rope<_CharT, _Alloc>:: + _S_min_len[int(__detail::_S_max_rope_depth) + 1] = { + /* 0 */1, /* 1 */2, /* 2 */3, /* 3 */5, /* 4 */8, /* 5 */13, /* 6 */21, + /* 7 */34, /* 8 */55, /* 9 */89, /* 10 */144, /* 11 */233, /* 12 */377, + /* 13 */610, /* 14 */987, /* 15 */1597, /* 16 */2584, /* 17 */4181, + /* 18 */6765, /* 19 */10946, /* 20 */17711, /* 21 */28657, /* 22 */46368, + /* 23 */75025, /* 24 */121393, /* 25 */196418, /* 26 */317811, + /* 27 */514229, /* 28 */832040, /* 29 */1346269, /* 30 */2178309, + /* 31 */3524578, /* 32 */5702887, /* 33 */9227465, /* 34 */14930352, + /* 35 */24157817, /* 36 */39088169, /* 37 */63245986, /* 38 */102334155, + /* 39 */165580141, /* 40 */267914296, /* 41 */433494437, + /* 42 */701408733, /* 43 */1134903170, /* 44 */1836311903, + /* 45 */2971215073u }; + // These are Fibonacci numbers < 2**32. + + template <class _CharT, class _Alloc> + typename rope<_CharT, _Alloc>::_RopeRep* + rope<_CharT, _Alloc>:: + _S_balance(_RopeRep* __r) + { + _RopeRep* __forest[int(__detail::_S_max_rope_depth) + 1]; + _RopeRep* __result = 0; + int __i; + // Invariant: + // The concatenation of forest in descending order is equal to __r. + // __forest[__i]._M_size >= _S_min_len[__i] + // __forest[__i]._M_depth = __i + // References from forest are included in refcount. + + for (__i = 0; __i <= int(__detail::_S_max_rope_depth); ++__i) + __forest[__i] = 0; + __try + { + _S_add_to_forest(__r, __forest); + for (__i = 0; __i <= int(__detail::_S_max_rope_depth); ++__i) + if (0 != __forest[__i]) + { +#ifndef __GC + _Self_destruct_ptr __old(__result); +#endif + __result = _S_concat(__forest[__i], __result); + __forest[__i]->_M_unref_nonnil(); +#if !defined(__GC) && defined(__EXCEPTIONS) + __forest[__i] = 0; +#endif + } + } + __catch(...) + { + for(__i = 0; __i <= int(__detail::_S_max_rope_depth); __i++) + _S_unref(__forest[__i]); + __throw_exception_again; + } + + if (__result->_M_depth > int(__detail::_S_max_rope_depth)) + __throw_length_error(__N("rope::_S_balance")); + return(__result); + } + + template <class _CharT, class _Alloc> + void + rope<_CharT, _Alloc>:: + _S_add_to_forest(_RopeRep* __r, _RopeRep** __forest) + { + if (__r->_M_is_balanced) + { + _S_add_leaf_to_forest(__r, __forest); + return; + } + + { + _RopeConcatenation* __c = (_RopeConcatenation*)__r; + + _S_add_to_forest(__c->_M_left, __forest); + _S_add_to_forest(__c->_M_right, __forest); + } + } + + + template <class _CharT, class _Alloc> + void + rope<_CharT, _Alloc>:: + _S_add_leaf_to_forest(_RopeRep* __r, _RopeRep** __forest) + { + _RopeRep* __insertee; // included in refcount + _RopeRep* __too_tiny = 0; // included in refcount + int __i; // forest[0..__i-1] is empty + size_t __s = __r->_M_size; + + for (__i = 0; __s >= _S_min_len[__i+1]/* not this bucket */; ++__i) + { + if (0 != __forest[__i]) + { +#ifndef __GC + _Self_destruct_ptr __old(__too_tiny); +#endif + __too_tiny = _S_concat_and_set_balanced(__forest[__i], + __too_tiny); + __forest[__i]->_M_unref_nonnil(); + __forest[__i] = 0; + } + } + { +#ifndef __GC + _Self_destruct_ptr __old(__too_tiny); +#endif + __insertee = _S_concat_and_set_balanced(__too_tiny, __r); + } + // Too_tiny dead, and no longer included in refcount. + // Insertee is live and included. + for (;; ++__i) + { + if (0 != __forest[__i]) + { +#ifndef __GC + _Self_destruct_ptr __old(__insertee); +#endif + __insertee = _S_concat_and_set_balanced(__forest[__i], + __insertee); + __forest[__i]->_M_unref_nonnil(); + __forest[__i] = 0; + } + if (__i == int(__detail::_S_max_rope_depth) + || __insertee->_M_size < _S_min_len[__i+1]) + { + __forest[__i] = __insertee; + // refcount is OK since __insertee is now dead. + return; + } + } + } + + template <class _CharT, class _Alloc> + _CharT + rope<_CharT, _Alloc>:: + _S_fetch(_RopeRep* __r, size_type __i) + { + __GC_CONST _CharT* __cstr = __r->_M_c_string; + + if (0 != __cstr) + return __cstr[__i]; + for(;;) + { + switch(__r->_M_tag) + { + case __detail::_S_concat: + { + _RopeConcatenation* __c = (_RopeConcatenation*)__r; + _RopeRep* __left = __c->_M_left; + size_t __left_len = __left->_M_size; + + if (__i >= __left_len) + { + __i -= __left_len; + __r = __c->_M_right; + } + else + __r = __left; + } + break; + case __detail::_S_leaf: + { + _RopeLeaf* __l = (_RopeLeaf*)__r; + return __l->_M_data[__i]; + } + case __detail::_S_function: + case __detail::_S_substringfn: + { + _RopeFunction* __f = (_RopeFunction*)__r; + _CharT __result; + + (*(__f->_M_fn))(__i, 1, &__result); + return __result; + } + } + } + } + +#ifndef __GC + // Return a uniquely referenced character slot for the given + // position, or 0 if that's not possible. + template <class _CharT, class _Alloc> + _CharT* + rope<_CharT, _Alloc>:: + _S_fetch_ptr(_RopeRep* __r, size_type __i) + { + _RopeRep* __clrstack[__detail::_S_max_rope_depth]; + size_t __csptr = 0; + + for(;;) + { + if (__r->_M_ref_count > 1) + return 0; + switch(__r->_M_tag) + { + case __detail::_S_concat: + { + _RopeConcatenation* __c = (_RopeConcatenation*)__r; + _RopeRep* __left = __c->_M_left; + size_t __left_len = __left->_M_size; + + if (__c->_M_c_string != 0) + __clrstack[__csptr++] = __c; + if (__i >= __left_len) + { + __i -= __left_len; + __r = __c->_M_right; + } + else + __r = __left; + } + break; + case __detail::_S_leaf: + { + _RopeLeaf* __l = (_RopeLeaf*)__r; + if (__l->_M_c_string != __l->_M_data && __l->_M_c_string != 0) + __clrstack[__csptr++] = __l; + while (__csptr > 0) + { + -- __csptr; + _RopeRep* __d = __clrstack[__csptr]; + __d->_M_free_c_string(); + __d->_M_c_string = 0; + } + return __l->_M_data + __i; + } + case __detail::_S_function: + case __detail::_S_substringfn: + return 0; + } + } + } +#endif /* __GC */ + + // The following could be implemented trivially using + // lexicographical_compare_3way. + // We do a little more work to avoid dealing with rope iterators for + // flat strings. + template <class _CharT, class _Alloc> + int + rope<_CharT, _Alloc>:: + _S_compare (const _RopeRep* __left, const _RopeRep* __right) + { + size_t __left_len; + size_t __right_len; + + if (0 == __right) + return 0 != __left; + if (0 == __left) + return -1; + __left_len = __left->_M_size; + __right_len = __right->_M_size; + if (__detail::_S_leaf == __left->_M_tag) + { + _RopeLeaf* __l = (_RopeLeaf*) __left; + if (__detail::_S_leaf == __right->_M_tag) + { + _RopeLeaf* __r = (_RopeLeaf*) __right; + return lexicographical_compare_3way(__l->_M_data, + __l->_M_data + __left_len, + __r->_M_data, __r->_M_data + + __right_len); + } + else + { + const_iterator __rstart(__right, 0); + const_iterator __rend(__right, __right_len); + return lexicographical_compare_3way(__l->_M_data, __l->_M_data + + __left_len, + __rstart, __rend); + } + } + else + { + const_iterator __lstart(__left, 0); + const_iterator __lend(__left, __left_len); + if (__detail::_S_leaf == __right->_M_tag) + { + _RopeLeaf* __r = (_RopeLeaf*) __right; + return lexicographical_compare_3way(__lstart, __lend, + __r->_M_data, __r->_M_data + + __right_len); + } + else + { + const_iterator __rstart(__right, 0); + const_iterator __rend(__right, __right_len); + return lexicographical_compare_3way(__lstart, __lend, + __rstart, __rend); + } + } + } + + // Assignment to reference proxies. + template <class _CharT, class _Alloc> + _Rope_char_ref_proxy<_CharT, _Alloc>& + _Rope_char_ref_proxy<_CharT, _Alloc>:: + operator=(_CharT __c) + { + _RopeRep* __old = _M_root->_M_tree_ptr; +#ifndef __GC + // First check for the case in which everything is uniquely + // referenced. In that case we can do this destructively. + _CharT* __ptr = _My_rope::_S_fetch_ptr(__old, _M_pos); + if (0 != __ptr) + { + *__ptr = __c; + return *this; + } +#endif + _Self_destruct_ptr __left(_My_rope::_S_substring(__old, 0, _M_pos)); + _Self_destruct_ptr __right(_My_rope::_S_substring(__old, _M_pos + 1, + __old->_M_size)); + _Self_destruct_ptr __result_left(_My_rope:: + _S_destr_concat_char_iter(__left, + &__c, 1)); + + _RopeRep* __result = _My_rope::_S_concat(__result_left, __right); +#ifndef __GC + _RopeRep::_S_unref(__old); +#endif + _M_root->_M_tree_ptr = __result; + return *this; + } + + template <class _CharT, class _Alloc> + inline _Rope_char_ref_proxy<_CharT, _Alloc>:: + operator _CharT() const + { + if (_M_current_valid) + return _M_current; + else + return _My_rope::_S_fetch(_M_root->_M_tree_ptr, _M_pos); + } + + template <class _CharT, class _Alloc> + _Rope_char_ptr_proxy<_CharT, _Alloc> + _Rope_char_ref_proxy<_CharT, _Alloc>:: + operator&() const + { return _Rope_char_ptr_proxy<_CharT, _Alloc>(*this); } + + template <class _CharT, class _Alloc> + rope<_CharT, _Alloc>:: + rope(size_t __n, _CharT __c, const allocator_type& __a) + : _Base(__a) + { + rope<_CharT,_Alloc> __result; + const size_t __exponentiate_threshold = 32; + size_t __exponent; + size_t __rest; + _CharT* __rest_buffer; + _RopeRep* __remainder; + rope<_CharT, _Alloc> __remainder_rope; + + if (0 == __n) + return; + + __exponent = __n / __exponentiate_threshold; + __rest = __n % __exponentiate_threshold; + if (0 == __rest) + __remainder = 0; + else + { + __rest_buffer = this->_Data_allocate(_S_rounded_up_size(__rest)); + __uninitialized_fill_n_a(__rest_buffer, __rest, __c, + _M_get_allocator()); + _S_cond_store_eos(__rest_buffer[__rest]); + __try + { __remainder = _S_new_RopeLeaf(__rest_buffer, __rest, + _M_get_allocator()); } + __catch(...) + { + _RopeRep::__STL_FREE_STRING(__rest_buffer, __rest, + _M_get_allocator()); + __throw_exception_again; + } + } + __remainder_rope._M_tree_ptr = __remainder; + if (__exponent != 0) + { + _CharT* __base_buffer = + this->_Data_allocate(_S_rounded_up_size(__exponentiate_threshold)); + _RopeLeaf* __base_leaf; + rope __base_rope; + __uninitialized_fill_n_a(__base_buffer, __exponentiate_threshold, __c, + _M_get_allocator()); + _S_cond_store_eos(__base_buffer[__exponentiate_threshold]); + __try + { + __base_leaf = _S_new_RopeLeaf(__base_buffer, + __exponentiate_threshold, + _M_get_allocator()); + } + __catch(...) + { + _RopeRep::__STL_FREE_STRING(__base_buffer, + __exponentiate_threshold, + _M_get_allocator()); + __throw_exception_again; + } + __base_rope._M_tree_ptr = __base_leaf; + if (1 == __exponent) + __result = __base_rope; + else + __result = power(__base_rope, __exponent, + _Rope_Concat_fn<_CharT, _Alloc>()); + + if (0 != __remainder) + __result += __remainder_rope; + } + else + __result = __remainder_rope; + + this->_M_tree_ptr = __result._M_tree_ptr; + this->_M_tree_ptr->_M_ref_nonnil(); + } + + template<class _CharT, class _Alloc> + _CharT + rope<_CharT, _Alloc>::_S_empty_c_str[1]; + + template<class _CharT, class _Alloc> + const _CharT* + rope<_CharT, _Alloc>:: + c_str() const + { + if (0 == this->_M_tree_ptr) + { + _S_empty_c_str[0] = _S_eos((_CharT*)0); // Possibly redundant, + // but probably fast. + return _S_empty_c_str; + } + __gthread_mutex_lock (&this->_M_tree_ptr->_M_c_string_lock); + __GC_CONST _CharT* __result = this->_M_tree_ptr->_M_c_string; + if (0 == __result) + { + size_t __s = size(); + __result = this->_Data_allocate(__s + 1); + _S_flatten(this->_M_tree_ptr, __result); + __result[__s] = _S_eos((_CharT*)0); + this->_M_tree_ptr->_M_c_string = __result; + } + __gthread_mutex_unlock (&this->_M_tree_ptr->_M_c_string_lock); + return(__result); + } + + template<class _CharT, class _Alloc> + const _CharT* rope<_CharT, _Alloc>:: + replace_with_c_str() + { + if (0 == this->_M_tree_ptr) + { + _S_empty_c_str[0] = _S_eos((_CharT*)0); + return _S_empty_c_str; + } + __GC_CONST _CharT* __old_c_string = this->_M_tree_ptr->_M_c_string; + if (__detail::_S_leaf == this->_M_tree_ptr->_M_tag + && 0 != __old_c_string) + return(__old_c_string); + size_t __s = size(); + _CharT* __result = this->_Data_allocate(_S_rounded_up_size(__s)); + _S_flatten(this->_M_tree_ptr, __result); + __result[__s] = _S_eos((_CharT*)0); + this->_M_tree_ptr->_M_unref_nonnil(); + this->_M_tree_ptr = _S_new_RopeLeaf(__result, __s, + this->_M_get_allocator()); + return(__result); + } + + // Algorithm specializations. More should be added. + + template<class _Rope_iterator> // was templated on CharT and Alloc + void // VC++ workaround + _Rope_rotate(_Rope_iterator __first, + _Rope_iterator __middle, + _Rope_iterator __last) + { + typedef typename _Rope_iterator::value_type _CharT; + typedef typename _Rope_iterator::_allocator_type _Alloc; + + rope<_CharT, _Alloc>& __r(__first.container()); + rope<_CharT, _Alloc> __prefix = __r.substr(0, __first.index()); + rope<_CharT, _Alloc> __suffix = + __r.substr(__last.index(), __r.size() - __last.index()); + rope<_CharT, _Alloc> __part1 = + __r.substr(__middle.index(), __last.index() - __middle.index()); + rope<_CharT, _Alloc> __part2 = + __r.substr(__first.index(), __middle.index() - __first.index()); + __r = __prefix; + __r += __part1; + __r += __part2; + __r += __suffix; + } + +#if !defined(__GNUC__) + // Appears to confuse g++ + inline void + rotate(_Rope_iterator<char, __STL_DEFAULT_ALLOCATOR(char)> __first, + _Rope_iterator<char, __STL_DEFAULT_ALLOCATOR(char)> __middle, + _Rope_iterator<char, __STL_DEFAULT_ALLOCATOR(char)> __last) + { _Rope_rotate(__first, __middle, __last); } +#endif + +# if 0 + // Probably not useful for several reasons: + // - for SGIs 7.1 compiler and probably some others, + // this forces lots of rope<wchar_t, ...> instantiations, creating a + // code bloat and compile time problem. (Fixed in 7.2.) + // - wchar_t is 4 bytes wide on most UNIX platforms, making it + // unattractive for unicode strings. Unsigned short may be a better + // character type. + inline void + rotate(_Rope_iterator<wchar_t, __STL_DEFAULT_ALLOCATOR(char)> __first, + _Rope_iterator<wchar_t, __STL_DEFAULT_ALLOCATOR(char)> __middle, + _Rope_iterator<wchar_t, __STL_DEFAULT_ALLOCATOR(char)> __last) + { _Rope_rotate(__first, __middle, __last); } +# endif + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/gcc-4.9/libstdc++-v3/include/ext/slist b/gcc-4.9/libstdc++-v3/include/ext/slist new file mode 100644 index 0000000..5ef18ad --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/slist @@ -0,0 +1,1082 @@ +// Singly-linked list implementation -*- C++ -*- + +// Copyright (C) 2001-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/* + * Copyright (c) 1997 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +/** @file ext/slist + * This file is a GNU extension to the Standard C++ Library (possibly + * containing extensions from the HP/SGI STL subset). + */ + +#ifndef _SLIST +#define _SLIST 1 + +#include <algorithm> +#include <bits/allocator.h> +#include <bits/stl_construct.h> +#include <bits/stl_uninitialized.h> +#include <bits/concept_check.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + using std::size_t; + using std::ptrdiff_t; + using std::_Construct; + using std::_Destroy; + using std::allocator; + using std::__true_type; + using std::__false_type; + + struct _Slist_node_base + { + _Slist_node_base* _M_next; + }; + + inline _Slist_node_base* + __slist_make_link(_Slist_node_base* __prev_node, + _Slist_node_base* __new_node) + { + __new_node->_M_next = __prev_node->_M_next; + __prev_node->_M_next = __new_node; + return __new_node; + } + + inline _Slist_node_base* + __slist_previous(_Slist_node_base* __head, + const _Slist_node_base* __node) + { + while (__head && __head->_M_next != __node) + __head = __head->_M_next; + return __head; + } + + inline const _Slist_node_base* + __slist_previous(const _Slist_node_base* __head, + const _Slist_node_base* __node) + { + while (__head && __head->_M_next != __node) + __head = __head->_M_next; + return __head; + } + + inline void + __slist_splice_after(_Slist_node_base* __pos, + _Slist_node_base* __before_first, + _Slist_node_base* __before_last) + { + if (__pos != __before_first && __pos != __before_last) + { + _Slist_node_base* __first = __before_first->_M_next; + _Slist_node_base* __after = __pos->_M_next; + __before_first->_M_next = __before_last->_M_next; + __pos->_M_next = __first; + __before_last->_M_next = __after; + } + } + + inline void + __slist_splice_after(_Slist_node_base* __pos, _Slist_node_base* __head) + { + _Slist_node_base* __before_last = __slist_previous(__head, 0); + if (__before_last != __head) + { + _Slist_node_base* __after = __pos->_M_next; + __pos->_M_next = __head->_M_next; + __head->_M_next = 0; + __before_last->_M_next = __after; + } + } + + inline _Slist_node_base* + __slist_reverse(_Slist_node_base* __node) + { + _Slist_node_base* __result = __node; + __node = __node->_M_next; + __result->_M_next = 0; + while(__node) + { + _Slist_node_base* __next = __node->_M_next; + __node->_M_next = __result; + __result = __node; + __node = __next; + } + return __result; + } + + inline size_t + __slist_size(_Slist_node_base* __node) + { + size_t __result = 0; + for (; __node != 0; __node = __node->_M_next) + ++__result; + return __result; + } + + template <class _Tp> + struct _Slist_node : public _Slist_node_base + { + _Tp _M_data; + }; + + struct _Slist_iterator_base + { + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef std::forward_iterator_tag iterator_category; + + _Slist_node_base* _M_node; + + _Slist_iterator_base(_Slist_node_base* __x) + : _M_node(__x) {} + + void + _M_incr() + { _M_node = _M_node->_M_next; } + + bool + operator==(const _Slist_iterator_base& __x) const + { return _M_node == __x._M_node; } + + bool + operator!=(const _Slist_iterator_base& __x) const + { return _M_node != __x._M_node; } + }; + + template <class _Tp, class _Ref, class _Ptr> + struct _Slist_iterator : public _Slist_iterator_base + { + typedef _Slist_iterator<_Tp, _Tp&, _Tp*> iterator; + typedef _Slist_iterator<_Tp, const _Tp&, const _Tp*> const_iterator; + typedef _Slist_iterator<_Tp, _Ref, _Ptr> _Self; + + typedef _Tp value_type; + typedef _Ptr pointer; + typedef _Ref reference; + typedef _Slist_node<_Tp> _Node; + + explicit + _Slist_iterator(_Node* __x) + : _Slist_iterator_base(__x) {} + + _Slist_iterator() + : _Slist_iterator_base(0) {} + + _Slist_iterator(const iterator& __x) + : _Slist_iterator_base(__x._M_node) {} + + reference + operator*() const + { return ((_Node*) _M_node)->_M_data; } + + pointer + operator->() const + { return &(operator*()); } + + _Self& + operator++() + { + _M_incr(); + return *this; + } + + _Self + operator++(int) + { + _Self __tmp = *this; + _M_incr(); + return __tmp; + } + }; + + template <class _Tp, class _Alloc> + struct _Slist_base + : public _Alloc::template rebind<_Slist_node<_Tp> >::other + { + typedef typename _Alloc::template rebind<_Slist_node<_Tp> >::other + _Node_alloc; + typedef _Alloc allocator_type; + + allocator_type + get_allocator() const + { return *static_cast<const _Node_alloc*>(this); } + + _Slist_base(const allocator_type& __a) + : _Node_alloc(__a) + { this->_M_head._M_next = 0; } + + ~_Slist_base() + { _M_erase_after(&this->_M_head, 0); } + + protected: + _Slist_node_base _M_head; + + _Slist_node<_Tp>* + _M_get_node() + { return _Node_alloc::allocate(1); } + + void + _M_put_node(_Slist_node<_Tp>* __p) + { _Node_alloc::deallocate(__p, 1); } + + protected: + _Slist_node_base* _M_erase_after(_Slist_node_base* __pos) + { + _Slist_node<_Tp>* __next = (_Slist_node<_Tp>*) (__pos->_M_next); + _Slist_node_base* __next_next = __next->_M_next; + __pos->_M_next = __next_next; + get_allocator().destroy(&__next->_M_data); + _M_put_node(__next); + return __next_next; + } + _Slist_node_base* _M_erase_after(_Slist_node_base*, _Slist_node_base*); + }; + + template <class _Tp, class _Alloc> + _Slist_node_base* + _Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first, + _Slist_node_base* __last_node) + { + _Slist_node<_Tp>* __cur = (_Slist_node<_Tp>*) (__before_first->_M_next); + while (__cur != __last_node) + { + _Slist_node<_Tp>* __tmp = __cur; + __cur = (_Slist_node<_Tp>*) __cur->_M_next; + get_allocator().destroy(&__tmp->_M_data); + _M_put_node(__tmp); + } + __before_first->_M_next = __last_node; + return __last_node; + } + + /** + * This is an SGI extension. + * @ingroup SGIextensions + * @doctodo + */ + template <class _Tp, class _Alloc = allocator<_Tp> > + class slist : private _Slist_base<_Tp,_Alloc> + { + // concept requirements + __glibcxx_class_requires(_Tp, _SGIAssignableConcept) + + private: + typedef _Slist_base<_Tp,_Alloc> _Base; + + public: + typedef _Tp value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + typedef _Slist_iterator<_Tp, _Tp&, _Tp*> iterator; + typedef _Slist_iterator<_Tp, const _Tp&, const _Tp*> const_iterator; + + typedef typename _Base::allocator_type allocator_type; + + allocator_type + get_allocator() const + { return _Base::get_allocator(); } + + private: + typedef _Slist_node<_Tp> _Node; + typedef _Slist_node_base _Node_base; + typedef _Slist_iterator_base _Iterator_base; + + _Node* + _M_create_node(const value_type& __x) + { + _Node* __node = this->_M_get_node(); + __try + { + get_allocator().construct(&__node->_M_data, __x); + __node->_M_next = 0; + } + __catch(...) + { + this->_M_put_node(__node); + __throw_exception_again; + } + return __node; + } + + _Node* + _M_create_node() + { + _Node* __node = this->_M_get_node(); + __try + { + get_allocator().construct(&__node->_M_data, value_type()); + __node->_M_next = 0; + } + __catch(...) + { + this->_M_put_node(__node); + __throw_exception_again; + } + return __node; + } + + public: + explicit + slist(const allocator_type& __a = allocator_type()) + : _Base(__a) {} + + slist(size_type __n, const value_type& __x, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { _M_insert_after_fill(&this->_M_head, __n, __x); } + + explicit + slist(size_type __n) + : _Base(allocator_type()) + { _M_insert_after_fill(&this->_M_head, __n, value_type()); } + + // We don't need any dispatching tricks here, because + // _M_insert_after_range already does them. + template <class _InputIterator> + slist(_InputIterator __first, _InputIterator __last, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { _M_insert_after_range(&this->_M_head, __first, __last); } + + slist(const slist& __x) + : _Base(__x.get_allocator()) + { _M_insert_after_range(&this->_M_head, __x.begin(), __x.end()); } + + slist& + operator= (const slist& __x); + + ~slist() {} + + public: + // assign(), a generalized assignment member function. Two + // versions: one that takes a count, and one that takes a range. + // The range version is a member template, so we dispatch on whether + // or not the type is an integer. + + void + assign(size_type __n, const _Tp& __val) + { _M_fill_assign(__n, __val); } + + void + _M_fill_assign(size_type __n, const _Tp& __val); + + template <class _InputIterator> + void + assign(_InputIterator __first, _InputIterator __last) + { + typedef typename std::__is_integer<_InputIterator>::__type _Integral; + _M_assign_dispatch(__first, __last, _Integral()); + } + + template <class _Integer> + void + _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) + { _M_fill_assign((size_type) __n, (_Tp) __val); } + + template <class _InputIterator> + void + _M_assign_dispatch(_InputIterator __first, _InputIterator __last, + __false_type); + + public: + + iterator + begin() + { return iterator((_Node*)this->_M_head._M_next); } + + const_iterator + begin() const + { return const_iterator((_Node*)this->_M_head._M_next);} + + iterator + end() + { return iterator(0); } + + const_iterator + end() const + { return const_iterator(0); } + + // Experimental new feature: before_begin() returns a + // non-dereferenceable iterator that, when incremented, yields + // begin(). This iterator may be used as the argument to + // insert_after, erase_after, etc. Note that even for an empty + // slist, before_begin() is not the same iterator as end(). It + // is always necessary to increment before_begin() at least once to + // obtain end(). + iterator + before_begin() + { return iterator((_Node*) &this->_M_head); } + + const_iterator + before_begin() const + { return const_iterator((_Node*) &this->_M_head); } + + size_type + size() const + { return __slist_size(this->_M_head._M_next); } + + size_type + max_size() const + { return size_type(-1); } + + bool + empty() const + { return this->_M_head._M_next == 0; } + + void + swap(slist& __x) + { std::swap(this->_M_head._M_next, __x._M_head._M_next); } + + public: + + reference + front() + { return ((_Node*) this->_M_head._M_next)->_M_data; } + + const_reference + front() const + { return ((_Node*) this->_M_head._M_next)->_M_data; } + + void + push_front(const value_type& __x) + { __slist_make_link(&this->_M_head, _M_create_node(__x)); } + + void + push_front() + { __slist_make_link(&this->_M_head, _M_create_node()); } + + void + pop_front() + { + _Node* __node = (_Node*) this->_M_head._M_next; + this->_M_head._M_next = __node->_M_next; + get_allocator().destroy(&__node->_M_data); + this->_M_put_node(__node); + } + + iterator + previous(const_iterator __pos) + { return iterator((_Node*) __slist_previous(&this->_M_head, + __pos._M_node)); } + + const_iterator + previous(const_iterator __pos) const + { return const_iterator((_Node*) __slist_previous(&this->_M_head, + __pos._M_node)); } + + private: + _Node* + _M_insert_after(_Node_base* __pos, const value_type& __x) + { return (_Node*) (__slist_make_link(__pos, _M_create_node(__x))); } + + _Node* + _M_insert_after(_Node_base* __pos) + { return (_Node*) (__slist_make_link(__pos, _M_create_node())); } + + void + _M_insert_after_fill(_Node_base* __pos, + size_type __n, const value_type& __x) + { + for (size_type __i = 0; __i < __n; ++__i) + __pos = __slist_make_link(__pos, _M_create_node(__x)); + } + + // Check whether it's an integral type. If so, it's not an iterator. + template <class _InIterator> + void + _M_insert_after_range(_Node_base* __pos, + _InIterator __first, _InIterator __last) + { + typedef typename std::__is_integer<_InIterator>::__type _Integral; + _M_insert_after_range(__pos, __first, __last, _Integral()); + } + + template <class _Integer> + void + _M_insert_after_range(_Node_base* __pos, _Integer __n, _Integer __x, + __true_type) + { _M_insert_after_fill(__pos, __n, __x); } + + template <class _InIterator> + void + _M_insert_after_range(_Node_base* __pos, + _InIterator __first, _InIterator __last, + __false_type) + { + while (__first != __last) + { + __pos = __slist_make_link(__pos, _M_create_node(*__first)); + ++__first; + } + } + + public: + iterator + insert_after(iterator __pos, const value_type& __x) + { return iterator(_M_insert_after(__pos._M_node, __x)); } + + iterator + insert_after(iterator __pos) + { return insert_after(__pos, value_type()); } + + void + insert_after(iterator __pos, size_type __n, const value_type& __x) + { _M_insert_after_fill(__pos._M_node, __n, __x); } + + // We don't need any dispatching tricks here, because + // _M_insert_after_range already does them. + template <class _InIterator> + void + insert_after(iterator __pos, _InIterator __first, _InIterator __last) + { _M_insert_after_range(__pos._M_node, __first, __last); } + + iterator + insert(iterator __pos, const value_type& __x) + { return iterator(_M_insert_after(__slist_previous(&this->_M_head, + __pos._M_node), + __x)); } + + iterator + insert(iterator __pos) + { return iterator(_M_insert_after(__slist_previous(&this->_M_head, + __pos._M_node), + value_type())); } + + void + insert(iterator __pos, size_type __n, const value_type& __x) + { _M_insert_after_fill(__slist_previous(&this->_M_head, __pos._M_node), + __n, __x); } + + // We don't need any dispatching tricks here, because + // _M_insert_after_range already does them. + template <class _InIterator> + void + insert(iterator __pos, _InIterator __first, _InIterator __last) + { _M_insert_after_range(__slist_previous(&this->_M_head, __pos._M_node), + __first, __last); } + + public: + iterator + erase_after(iterator __pos) + { return iterator((_Node*) this->_M_erase_after(__pos._M_node)); } + + iterator + erase_after(iterator __before_first, iterator __last) + { + return iterator((_Node*) this->_M_erase_after(__before_first._M_node, + __last._M_node)); + } + + iterator + erase(iterator __pos) + { + return iterator((_Node*) this->_M_erase_after + (__slist_previous(&this->_M_head, __pos._M_node))); + } + + iterator + erase(iterator __first, iterator __last) + { + return iterator((_Node*) this->_M_erase_after + (__slist_previous(&this->_M_head, __first._M_node), + __last._M_node)); + } + + void + resize(size_type new_size, const _Tp& __x); + + void + resize(size_type new_size) + { resize(new_size, _Tp()); } + + void + clear() + { this->_M_erase_after(&this->_M_head, 0); } + + public: + // Moves the range [__before_first + 1, __before_last + 1) to *this, + // inserting it immediately after __pos. This is constant time. + void + splice_after(iterator __pos, + iterator __before_first, iterator __before_last) + { + if (__before_first != __before_last) + __slist_splice_after(__pos._M_node, __before_first._M_node, + __before_last._M_node); + } + + // Moves the element that follows __prev to *this, inserting it + // immediately after __pos. This is constant time. + void + splice_after(iterator __pos, iterator __prev) + { __slist_splice_after(__pos._M_node, + __prev._M_node, __prev._M_node->_M_next); } + + // Removes all of the elements from the list __x to *this, inserting + // them immediately after __pos. __x must not be *this. Complexity: + // linear in __x.size(). + void + splice_after(iterator __pos, slist& __x) + { __slist_splice_after(__pos._M_node, &__x._M_head); } + + // Linear in distance(begin(), __pos), and linear in __x.size(). + void + splice(iterator __pos, slist& __x) + { + if (__x._M_head._M_next) + __slist_splice_after(__slist_previous(&this->_M_head, __pos._M_node), + &__x._M_head, + __slist_previous(&__x._M_head, 0)); } + + // Linear in distance(begin(), __pos), and in distance(__x.begin(), __i). + void + splice(iterator __pos, slist& __x, iterator __i) + { __slist_splice_after(__slist_previous(&this->_M_head, __pos._M_node), + __slist_previous(&__x._M_head, __i._M_node), + __i._M_node); } + + // Linear in distance(begin(), __pos), in distance(__x.begin(), __first), + // and in distance(__first, __last). + void + splice(iterator __pos, slist& __x, iterator __first, iterator __last) + { + if (__first != __last) + __slist_splice_after(__slist_previous(&this->_M_head, __pos._M_node), + __slist_previous(&__x._M_head, __first._M_node), + __slist_previous(__first._M_node, + __last._M_node)); + } + + public: + void + reverse() + { + if (this->_M_head._M_next) + this->_M_head._M_next = __slist_reverse(this->_M_head._M_next); + } + + void + remove(const _Tp& __val); + + void + unique(); + + void + merge(slist& __x); + + void + sort(); + + template <class _Predicate> + void + remove_if(_Predicate __pred); + + template <class _BinaryPredicate> + void + unique(_BinaryPredicate __pred); + + template <class _StrictWeakOrdering> + void + merge(slist&, _StrictWeakOrdering); + + template <class _StrictWeakOrdering> + void + sort(_StrictWeakOrdering __comp); + }; + + template <class _Tp, class _Alloc> + slist<_Tp, _Alloc>& + slist<_Tp, _Alloc>::operator=(const slist<_Tp, _Alloc>& __x) + { + if (&__x != this) + { + _Node_base* __p1 = &this->_M_head; + _Node* __n1 = (_Node*) this->_M_head._M_next; + const _Node* __n2 = (const _Node*) __x._M_head._M_next; + while (__n1 && __n2) + { + __n1->_M_data = __n2->_M_data; + __p1 = __n1; + __n1 = (_Node*) __n1->_M_next; + __n2 = (const _Node*) __n2->_M_next; + } + if (__n2 == 0) + this->_M_erase_after(__p1, 0); + else + _M_insert_after_range(__p1, const_iterator((_Node*)__n2), + const_iterator(0)); + } + return *this; + } + + template <class _Tp, class _Alloc> + void + slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) + { + _Node_base* __prev = &this->_M_head; + _Node* __node = (_Node*) this->_M_head._M_next; + for (; __node != 0 && __n > 0; --__n) + { + __node->_M_data = __val; + __prev = __node; + __node = (_Node*) __node->_M_next; + } + if (__n > 0) + _M_insert_after_fill(__prev, __n, __val); + else + this->_M_erase_after(__prev, 0); + } + + template <class _Tp, class _Alloc> + template <class _InputIterator> + void + slist<_Tp, _Alloc>::_M_assign_dispatch(_InputIterator __first, + _InputIterator __last, + __false_type) + { + _Node_base* __prev = &this->_M_head; + _Node* __node = (_Node*) this->_M_head._M_next; + while (__node != 0 && __first != __last) + { + __node->_M_data = *__first; + __prev = __node; + __node = (_Node*) __node->_M_next; + ++__first; + } + if (__first != __last) + _M_insert_after_range(__prev, __first, __last); + else + this->_M_erase_after(__prev, 0); + } + + template <class _Tp, class _Alloc> + inline bool + operator==(const slist<_Tp, _Alloc>& _SL1, const slist<_Tp, _Alloc>& _SL2) + { + typedef typename slist<_Tp,_Alloc>::const_iterator const_iterator; + const_iterator __end1 = _SL1.end(); + const_iterator __end2 = _SL2.end(); + + const_iterator __i1 = _SL1.begin(); + const_iterator __i2 = _SL2.begin(); + while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) + { + ++__i1; + ++__i2; + } + return __i1 == __end1 && __i2 == __end2; + } + + + template <class _Tp, class _Alloc> + inline bool + operator<(const slist<_Tp, _Alloc>& _SL1, const slist<_Tp, _Alloc>& _SL2) + { return std::lexicographical_compare(_SL1.begin(), _SL1.end(), + _SL2.begin(), _SL2.end()); } + + template <class _Tp, class _Alloc> + inline bool + operator!=(const slist<_Tp, _Alloc>& _SL1, const slist<_Tp, _Alloc>& _SL2) + { return !(_SL1 == _SL2); } + + template <class _Tp, class _Alloc> + inline bool + operator>(const slist<_Tp, _Alloc>& _SL1, const slist<_Tp, _Alloc>& _SL2) + { return _SL2 < _SL1; } + + template <class _Tp, class _Alloc> + inline bool + operator<=(const slist<_Tp, _Alloc>& _SL1, const slist<_Tp, _Alloc>& _SL2) + { return !(_SL2 < _SL1); } + + template <class _Tp, class _Alloc> + inline bool + operator>=(const slist<_Tp, _Alloc>& _SL1, const slist<_Tp, _Alloc>& _SL2) + { return !(_SL1 < _SL2); } + + template <class _Tp, class _Alloc> + inline void + swap(slist<_Tp, _Alloc>& __x, slist<_Tp, _Alloc>& __y) + { __x.swap(__y); } + + template <class _Tp, class _Alloc> + void + slist<_Tp, _Alloc>::resize(size_type __len, const _Tp& __x) + { + _Node_base* __cur = &this->_M_head; + while (__cur->_M_next != 0 && __len > 0) + { + --__len; + __cur = __cur->_M_next; + } + if (__cur->_M_next) + this->_M_erase_after(__cur, 0); + else + _M_insert_after_fill(__cur, __len, __x); + } + + template <class _Tp, class _Alloc> + void + slist<_Tp, _Alloc>::remove(const _Tp& __val) + { + _Node_base* __cur = &this->_M_head; + while (__cur && __cur->_M_next) + { + if (((_Node*) __cur->_M_next)->_M_data == __val) + this->_M_erase_after(__cur); + else + __cur = __cur->_M_next; + } + } + + template <class _Tp, class _Alloc> + void + slist<_Tp, _Alloc>::unique() + { + _Node_base* __cur = this->_M_head._M_next; + if (__cur) + { + while (__cur->_M_next) + { + if (((_Node*)__cur)->_M_data + == ((_Node*)(__cur->_M_next))->_M_data) + this->_M_erase_after(__cur); + else + __cur = __cur->_M_next; + } + } + } + + template <class _Tp, class _Alloc> + void + slist<_Tp, _Alloc>::merge(slist<_Tp, _Alloc>& __x) + { + _Node_base* __n1 = &this->_M_head; + while (__n1->_M_next && __x._M_head._M_next) + { + if (((_Node*) __x._M_head._M_next)->_M_data + < ((_Node*) __n1->_M_next)->_M_data) + __slist_splice_after(__n1, &__x._M_head, __x._M_head._M_next); + __n1 = __n1->_M_next; + } + if (__x._M_head._M_next) + { + __n1->_M_next = __x._M_head._M_next; + __x._M_head._M_next = 0; + } + } + + template <class _Tp, class _Alloc> + void + slist<_Tp, _Alloc>::sort() + { + if (this->_M_head._M_next && this->_M_head._M_next->_M_next) + { + slist __carry; + slist __counter[64]; + int __fill = 0; + while (!empty()) + { + __slist_splice_after(&__carry._M_head, + &this->_M_head, this->_M_head._M_next); + int __i = 0; + while (__i < __fill && !__counter[__i].empty()) + { + __counter[__i].merge(__carry); + __carry.swap(__counter[__i]); + ++__i; + } + __carry.swap(__counter[__i]); + if (__i == __fill) + ++__fill; + } + + for (int __i = 1; __i < __fill; ++__i) + __counter[__i].merge(__counter[__i-1]); + this->swap(__counter[__fill-1]); + } + } + + template <class _Tp, class _Alloc> + template <class _Predicate> + void slist<_Tp, _Alloc>::remove_if(_Predicate __pred) + { + _Node_base* __cur = &this->_M_head; + while (__cur->_M_next) + { + if (__pred(((_Node*) __cur->_M_next)->_M_data)) + this->_M_erase_after(__cur); + else + __cur = __cur->_M_next; + } + } + + template <class _Tp, class _Alloc> + template <class _BinaryPredicate> + void + slist<_Tp, _Alloc>::unique(_BinaryPredicate __pred) + { + _Node* __cur = (_Node*) this->_M_head._M_next; + if (__cur) + { + while (__cur->_M_next) + { + if (__pred(((_Node*)__cur)->_M_data, + ((_Node*)(__cur->_M_next))->_M_data)) + this->_M_erase_after(__cur); + else + __cur = (_Node*) __cur->_M_next; + } + } + } + + template <class _Tp, class _Alloc> + template <class _StrictWeakOrdering> + void + slist<_Tp, _Alloc>::merge(slist<_Tp, _Alloc>& __x, + _StrictWeakOrdering __comp) + { + _Node_base* __n1 = &this->_M_head; + while (__n1->_M_next && __x._M_head._M_next) + { + if (__comp(((_Node*) __x._M_head._M_next)->_M_data, + ((_Node*) __n1->_M_next)->_M_data)) + __slist_splice_after(__n1, &__x._M_head, __x._M_head._M_next); + __n1 = __n1->_M_next; + } + if (__x._M_head._M_next) + { + __n1->_M_next = __x._M_head._M_next; + __x._M_head._M_next = 0; + } + } + + template <class _Tp, class _Alloc> + template <class _StrictWeakOrdering> + void + slist<_Tp, _Alloc>::sort(_StrictWeakOrdering __comp) + { + if (this->_M_head._M_next && this->_M_head._M_next->_M_next) + { + slist __carry; + slist __counter[64]; + int __fill = 0; + while (!empty()) + { + __slist_splice_after(&__carry._M_head, + &this->_M_head, this->_M_head._M_next); + int __i = 0; + while (__i < __fill && !__counter[__i].empty()) + { + __counter[__i].merge(__carry, __comp); + __carry.swap(__counter[__i]); + ++__i; + } + __carry.swap(__counter[__i]); + if (__i == __fill) + ++__fill; + } + + for (int __i = 1; __i < __fill; ++__i) + __counter[__i].merge(__counter[__i-1], __comp); + this->swap(__counter[__fill-1]); + } + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // Specialization of insert_iterator so that insertions will be constant + // time rather than linear time. + template <class _Tp, class _Alloc> + class insert_iterator<__gnu_cxx::slist<_Tp, _Alloc> > + { + protected: + typedef __gnu_cxx::slist<_Tp, _Alloc> _Container; + _Container* container; + typename _Container::iterator iter; + + public: + typedef _Container container_type; + typedef output_iterator_tag iterator_category; + typedef void value_type; + typedef void difference_type; + typedef void pointer; + typedef void reference; + + insert_iterator(_Container& __x, typename _Container::iterator __i) + : container(&__x) + { + if (__i == __x.begin()) + iter = __x.before_begin(); + else + iter = __x.previous(__i); + } + + insert_iterator<_Container>& + operator=(const typename _Container::value_type& __value) + { + iter = container->insert_after(iter, __value); + return *this; + } + + insert_iterator<_Container>& + operator*() + { return *this; } + + insert_iterator<_Container>& + operator++() + { return *this; } + + insert_iterator<_Container>& + operator++(int) + { return *this; } + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/sso_string_base.h b/gcc-4.9/libstdc++-v3/include/ext/sso_string_base.h new file mode 100644 index 0000000..80c88ae --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/sso_string_base.h @@ -0,0 +1,576 @@ +// Short-string-optimized versatile string base -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/sso_string_base.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{ext/vstring.h} + */ + +#ifndef _SSO_STRING_BASE_H +#define _SSO_STRING_BASE_H 1 + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template<typename _CharT, typename _Traits, typename _Alloc> + class __sso_string_base + : protected __vstring_utility<_CharT, _Traits, _Alloc> + { + public: + typedef _Traits traits_type; + typedef typename _Traits::char_type value_type; + + typedef __vstring_utility<_CharT, _Traits, _Alloc> _Util_Base; + typedef typename _Util_Base::_CharT_alloc_type _CharT_alloc_type; + typedef typename _CharT_alloc_type::size_type size_type; + + private: + // Data Members: + typename _Util_Base::template _Alloc_hider<_CharT_alloc_type> + _M_dataplus; + size_type _M_string_length; + + enum { _S_local_capacity = 15 }; + + union + { + _CharT _M_local_data[_S_local_capacity + 1]; + size_type _M_allocated_capacity; + }; + + void + _M_data(_CharT* __p) + { _M_dataplus._M_p = __p; } + + void + _M_length(size_type __length) + { _M_string_length = __length; } + + void + _M_capacity(size_type __capacity) + { _M_allocated_capacity = __capacity; } + + bool + _M_is_local() const + { return _M_data() == _M_local_data; } + + // Create & Destroy + _CharT* + _M_create(size_type&, size_type); + + void + _M_dispose() + { + if (!_M_is_local()) + _M_destroy(_M_allocated_capacity); + } + + void + _M_destroy(size_type __size) throw() + { _M_get_allocator().deallocate(_M_data(), __size + 1); } + + // _M_construct_aux is used to implement the 21.3.1 para 15 which + // requires special behaviour if _InIterator is an integral type + template<typename _InIterator> + void + _M_construct_aux(_InIterator __beg, _InIterator __end, + std::__false_type) + { + typedef typename iterator_traits<_InIterator>::iterator_category _Tag; + _M_construct(__beg, __end, _Tag()); + } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 438. Ambiguity in the "do the right thing" clause + template<typename _Integer> + void + _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type) + { _M_construct_aux_2(static_cast<size_type>(__beg), __end); } + + void + _M_construct_aux_2(size_type __req, _CharT __c) + { _M_construct(__req, __c); } + + template<typename _InIterator> + void + _M_construct(_InIterator __beg, _InIterator __end) + { + typedef typename std::__is_integer<_InIterator>::__type _Integral; + _M_construct_aux(__beg, __end, _Integral()); + } + + // For Input Iterators, used in istreambuf_iterators, etc. + template<typename _InIterator> + void + _M_construct(_InIterator __beg, _InIterator __end, + std::input_iterator_tag); + + // For forward_iterators up to random_access_iterators, used for + // string::iterator, _CharT*, etc. + template<typename _FwdIterator> + void + _M_construct(_FwdIterator __beg, _FwdIterator __end, + std::forward_iterator_tag); + + void + _M_construct(size_type __req, _CharT __c); + + public: + size_type + _M_max_size() const + { return (_M_get_allocator().max_size() - 1) / 2; } + + _CharT* + _M_data() const + { return _M_dataplus._M_p; } + + size_type + _M_length() const + { return _M_string_length; } + + size_type + _M_capacity() const + { + return _M_is_local() ? size_type(_S_local_capacity) + : _M_allocated_capacity; + } + + bool + _M_is_shared() const + { return false; } + + void + _M_set_leaked() { } + + void + _M_leak() { } + + void + _M_set_length(size_type __n) + { + _M_length(__n); + traits_type::assign(_M_data()[__n], _CharT()); + } + + __sso_string_base() + : _M_dataplus(_M_local_data) + { _M_set_length(0); } + + __sso_string_base(const _Alloc& __a); + + __sso_string_base(const __sso_string_base& __rcs); + +#if __cplusplus >= 201103L + __sso_string_base(__sso_string_base&& __rcs); +#endif + + __sso_string_base(size_type __n, _CharT __c, const _Alloc& __a); + + template<typename _InputIterator> + __sso_string_base(_InputIterator __beg, _InputIterator __end, + const _Alloc& __a); + + ~__sso_string_base() + { _M_dispose(); } + + _CharT_alloc_type& + _M_get_allocator() + { return _M_dataplus; } + + const _CharT_alloc_type& + _M_get_allocator() const + { return _M_dataplus; } + + void + _M_swap(__sso_string_base& __rcs); + + void + _M_assign(const __sso_string_base& __rcs); + + void + _M_reserve(size_type __res); + + void + _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, + size_type __len2); + + void + _M_erase(size_type __pos, size_type __n); + + void + _M_clear() + { _M_set_length(0); } + + bool + _M_compare(const __sso_string_base&) const + { return false; } + }; + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __sso_string_base<_CharT, _Traits, _Alloc>:: + _M_swap(__sso_string_base& __rcs) + { + if (this == &__rcs) + return; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<_CharT_alloc_type>::_S_do_it(_M_get_allocator(), + __rcs._M_get_allocator()); + + if (_M_is_local()) + if (__rcs._M_is_local()) + { + if (_M_length() && __rcs._M_length()) + { + _CharT __tmp_data[_S_local_capacity + 1]; + traits_type::copy(__tmp_data, __rcs._M_local_data, + _S_local_capacity + 1); + traits_type::copy(__rcs._M_local_data, _M_local_data, + _S_local_capacity + 1); + traits_type::copy(_M_local_data, __tmp_data, + _S_local_capacity + 1); + } + else if (__rcs._M_length()) + { + traits_type::copy(_M_local_data, __rcs._M_local_data, + _S_local_capacity + 1); + _M_length(__rcs._M_length()); + __rcs._M_set_length(0); + return; + } + else if (_M_length()) + { + traits_type::copy(__rcs._M_local_data, _M_local_data, + _S_local_capacity + 1); + __rcs._M_length(_M_length()); + _M_set_length(0); + return; + } + } + else + { + const size_type __tmp_capacity = __rcs._M_allocated_capacity; + traits_type::copy(__rcs._M_local_data, _M_local_data, + _S_local_capacity + 1); + _M_data(__rcs._M_data()); + __rcs._M_data(__rcs._M_local_data); + _M_capacity(__tmp_capacity); + } + else + { + const size_type __tmp_capacity = _M_allocated_capacity; + if (__rcs._M_is_local()) + { + traits_type::copy(_M_local_data, __rcs._M_local_data, + _S_local_capacity + 1); + __rcs._M_data(_M_data()); + _M_data(_M_local_data); + } + else + { + _CharT* __tmp_ptr = _M_data(); + _M_data(__rcs._M_data()); + __rcs._M_data(__tmp_ptr); + _M_capacity(__rcs._M_allocated_capacity); + } + __rcs._M_capacity(__tmp_capacity); + } + + const size_type __tmp_length = _M_length(); + _M_length(__rcs._M_length()); + __rcs._M_length(__tmp_length); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + _CharT* + __sso_string_base<_CharT, _Traits, _Alloc>:: + _M_create(size_type& __capacity, size_type __old_capacity) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 83. String::npos vs. string::max_size() + if (__capacity > _M_max_size()) + std::__throw_length_error(__N("__sso_string_base::_M_create")); + + // The below implements an exponential growth policy, necessary to + // meet amortized linear time requirements of the library: see + // http://gcc.gnu.org/ml/libstdc++/2001-07/msg00085.html. + if (__capacity > __old_capacity && __capacity < 2 * __old_capacity) + { + __capacity = 2 * __old_capacity; + // Never allocate a string bigger than max_size. + if (__capacity > _M_max_size()) + __capacity = _M_max_size(); + } + + // NB: Need an array of char_type[__capacity], plus a terminating + // null char_type() element. + return _M_get_allocator().allocate(__capacity + 1); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + __sso_string_base<_CharT, _Traits, _Alloc>:: + __sso_string_base(const _Alloc& __a) + : _M_dataplus(__a, _M_local_data) + { _M_set_length(0); } + + template<typename _CharT, typename _Traits, typename _Alloc> + __sso_string_base<_CharT, _Traits, _Alloc>:: + __sso_string_base(const __sso_string_base& __rcs) + : _M_dataplus(__rcs._M_get_allocator(), _M_local_data) + { _M_construct(__rcs._M_data(), __rcs._M_data() + __rcs._M_length()); } + +#if __cplusplus >= 201103L + template<typename _CharT, typename _Traits, typename _Alloc> + __sso_string_base<_CharT, _Traits, _Alloc>:: + __sso_string_base(__sso_string_base&& __rcs) + : _M_dataplus(__rcs._M_get_allocator(), _M_local_data) + { + if (__rcs._M_is_local()) + { + if (__rcs._M_length()) + traits_type::copy(_M_local_data, __rcs._M_local_data, + _S_local_capacity + 1); + } + else + { + _M_data(__rcs._M_data()); + _M_capacity(__rcs._M_allocated_capacity); + } + + _M_set_length(__rcs._M_length()); + __rcs._M_data(__rcs._M_local_data); + __rcs._M_set_length(0); + } +#endif + + template<typename _CharT, typename _Traits, typename _Alloc> + __sso_string_base<_CharT, _Traits, _Alloc>:: + __sso_string_base(size_type __n, _CharT __c, const _Alloc& __a) + : _M_dataplus(__a, _M_local_data) + { _M_construct(__n, __c); } + + template<typename _CharT, typename _Traits, typename _Alloc> + template<typename _InputIterator> + __sso_string_base<_CharT, _Traits, _Alloc>:: + __sso_string_base(_InputIterator __beg, _InputIterator __end, + const _Alloc& __a) + : _M_dataplus(__a, _M_local_data) + { _M_construct(__beg, __end); } + + // NB: This is the special case for Input Iterators, used in + // istreambuf_iterators, etc. + // Input Iterators have a cost structure very different from + // pointers, calling for a different coding style. + template<typename _CharT, typename _Traits, typename _Alloc> + template<typename _InIterator> + void + __sso_string_base<_CharT, _Traits, _Alloc>:: + _M_construct(_InIterator __beg, _InIterator __end, + std::input_iterator_tag) + { + size_type __len = 0; + size_type __capacity = size_type(_S_local_capacity); + + while (__beg != __end && __len < __capacity) + { + _M_data()[__len++] = *__beg; + ++__beg; + } + + __try + { + while (__beg != __end) + { + if (__len == __capacity) + { + // Allocate more space. + __capacity = __len + 1; + _CharT* __another = _M_create(__capacity, __len); + this->_S_copy(__another, _M_data(), __len); + _M_dispose(); + _M_data(__another); + _M_capacity(__capacity); + } + _M_data()[__len++] = *__beg; + ++__beg; + } + } + __catch(...) + { + _M_dispose(); + __throw_exception_again; + } + + _M_set_length(__len); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + template<typename _InIterator> + void + __sso_string_base<_CharT, _Traits, _Alloc>:: + _M_construct(_InIterator __beg, _InIterator __end, + std::forward_iterator_tag) + { + // NB: Not required, but considered best practice. + if (__is_null_pointer(__beg) && __beg != __end) + std::__throw_logic_error(__N("__sso_string_base::" + "_M_construct null not valid")); + + size_type __dnew = static_cast<size_type>(std::distance(__beg, __end)); + + if (__dnew > size_type(_S_local_capacity)) + { + _M_data(_M_create(__dnew, size_type(0))); + _M_capacity(__dnew); + } + + // Check for out_of_range and length_error exceptions. + __try + { this->_S_copy_chars(_M_data(), __beg, __end); } + __catch(...) + { + _M_dispose(); + __throw_exception_again; + } + + _M_set_length(__dnew); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __sso_string_base<_CharT, _Traits, _Alloc>:: + _M_construct(size_type __n, _CharT __c) + { + if (__n > size_type(_S_local_capacity)) + { + _M_data(_M_create(__n, size_type(0))); + _M_capacity(__n); + } + + if (__n) + this->_S_assign(_M_data(), __n, __c); + + _M_set_length(__n); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __sso_string_base<_CharT, _Traits, _Alloc>:: + _M_assign(const __sso_string_base& __rcs) + { + if (this != &__rcs) + { + const size_type __rsize = __rcs._M_length(); + const size_type __capacity = _M_capacity(); + + if (__rsize > __capacity) + { + size_type __new_capacity = __rsize; + _CharT* __tmp = _M_create(__new_capacity, __capacity); + _M_dispose(); + _M_data(__tmp); + _M_capacity(__new_capacity); + } + + if (__rsize) + this->_S_copy(_M_data(), __rcs._M_data(), __rsize); + + _M_set_length(__rsize); + } + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __sso_string_base<_CharT, _Traits, _Alloc>:: + _M_reserve(size_type __res) + { + // Make sure we don't shrink below the current size. + if (__res < _M_length()) + __res = _M_length(); + + const size_type __capacity = _M_capacity(); + if (__res != __capacity) + { + if (__res > __capacity + || __res > size_type(_S_local_capacity)) + { + _CharT* __tmp = _M_create(__res, __capacity); + this->_S_copy(__tmp, _M_data(), _M_length() + 1); + _M_dispose(); + _M_data(__tmp); + _M_capacity(__res); + } + else if (!_M_is_local()) + { + this->_S_copy(_M_local_data, _M_data(), _M_length() + 1); + _M_destroy(__capacity); + _M_data(_M_local_data); + } + } + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __sso_string_base<_CharT, _Traits, _Alloc>:: + _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, + size_type __len2) + { + const size_type __how_much = _M_length() - __pos - __len1; + + size_type __new_capacity = _M_length() + __len2 - __len1; + _CharT* __r = _M_create(__new_capacity, _M_capacity()); + + if (__pos) + this->_S_copy(__r, _M_data(), __pos); + if (__s && __len2) + this->_S_copy(__r + __pos, __s, __len2); + if (__how_much) + this->_S_copy(__r + __pos + __len2, + _M_data() + __pos + __len1, __how_much); + + _M_dispose(); + _M_data(__r); + _M_capacity(__new_capacity); + } + + template<typename _CharT, typename _Traits, typename _Alloc> + void + __sso_string_base<_CharT, _Traits, _Alloc>:: + _M_erase(size_type __pos, size_type __n) + { + const size_type __how_much = _M_length() - __pos - __n; + + if (__how_much && __n) + this->_S_move(_M_data() + __pos, _M_data() + __pos + __n, __how_much); + + _M_set_length(_M_length() - __n); + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif /* _SSO_STRING_BASE_H */ diff --git a/gcc-4.9/libstdc++-v3/include/ext/stdio_filebuf.h b/gcc-4.9/libstdc++-v3/include/ext/stdio_filebuf.h new file mode 100644 index 0000000..2874163 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/stdio_filebuf.h @@ -0,0 +1,162 @@ +// File descriptor layer for filebuf -*- C++ -*- + +// Copyright (C) 2002-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/stdio_filebuf.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _STDIO_FILEBUF_H +#define _STDIO_FILEBUF_H 1 + +#pragma GCC system_header + +#include <fstream> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * @brief Provides a layer of compatibility for C/POSIX. + * @ingroup io + * + * This GNU extension provides extensions for working with standard C + * FILE*'s and POSIX file descriptors. It must be instantiated by the + * user with the type of character used in the file stream, e.g., + * stdio_filebuf<char>. + */ + template<typename _CharT, typename _Traits = std::char_traits<_CharT> > + class stdio_filebuf : public std::basic_filebuf<_CharT, _Traits> + { + public: + // Types: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef std::size_t size_t; + + public: + /** + * deferred initialization + */ + stdio_filebuf() : std::basic_filebuf<_CharT, _Traits>() {} + + /** + * @param __fd An open file descriptor. + * @param __mode Same meaning as in a standard filebuf. + * @param __size Optimal or preferred size of internal buffer, + * in chars. + * + * This constructor associates a file stream buffer with an open + * POSIX file descriptor. The file descriptor will be automatically + * closed when the stdio_filebuf is closed/destroyed. + */ + stdio_filebuf(int __fd, std::ios_base::openmode __mode, + size_t __size = static_cast<size_t>(BUFSIZ)); + + /** + * @param __f An open @c FILE*. + * @param __mode Same meaning as in a standard filebuf. + * @param __size Optimal or preferred size of internal buffer, + * in chars. Defaults to system's @c BUFSIZ. + * + * This constructor associates a file stream buffer with an open + * C @c FILE*. The @c FILE* will not be automatically closed when the + * stdio_filebuf is closed/destroyed. + */ + stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, + size_t __size = static_cast<size_t>(BUFSIZ)); + + /** + * Closes the external data stream if the file descriptor constructor + * was used. + */ + virtual + ~stdio_filebuf(); + + /** + * @return The underlying file descriptor. + * + * Once associated with an external data stream, this function can be + * used to access the underlying POSIX file descriptor. Note that + * there is no way for the library to track what you do with the + * descriptor, so be careful. + */ + int + fd() { return this->_M_file.fd(); } + + /** + * @return The underlying FILE*. + * + * This function can be used to access the underlying "C" file pointer. + * Note that there is no way for the library to track what you do + * with the file, so be careful. + */ + std::__c_file* + file() { return this->_M_file.file(); } + }; + + template<typename _CharT, typename _Traits> + stdio_filebuf<_CharT, _Traits>::~stdio_filebuf() + { } + + template<typename _CharT, typename _Traits> + stdio_filebuf<_CharT, _Traits>:: + stdio_filebuf(int __fd, std::ios_base::openmode __mode, size_t __size) + { + this->_M_file.sys_open(__fd, __mode); + if (this->is_open()) + { + this->_M_mode = __mode; + this->_M_buf_size = __size; + this->_M_allocate_internal_buffer(); + this->_M_reading = false; + this->_M_writing = false; + this->_M_set_buffer(-1); + } + } + + template<typename _CharT, typename _Traits> + stdio_filebuf<_CharT, _Traits>:: + stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, + size_t __size) + { + this->_M_file.sys_open(__f, __mode); + if (this->is_open()) + { + this->_M_mode = __mode; + this->_M_buf_size = __size; + this->_M_allocate_internal_buffer(); + this->_M_reading = false; + this->_M_writing = false; + this->_M_set_buffer(-1); + } + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/stdio_sync_filebuf.h b/gcc-4.9/libstdc++-v3/include/ext/stdio_sync_filebuf.h new file mode 100644 index 0000000..5ca16eb --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/stdio_sync_filebuf.h @@ -0,0 +1,289 @@ +// Iostreams wrapper for stdio FILE* -*- C++ -*- + +// Copyright (C) 2003-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/stdio_sync_filebuf.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _STDIO_SYNC_FILEBUF_H +#define _STDIO_SYNC_FILEBUF_H 1 + +#pragma GCC system_header + +#include <streambuf> +#include <unistd.h> +#include <cstdio> +#include <bits/c++io.h> // For __c_file + +#ifdef _GLIBCXX_USE_WCHAR_T +#include <cwchar> +#endif + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * @brief Provides a layer of compatibility for C. + * @ingroup io + * + * This GNU extension provides extensions for working with standard + * C FILE*'s. It must be instantiated by the user with the type of + * character used in the file stream, e.g., stdio_filebuf<char>. + */ + template<typename _CharT, typename _Traits = std::char_traits<_CharT> > + class stdio_sync_filebuf : public std::basic_streambuf<_CharT, _Traits> + { + public: + // Types: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + private: + // Underlying stdio FILE + std::__c_file* const _M_file; + + // Last character gotten. This is used when pbackfail is + // called from basic_streambuf::sungetc() + int_type _M_unget_buf; + + public: + explicit + stdio_sync_filebuf(std::__c_file* __f) + : _M_file(__f), _M_unget_buf(traits_type::eof()) + { } + + /** + * @return The underlying FILE*. + * + * This function can be used to access the underlying C file pointer. + * Note that there is no way for the library to track what you do + * with the file, so be careful. + */ + std::__c_file* const + file() { return this->_M_file; } + + protected: + int_type + syncgetc(); + + int_type + syncungetc(int_type __c); + + int_type + syncputc(int_type __c); + + virtual int_type + underflow() + { + int_type __c = this->syncgetc(); + return this->syncungetc(__c); + } + + virtual int_type + uflow() + { + // Store the gotten character in case we need to unget it. + _M_unget_buf = this->syncgetc(); + return _M_unget_buf; + } + + virtual int_type + pbackfail(int_type __c = traits_type::eof()) + { + int_type __ret; + const int_type __eof = traits_type::eof(); + + // Check if the unget or putback was requested + if (traits_type::eq_int_type(__c, __eof)) // unget + { + if (!traits_type::eq_int_type(_M_unget_buf, __eof)) + __ret = this->syncungetc(_M_unget_buf); + else // buffer invalid, fail. + __ret = __eof; + } + else // putback + __ret = this->syncungetc(__c); + + // The buffered character is no longer valid, discard it. + _M_unget_buf = __eof; + return __ret; + } + + virtual std::streamsize + xsgetn(char_type* __s, std::streamsize __n); + + virtual int_type + overflow(int_type __c = traits_type::eof()) + { + int_type __ret; + if (traits_type::eq_int_type(__c, traits_type::eof())) + { + if (std::fflush(_M_file)) + __ret = traits_type::eof(); + else + __ret = traits_type::not_eof(__c); + } + else + __ret = this->syncputc(__c); + return __ret; + } + + virtual std::streamsize + xsputn(const char_type* __s, std::streamsize __n); + + virtual int + sync() + { return std::fflush(_M_file); } + + virtual std::streampos + seekoff(std::streamoff __off, std::ios_base::seekdir __dir, + std::ios_base::openmode = std::ios_base::in | std::ios_base::out) + { + std::streampos __ret(std::streamoff(-1)); + int __whence; + if (__dir == std::ios_base::beg) + __whence = SEEK_SET; + else if (__dir == std::ios_base::cur) + __whence = SEEK_CUR; + else + __whence = SEEK_END; +#ifdef _GLIBCXX_USE_LFS + if (!fseeko64(_M_file, __off, __whence)) + __ret = std::streampos(ftello64(_M_file)); +#else + if (!fseek(_M_file, __off, __whence)) + __ret = std::streampos(std::ftell(_M_file)); +#endif + return __ret; + } + + virtual std::streampos + seekpos(std::streampos __pos, + std::ios_base::openmode __mode = + std::ios_base::in | std::ios_base::out) + { return seekoff(std::streamoff(__pos), std::ios_base::beg, __mode); } + }; + + template<> + inline stdio_sync_filebuf<char>::int_type + stdio_sync_filebuf<char>::syncgetc() + { return std::getc(_M_file); } + + template<> + inline stdio_sync_filebuf<char>::int_type + stdio_sync_filebuf<char>::syncungetc(int_type __c) + { return std::ungetc(__c, _M_file); } + + template<> + inline stdio_sync_filebuf<char>::int_type + stdio_sync_filebuf<char>::syncputc(int_type __c) + { return std::putc(__c, _M_file); } + + template<> + inline std::streamsize + stdio_sync_filebuf<char>::xsgetn(char* __s, std::streamsize __n) + { + std::streamsize __ret = std::fread(__s, 1, __n, _M_file); + if (__ret > 0) + _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]); + else + _M_unget_buf = traits_type::eof(); + return __ret; + } + + template<> + inline std::streamsize + stdio_sync_filebuf<char>::xsputn(const char* __s, std::streamsize __n) + { return std::fwrite(__s, 1, __n, _M_file); } + +#ifdef _GLIBCXX_USE_WCHAR_T + template<> + inline stdio_sync_filebuf<wchar_t>::int_type + stdio_sync_filebuf<wchar_t>::syncgetc() + { return std::getwc(_M_file); } + + template<> + inline stdio_sync_filebuf<wchar_t>::int_type + stdio_sync_filebuf<wchar_t>::syncungetc(int_type __c) + { return std::ungetwc(__c, _M_file); } + + template<> + inline stdio_sync_filebuf<wchar_t>::int_type + stdio_sync_filebuf<wchar_t>::syncputc(int_type __c) + { return std::putwc(__c, _M_file); } + + template<> + inline std::streamsize + stdio_sync_filebuf<wchar_t>::xsgetn(wchar_t* __s, std::streamsize __n) + { + std::streamsize __ret = 0; + const int_type __eof = traits_type::eof(); + while (__n--) + { + int_type __c = this->syncgetc(); + if (traits_type::eq_int_type(__c, __eof)) + break; + __s[__ret] = traits_type::to_char_type(__c); + ++__ret; + } + + if (__ret > 0) + _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]); + else + _M_unget_buf = traits_type::eof(); + return __ret; + } + + template<> + inline std::streamsize + stdio_sync_filebuf<wchar_t>::xsputn(const wchar_t* __s, + std::streamsize __n) + { + std::streamsize __ret = 0; + const int_type __eof = traits_type::eof(); + while (__n--) + { + if (traits_type::eq_int_type(this->syncputc(*__s++), __eof)) + break; + ++__ret; + } + return __ret; + } +#endif + +#if _GLIBCXX_EXTERN_TEMPLATE + extern template class stdio_sync_filebuf<char>; +#ifdef _GLIBCXX_USE_WCHAR_T + extern template class stdio_sync_filebuf<wchar_t>; +#endif +#endif + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/string_conversions.h b/gcc-4.9/libstdc++-v3/include/ext/string_conversions.h new file mode 100644 index 0000000..92ba913 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/string_conversions.h @@ -0,0 +1,107 @@ +// String Conversions -*- C++ -*- + +// Copyright (C) 2008-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/string_conversions.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _STRING_CONVERSIONS_H +#define _STRING_CONVERSIONS_H 1 + +#pragma GCC system_header + +#if __cplusplus < 201103L +# include <bits/c++0x_warning.h> +#else + +#include <bits/c++config.h> +#include <ext/numeric_traits.h> +#include <bits/functexcept.h> +#include <cstdlib> +#include <cwchar> +#include <cstdio> +#include <cerrno> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // Helper for all the sto* functions. + template<typename _TRet, typename _Ret = _TRet, typename _CharT, + typename... _Base> + _Ret + __stoa(_TRet (*__convf) (const _CharT*, _CharT**, _Base...), + const char* __name, const _CharT* __str, std::size_t* __idx, + _Base... __base) + { + _Ret __ret; + + _CharT* __endptr; + errno = 0; + const _TRet __tmp = __convf(__str, &__endptr, __base...); + + if (__endptr == __str) + std::__throw_invalid_argument(__name); + else if (errno == ERANGE + || (std::__are_same<_Ret, int>::__value + && (__tmp < __numeric_traits<int>::__min + || __tmp > __numeric_traits<int>::__max))) + std::__throw_out_of_range(__name); + else + __ret = __tmp; + + if (__idx) + *__idx = __endptr - __str; + + return __ret; + } + + // Helper for the to_string / to_wstring functions. + template<typename _String, typename _CharT = typename _String::value_type> + _String + __to_xstring(int (*__convf) (_CharT*, std::size_t, const _CharT*, + __builtin_va_list), std::size_t __n, + const _CharT* __fmt, ...) + { + // XXX Eventually the result will be constructed in place in + // the C++0x string, likely with the help of internal hooks. + _CharT* __s = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __n)); + + __builtin_va_list __args; + __builtin_va_start(__args, __fmt); + + const int __len = __convf(__s, __n, __fmt, __args); + + __builtin_va_end(__args); + + return _String(__s, __s + __len); + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif // C++11 + +#endif // _STRING_CONVERSIONS_H diff --git a/gcc-4.9/libstdc++-v3/include/ext/throw_allocator.h b/gcc-4.9/libstdc++-v3/include/ext/throw_allocator.h new file mode 100644 index 0000000..30b6c47 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/throw_allocator.h @@ -0,0 +1,980 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** @file ext/throw_allocator.h + * This file is a GNU extension to the Standard C++ Library. + * + * Contains two exception-generating types (throw_value, throw_allocator) + * intended to be used as value and allocator types while testing + * exception safety in templatized containers and algorithms. The + * allocator has additional log and debug features. The exception + * generated is of type forced_exception_error. + */ + +#ifndef _THROW_ALLOCATOR_H +#define _THROW_ALLOCATOR_H 1 + +#include <cmath> +#include <ctime> +#include <map> +#include <string> +#include <ostream> +#include <stdexcept> +#include <utility> +#include <bits/functexcept.h> +#include <bits/move.h> +#if __cplusplus >= 201103L +# include <functional> +# include <random> +#else +# include <tr1/functional> +# include <tr1/random> +#endif + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * @brief Thown by exception safety machinery. + * @ingroup exceptions + */ + struct forced_error : public std::exception + { }; + + // Substitute for forced_error object when -fno-exceptions. + inline void + __throw_forced_error() + { _GLIBCXX_THROW_OR_ABORT(forced_error()); } + + /** + * @brief Base class for checking address and label information + * about allocations. Create a std::map between the allocated + * address (void*) and a datum for annotations, which are a pair of + * numbers corresponding to label and allocated size. + */ + struct annotate_base + { + annotate_base() + { + label(); + map_alloc(); + } + + static void + set_label(size_t l) + { label() = l; } + + static size_t + get_label() + { return label(); } + + void + insert(void* p, size_t size) + { + if (!p) + { + std::string error("annotate_base::insert null insert!\n"); + log_to_string(error, make_entry(p, size)); + std::__throw_logic_error(error.c_str()); + } + + const_iterator found = map_alloc().find(p); + if (found != map_alloc().end()) + { + std::string error("annotate_base::insert double insert!\n"); + log_to_string(error, make_entry(p, size)); + log_to_string(error, *found); + std::__throw_logic_error(error.c_str()); + } + + map_alloc().insert(make_entry(p, size)); + } + + void + erase(void* p, size_t size) + { + check_allocated(p, size); + map_alloc().erase(p); + } + +#if __cplusplus >= 201103L + void + insert_construct(void* p) + { + if (!p) + { + std::string error("annotate_base::insert_construct null!\n"); + std::__throw_logic_error(error.c_str()); + } + + auto found = map_construct().find(p); + if (found != map_construct().end()) + { + std::string error("annotate_base::insert_construct double insert!\n"); + log_to_string(error, std::make_pair(p, get_label())); + log_to_string(error, *found); + std::__throw_logic_error(error.c_str()); + } + + map_construct().insert(std::make_pair(p, get_label())); + } + + void + erase_construct(void* p) + { + check_constructed(p); + map_construct().erase(p); + } +#endif + + // See if a particular address and allocation size has been saved. + inline void + check_allocated(void* p, size_t size) + { + const_iterator found = map_alloc().find(p); + if (found == map_alloc().end()) + { + std::string error("annotate_base::check_allocated by value " + "null erase!\n"); + log_to_string(error, make_entry(p, size)); + std::__throw_logic_error(error.c_str()); + } + + if (found->second.second != size) + { + std::string error("annotate_base::check_allocated by value " + "wrong-size erase!\n"); + log_to_string(error, make_entry(p, size)); + log_to_string(error, *found); + std::__throw_logic_error(error.c_str()); + } + } + + // See if a given label has been allocated. + inline void + check(size_t label) + { + std::string found; + { + const_iterator beg = map_alloc().begin(); + const_iterator end = map_alloc().end(); + while (beg != end) + { + if (beg->second.first == label) + log_to_string(found, *beg); + ++beg; + } + } + +#if __cplusplus >= 201103L + { + auto beg = map_construct().begin(); + auto end = map_construct().end(); + while (beg != end) + { + if (beg->second == label) + log_to_string(found, *beg); + ++beg; + } + } +#endif + + if (!found.empty()) + { + std::string error("annotate_base::check by label\n"); + error += found; + std::__throw_logic_error(error.c_str()); + } + } + + // See if there is anything left allocated or constructed. + inline static void + check() + { + std::string found; + { + const_iterator beg = map_alloc().begin(); + const_iterator end = map_alloc().end(); + while (beg != end) + { + log_to_string(found, *beg); + ++beg; + } + } + +#if __cplusplus >= 201103L + { + auto beg = map_construct().begin(); + auto end = map_construct().end(); + while (beg != end) + { + log_to_string(found, *beg); + ++beg; + } + } +#endif + + if (!found.empty()) + { + std::string error("annotate_base::check \n"); + error += found; + std::__throw_logic_error(error.c_str()); + } + } + +#if __cplusplus >= 201103L + inline void + check_constructed(void* p) + { + auto found = map_construct().find(p); + if (found == map_construct().end()) + { + std::string error("annotate_base::check_constructed not " + "constructed!\n"); + log_to_string(error, std::make_pair(p, get_label())); + std::__throw_logic_error(error.c_str()); + } + } + + inline void + check_constructed(size_t label) + { + auto beg = map_construct().begin(); + auto end = map_construct().end(); + std::string found; + while (beg != end) + { + if (beg->second == label) + log_to_string(found, *beg); + ++beg; + } + + if (!found.empty()) + { + std::string error("annotate_base::check_constructed by label\n"); + error += found; + std::__throw_logic_error(error.c_str()); + } + } +#endif + + private: + typedef std::pair<size_t, size_t> data_type; + typedef std::map<void*, data_type> map_alloc_type; + typedef map_alloc_type::value_type entry_type; + typedef map_alloc_type::const_iterator const_iterator; + typedef map_alloc_type::const_reference const_reference; +#if __cplusplus >= 201103L + typedef std::map<void*, size_t> map_construct_type; +#endif + + friend std::ostream& + operator<<(std::ostream&, const annotate_base&); + + entry_type + make_entry(void* p, size_t size) + { return std::make_pair(p, data_type(get_label(), size)); } + + static void + log_to_string(std::string& s, const_reference ref) + { + char buf[40]; + const char tab('\t'); + s += "label: "; + unsigned long l = static_cast<unsigned long>(ref.second.first); + __builtin_sprintf(buf, "%lu", l); + s += buf; + s += tab; + s += "size: "; + l = static_cast<unsigned long>(ref.second.second); + __builtin_sprintf(buf, "%lu", l); + s += buf; + s += tab; + s += "address: "; + __builtin_sprintf(buf, "%p", ref.first); + s += buf; + s += '\n'; + } + +#if __cplusplus >= 201103L + static void + log_to_string(std::string& s, const std::pair<const void*, size_t>& ref) + { + char buf[40]; + const char tab('\t'); + s += "label: "; + unsigned long l = static_cast<unsigned long>(ref.second); + __builtin_sprintf(buf, "%lu", l); + s += buf; + s += tab; + s += "address: "; + __builtin_sprintf(buf, "%p", ref.first); + s += buf; + s += '\n'; + } +#endif + + static size_t& + label() + { + static size_t _S_label(std::numeric_limits<size_t>::max()); + return _S_label; + } + + static map_alloc_type& + map_alloc() + { + static map_alloc_type _S_map; + return _S_map; + } + +#if __cplusplus >= 201103L + static map_construct_type& + map_construct() + { + static map_construct_type _S_map; + return _S_map; + } +#endif + }; + + inline std::ostream& + operator<<(std::ostream& os, const annotate_base& __b) + { + std::string error; + typedef annotate_base base_type; + { + base_type::const_iterator beg = __b.map_alloc().begin(); + base_type::const_iterator end = __b.map_alloc().end(); + for (; beg != end; ++beg) + __b.log_to_string(error, *beg); + } +#if __cplusplus >= 201103L + { + auto beg = __b.map_construct().begin(); + auto end = __b.map_construct().end(); + for (; beg != end; ++beg) + __b.log_to_string(error, *beg); + } +#endif + return os << error; + } + + + /** + * @brief Base struct for condition policy. + * + * Requires a public member function with the signature + * void throw_conditionally() + */ + struct condition_base + { + virtual ~condition_base() { }; + }; + + + /** + * @brief Base class for incremental control and throw. + */ + struct limit_condition : public condition_base + { + // Scope-level adjustor objects: set limit for throw at the + // beginning of a scope block, and restores to previous limit when + // object is destroyed on exiting the block. + struct adjustor_base + { + private: + const size_t _M_orig; + + public: + adjustor_base() : _M_orig(limit()) { } + + virtual + ~adjustor_base() { set_limit(_M_orig); } + }; + + /// Never enter the condition. + struct never_adjustor : public adjustor_base + { + never_adjustor() { set_limit(std::numeric_limits<size_t>::max()); } + }; + + /// Always enter the condition. + struct always_adjustor : public adjustor_base + { + always_adjustor() { set_limit(count()); } + }; + + /// Enter the nth condition. + struct limit_adjustor : public adjustor_base + { + limit_adjustor(const size_t __l) { set_limit(__l); } + }; + + // Increment _S_count every time called. + // If _S_count matches the limit count, throw. + static void + throw_conditionally() + { + if (count() == limit()) + __throw_forced_error(); + ++count(); + } + + static size_t& + count() + { + static size_t _S_count(0); + return _S_count; + } + + static size_t& + limit() + { + static size_t _S_limit(std::numeric_limits<size_t>::max()); + return _S_limit; + } + + // Zero the throw counter, set limit to argument. + static void + set_limit(const size_t __l) + { + limit() = __l; + count() = 0; + } + }; + + + /** + * @brief Base class for random probability control and throw. + */ + struct random_condition : public condition_base + { + // Scope-level adjustor objects: set probability for throw at the + // beginning of a scope block, and restores to previous + // probability when object is destroyed on exiting the block. + struct adjustor_base + { + private: + const double _M_orig; + + public: + adjustor_base() : _M_orig(probability()) { } + + virtual ~adjustor_base() + { set_probability(_M_orig); } + }; + + /// Group condition. + struct group_adjustor : public adjustor_base + { + group_adjustor(size_t size) + { set_probability(1 - std::pow(double(1 - probability()), + double(0.5 / (size + 1)))); + } + }; + + /// Never enter the condition. + struct never_adjustor : public adjustor_base + { + never_adjustor() { set_probability(0); } + }; + + /// Always enter the condition. + struct always_adjustor : public adjustor_base + { + always_adjustor() { set_probability(1); } + }; + + random_condition() + { + probability(); + engine(); + } + + static void + set_probability(double __p) + { probability() = __p; } + + static void + throw_conditionally() + { + if (generate() < probability()) + __throw_forced_error(); + } + + void + seed(unsigned long __s) + { engine().seed(__s); } + + private: +#if __cplusplus >= 201103L + typedef std::uniform_real_distribution<double> distribution_type; + typedef std::mt19937 engine_type; +#else + typedef std::tr1::uniform_real<double> distribution_type; + typedef std::tr1::mt19937 engine_type; +#endif + + static double + generate() + { +#if __cplusplus >= 201103L + const distribution_type distribution(0, 1); + static auto generator = std::bind(distribution, engine()); +#else + // Use variate_generator to get normalized results. + typedef std::tr1::variate_generator<engine_type, distribution_type> gen_t; + distribution_type distribution(0, 1); + static gen_t generator(engine(), distribution); +#endif + + double random = generator(); + if (random < distribution.min() || random > distribution.max()) + { + std::string __s("random_condition::generate"); + __s += "\n"; + __s += "random number generated is: "; + char buf[40]; + __builtin_sprintf(buf, "%f", random); + __s += buf; + std::__throw_out_of_range(__s.c_str()); + } + + return random; + } + + static double& + probability() + { + static double _S_p; + return _S_p; + } + + static engine_type& + engine() + { + static engine_type _S_e; + return _S_e; + } + }; + + + /** + * @brief Class with exception generation control. Intended to be + * used as a value_type in templatized code. + * + * Note: Destructor not allowed to throw. + */ + template<typename _Cond> + struct throw_value_base : public _Cond + { + typedef _Cond condition_type; + + using condition_type::throw_conditionally; + + std::size_t _M_i; + +#ifndef _GLIBCXX_IS_AGGREGATE + throw_value_base() : _M_i(0) + { throw_conditionally(); } + + throw_value_base(const throw_value_base& __v) : _M_i(__v._M_i) + { throw_conditionally(); } + +#if __cplusplus >= 201103L + // Shall not throw. + throw_value_base(throw_value_base&&) = default; +#endif + + explicit throw_value_base(const std::size_t __i) : _M_i(__i) + { throw_conditionally(); } +#endif + + throw_value_base& + operator=(const throw_value_base& __v) + { + throw_conditionally(); + _M_i = __v._M_i; + return *this; + } + +#if __cplusplus >= 201103L + // Shall not throw. + throw_value_base& + operator=(throw_value_base&&) = default; +#endif + + throw_value_base& + operator++() + { + throw_conditionally(); + ++_M_i; + return *this; + } + }; + + template<typename _Cond> + inline void + swap(throw_value_base<_Cond>& __a, throw_value_base<_Cond>& __b) + { + typedef throw_value_base<_Cond> throw_value; + throw_value::throw_conditionally(); + throw_value orig(__a); + __a = __b; + __b = orig; + } + + // General instantiable types requirements. + template<typename _Cond> + inline bool + operator==(const throw_value_base<_Cond>& __a, + const throw_value_base<_Cond>& __b) + { + typedef throw_value_base<_Cond> throw_value; + throw_value::throw_conditionally(); + bool __ret = __a._M_i == __b._M_i; + return __ret; + } + + template<typename _Cond> + inline bool + operator<(const throw_value_base<_Cond>& __a, + const throw_value_base<_Cond>& __b) + { + typedef throw_value_base<_Cond> throw_value; + throw_value::throw_conditionally(); + bool __ret = __a._M_i < __b._M_i; + return __ret; + } + + // Numeric algorithms instantiable types requirements. + template<typename _Cond> + inline throw_value_base<_Cond> + operator+(const throw_value_base<_Cond>& __a, + const throw_value_base<_Cond>& __b) + { + typedef throw_value_base<_Cond> throw_value; + throw_value::throw_conditionally(); + throw_value __ret(__a._M_i + __b._M_i); + return __ret; + } + + template<typename _Cond> + inline throw_value_base<_Cond> + operator-(const throw_value_base<_Cond>& __a, + const throw_value_base<_Cond>& __b) + { + typedef throw_value_base<_Cond> throw_value; + throw_value::throw_conditionally(); + throw_value __ret(__a._M_i - __b._M_i); + return __ret; + } + + template<typename _Cond> + inline throw_value_base<_Cond> + operator*(const throw_value_base<_Cond>& __a, + const throw_value_base<_Cond>& __b) + { + typedef throw_value_base<_Cond> throw_value; + throw_value::throw_conditionally(); + throw_value __ret(__a._M_i * __b._M_i); + return __ret; + } + + + /// Type throwing via limit condition. + struct throw_value_limit : public throw_value_base<limit_condition> + { + typedef throw_value_base<limit_condition> base_type; + +#ifndef _GLIBCXX_IS_AGGREGATE + throw_value_limit() { } + + throw_value_limit(const throw_value_limit& __other) + : base_type(__other._M_i) { } + +#if __cplusplus >= 201103L + throw_value_limit(throw_value_limit&&) = default; +#endif + + explicit throw_value_limit(const std::size_t __i) : base_type(__i) { } +#endif + + throw_value_limit& + operator=(const throw_value_limit& __other) + { + base_type::operator=(__other); + return *this; + } + +#if __cplusplus >= 201103L + throw_value_limit& + operator=(throw_value_limit&&) = default; +#endif + }; + + /// Type throwing via random condition. + struct throw_value_random : public throw_value_base<random_condition> + { + typedef throw_value_base<random_condition> base_type; + +#ifndef _GLIBCXX_IS_AGGREGATE + throw_value_random() { } + + throw_value_random(const throw_value_random& __other) + : base_type(__other._M_i) { } + +#if __cplusplus >= 201103L + throw_value_random(throw_value_random&&) = default; +#endif + + explicit throw_value_random(const std::size_t __i) : base_type(__i) { } +#endif + + throw_value_random& + operator=(const throw_value_random& __other) + { + base_type::operator=(__other); + return *this; + } + +#if __cplusplus >= 201103L + throw_value_random& + operator=(throw_value_random&&) = default; +#endif + }; + + + /** + * @brief Allocator class with logging and exception generation control. + * Intended to be used as an allocator_type in templatized code. + * @ingroup allocators + * + * Note: Deallocate not allowed to throw. + */ + template<typename _Tp, typename _Cond> + class throw_allocator_base + : public annotate_base, public _Cond + { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + +#if __cplusplus >= 201103L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2103. std::allocator propagate_on_container_move_assignment + typedef std::true_type propagate_on_container_move_assignment; +#endif + + private: + typedef _Cond condition_type; + + std::allocator<value_type> _M_allocator; + + using condition_type::throw_conditionally; + + public: + size_type + max_size() const _GLIBCXX_USE_NOEXCEPT + { return _M_allocator.max_size(); } + + pointer + address(reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + const_pointer + address(const_reference __x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(__x); } + + pointer + allocate(size_type __n, std::allocator<void>::const_pointer hint = 0) + { + if (__n > this->max_size()) + std::__throw_bad_alloc(); + + throw_conditionally(); + pointer const a = _M_allocator.allocate(__n, hint); + insert(a, sizeof(value_type) * __n); + return a; + } + +#if __cplusplus >= 201103L + template<typename _Up, typename... _Args> + void + construct(_Up* __p, _Args&&... __args) + { + _M_allocator.construct(__p, std::forward<_Args>(__args)...); + insert_construct(__p); + } + + template<typename _Up> + void + destroy(_Up* __p) + { + erase_construct(__p); + _M_allocator.destroy(__p); + } +#else + void + construct(pointer __p, const value_type& val) + { return _M_allocator.construct(__p, val); } + + void + destroy(pointer __p) + { _M_allocator.destroy(__p); } +#endif + + void + deallocate(pointer __p, size_type __n) + { + erase(__p, sizeof(value_type) * __n); + _M_allocator.deallocate(__p, __n); + } + + void + check_allocated(pointer __p, size_type __n) + { + size_type __t = sizeof(value_type) * __n; + annotate_base::check_allocated(__p, __t); + } + + void + check(size_type __n) + { annotate_base::check(__n); } + }; + + template<typename _Tp, typename _Cond> + inline bool + operator==(const throw_allocator_base<_Tp, _Cond>&, + const throw_allocator_base<_Tp, _Cond>&) + { return true; } + + template<typename _Tp, typename _Cond> + inline bool + operator!=(const throw_allocator_base<_Tp, _Cond>&, + const throw_allocator_base<_Tp, _Cond>&) + { return false; } + + /// Allocator throwing via limit condition. + template<typename _Tp> + struct throw_allocator_limit + : public throw_allocator_base<_Tp, limit_condition> + { + template<typename _Tp1> + struct rebind + { typedef throw_allocator_limit<_Tp1> other; }; + + throw_allocator_limit() _GLIBCXX_USE_NOEXCEPT { } + + throw_allocator_limit(const throw_allocator_limit&) + _GLIBCXX_USE_NOEXCEPT { } + + template<typename _Tp1> + throw_allocator_limit(const throw_allocator_limit<_Tp1>&) + _GLIBCXX_USE_NOEXCEPT { } + + ~throw_allocator_limit() _GLIBCXX_USE_NOEXCEPT { } + }; + + /// Allocator throwing via random condition. + template<typename _Tp> + struct throw_allocator_random + : public throw_allocator_base<_Tp, random_condition> + { + template<typename _Tp1> + struct rebind + { typedef throw_allocator_random<_Tp1> other; }; + + throw_allocator_random() _GLIBCXX_USE_NOEXCEPT { } + + throw_allocator_random(const throw_allocator_random&) + _GLIBCXX_USE_NOEXCEPT { } + + template<typename _Tp1> + throw_allocator_random(const throw_allocator_random<_Tp1>&) + _GLIBCXX_USE_NOEXCEPT { } + + ~throw_allocator_random() _GLIBCXX_USE_NOEXCEPT { } + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#if __cplusplus >= 201103L + +# include <bits/functional_hash.h> + +namespace std _GLIBCXX_VISIBILITY(default) +{ + /// Explicit specialization of std::hash for __gnu_cxx::throw_value_limit. + template<> + struct hash<__gnu_cxx::throw_value_limit> + : public std::unary_function<__gnu_cxx::throw_value_limit, size_t> + { + size_t + operator()(const __gnu_cxx::throw_value_limit& __val) const + { + __gnu_cxx::throw_value_limit::throw_conditionally(); + std::hash<std::size_t> __h; + size_t __result = __h(__val._M_i); + return __result; + } + }; + + /// Explicit specialization of std::hash for __gnu_cxx::throw_value_random. + template<> + struct hash<__gnu_cxx::throw_value_random> + : public std::unary_function<__gnu_cxx::throw_value_random, size_t> + { + size_t + operator()(const __gnu_cxx::throw_value_random& __val) const + { + __gnu_cxx::throw_value_random::throw_conditionally(); + std::hash<std::size_t> __h; + size_t __result = __h(__val._M_i); + return __result; + } + }; +} // end namespace std +#endif + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/type_traits.h b/gcc-4.9/libstdc++-v3/include/ext/type_traits.h new file mode 100644 index 0000000..c9af8ff --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/type_traits.h @@ -0,0 +1,218 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/type_traits.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _EXT_TYPE_TRAITS +#define _EXT_TYPE_TRAITS 1 + +#pragma GCC system_header + +#include <bits/c++config.h> +#include <bits/cpp_type_traits.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // Define a nested type if some predicate holds. + template<bool, typename> + struct __enable_if + { }; + + template<typename _Tp> + struct __enable_if<true, _Tp> + { typedef _Tp __type; }; + + + // Conditional expression for types. If true, first, if false, second. + template<bool _Cond, typename _Iftrue, typename _Iffalse> + struct __conditional_type + { typedef _Iftrue __type; }; + + template<typename _Iftrue, typename _Iffalse> + struct __conditional_type<false, _Iftrue, _Iffalse> + { typedef _Iffalse __type; }; + + + // Given an integral builtin type, return the corresponding unsigned type. + template<typename _Tp> + struct __add_unsigned + { + private: + typedef __enable_if<std::__is_integer<_Tp>::__value, _Tp> __if_type; + + public: + typedef typename __if_type::__type __type; + }; + + template<> + struct __add_unsigned<char> + { typedef unsigned char __type; }; + + template<> + struct __add_unsigned<signed char> + { typedef unsigned char __type; }; + + template<> + struct __add_unsigned<short> + { typedef unsigned short __type; }; + + template<> + struct __add_unsigned<int> + { typedef unsigned int __type; }; + + template<> + struct __add_unsigned<long> + { typedef unsigned long __type; }; + + template<> + struct __add_unsigned<long long> + { typedef unsigned long long __type; }; + + // Declare but don't define. + template<> + struct __add_unsigned<bool>; + + template<> + struct __add_unsigned<wchar_t>; + + + // Given an integral builtin type, return the corresponding signed type. + template<typename _Tp> + struct __remove_unsigned + { + private: + typedef __enable_if<std::__is_integer<_Tp>::__value, _Tp> __if_type; + + public: + typedef typename __if_type::__type __type; + }; + + template<> + struct __remove_unsigned<char> + { typedef signed char __type; }; + + template<> + struct __remove_unsigned<unsigned char> + { typedef signed char __type; }; + + template<> + struct __remove_unsigned<unsigned short> + { typedef short __type; }; + + template<> + struct __remove_unsigned<unsigned int> + { typedef int __type; }; + + template<> + struct __remove_unsigned<unsigned long> + { typedef long __type; }; + + template<> + struct __remove_unsigned<unsigned long long> + { typedef long long __type; }; + + // Declare but don't define. + template<> + struct __remove_unsigned<bool>; + + template<> + struct __remove_unsigned<wchar_t>; + + + // For use in string and vstring. + template<typename _Type> + inline bool + __is_null_pointer(_Type* __ptr) + { return __ptr == 0; } + + template<typename _Type> + inline bool + __is_null_pointer(_Type) + { return false; } + +#if __cplusplus >= 201103L + inline bool + __is_null_pointer(std::nullptr_t) + { return true; } +#endif + + // For complex and cmath + template<typename _Tp, bool = std::__is_integer<_Tp>::__value> + struct __promote + { typedef double __type; }; + + // No nested __type member for non-integer non-floating point types, + // allows this type to be used for SFINAE to constrain overloads in + // <cmath> and <complex> to only the intended types. + template<typename _Tp> + struct __promote<_Tp, false> + { }; + + template<> + struct __promote<long double> + { typedef long double __type; }; + + template<> + struct __promote<double> + { typedef double __type; }; + + template<> + struct __promote<float> + { typedef float __type; }; + + template<typename _Tp, typename _Up, + typename _Tp2 = typename __promote<_Tp>::__type, + typename _Up2 = typename __promote<_Up>::__type> + struct __promote_2 + { + typedef __typeof__(_Tp2() + _Up2()) __type; + }; + + template<typename _Tp, typename _Up, typename _Vp, + typename _Tp2 = typename __promote<_Tp>::__type, + typename _Up2 = typename __promote<_Up>::__type, + typename _Vp2 = typename __promote<_Vp>::__type> + struct __promote_3 + { + typedef __typeof__(_Tp2() + _Up2() + _Vp2()) __type; + }; + + template<typename _Tp, typename _Up, typename _Vp, typename _Wp, + typename _Tp2 = typename __promote<_Tp>::__type, + typename _Up2 = typename __promote<_Up>::__type, + typename _Vp2 = typename __promote<_Vp>::__type, + typename _Wp2 = typename __promote<_Wp>::__type> + struct __promote_4 + { + typedef __typeof__(_Tp2() + _Up2() + _Vp2() + _Wp2()) __type; + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/typelist.h b/gcc-4.9/libstdc++-v3/include/ext/typelist.h new file mode 100644 index 0000000..626e1c7 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/typelist.h @@ -0,0 +1,559 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice and +// this permission notice appear in supporting documentation. None of +// the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied warranty. + +/** + * @file ext/typelist.h + * This file is a GNU extension to the Standard C++ Library. + * + * Contains typelist_chain definitions. + * Typelists are an idea by Andrei Alexandrescu. + */ + +#ifndef _TYPELIST_H +#define _TYPELIST_H 1 + +#include <ext/type_traits.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +/** @namespace __gnu_cxx::typelist + * @brief GNU typelist extensions for public compile-time use. +*/ +namespace typelist +{ + struct null_type { }; + + template<typename Root> + struct node + { + typedef Root root; + }; + + // Forward declarations of functors. + template<typename Hd, typename Typelist> + struct chain + { + typedef Hd head; + typedef Typelist tail; + }; + + // Apply all typelist types to unary functor. + template<typename Fn, typename Typelist> + void + apply(Fn&, Typelist); + + /// Apply all typelist types to generator functor. + template<typename Gn, typename Typelist> + void + apply_generator(Gn&, Typelist); + + // Apply all typelist types and values to generator functor. + template<typename Gn, typename TypelistT, typename TypelistV> + void + apply_generator(Gn&, TypelistT, TypelistV); + + template<typename Typelist0, typename Typelist1> + struct append; + + template<typename Typelist_Typelist> + struct append_typelist; + + template<typename Typelist, typename T> + struct contains; + + template<typename Typelist, template<typename T> class Pred> + struct filter; + + template<typename Typelist, int i> + struct at_index; + + template<typename Typelist, template<typename T> class Transform> + struct transform; + + template<typename Typelist_Typelist> + struct flatten; + + template<typename Typelist> + struct from_first; + + template<typename T1> + struct create1; + + template<typename T1, typename T2> + struct create2; + + template<typename T1, typename T2, typename T3> + struct create3; + + template<typename T1, typename T2, typename T3, typename T4> + struct create4; + + template<typename T1, typename T2, typename T3, typename T4, typename T5> + struct create5; + + template<typename T1, typename T2, typename T3, + typename T4, typename T5, typename T6> + struct create6; +} // namespace typelist + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +namespace typelist +{ +namespace detail +{ + template<typename Fn, typename Typelist_Chain> + struct apply_; + + template<typename Fn, typename Hd, typename Tl> + struct apply_<Fn, chain<Hd, Tl> > + { + void + operator()(Fn& f) + { + f.operator()(Hd()); + apply_<Fn, Tl> next; + next(f); + } + }; + + template<typename Fn> + struct apply_<Fn, null_type> + { + void + operator()(Fn&) { } + }; + + template<typename Gn, typename Typelist_Chain> + struct apply_generator1_; + + template<typename Gn, typename Hd, typename Tl> + struct apply_generator1_<Gn, chain<Hd, Tl> > + { + void + operator()(Gn& g) + { + g.template operator()<Hd>(); + apply_generator1_<Gn, Tl> next; + next(g); + } + }; + + template<typename Gn> + struct apply_generator1_<Gn, null_type> + { + void + operator()(Gn&) { } + }; + + template<typename Gn, typename TypelistT_Chain, typename TypelistV_Chain> + struct apply_generator2_; + + template<typename Gn, typename Hd1, typename TlT, typename Hd2, typename TlV> + struct apply_generator2_<Gn, chain<Hd1, TlT>, chain<Hd2, TlV> > + { + void + operator()(Gn& g) + { + g.template operator()<Hd1, Hd2>(); + apply_generator2_<Gn, TlT, TlV> next; + next(g); + } + }; + + template<typename Gn> + struct apply_generator2_<Gn, null_type, null_type> + { + void + operator()(Gn&) { } + }; + + template<typename Typelist_Chain0, typename Typelist_Chain1> + struct append_; + + template<typename Hd, typename Tl, typename Typelist_Chain> + struct append_<chain<Hd, Tl>, Typelist_Chain> + { + private: + typedef append_<Tl, Typelist_Chain> append_type; + + public: + typedef chain<Hd, typename append_type::type> type; + }; + + template<typename Typelist_Chain> + struct append_<null_type, Typelist_Chain> + { + typedef Typelist_Chain type; + }; + + template<typename Typelist_Chain> + struct append_<Typelist_Chain, null_type> + { + typedef Typelist_Chain type; + }; + + template<> + struct append_<null_type, null_type> + { + typedef null_type type; + }; + + template<typename Typelist_Typelist_Chain> + struct append_typelist_; + + template<typename Hd> + struct append_typelist_<chain<Hd, null_type> > + { + typedef chain<Hd, null_type> type; + }; + + template<typename Hd, typename Tl> + struct append_typelist_<chain< Hd, Tl> > + { + private: + typedef typename append_typelist_<Tl>::type rest_type; + + public: + typedef typename append<Hd, node<rest_type> >::type::root type; + }; + + template<typename Typelist_Chain, typename T> + struct contains_; + + template<typename T> + struct contains_<null_type, T> + { + enum + { + value = false + }; + }; + + template<typename Hd, typename Tl, typename T> + struct contains_<chain<Hd, Tl>, T> + { + enum + { + value = contains_<Tl, T>::value + }; + }; + + template<typename Tl, typename T> + struct contains_<chain<T, Tl>, T> + { + enum + { + value = true + }; + }; + + template<typename Typelist_Chain, template<typename T> class Pred> + struct chain_filter_; + + template<template<typename T> class Pred> + struct chain_filter_<null_type, Pred> + { + typedef null_type type; + }; + + template<typename Hd, typename Tl, template<typename T> class Pred> + struct chain_filter_<chain<Hd, Tl>, Pred> + { + private: + enum + { + include_hd = Pred<Hd>::value + }; + + typedef typename chain_filter_<Tl, Pred>::type rest_type; + typedef chain<Hd, rest_type> chain_type; + + public: + typedef typename __conditional_type<include_hd, chain_type, rest_type>::__type type; + }; + + template<typename Typelist_Chain, int i> + struct chain_at_index_; + + template<typename Hd, typename Tl> + struct chain_at_index_<chain<Hd, Tl>, 0> + { + typedef Hd type; + }; + + template<typename Hd, typename Tl, int i> + struct chain_at_index_<chain<Hd, Tl>, i> + { + typedef typename chain_at_index_<Tl, i - 1>::type type; + }; + + template<class Typelist_Chain, template<typename T> class Transform> + struct chain_transform_; + + template<template<typename T> class Transform> + struct chain_transform_<null_type, Transform> + { + typedef null_type type; + }; + + template<class Hd, class Tl, template<typename T> class Transform> + struct chain_transform_<chain<Hd, Tl>, Transform> + { + private: + typedef typename chain_transform_<Tl, Transform>::type rest_type; + typedef typename Transform<Hd>::type transform_type; + + public: + typedef chain<transform_type, rest_type> type; + }; + + template<typename Typelist_Typelist_Chain> + struct chain_flatten_; + + template<typename Hd_Tl> + struct chain_flatten_<chain<Hd_Tl, null_type> > + { + typedef typename Hd_Tl::root type; + }; + + template<typename Hd_Typelist, class Tl_Typelist> + struct chain_flatten_<chain<Hd_Typelist, Tl_Typelist> > + { + private: + typedef typename chain_flatten_<Tl_Typelist>::type rest_type; + typedef append<Hd_Typelist, node<rest_type> > append_type; + public: + typedef typename append_type::type::root type; + }; +} // namespace detail +} // namespace typelist + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#define _GLIBCXX_TYPELIST_CHAIN1(X0) __gnu_cxx::typelist::chain<X0, __gnu_cxx::typelist::null_type> +#define _GLIBCXX_TYPELIST_CHAIN2(X0, X1) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN1(X1) > +#define _GLIBCXX_TYPELIST_CHAIN3(X0, X1, X2) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN2(X1, X2) > +#define _GLIBCXX_TYPELIST_CHAIN4(X0, X1, X2, X3) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN3(X1, X2, X3) > +#define _GLIBCXX_TYPELIST_CHAIN5(X0, X1, X2, X3, X4) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN4(X1, X2, X3, X4) > +#define _GLIBCXX_TYPELIST_CHAIN6(X0, X1, X2, X3, X4, X5) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN5(X1, X2, X3, X4, X5) > +#define _GLIBCXX_TYPELIST_CHAIN7(X0, X1, X2, X3, X4, X5, X6) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN6(X1, X2, X3, X4, X5, X6) > +#define _GLIBCXX_TYPELIST_CHAIN8(X0, X1, X2, X3, X4, X5, X6, X7) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN7(X1, X2, X3, X4, X5, X6, X7) > +#define _GLIBCXX_TYPELIST_CHAIN9(X0, X1, X2, X3, X4, X5, X6, X7, X8) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN8(X1, X2, X3, X4, X5, X6, X7, X8) > +#define _GLIBCXX_TYPELIST_CHAIN10(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN9(X1, X2, X3, X4, X5, X6, X7, X8, X9) > +#define _GLIBCXX_TYPELIST_CHAIN11(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN10(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) > +#define _GLIBCXX_TYPELIST_CHAIN12(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN11(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) > +#define _GLIBCXX_TYPELIST_CHAIN13(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN12(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) > +#define _GLIBCXX_TYPELIST_CHAIN14(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN13(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) > +#define _GLIBCXX_TYPELIST_CHAIN15(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN14(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) > +#define _GLIBCXX_TYPELIST_CHAIN16(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN15(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15) > +#define _GLIBCXX_TYPELIST_CHAIN17(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN16(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16) > +#define _GLIBCXX_TYPELIST_CHAIN18(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN17(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17) > +#define _GLIBCXX_TYPELIST_CHAIN19(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN18(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18) > +#define _GLIBCXX_TYPELIST_CHAIN20(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19) __gnu_cxx::typelist::chain<X0, _GLIBCXX_TYPELIST_CHAIN19(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19) > + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +namespace typelist +{ + template<typename Fn, typename Typelist> + void + apply(Fn& fn, Typelist) + { + detail::apply_<Fn, typename Typelist::root> a; + a(fn); + } + + template<typename Fn, typename Typelist> + void + apply_generator(Fn& fn, Typelist) + { + detail::apply_generator1_<Fn, typename Typelist::root> a; + a(fn); + } + + template<typename Fn, typename TypelistT, typename TypelistV> + void + apply_generator(Fn& fn, TypelistT, TypelistV) + { + typedef typename TypelistT::root rootT; + typedef typename TypelistV::root rootV; + detail::apply_generator2_<Fn, rootT, rootV> a; + a(fn); + } + + template<typename Typelist0, typename Typelist1> + struct append + { + private: + typedef typename Typelist0::root root0_type; + typedef typename Typelist1::root root1_type; + typedef detail::append_<root0_type, root1_type> append_type; + + public: + typedef node<typename append_type::type> type; + }; + + template<typename Typelist_Typelist> + struct append_typelist + { + private: + typedef typename Typelist_Typelist::root root_type; + typedef detail::append_typelist_<root_type> append_type; + + public: + typedef node<typename append_type::type> type; + }; + + template<typename Typelist, typename T> + struct contains + { + private: + typedef typename Typelist::root root_type; + + public: + enum + { + value = detail::contains_<root_type, T>::value + }; + }; + + template<typename Typelist, template<typename T> class Pred> + struct filter + { + private: + typedef typename Typelist::root root_type; + typedef detail::chain_filter_<root_type, Pred> filter_type; + + public: + typedef node<typename filter_type::type> type; + }; + + template<typename Typelist, int i> + struct at_index + { + private: + typedef typename Typelist::root root_type; + typedef detail::chain_at_index_<root_type, i> index_type; + + public: + typedef typename index_type::type type; + }; + + template<typename Typelist, template<typename T> class Transform> + struct transform + { + private: + typedef typename Typelist::root root_type; + typedef detail::chain_transform_<root_type, Transform> transform_type; + + public: + typedef node<typename transform_type::type> type; + }; + + template<typename Typelist_Typelist> + struct flatten + { + private: + typedef typename Typelist_Typelist::root root_type; + typedef typename detail::chain_flatten_<root_type>::type flatten_type; + + public: + typedef node<flatten_type> type; + }; + + template<typename Typelist> + struct from_first + { + private: + typedef typename at_index<Typelist, 0>::type first_type; + + public: + typedef node<chain<first_type, null_type> > type; + }; + + template<typename T1> + struct create1 + { + typedef node<_GLIBCXX_TYPELIST_CHAIN1(T1)> type; + }; + + template<typename T1, typename T2> + struct create2 + { + typedef node<_GLIBCXX_TYPELIST_CHAIN2(T1,T2)> type; + }; + + template<typename T1, typename T2, typename T3> + struct create3 + { + typedef node<_GLIBCXX_TYPELIST_CHAIN3(T1,T2,T3)> type; + }; + + template<typename T1, typename T2, typename T3, typename T4> + struct create4 + { + typedef node<_GLIBCXX_TYPELIST_CHAIN4(T1,T2,T3,T4)> type; + }; + + template<typename T1, typename T2, typename T3, + typename T4, typename T5> + struct create5 + { + typedef node<_GLIBCXX_TYPELIST_CHAIN5(T1,T2,T3,T4,T5)> type; + }; + + template<typename T1, typename T2, typename T3, + typename T4, typename T5, typename T6> + struct create6 + { + typedef node<_GLIBCXX_TYPELIST_CHAIN6(T1,T2,T3,T4,T5,T6)> type; + }; +} // namespace typelist +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/vstring.h b/gcc-4.9/libstdc++-v3/include/ext/vstring.h new file mode 100644 index 0000000..749d370 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/vstring.h @@ -0,0 +1,2963 @@ +// Versatile string -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/vstring.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _VSTRING_H +#define _VSTRING_H 1 + +#pragma GCC system_header + +#if __cplusplus >= 201103L +#include <initializer_list> +#endif + +#include <ext/vstring_util.h> +#include <ext/rc_string_base.h> +#include <ext/sso_string_base.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * @class __versa_string vstring.h + * @brief Template class __versa_string. + * @ingroup extensions + * + * Data structure managing sequences of characters and + * character-like objects. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + class __versa_string + : private _Base<_CharT, _Traits, _Alloc> + { + typedef _Base<_CharT, _Traits, _Alloc> __vstring_base; + typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type; + + // Types: + public: + typedef _Traits traits_type; + typedef typename _Traits::char_type value_type; + typedef _Alloc allocator_type; + typedef typename _CharT_alloc_type::size_type size_type; + typedef typename _CharT_alloc_type::difference_type difference_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename _CharT_alloc_type::pointer pointer; + typedef typename _CharT_alloc_type::const_pointer const_pointer; + typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator; + typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string> + const_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + typedef std::reverse_iterator<iterator> reverse_iterator; + + // Data Member (public): + /// Value returned by various member functions when they fail. + static const size_type npos = static_cast<size_type>(-1); + + private: + size_type + _M_check(size_type __pos, const char* __s) const + { + if (__pos > this->size()) + std::__throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " + "this->size() (which is %zu)"), + __s, __pos, this->size()); + return __pos; + } + + void + _M_check_length(size_type __n1, size_type __n2, const char* __s) const + { + if (this->max_size() - (this->size() - __n1) < __n2) + std::__throw_length_error(__N(__s)); + } + + // NB: _M_limit doesn't check for a bad __pos value. + size_type + _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT + { + const bool __testoff = __off < this->size() - __pos; + return __testoff ? __off : this->size() - __pos; + } + + // True if _Rep and source do not overlap. + bool + _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT + { + return (std::less<const _CharT*>()(__s, this->_M_data()) + || std::less<const _CharT*>()(this->_M_data() + + this->size(), __s)); + } + + // For the internal use we have functions similar to `begin'/`end' + // but they do not call _M_leak. + iterator + _M_ibegin() const _GLIBCXX_NOEXCEPT + { return iterator(this->_M_data()); } + + iterator + _M_iend() const _GLIBCXX_NOEXCEPT + { return iterator(this->_M_data() + this->_M_length()); } + + public: + // Construct/copy/destroy: + // NB: We overload ctors in some cases instead of using default + // arguments, per 17.4.4.4 para. 2 item 2. + + /** + * @brief Construct an empty string using allocator @a a. + */ + explicit + __versa_string(const _Alloc& __a = _Alloc()) _GLIBCXX_NOEXCEPT + : __vstring_base(__a) { } + + // NB: per LWG issue 42, semantics different from IS: + /** + * @brief Construct string with copy of value of @a __str. + * @param __str Source string. + */ + __versa_string(const __versa_string& __str) + : __vstring_base(__str) { } + +#if __cplusplus >= 201103L + /** + * @brief String move constructor. + * @param __str Source string. + * + * The newly-constructed %string contains the exact contents of + * @a __str. The contents of @a __str are a valid, but unspecified + * string. + */ + __versa_string(__versa_string&& __str) noexcept + : __vstring_base(std::move(__str)) { } + + /** + * @brief Construct string from an initializer list. + * @param __l std::initializer_list of characters. + * @param __a Allocator to use (default is default allocator). + */ + __versa_string(std::initializer_list<_CharT> __l, + const _Alloc& __a = _Alloc()) + : __vstring_base(__l.begin(), __l.end(), __a) { } +#endif + + /** + * @brief Construct string as copy of a substring. + * @param __str Source string. + * @param __pos Index of first character to copy from. + * @param __n Number of characters to copy (default remainder). + */ + __versa_string(const __versa_string& __str, size_type __pos, + size_type __n = npos) + : __vstring_base(__str._M_data() + + __str._M_check(__pos, + "__versa_string::__versa_string"), + __str._M_data() + __str._M_limit(__pos, __n) + + __pos, _Alloc()) { } + + /** + * @brief Construct string as copy of a substring. + * @param __str Source string. + * @param __pos Index of first character to copy from. + * @param __n Number of characters to copy. + * @param __a Allocator to use. + */ + __versa_string(const __versa_string& __str, size_type __pos, + size_type __n, const _Alloc& __a) + : __vstring_base(__str._M_data() + + __str._M_check(__pos, + "__versa_string::__versa_string"), + __str._M_data() + __str._M_limit(__pos, __n) + + __pos, __a) { } + + /** + * @brief Construct string initialized by a character array. + * @param __s Source character array. + * @param __n Number of characters to copy. + * @param __a Allocator to use (default is default allocator). + * + * NB: @a __s must have at least @a __n characters, '\\0' has no special + * meaning. + */ + __versa_string(const _CharT* __s, size_type __n, + const _Alloc& __a = _Alloc()) + : __vstring_base(__s, __s + __n, __a) { } + + /** + * @brief Construct string as copy of a C string. + * @param __s Source C string. + * @param __a Allocator to use (default is default allocator). + */ + __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc()) + : __vstring_base(__s, __s ? __s + traits_type::length(__s) : + __s + npos, __a) { } + + /** + * @brief Construct string as multiple characters. + * @param __n Number of characters. + * @param __c Character to use. + * @param __a Allocator to use (default is default allocator). + */ + __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) + : __vstring_base(__n, __c, __a) { } + + /** + * @brief Construct string as copy of a range. + * @param __beg Start of range. + * @param __end End of range. + * @param __a Allocator to use (default is default allocator). + */ +#if __cplusplus >= 201103L + template<class _InputIterator, + typename = std::_RequireInputIter<_InputIterator>> +#else + template<class _InputIterator> +#endif + __versa_string(_InputIterator __beg, _InputIterator __end, + const _Alloc& __a = _Alloc()) + : __vstring_base(__beg, __end, __a) { } + + /** + * @brief Destroy the string instance. + */ + ~__versa_string() _GLIBCXX_NOEXCEPT { } + + /** + * @brief Assign the value of @a str to this string. + * @param __str Source string. + */ + __versa_string& + operator=(const __versa_string& __str) + { return this->assign(__str); } + +#if __cplusplus >= 201103L + /** + * @brief String move assignment operator. + * @param __str Source string. + * + * The contents of @a __str are moved into this string (without + * copying). @a __str is a valid, but unspecified string. + */ + __versa_string& + operator=(__versa_string&& __str) noexcept + { + // NB: DR 1204. + this->swap(__str); + return *this; + } + + /** + * @brief Set value to string constructed from initializer list. + * @param __l std::initializer_list. + */ + __versa_string& + operator=(std::initializer_list<_CharT> __l) + { + this->assign(__l.begin(), __l.end()); + return *this; + } +#endif + + /** + * @brief Copy contents of @a __s into this string. + * @param __s Source null-terminated string. + */ + __versa_string& + operator=(const _CharT* __s) + { return this->assign(__s); } + + /** + * @brief Set value to string of length 1. + * @param __c Source character. + * + * Assigning to a character makes this string length 1 and + * (*this)[0] == @a __c. + */ + __versa_string& + operator=(_CharT __c) + { + this->assign(1, __c); + return *this; + } + + // Iterators: + /** + * Returns a read/write iterator that points to the first character in + * the %string. Unshares the string. + */ + iterator + begin() _GLIBCXX_NOEXCEPT + { + this->_M_leak(); + return iterator(this->_M_data()); + } + + /** + * Returns a read-only (constant) iterator that points to the first + * character in the %string. + */ + const_iterator + begin() const _GLIBCXX_NOEXCEPT + { return const_iterator(this->_M_data()); } + + /** + * Returns a read/write iterator that points one past the last + * character in the %string. Unshares the string. + */ + iterator + end() _GLIBCXX_NOEXCEPT + { + this->_M_leak(); + return iterator(this->_M_data() + this->size()); + } + + /** + * Returns a read-only (constant) iterator that points one past the + * last character in the %string. + */ + const_iterator + end() const _GLIBCXX_NOEXCEPT + { return const_iterator(this->_M_data() + this->size()); } + + /** + * Returns a read/write reverse iterator that points to the last + * character in the %string. Iteration is done in reverse element + * order. Unshares the string. + */ + reverse_iterator + rbegin() _GLIBCXX_NOEXCEPT + { return reverse_iterator(this->end()); } + + /** + * Returns a read-only (constant) reverse iterator that points + * to the last character in the %string. Iteration is done in + * reverse element order. + */ + const_reverse_iterator + rbegin() const _GLIBCXX_NOEXCEPT + { return const_reverse_iterator(this->end()); } + + /** + * Returns a read/write reverse iterator that points to one before the + * first character in the %string. Iteration is done in reverse + * element order. Unshares the string. + */ + reverse_iterator + rend() _GLIBCXX_NOEXCEPT + { return reverse_iterator(this->begin()); } + + /** + * Returns a read-only (constant) reverse iterator that points + * to one before the first character in the %string. Iteration + * is done in reverse element order. + */ + const_reverse_iterator + rend() const _GLIBCXX_NOEXCEPT + { return const_reverse_iterator(this->begin()); } + +#if __cplusplus >= 201103L + /** + * Returns a read-only (constant) iterator that points to the first + * character in the %string. + */ + const_iterator + cbegin() const noexcept + { return const_iterator(this->_M_data()); } + + /** + * Returns a read-only (constant) iterator that points one past the + * last character in the %string. + */ + const_iterator + cend() const noexcept + { return const_iterator(this->_M_data() + this->size()); } + + /** + * Returns a read-only (constant) reverse iterator that points + * to the last character in the %string. Iteration is done in + * reverse element order. + */ + const_reverse_iterator + crbegin() const noexcept + { return const_reverse_iterator(this->end()); } + + /** + * Returns a read-only (constant) reverse iterator that points + * to one before the first character in the %string. Iteration + * is done in reverse element order. + */ + const_reverse_iterator + crend() const noexcept + { return const_reverse_iterator(this->begin()); } +#endif + + public: + // Capacity: + /// Returns the number of characters in the string, not including any + /// null-termination. + size_type + size() const _GLIBCXX_NOEXCEPT + { return this->_M_length(); } + + /// Returns the number of characters in the string, not including any + /// null-termination. + size_type + length() const _GLIBCXX_NOEXCEPT + { return this->_M_length(); } + + /// Returns the size() of the largest possible %string. + size_type + max_size() const _GLIBCXX_NOEXCEPT + { return this->_M_max_size(); } + + /** + * @brief Resizes the %string to the specified number of characters. + * @param __n Number of characters the %string should contain. + * @param __c Character to fill any new elements. + * + * This function will %resize the %string to the specified + * number of characters. If the number is smaller than the + * %string's current size the %string is truncated, otherwise + * the %string is extended and new elements are set to @a __c. + */ + void + resize(size_type __n, _CharT __c); + + /** + * @brief Resizes the %string to the specified number of characters. + * @param __n Number of characters the %string should contain. + * + * This function will resize the %string to the specified + * length. If the new size is smaller than the %string's + * current size the %string is truncated, otherwise the %string + * is extended and new characters are default-constructed. For + * basic types such as char, this means setting them to 0. + */ + void + resize(size_type __n) + { this->resize(__n, _CharT()); } + +#if __cplusplus >= 201103L + /// A non-binding request to reduce capacity() to size(). + void + shrink_to_fit() noexcept + { + if (capacity() > size()) + { + __try + { this->reserve(0); } + __catch(...) + { } + } + } +#endif + + /** + * Returns the total number of characters that the %string can + * hold before needing to allocate more memory. + */ + size_type + capacity() const _GLIBCXX_NOEXCEPT + { return this->_M_capacity(); } + + /** + * @brief Attempt to preallocate enough memory for specified number of + * characters. + * @param __res_arg Number of characters required. + * @throw std::length_error If @a __res_arg exceeds @c max_size(). + * + * This function attempts to reserve enough memory for the + * %string to hold the specified number of characters. If the + * number requested is more than max_size(), length_error is + * thrown. + * + * The advantage of this function is that if optimal code is a + * necessity and the user can determine the string length that + * will be required, the user can reserve the memory in + * %advance, and thus prevent a possible reallocation of memory + * and copying of %string data. + */ + void + reserve(size_type __res_arg = 0) + { this->_M_reserve(__res_arg); } + + /** + * Erases the string, making it empty. + */ + void + clear() _GLIBCXX_NOEXCEPT + { this->_M_clear(); } + + /** + * Returns true if the %string is empty. Equivalent to + * <code>*this == ""</code>. + */ + bool + empty() const _GLIBCXX_NOEXCEPT + { return this->size() == 0; } + + // Element access: + /** + * @brief Subscript access to the data contained in the %string. + * @param __pos The index of the character to access. + * @return Read-only (constant) reference to the character. + * + * This operator allows for easy, array-style, data access. + * Note that data access with this operator is unchecked and + * out_of_range lookups are not defined. (For checked lookups + * see at().) + */ + const_reference + operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT + { + _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); + return this->_M_data()[__pos]; + } + + /** + * @brief Subscript access to the data contained in the %string. + * @param __pos The index of the character to access. + * @return Read/write reference to the character. + * + * This operator allows for easy, array-style, data access. + * Note that data access with this operator is unchecked and + * out_of_range lookups are not defined. (For checked lookups + * see at().) Unshares the string. + */ + reference + operator[](size_type __pos) _GLIBCXX_NOEXCEPT + { + // Allow pos == size() both in C++98 mode, as v3 extension, + // and in C++11 mode. + _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); + // In pedantic mode be strict in C++98 mode. + _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L + || __pos < this->size()); + this->_M_leak(); + return this->_M_data()[__pos]; + } + + /** + * @brief Provides access to the data contained in the %string. + * @param __n The index of the character to access. + * @return Read-only (const) reference to the character. + * @throw std::out_of_range If @a __n is an invalid index. + * + * This function provides for safer data access. The parameter + * is first checked that it is in the range of the string. The + * function throws out_of_range if the check fails. + */ + const_reference + at(size_type __n) const + { + if (__n >= this->size()) + std::__throw_out_of_range_fmt(__N("__versa_string::at: __n " + "(which is %zu) >= this->size() " + "(which is %zu)"), + __n, this->size()); + return this->_M_data()[__n]; + } + + /** + * @brief Provides access to the data contained in the %string. + * @param __n The index of the character to access. + * @return Read/write reference to the character. + * @throw std::out_of_range If @a __n is an invalid index. + * + * This function provides for safer data access. The parameter + * is first checked that it is in the range of the string. The + * function throws out_of_range if the check fails. Success + * results in unsharing the string. + */ + reference + at(size_type __n) + { + if (__n >= this->size()) + std::__throw_out_of_range_fmt(__N("__versa_string::at: __n " + "(which is %zu) >= this->size() " + "(which is %zu)"), + __n, this->size()); + this->_M_leak(); + return this->_M_data()[__n]; + } + +#if __cplusplus >= 201103L + /** + * Returns a read/write reference to the data at the first + * element of the %string. + */ + reference + front() _GLIBCXX_NOEXCEPT + { return operator[](0); } + + /** + * Returns a read-only (constant) reference to the data at the first + * element of the %string. + */ + const_reference + front() const _GLIBCXX_NOEXCEPT + { return operator[](0); } + + /** + * Returns a read/write reference to the data at the last + * element of the %string. + */ + reference + back() _GLIBCXX_NOEXCEPT + { return operator[](this->size() - 1); } + + /** + * Returns a read-only (constant) reference to the data at the + * last element of the %string. + */ + const_reference + back() const _GLIBCXX_NOEXCEPT + { return operator[](this->size() - 1); } +#endif + + // Modifiers: + /** + * @brief Append a string to this string. + * @param __str The string to append. + * @return Reference to this string. + */ + __versa_string& + operator+=(const __versa_string& __str) + { return this->append(__str); } + + /** + * @brief Append a C string. + * @param __s The C string to append. + * @return Reference to this string. + */ + __versa_string& + operator+=(const _CharT* __s) + { return this->append(__s); } + + /** + * @brief Append a character. + * @param __c The character to append. + * @return Reference to this string. + */ + __versa_string& + operator+=(_CharT __c) + { + this->push_back(__c); + return *this; + } + +#if __cplusplus >= 201103L + /** + * @brief Append an initializer_list of characters. + * @param __l The initializer_list of characters to be appended. + * @return Reference to this string. + */ + __versa_string& + operator+=(std::initializer_list<_CharT> __l) + { return this->append(__l.begin(), __l.end()); } +#endif // C++11 + + /** + * @brief Append a string to this string. + * @param __str The string to append. + * @return Reference to this string. + */ + __versa_string& + append(const __versa_string& __str) + { return _M_append(__str._M_data(), __str.size()); } + + /** + * @brief Append a substring. + * @param __str The string to append. + * @param __pos Index of the first character of str to append. + * @param __n The number of characters to append. + * @return Reference to this string. + * @throw std::out_of_range if @a pos is not a valid index. + * + * This function appends @a __n characters from @a __str + * starting at @a __pos to this string. If @a __n is is larger + * than the number of available characters in @a __str, the + * remainder of @a __str is appended. + */ + __versa_string& + append(const __versa_string& __str, size_type __pos, size_type __n) + { return _M_append(__str._M_data() + + __str._M_check(__pos, "__versa_string::append"), + __str._M_limit(__pos, __n)); } + + /** + * @brief Append a C substring. + * @param __s The C string to append. + * @param __n The number of characters to append. + * @return Reference to this string. + */ + __versa_string& + append(const _CharT* __s, size_type __n) + { + __glibcxx_requires_string_len(__s, __n); + _M_check_length(size_type(0), __n, "__versa_string::append"); + return _M_append(__s, __n); + } + + /** + * @brief Append a C string. + * @param __s The C string to append. + * @return Reference to this string. + */ + __versa_string& + append(const _CharT* __s) + { + __glibcxx_requires_string(__s); + const size_type __n = traits_type::length(__s); + _M_check_length(size_type(0), __n, "__versa_string::append"); + return _M_append(__s, __n); + } + + /** + * @brief Append multiple characters. + * @param __n The number of characters to append. + * @param __c The character to use. + * @return Reference to this string. + * + * Appends n copies of c to this string. + */ + __versa_string& + append(size_type __n, _CharT __c) + { return _M_replace_aux(this->size(), size_type(0), __n, __c); } + +#if __cplusplus >= 201103L + /** + * @brief Append an initializer_list of characters. + * @param __l The initializer_list of characters to append. + * @return Reference to this string. + */ + __versa_string& + append(std::initializer_list<_CharT> __l) + { return this->append(__l.begin(), __l.end()); } +#endif // C++11 + + /** + * @brief Append a range of characters. + * @param __first Iterator referencing the first character to append. + * @param __last Iterator marking the end of the range. + * @return Reference to this string. + * + * Appends characters in the range [first,last) to this string. + */ +#if __cplusplus >= 201103L + template<class _InputIterator, + typename = std::_RequireInputIter<_InputIterator>> +#else + template<class _InputIterator> +#endif + __versa_string& + append(_InputIterator __first, _InputIterator __last) + { return this->replace(_M_iend(), _M_iend(), __first, __last); } + + /** + * @brief Append a single character. + * @param __c Character to append. + */ + void + push_back(_CharT __c) + { + const size_type __size = this->size(); + if (__size + 1 > this->capacity() || this->_M_is_shared()) + this->_M_mutate(__size, size_type(0), 0, size_type(1)); + traits_type::assign(this->_M_data()[__size], __c); + this->_M_set_length(__size + 1); + } + + /** + * @brief Set value to contents of another string. + * @param __str Source string to use. + * @return Reference to this string. + */ + __versa_string& + assign(const __versa_string& __str) + { + this->_M_assign(__str); + return *this; + } + +#if __cplusplus >= 201103L + /** + * @brief Set value to contents of another string. + * @param __str Source string to use. + * @return Reference to this string. + * + * This function sets this string to the exact contents of @a __str. + * @a __str is a valid, but unspecified string. + */ + __versa_string& + assign(__versa_string&& __str) noexcept + { + this->swap(__str); + return *this; + } +#endif // C++11 + + /** + * @brief Set value to a substring of a string. + * @param __str The string to use. + * @param __pos Index of the first character of str. + * @param __n Number of characters to use. + * @return Reference to this string. + * @throw std::out_of_range if @a __pos is not a valid index. + * + * This function sets this string to the substring of @a __str + * consisting of @a __n characters at @a __pos. If @a __n is + * is larger than the number of available characters in @a + * __str, the remainder of @a __str is used. + */ + __versa_string& + assign(const __versa_string& __str, size_type __pos, size_type __n) + { return _M_replace(size_type(0), this->size(), __str._M_data() + + __str._M_check(__pos, "__versa_string::assign"), + __str._M_limit(__pos, __n)); } + + /** + * @brief Set value to a C substring. + * @param __s The C string to use. + * @param __n Number of characters to use. + * @return Reference to this string. + * + * This function sets the value of this string to the first @a + * __n characters of @a __s. If @a __n is is larger than the + * number of available characters in @a __s, the remainder of + * @a __s is used. + */ + __versa_string& + assign(const _CharT* __s, size_type __n) + { + __glibcxx_requires_string_len(__s, __n); + return _M_replace(size_type(0), this->size(), __s, __n); + } + + /** + * @brief Set value to contents of a C string. + * @param __s The C string to use. + * @return Reference to this string. + * + * This function sets the value of this string to the value of + * @a __s. The data is copied, so there is no dependence on @a + * __s once the function returns. + */ + __versa_string& + assign(const _CharT* __s) + { + __glibcxx_requires_string(__s); + return _M_replace(size_type(0), this->size(), __s, + traits_type::length(__s)); + } + + /** + * @brief Set value to multiple characters. + * @param __n Length of the resulting string. + * @param __c The character to use. + * @return Reference to this string. + * + * This function sets the value of this string to @a __n copies of + * character @a __c. + */ + __versa_string& + assign(size_type __n, _CharT __c) + { return _M_replace_aux(size_type(0), this->size(), __n, __c); } + + /** + * @brief Set value to a range of characters. + * @param __first Iterator referencing the first character to append. + * @param __last Iterator marking the end of the range. + * @return Reference to this string. + * + * Sets value of string to characters in the range + * [first,last). + */ +#if __cplusplus >= 201103L + template<class _InputIterator, + typename = std::_RequireInputIter<_InputIterator>> +#else + template<class _InputIterator> +#endif + __versa_string& + assign(_InputIterator __first, _InputIterator __last) + { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } + +#if __cplusplus >= 201103L + /** + * @brief Set value to an initializer_list of characters. + * @param __l The initializer_list of characters to assign. + * @return Reference to this string. + */ + __versa_string& + assign(std::initializer_list<_CharT> __l) + { return this->assign(__l.begin(), __l.end()); } +#endif // C++11 + +#if __cplusplus >= 201103L + /** + * @brief Insert multiple characters. + * @param __p Const_iterator referencing location in string to + * insert at. + * @param __n Number of characters to insert + * @param __c The character to insert. + * @return Iterator referencing the first inserted char. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Inserts @a __n copies of character @a __c starting at the + * position referenced by iterator @a __p. If adding + * characters causes the length to exceed max_size(), + * length_error is thrown. The value of the string doesn't + * change if an error is thrown. + */ + iterator + insert(const_iterator __p, size_type __n, _CharT __c) + { + _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); + const size_type __pos = __p - _M_ibegin(); + this->replace(__p, __p, __n, __c); + return iterator(this->_M_data() + __pos); + } +#else + /** + * @brief Insert multiple characters. + * @param __p Iterator referencing location in string to insert at. + * @param __n Number of characters to insert + * @param __c The character to insert. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Inserts @a __n copies of character @a __c starting at the + * position referenced by iterator @a __p. If adding + * characters causes the length to exceed max_size(), + * length_error is thrown. The value of the string doesn't + * change if an error is thrown. + */ + void + insert(iterator __p, size_type __n, _CharT __c) + { this->replace(__p, __p, __n, __c); } +#endif + +#if __cplusplus >= 201103L + /** + * @brief Insert a range of characters. + * @param __p Const_iterator referencing location in string to + * insert at. + * @param __beg Start of range. + * @param __end End of range. + * @return Iterator referencing the first inserted char. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Inserts characters in range [beg,end). If adding characters + * causes the length to exceed max_size(), length_error is + * thrown. The value of the string doesn't change if an error + * is thrown. + */ + template<class _InputIterator, + typename = std::_RequireInputIter<_InputIterator>> + iterator + insert(const_iterator __p, _InputIterator __beg, _InputIterator __end) + { + _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); + const size_type __pos = __p - _M_ibegin(); + this->replace(__p, __p, __beg, __end); + return iterator(this->_M_data() + __pos); + } +#else + /** + * @brief Insert a range of characters. + * @param __p Iterator referencing location in string to insert at. + * @param __beg Start of range. + * @param __end End of range. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Inserts characters in range [beg,end). If adding characters + * causes the length to exceed max_size(), length_error is + * thrown. The value of the string doesn't change if an error + * is thrown. + */ + template<class _InputIterator> + void + insert(iterator __p, _InputIterator __beg, _InputIterator __end) + { this->replace(__p, __p, __beg, __end); } +#endif + +#if __cplusplus >= 201103L + /** + * @brief Insert an initializer_list of characters. + * @param __p Const_iterator referencing location in string to + * insert at. + * @param __l The initializer_list of characters to insert. + * @return Iterator referencing the first inserted char. + * @throw std::length_error If new length exceeds @c max_size(). + */ + iterator + insert(const_iterator __p, std::initializer_list<_CharT> __l) + { return this->insert(__p, __l.begin(), __l.end()); } +#endif // C++11 + + /** + * @brief Insert value of a string. + * @param __pos1 Iterator referencing location in string to insert at. + * @param __str The string to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Inserts value of @a __str starting at @a __pos1. If adding + * characters causes the length to exceed max_size(), + * length_error is thrown. The value of the string doesn't + * change if an error is thrown. + */ + __versa_string& + insert(size_type __pos1, const __versa_string& __str) + { return this->replace(__pos1, size_type(0), + __str._M_data(), __str.size()); } + + /** + * @brief Insert a substring. + * @param __pos1 Iterator referencing location in string to insert at. + * @param __str The string to insert. + * @param __pos2 Start of characters in str to insert. + * @param __n Number of characters to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * @throw std::out_of_range If @a __pos1 > size() or + * @a __pos2 > @a __str.size(). + * + * Starting at @a __pos1, insert @a __n character of @a __str + * beginning with @a __pos2. If adding characters causes the + * length to exceed max_size(), length_error is thrown. If @a + * __pos1 is beyond the end of this string or @a __pos2 is + * beyond the end of @a __str, out_of_range is thrown. The + * value of the string doesn't change if an error is thrown. + */ + __versa_string& + insert(size_type __pos1, const __versa_string& __str, + size_type __pos2, size_type __n) + { return this->replace(__pos1, size_type(0), __str._M_data() + + __str._M_check(__pos2, "__versa_string::insert"), + __str._M_limit(__pos2, __n)); } + + /** + * @brief Insert a C substring. + * @param __pos Iterator referencing location in string to insert at. + * @param __s The C string to insert. + * @param __n The number of characters to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * @throw std::out_of_range If @a __pos is beyond the end of this + * string. + * + * Inserts the first @a __n characters of @a __s starting at @a + * __pos. If adding characters causes the length to exceed + * max_size(), length_error is thrown. If @a __pos is beyond + * end(), out_of_range is thrown. The value of the string + * doesn't change if an error is thrown. + */ + __versa_string& + insert(size_type __pos, const _CharT* __s, size_type __n) + { return this->replace(__pos, size_type(0), __s, __n); } + + /** + * @brief Insert a C string. + * @param __pos Iterator referencing location in string to insert at. + * @param __s The C string to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * @throw std::out_of_range If @a __pos is beyond the end of this + * string. + * + * Inserts the first @a __n characters of @a __s starting at @a + * __pos. If adding characters causes the length to exceed + * max_size(), length_error is thrown. If @a __pos is beyond + * end(), out_of_range is thrown. The value of the string + * doesn't change if an error is thrown. + */ + __versa_string& + insert(size_type __pos, const _CharT* __s) + { + __glibcxx_requires_string(__s); + return this->replace(__pos, size_type(0), __s, + traits_type::length(__s)); + } + + /** + * @brief Insert multiple characters. + * @param __pos Index in string to insert at. + * @param __n Number of characters to insert + * @param __c The character to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * @throw std::out_of_range If @a __pos is beyond the end of this + * string. + * + * Inserts @a __n copies of character @a __c starting at index + * @a __pos. If adding characters causes the length to exceed + * max_size(), length_error is thrown. If @a __pos > length(), + * out_of_range is thrown. The value of the string doesn't + * change if an error is thrown. + */ + __versa_string& + insert(size_type __pos, size_type __n, _CharT __c) + { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"), + size_type(0), __n, __c); } + + /** + * @brief Insert one character. + * @param __p Iterator referencing position in string to insert at. + * @param __c The character to insert. + * @return Iterator referencing newly inserted char. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Inserts character @a __c at position referenced by @a __p. + * If adding character causes the length to exceed max_size(), + * length_error is thrown. If @a __p is beyond end of string, + * out_of_range is thrown. The value of the string doesn't + * change if an error is thrown. + */ + iterator +#if __cplusplus >= 201103L + insert(const_iterator __p, _CharT __c) +#else + insert(iterator __p, _CharT __c) +#endif + { + _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); + const size_type __pos = __p - _M_ibegin(); + _M_replace_aux(__pos, size_type(0), size_type(1), __c); + this->_M_set_leaked(); + return iterator(this->_M_data() + __pos); + } + + /** + * @brief Remove characters. + * @param __pos Index of first character to remove (default 0). + * @param __n Number of characters to remove (default remainder). + * @return Reference to this string. + * @throw std::out_of_range If @a __pos is beyond the end of this + * string. + * + * Removes @a __n characters from this string starting at @a + * __pos. The length of the string is reduced by @a __n. If + * there are < @a __n characters to remove, the remainder of + * the string is truncated. If @a __p is beyond end of string, + * out_of_range is thrown. The value of the string doesn't + * change if an error is thrown. + */ + __versa_string& + erase(size_type __pos = 0, size_type __n = npos) + { + this->_M_erase(_M_check(__pos, "__versa_string::erase"), + _M_limit(__pos, __n)); + return *this; + } + + /** + * @brief Remove one character. + * @param __position Iterator referencing the character to remove. + * @return iterator referencing same location after removal. + * + * Removes the character at @a __position from this string. The + * value of the string doesn't change if an error is thrown. + */ + iterator +#if __cplusplus >= 201103L + erase(const_iterator __position) +#else + erase(iterator __position) +#endif + { + _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() + && __position < _M_iend()); + const size_type __pos = __position - _M_ibegin(); + this->_M_erase(__pos, size_type(1)); + this->_M_set_leaked(); + return iterator(this->_M_data() + __pos); + } + + /** + * @brief Remove a range of characters. + * @param __first Iterator referencing the first character to remove. + * @param __last Iterator referencing the end of the range. + * @return Iterator referencing location of first after removal. + * + * Removes the characters in the range [first,last) from this + * string. The value of the string doesn't change if an error + * is thrown. + */ + iterator +#if __cplusplus >= 201103L + erase(const_iterator __first, const_iterator __last) +#else + erase(iterator __first, iterator __last) +#endif + { + _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last + && __last <= _M_iend()); + const size_type __pos = __first - _M_ibegin(); + this->_M_erase(__pos, __last - __first); + this->_M_set_leaked(); + return iterator(this->_M_data() + __pos); + } + +#if __cplusplus >= 201103L + /** + * @brief Remove the last character. + * + * The string must be non-empty. + */ + void + pop_back() + { this->_M_erase(size()-1, 1); } +#endif // C++11 + + /** + * @brief Replace characters with value from another string. + * @param __pos Index of first character to replace. + * @param __n Number of characters to be replaced. + * @param __str String to insert. + * @return Reference to this string. + * @throw std::out_of_range If @a __pos is beyond the end of this + * string. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [pos,pos+n) from this + * string. In place, the value of @a __str is inserted. If @a + * __pos is beyond end of string, out_of_range is thrown. If + * the length of the result exceeds max_size(), length_error is + * thrown. The value of the string doesn't change if an error + * is thrown. + */ + __versa_string& + replace(size_type __pos, size_type __n, const __versa_string& __str) + { return this->replace(__pos, __n, __str._M_data(), __str.size()); } + + /** + * @brief Replace characters with value from another string. + * @param __pos1 Index of first character to replace. + * @param __n1 Number of characters to be replaced. + * @param __str String to insert. + * @param __pos2 Index of first character of str to use. + * @param __n2 Number of characters from str to use. + * @return Reference to this string. + * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > + * str.size(). + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [pos1,pos1 + n) from + * this string. In place, the value of @a __str is inserted. + * If @a __pos is beyond end of string, out_of_range is thrown. + * If the length of the result exceeds max_size(), length_error + * is thrown. The value of the string doesn't change if an + * error is thrown. + */ + __versa_string& + replace(size_type __pos1, size_type __n1, const __versa_string& __str, + size_type __pos2, size_type __n2) + { + return this->replace(__pos1, __n1, __str._M_data() + + __str._M_check(__pos2, + "__versa_string::replace"), + __str._M_limit(__pos2, __n2)); + } + + /** + * @brief Replace characters with value of a C substring. + * @param __pos Index of first character to replace. + * @param __n1 Number of characters to be replaced. + * @param __s C string to insert. + * @param __n2 Number of characters from @a __s to use. + * @return Reference to this string. + * @throw std::out_of_range If @a __pos1 > size(). + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [pos,pos + n1) from this + * string. In place, the first @a __n2 characters of @a __s + * are inserted, or all of @a __s if @a __n2 is too large. If + * @a __pos is beyond end of string, out_of_range is thrown. + * If the length of result exceeds max_size(), length_error is + * thrown. The value of the string doesn't change if an error + * is thrown. + */ + __versa_string& + replace(size_type __pos, size_type __n1, const _CharT* __s, + size_type __n2) + { + __glibcxx_requires_string_len(__s, __n2); + return _M_replace(_M_check(__pos, "__versa_string::replace"), + _M_limit(__pos, __n1), __s, __n2); + } + + /** + * @brief Replace characters with value of a C string. + * @param __pos Index of first character to replace. + * @param __n1 Number of characters to be replaced. + * @param __s C string to insert. + * @return Reference to this string. + * @throw std::out_of_range If @a __pos > size(). + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [pos,pos + n1) from this + * string. In place, the characters of @a __s are inserted. If + * @a pos is beyond end of string, out_of_range is thrown. If + * the length of result exceeds max_size(), length_error is thrown. + * The value of the string doesn't change if an error is thrown. + */ + __versa_string& + replace(size_type __pos, size_type __n1, const _CharT* __s) + { + __glibcxx_requires_string(__s); + return this->replace(__pos, __n1, __s, traits_type::length(__s)); + } + + /** + * @brief Replace characters with multiple characters. + * @param __pos Index of first character to replace. + * @param __n1 Number of characters to be replaced. + * @param __n2 Number of characters to insert. + * @param __c Character to insert. + * @return Reference to this string. + * @throw std::out_of_range If @a __pos > size(). + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [pos,pos + n1) from this + * string. In place, @a __n2 copies of @a __c are inserted. + * If @a __pos is beyond end of string, out_of_range is thrown. + * If the length of result exceeds max_size(), length_error is + * thrown. The value of the string doesn't change if an error + * is thrown. + */ + __versa_string& + replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) + { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"), + _M_limit(__pos, __n1), __n2, __c); } + + /** + * @brief Replace range of characters with string. + * @param __i1 Iterator referencing start of range to replace. + * @param __i2 Iterator referencing end of range to replace. + * @param __str String value to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [i1,i2). In place, the + * value of @a __str is inserted. If the length of result + * exceeds max_size(), length_error is thrown. The value of + * the string doesn't change if an error is thrown. + */ + __versa_string& +#if __cplusplus >= 201103L + replace(const_iterator __i1, const_iterator __i2, + const __versa_string& __str) +#else + replace(iterator __i1, iterator __i2, const __versa_string& __str) +#endif + { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } + + /** + * @brief Replace range of characters with C substring. + * @param __i1 Iterator referencing start of range to replace. + * @param __i2 Iterator referencing end of range to replace. + * @param __s C string value to insert. + * @param __n Number of characters from s to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [i1,i2). In place, the + * first @a n characters of @a __s are inserted. If the length + * of result exceeds max_size(), length_error is thrown. The + * value of the string doesn't change if an error is thrown. + */ + __versa_string& +#if __cplusplus >= 201103L + replace(const_iterator __i1, const_iterator __i2, + const _CharT* __s, size_type __n) +#else + replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) +#endif + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); + } + + /** + * @brief Replace range of characters with C string. + * @param __i1 Iterator referencing start of range to replace. + * @param __i2 Iterator referencing end of range to replace. + * @param __s C string value to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [i1,i2). In place, the + * characters of @a __s are inserted. If the length of result + * exceeds max_size(), length_error is thrown. The value of + * the string doesn't change if an error is thrown. + */ + __versa_string& +#if __cplusplus >= 201103L + replace(const_iterator __i1, const_iterator __i2, const _CharT* __s) +#else + replace(iterator __i1, iterator __i2, const _CharT* __s) +#endif + { + __glibcxx_requires_string(__s); + return this->replace(__i1, __i2, __s, traits_type::length(__s)); + } + + /** + * @brief Replace range of characters with multiple characters + * @param __i1 Iterator referencing start of range to replace. + * @param __i2 Iterator referencing end of range to replace. + * @param __n Number of characters to insert. + * @param __c Character to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [i1,i2). In place, @a + * __n copies of @a __c are inserted. If the length of result + * exceeds max_size(), length_error is thrown. The value of + * the string doesn't change if an error is thrown. + */ + __versa_string& +#if __cplusplus >= 201103L + replace(const_iterator __i1, const_iterator __i2, size_type __n, + _CharT __c) +#else + replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) +#endif + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); + } + + /** + * @brief Replace range of characters with range. + * @param __i1 Iterator referencing start of range to replace. + * @param __i2 Iterator referencing end of range to replace. + * @param __k1 Iterator referencing start of range to insert. + * @param __k2 Iterator referencing end of range to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [i1,i2). In place, + * characters in the range [k1,k2) are inserted. If the length + * of result exceeds max_size(), length_error is thrown. The + * value of the string doesn't change if an error is thrown. + */ +#if __cplusplus >= 201103L + template<class _InputIterator, + typename = std::_RequireInputIter<_InputIterator>> + __versa_string& + replace(const_iterator __i1, const_iterator __i2, + _InputIterator __k1, _InputIterator __k2) + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + __glibcxx_requires_valid_range(__k1, __k2); + return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, + std::__false_type()); + } +#else + template<class _InputIterator> + __versa_string& + replace(iterator __i1, iterator __i2, + _InputIterator __k1, _InputIterator __k2) + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + __glibcxx_requires_valid_range(__k1, __k2); + typedef typename std::__is_integer<_InputIterator>::__type _Integral; + return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); + } +#endif + + // Specializations for the common case of pointer and iterator: + // useful to avoid the overhead of temporary buffering in _M_replace. + __versa_string& +#if __cplusplus >= 201103L + replace(const_iterator __i1, const_iterator __i2, + _CharT* __k1, _CharT* __k2) +#else + replace(iterator __i1, iterator __i2, + _CharT* __k1, _CharT* __k2) +#endif + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + __glibcxx_requires_valid_range(__k1, __k2); + return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1, __k2 - __k1); + } + + __versa_string& +#if __cplusplus >= 201103L + replace(const_iterator __i1, const_iterator __i2, + const _CharT* __k1, const _CharT* __k2) +#else + replace(iterator __i1, iterator __i2, + const _CharT* __k1, const _CharT* __k2) +#endif + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + __glibcxx_requires_valid_range(__k1, __k2); + return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1, __k2 - __k1); + } + + __versa_string& +#if __cplusplus >= 201103L + replace(const_iterator __i1, const_iterator __i2, + iterator __k1, iterator __k2) +#else + replace(iterator __i1, iterator __i2, + iterator __k1, iterator __k2) +#endif + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + __glibcxx_requires_valid_range(__k1, __k2); + return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1.base(), __k2 - __k1); + } + + __versa_string& +#if __cplusplus >= 201103L + replace(const_iterator __i1, const_iterator __i2, + const_iterator __k1, const_iterator __k2) +#else + replace(iterator __i1, iterator __i2, + const_iterator __k1, const_iterator __k2) +#endif + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + __glibcxx_requires_valid_range(__k1, __k2); + return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1.base(), __k2 - __k1); + } + +#if __cplusplus >= 201103L + /** + * @brief Replace range of characters with initializer_list. + * @param __i1 Iterator referencing start of range to replace. + * @param __i2 Iterator referencing end of range to replace. + * @param __l The initializer_list of characters to insert. + * @return Reference to this string. + * @throw std::length_error If new length exceeds @c max_size(). + * + * Removes the characters in the range [i1,i2). In place, + * characters in the range [k1,k2) are inserted. If the length + * of result exceeds max_size(), length_error is thrown. The + * value of the string doesn't change if an error is thrown. + */ + __versa_string& + replace(const_iterator __i1, const_iterator __i2, + std::initializer_list<_CharT> __l) + { return this->replace(__i1, __i2, __l.begin(), __l.end()); } +#endif // C++11 + + private: + template<class _Integer> + __versa_string& + _M_replace_dispatch(const_iterator __i1, const_iterator __i2, + _Integer __n, _Integer __val, std::__true_type) + { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } + + template<class _InputIterator> + __versa_string& + _M_replace_dispatch(const_iterator __i1, const_iterator __i2, + _InputIterator __k1, _InputIterator __k2, + std::__false_type); + + __versa_string& + _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, + _CharT __c); + + __versa_string& + _M_replace(size_type __pos, size_type __len1, const _CharT* __s, + const size_type __len2); + + __versa_string& + _M_append(const _CharT* __s, size_type __n); + + public: + + /** + * @brief Copy substring into C string. + * @param __s C string to copy value into. + * @param __n Number of characters to copy. + * @param __pos Index of first character to copy. + * @return Number of characters actually copied + * @throw std::out_of_range If pos > size(). + * + * Copies up to @a __n characters starting at @a __pos into the + * C string @a s. If @a __pos is greater than size(), + * out_of_range is thrown. + */ + size_type + copy(_CharT* __s, size_type __n, size_type __pos = 0) const; + + /** + * @brief Swap contents with another string. + * @param __s String to swap with. + * + * Exchanges the contents of this string with that of @a __s in + * constant time. + */ + void + swap(__versa_string& __s) _GLIBCXX_NOEXCEPT + { this->_M_swap(__s); } + + // String operations: + /** + * @brief Return const pointer to null-terminated contents. + * + * This is a handle to internal data. Do not modify or dire things may + * happen. + */ + const _CharT* + c_str() const _GLIBCXX_NOEXCEPT + { return this->_M_data(); } + + /** + * @brief Return const pointer to contents. + * + * This is a handle to internal data. Do not modify or dire things may + * happen. + */ + const _CharT* + data() const _GLIBCXX_NOEXCEPT + { return this->_M_data(); } + + /** + * @brief Return copy of allocator used to construct this string. + */ + allocator_type + get_allocator() const _GLIBCXX_NOEXCEPT + { return allocator_type(this->_M_get_allocator()); } + + /** + * @brief Find position of a C substring. + * @param __s C string to locate. + * @param __pos Index of character to search from. + * @param __n Number of characters from @a __s to search for. + * @return Index of start of first occurrence. + * + * Starting from @a __pos, searches forward for the first @a + * __n characters in @a __s within this string. If found, + * returns the index where it begins. If not found, returns + * npos. + */ + size_type + find(const _CharT* __s, size_type __pos, size_type __n) const; + + /** + * @brief Find position of a string. + * @param __str String to locate. + * @param __pos Index of character to search from (default 0). + * @return Index of start of first occurrence. + * + * Starting from @a __pos, searches forward for value of @a + * __str within this string. If found, returns the index where + * it begins. If not found, returns npos. + */ + size_type + find(const __versa_string& __str, size_type __pos = 0) const + _GLIBCXX_NOEXCEPT + { return this->find(__str.data(), __pos, __str.size()); } + + /** + * @brief Find position of a C string. + * @param __s C string to locate. + * @param __pos Index of character to search from (default 0). + * @return Index of start of first occurrence. + * + * Starting from @a __pos, searches forward for the value of @a + * __s within this string. If found, returns the index where + * it begins. If not found, returns npos. + */ + size_type + find(const _CharT* __s, size_type __pos = 0) const + { + __glibcxx_requires_string(__s); + return this->find(__s, __pos, traits_type::length(__s)); + } + + /** + * @brief Find position of a character. + * @param __c Character to locate. + * @param __pos Index of character to search from (default 0). + * @return Index of first occurrence. + * + * Starting from @a __pos, searches forward for @a __c within + * this string. If found, returns the index where it was + * found. If not found, returns npos. + */ + size_type + find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; + + /** + * @brief Find last position of a string. + * @param __str String to locate. + * @param __pos Index of character to search back from (default end). + * @return Index of start of last occurrence. + * + * Starting from @a __pos, searches backward for value of @a + * __str within this string. If found, returns the index where + * it begins. If not found, returns npos. + */ + size_type + rfind(const __versa_string& __str, size_type __pos = npos) const + _GLIBCXX_NOEXCEPT + { return this->rfind(__str.data(), __pos, __str.size()); } + + /** + * @brief Find last position of a C substring. + * @param __s C string to locate. + * @param __pos Index of character to search back from. + * @param __n Number of characters from s to search for. + * @return Index of start of last occurrence. + * + * Starting from @a __pos, searches backward for the first @a + * __n characters in @a __s within this string. If found, + * returns the index where it begins. If not found, returns + * npos. + */ + size_type + rfind(const _CharT* __s, size_type __pos, size_type __n) const; + + /** + * @brief Find last position of a C string. + * @param __s C string to locate. + * @param __pos Index of character to start search at (default end). + * @return Index of start of last occurrence. + * + * Starting from @a __pos, searches backward for the value of + * @a __s within this string. If found, returns the index + * where it begins. If not found, returns npos. + */ + size_type + rfind(const _CharT* __s, size_type __pos = npos) const + { + __glibcxx_requires_string(__s); + return this->rfind(__s, __pos, traits_type::length(__s)); + } + + /** + * @brief Find last position of a character. + * @param __c Character to locate. + * @param __pos Index of character to search back from (default end). + * @return Index of last occurrence. + * + * Starting from @a __pos, searches backward for @a __c within + * this string. If found, returns the index where it was + * found. If not found, returns npos. + */ + size_type + rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; + + /** + * @brief Find position of a character of string. + * @param __str String containing characters to locate. + * @param __pos Index of character to search from (default 0). + * @return Index of first occurrence. + * + * Starting from @a __pos, searches forward for one of the characters of + * @a __str within this string. If found, returns the index where it was + * found. If not found, returns npos. + */ + size_type + find_first_of(const __versa_string& __str, size_type __pos = 0) const + _GLIBCXX_NOEXCEPT + { return this->find_first_of(__str.data(), __pos, __str.size()); } + + /** + * @brief Find position of a character of C substring. + * @param __s String containing characters to locate. + * @param __pos Index of character to search from. + * @param __n Number of characters from s to search for. + * @return Index of first occurrence. + * + * Starting from @a __pos, searches forward for one of the + * first @a __n characters of @a __s within this string. If + * found, returns the index where it was found. If not found, + * returns npos. + */ + size_type + find_first_of(const _CharT* __s, size_type __pos, size_type __n) const; + + /** + * @brief Find position of a character of C string. + * @param __s String containing characters to locate. + * @param __pos Index of character to search from (default 0). + * @return Index of first occurrence. + * + * Starting from @a __pos, searches forward for one of the + * characters of @a __s within this string. If found, returns + * the index where it was found. If not found, returns npos. + */ + size_type + find_first_of(const _CharT* __s, size_type __pos = 0) const + { + __glibcxx_requires_string(__s); + return this->find_first_of(__s, __pos, traits_type::length(__s)); + } + + /** + * @brief Find position of a character. + * @param __c Character to locate. + * @param __pos Index of character to search from (default 0). + * @return Index of first occurrence. + * + * Starting from @a __pos, searches forward for the character + * @a __c within this string. If found, returns the index + * where it was found. If not found, returns npos. + * + * Note: equivalent to find(c, pos). + */ + size_type + find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT + { return this->find(__c, __pos); } + + /** + * @brief Find last position of a character of string. + * @param __str String containing characters to locate. + * @param __pos Index of character to search back from (default end). + * @return Index of last occurrence. + * + * Starting from @a __pos, searches backward for one of the + * characters of @a __str within this string. If found, + * returns the index where it was found. If not found, returns + * npos. + */ + size_type + find_last_of(const __versa_string& __str, size_type __pos = npos) const + _GLIBCXX_NOEXCEPT + { return this->find_last_of(__str.data(), __pos, __str.size()); } + + /** + * @brief Find last position of a character of C substring. + * @param __s C string containing characters to locate. + * @param __pos Index of character to search back from. + * @param __n Number of characters from s to search for. + * @return Index of last occurrence. + * + * Starting from @a __pos, searches backward for one of the + * first @a __n characters of @a __s within this string. If + * found, returns the index where it was found. If not found, + * returns npos. + */ + size_type + find_last_of(const _CharT* __s, size_type __pos, size_type __n) const; + + /** + * @brief Find last position of a character of C string. + * @param __s C string containing characters to locate. + * @param __pos Index of character to search back from (default end). + * @return Index of last occurrence. + * + * Starting from @a __pos, searches backward for one of the + * characters of @a __s within this string. If found, returns + * the index where it was found. If not found, returns npos. + */ + size_type + find_last_of(const _CharT* __s, size_type __pos = npos) const + { + __glibcxx_requires_string(__s); + return this->find_last_of(__s, __pos, traits_type::length(__s)); + } + + /** + * @brief Find last position of a character. + * @param __c Character to locate. + * @param __pos Index of character to search back from (default end). + * @return Index of last occurrence. + * + * Starting from @a __pos, searches backward for @a __c within + * this string. If found, returns the index where it was + * found. If not found, returns npos. + * + * Note: equivalent to rfind(c, pos). + */ + size_type + find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT + { return this->rfind(__c, __pos); } + + /** + * @brief Find position of a character not in string. + * @param __str String containing characters to avoid. + * @param __pos Index of character to search from (default 0). + * @return Index of first occurrence. + * + * Starting from @a __pos, searches forward for a character not + * contained in @a __str within this string. If found, returns + * the index where it was found. If not found, returns npos. + */ + size_type + find_first_not_of(const __versa_string& __str, size_type __pos = 0) const + _GLIBCXX_NOEXCEPT + { return this->find_first_not_of(__str.data(), __pos, __str.size()); } + + /** + * @brief Find position of a character not in C substring. + * @param __s C string containing characters to avoid. + * @param __pos Index of character to search from. + * @param __n Number of characters from s to consider. + * @return Index of first occurrence. + * + * Starting from @a __pos, searches forward for a character not + * contained in the first @a __n characters of @a __s within + * this string. If found, returns the index where it was + * found. If not found, returns npos. + */ + size_type + find_first_not_of(const _CharT* __s, size_type __pos, + size_type __n) const; + + /** + * @brief Find position of a character not in C string. + * @param __s C string containing characters to avoid. + * @param __pos Index of character to search from (default 0). + * @return Index of first occurrence. + * + * Starting from @a __pos, searches forward for a character not + * contained in @a __s within this string. If found, returns + * the index where it was found. If not found, returns npos. + */ + size_type + find_first_not_of(const _CharT* __s, size_type __pos = 0) const + { + __glibcxx_requires_string(__s); + return this->find_first_not_of(__s, __pos, traits_type::length(__s)); + } + + /** + * @brief Find position of a different character. + * @param __c Character to avoid. + * @param __pos Index of character to search from (default 0). + * @return Index of first occurrence. + * + * Starting from @a __pos, searches forward for a character + * other than @a __c within this string. If found, returns the + * index where it was found. If not found, returns npos. + */ + size_type + find_first_not_of(_CharT __c, size_type __pos = 0) const + _GLIBCXX_NOEXCEPT; + + /** + * @brief Find last position of a character not in string. + * @param __str String containing characters to avoid. + * @param __pos Index of character to search back from (default end). + * @return Index of last occurrence. + * + * Starting from @a __pos, searches backward for a character + * not contained in @a __str within this string. If found, + * returns the index where it was found. If not found, returns + * npos. + */ + size_type + find_last_not_of(const __versa_string& __str, + size_type __pos = npos) const _GLIBCXX_NOEXCEPT + { return this->find_last_not_of(__str.data(), __pos, __str.size()); } + + /** + * @brief Find last position of a character not in C substring. + * @param __s C string containing characters to avoid. + * @param __pos Index of character to search back from. + * @param __n Number of characters from s to consider. + * @return Index of last occurrence. + * + * Starting from @a __pos, searches backward for a character + * not contained in the first @a __n characters of @a __s + * within this string. If found, returns the index where it + * was found. If not found, returns npos. + */ + size_type + find_last_not_of(const _CharT* __s, size_type __pos, + size_type __n) const; + /** + * @brief Find last position of a character not in C string. + * @param __s C string containing characters to avoid. + * @param __pos Index of character to search back from (default end). + * @return Index of last occurrence. + * + * Starting from @a __pos, searches backward for a character + * not contained in @a __s within this string. If found, + * returns the index where it was found. If not found, returns + * npos. + */ + size_type + find_last_not_of(const _CharT* __s, size_type __pos = npos) const + { + __glibcxx_requires_string(__s); + return this->find_last_not_of(__s, __pos, traits_type::length(__s)); + } + + /** + * @brief Find last position of a different character. + * @param __c Character to avoid. + * @param __pos Index of character to search back from (default end). + * @return Index of last occurrence. + * + * Starting from @a __pos, searches backward for a character + * other than @a __c within this string. If found, returns the + * index where it was found. If not found, returns npos. + */ + size_type + find_last_not_of(_CharT __c, size_type __pos = npos) const + _GLIBCXX_NOEXCEPT; + + /** + * @brief Get a substring. + * @param __pos Index of first character (default 0). + * @param __n Number of characters in substring (default remainder). + * @return The new string. + * @throw std::out_of_range If pos > size(). + * + * Construct and return a new string using the @a __n + * characters starting at @a __pos. If the string is too + * short, use the remainder of the characters. If @a __pos is + * beyond the end of the string, out_of_range is thrown. + */ + __versa_string + substr(size_type __pos = 0, size_type __n = npos) const + { + return __versa_string(*this, _M_check(__pos, "__versa_string::substr"), + __n); + } + + /** + * @brief Compare to a string. + * @param __str String to compare against. + * @return Integer < 0, 0, or > 0. + * + * Returns an integer < 0 if this string is ordered before @a + * __str, 0 if their values are equivalent, or > 0 if this + * string is ordered after @a __str. Determines the effective + * length rlen of the strings to compare as the smallest of + * size() and str.size(). The function then compares the two + * strings by calling traits::compare(data(), str.data(),rlen). + * If the result of the comparison is nonzero returns it, + * otherwise the shorter one is ordered first. + */ + int + compare(const __versa_string& __str) const + { + if (this->_M_compare(__str)) + return 0; + + const size_type __size = this->size(); + const size_type __osize = __str.size(); + const size_type __len = std::min(__size, __osize); + + int __r = traits_type::compare(this->_M_data(), __str.data(), __len); + if (!__r) + __r = this->_S_compare(__size, __osize); + return __r; + } + + /** + * @brief Compare substring to a string. + * @param __pos Index of first character of substring. + * @param __n Number of characters in substring. + * @param __str String to compare against. + * @return Integer < 0, 0, or > 0. + * + * Form the substring of this string from the @a __n characters + * starting at @a __pos. Returns an integer < 0 if the + * substring is ordered before @a __str, 0 if their values are + * equivalent, or > 0 if the substring is ordered after @a + * __str. Determines the effective length rlen of the strings + * to compare as the smallest of the length of the substring + * and @a __str.size(). The function then compares the two + * strings by calling + * traits::compare(substring.data(),str.data(),rlen). If the + * result of the comparison is nonzero returns it, otherwise + * the shorter one is ordered first. + */ + int + compare(size_type __pos, size_type __n, + const __versa_string& __str) const; + + /** + * @brief Compare substring to a substring. + * @param __pos1 Index of first character of substring. + * @param __n1 Number of characters in substring. + * @param __str String to compare against. + * @param __pos2 Index of first character of substring of str. + * @param __n2 Number of characters in substring of str. + * @return Integer < 0, 0, or > 0. + * + * Form the substring of this string from the @a __n1 + * characters starting at @a __pos1. Form the substring of @a + * __str from the @a __n2 characters starting at @a __pos2. + * Returns an integer < 0 if this substring is ordered before + * the substring of @a __str, 0 if their values are equivalent, + * or > 0 if this substring is ordered after the substring of + * @a __str. Determines the effective length rlen of the + * strings to compare as the smallest of the lengths of the + * substrings. The function then compares the two strings by + * calling + * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). + * If the result of the comparison is nonzero returns it, + * otherwise the shorter one is ordered first. + */ + int + compare(size_type __pos1, size_type __n1, const __versa_string& __str, + size_type __pos2, size_type __n2) const; + + /** + * @brief Compare to a C string. + * @param __s C string to compare against. + * @return Integer < 0, 0, or > 0. + * + * Returns an integer < 0 if this string is ordered before @a + * __s, 0 if their values are equivalent, or > 0 if this string + * is ordered after @a __s. Determines the effective length + * rlen of the strings to compare as the smallest of size() and + * the length of a string constructed from @a __s. The + * function then compares the two strings by calling + * traits::compare(data(),s,rlen). If the result of the + * comparison is nonzero returns it, otherwise the shorter one + * is ordered first. + */ + int + compare(const _CharT* __s) const; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 5 String::compare specification questionable + /** + * @brief Compare substring to a C string. + * @param __pos Index of first character of substring. + * @param __n1 Number of characters in substring. + * @param __s C string to compare against. + * @return Integer < 0, 0, or > 0. + * + * Form the substring of this string from the @a __n1 + * characters starting at @a __pos. Returns an integer < 0 if + * the substring is ordered before @a __s, 0 if their values + * are equivalent, or > 0 if the substring is ordered after @a + * __s. Determines the effective length rlen of the strings to + * compare as the smallest of the length of the substring and + * the length of a string constructed from @a __s. The + * function then compares the two string by calling + * traits::compare(substring.data(),s,rlen). If the result of + * the comparison is nonzero returns it, otherwise the shorter + * one is ordered first. + */ + int + compare(size_type __pos, size_type __n1, const _CharT* __s) const; + + /** + * @brief Compare substring against a character array. + * @param __pos Index of first character of substring. + * @param __n1 Number of characters in substring. + * @param __s character array to compare against. + * @param __n2 Number of characters of s. + * @return Integer < 0, 0, or > 0. + * + * Form the substring of this string from the @a __n1 + * characters starting at @a __pos. Form a string from the + * first @a __n2 characters of @a __s. Returns an integer < 0 + * if this substring is ordered before the string from @a __s, + * 0 if their values are equivalent, or > 0 if this substring + * is ordered after the string from @a __s. Determines the + * effective length rlen of the strings to compare as the + * smallest of the length of the substring and @a __n2. The + * function then compares the two strings by calling + * traits::compare(substring.data(),__s,rlen). If the result of + * the comparison is nonzero returns it, otherwise the shorter + * one is ordered first. + * + * NB: __s must have at least n2 characters, <em>\\0</em> has no special + * meaning. + */ + int + compare(size_type __pos, size_type __n1, const _CharT* __s, + size_type __n2) const; + }; + + // operator+ + /** + * @brief Concatenate two strings. + * @param __lhs First string. + * @param __rhs Last string. + * @return New string with value of @a __lhs followed by @a __rhs. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); + + /** + * @brief Concatenate C string and string. + * @param __lhs First string. + * @param __rhs Last string. + * @return New string with value of @a __lhs followed by @a __rhs. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(const _CharT* __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); + + /** + * @brief Concatenate character and string. + * @param __lhs First string. + * @param __rhs Last string. + * @return New string with @a __lhs followed by @a __rhs. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(_CharT __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); + + /** + * @brief Concatenate string and C string. + * @param __lhs First string. + * @param __rhs Last string. + * @return New string with @a __lhs followed by @a __rhs. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const _CharT* __rhs); + + /** + * @brief Concatenate string and character. + * @param __lhs First string. + * @param __rhs Last string. + * @return New string with @a __lhs followed by @a __rhs. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + _CharT __rhs); + +#if __cplusplus >= 201103L + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return std::move(__lhs.append(__rhs)); } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) + { return std::move(__rhs.insert(0, __lhs)); } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, + __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) + { + const auto __size = __lhs.size() + __rhs.size(); + const bool __cond = (__size > __lhs.capacity() + && __size <= __rhs.capacity()); + return __cond ? std::move(__rhs.insert(0, __lhs)) + : std::move(__lhs.append(__rhs)); + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(const _CharT* __lhs, + __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) + { return std::move(__rhs.insert(0, __lhs)); } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(_CharT __lhs, + __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) + { return std::move(__rhs.insert(0, 1, __lhs)); } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, + const _CharT* __rhs) + { return std::move(__lhs.append(__rhs)); } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, + _CharT __rhs) + { return std::move(__lhs.append(1, __rhs)); } +#endif + + // operator == + /** + * @brief Test equivalence of two strings. + * @param __lhs First string. + * @param __rhs Second string. + * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return __lhs.compare(__rhs) == 0; } + + template<typename _CharT, + template <typename, typename, typename> class _Base> + inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type + operator==(const __versa_string<_CharT, std::char_traits<_CharT>, + std::allocator<_CharT>, _Base>& __lhs, + const __versa_string<_CharT, std::char_traits<_CharT>, + std::allocator<_CharT>, _Base>& __rhs) + { return (__lhs.size() == __rhs.size() + && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(), + __lhs.size())); } + + /** + * @brief Test equivalence of C string and string. + * @param __lhs C string. + * @param __rhs String. + * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator==(const _CharT* __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return __rhs.compare(__lhs) == 0; } + + /** + * @brief Test equivalence of string and C string. + * @param __lhs String. + * @param __rhs C string. + * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const _CharT* __rhs) + { return __lhs.compare(__rhs) == 0; } + + // operator != + /** + * @brief Test difference of two strings. + * @param __lhs First string. + * @param __rhs Second string. + * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return !(__lhs == __rhs); } + + /** + * @brief Test difference of C string and string. + * @param __lhs C string. + * @param __rhs String. + * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator!=(const _CharT* __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return !(__lhs == __rhs); } + + /** + * @brief Test difference of string and C string. + * @param __lhs String. + * @param __rhs C string. + * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const _CharT* __rhs) + { return !(__lhs == __rhs); } + + // operator < + /** + * @brief Test if string precedes string. + * @param __lhs First string. + * @param __rhs Second string. + * @return True if @a __lhs precedes @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return __lhs.compare(__rhs) < 0; } + + /** + * @brief Test if string precedes C string. + * @param __lhs String. + * @param __rhs C string. + * @return True if @a __lhs precedes @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const _CharT* __rhs) + { return __lhs.compare(__rhs) < 0; } + + /** + * @brief Test if C string precedes string. + * @param __lhs C string. + * @param __rhs String. + * @return True if @a __lhs precedes @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator<(const _CharT* __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return __rhs.compare(__lhs) > 0; } + + // operator > + /** + * @brief Test if string follows string. + * @param __lhs First string. + * @param __rhs Second string. + * @return True if @a __lhs follows @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return __lhs.compare(__rhs) > 0; } + + /** + * @brief Test if string follows C string. + * @param __lhs String. + * @param __rhs C string. + * @return True if @a __lhs follows @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const _CharT* __rhs) + { return __lhs.compare(__rhs) > 0; } + + /** + * @brief Test if C string follows string. + * @param __lhs C string. + * @param __rhs String. + * @return True if @a __lhs follows @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator>(const _CharT* __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return __rhs.compare(__lhs) < 0; } + + // operator <= + /** + * @brief Test if string doesn't follow string. + * @param __lhs First string. + * @param __rhs Second string. + * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return __lhs.compare(__rhs) <= 0; } + + /** + * @brief Test if string doesn't follow C string. + * @param __lhs String. + * @param __rhs C string. + * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const _CharT* __rhs) + { return __lhs.compare(__rhs) <= 0; } + + /** + * @brief Test if C string doesn't follow string. + * @param __lhs C string. + * @param __rhs String. + * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator<=(const _CharT* __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return __rhs.compare(__lhs) >= 0; } + + // operator >= + /** + * @brief Test if string doesn't precede string. + * @param __lhs First string. + * @param __rhs Second string. + * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return __lhs.compare(__rhs) >= 0; } + + /** + * @brief Test if string doesn't precede C string. + * @param __lhs String. + * @param __rhs C string. + * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const _CharT* __rhs) + { return __lhs.compare(__rhs) >= 0; } + + /** + * @brief Test if C string doesn't precede string. + * @param __lhs C string. + * @param __rhs String. + * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline bool + operator>=(const _CharT* __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { return __rhs.compare(__lhs) <= 0; } + + /** + * @brief Swap contents of two strings. + * @param __lhs First string. + * @param __rhs Second string. + * + * Exchanges the contents of @a __lhs and @a __rhs in constant time. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline void + swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { __lhs.swap(__rhs); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * @brief Read stream into a string. + * @param __is Input stream. + * @param __str Buffer to store into. + * @return Reference to the input stream. + * + * Stores characters from @a __is into @a __str until whitespace is + * found, the end of the stream is encountered, or str.max_size() + * is reached. If is.width() is non-zero, that is the limit on the + * number of characters stored into @a __str. Any previous + * contents of @a __str are erased. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::__versa_string<_CharT, _Traits, + _Alloc, _Base>& __str); + + /** + * @brief Write string to a stream. + * @param __os Output stream. + * @param __str String to write out. + * @return Reference to the output stream. + * + * Output characters of @a __str into os following the same rules as for + * writing a C string. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, + _Base>& __str) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 586. string inserter not a formatted function + return __ostream_insert(__os, __str.data(), __str.size()); + } + + /** + * @brief Read a line from stream into a string. + * @param __is Input stream. + * @param __str Buffer to store into. + * @param __delim Character marking end of line. + * @return Reference to the input stream. + * + * Stores characters from @a __is into @a __str until @a __delim is + * found, the end of the stream is encountered, or str.max_size() + * is reached. If is.width() is non-zero, that is the limit on the + * number of characters stored into @a __str. Any previous + * contents of @a __str are erased. If @a delim was encountered, + * it is extracted but not stored into @a __str. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + basic_istream<_CharT, _Traits>& + getline(basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str, + _CharT __delim); + + /** + * @brief Read a line from stream into a string. + * @param __is Input stream. + * @param __str Buffer to store into. + * @return Reference to the input stream. + * + * Stores characters from is into @a __str until '\n' is + * found, the end of the stream is encountered, or str.max_size() + * is reached. If is.width() is non-zero, that is the limit on the + * number of characters stored into @a __str. Any previous + * contents of @a __str are erased. If end of line was + * encountered, it is extracted but not stored into @a __str. + */ + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + inline basic_istream<_CharT, _Traits>& + getline(basic_istream<_CharT, _Traits>& __is, + __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str) + { return getline(__is, __str, __is.widen('\n')); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99)) + +#include <ext/string_conversions.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // 21.4 Numeric Conversions [string.conversions]. + inline int + stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(), + __idx, __base); } + + inline long + stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), + __idx, __base); } + + inline unsigned long + stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), + __idx, __base); } + + inline long long + stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), + __idx, __base); } + + inline unsigned long long + stoull(const __vstring& __str, std::size_t* __idx, int __base = 10) + { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), + __idx, __base); } + + // NB: strtof vs strtod. + inline float + stof(const __vstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } + + inline double + stod(const __vstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } + + inline long double + stold(const __vstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } + + // NB: (v)snprintf vs sprintf. + + // DR 1261. + inline __vstring + to_string(int __val) + { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int), + "%d", __val); } + + inline __vstring + to_string(unsigned __val) + { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, + 4 * sizeof(unsigned), + "%u", __val); } + + inline __vstring + to_string(long __val) + { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, + 4 * sizeof(long), + "%ld", __val); } + + inline __vstring + to_string(unsigned long __val) + { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, + 4 * sizeof(unsigned long), + "%lu", __val); } + + + inline __vstring + to_string(long long __val) + { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, + 4 * sizeof(long long), + "%lld", __val); } + + inline __vstring + to_string(unsigned long long __val) + { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, + 4 * sizeof(unsigned long long), + "%llu", __val); } + + inline __vstring + to_string(float __val) + { + const int __n = __numeric_traits<float>::__max_exponent10 + 20; + return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, + "%f", __val); + } + + inline __vstring + to_string(double __val) + { + const int __n = __numeric_traits<double>::__max_exponent10 + 20; + return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, + "%f", __val); + } + + inline __vstring + to_string(long double __val) + { + const int __n = __numeric_traits<long double>::__max_exponent10 + 20; + return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, + "%Lf", __val); + } + +#ifdef _GLIBCXX_USE_WCHAR_T + inline int + stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(), + __idx, __base); } + + inline long + stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), + __idx, __base); } + + inline unsigned long + stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), + __idx, __base); } + + inline long long + stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), + __idx, __base); } + + inline unsigned long long + stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) + { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), + __idx, __base); } + + // NB: wcstof vs wcstod. + inline float + stof(const __wvstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } + + inline double + stod(const __wvstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } + + inline long double + stold(const __wvstring& __str, std::size_t* __idx = 0) + { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } + +#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF + // DR 1261. + inline __wvstring + to_wstring(int __val) + { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, + 4 * sizeof(int), + L"%d", __val); } + + inline __wvstring + to_wstring(unsigned __val) + { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, + 4 * sizeof(unsigned), + L"%u", __val); } + + inline __wvstring + to_wstring(long __val) + { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, + 4 * sizeof(long), + L"%ld", __val); } + + inline __wvstring + to_wstring(unsigned long __val) + { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, + 4 * sizeof(unsigned long), + L"%lu", __val); } + + inline __wvstring + to_wstring(long long __val) + { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, + 4 * sizeof(long long), + L"%lld", __val); } + + inline __wvstring + to_wstring(unsigned long long __val) + { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, + 4 * sizeof(unsigned long long), + L"%llu", __val); } + + inline __wvstring + to_wstring(float __val) + { + const int __n = __numeric_traits<float>::__max_exponent10 + 20; + return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, + L"%f", __val); + } + + inline __wvstring + to_wstring(double __val) + { + const int __n = __numeric_traits<double>::__max_exponent10 + 20; + return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, + L"%f", __val); + } + + inline __wvstring + to_wstring(long double __val) + { + const int __n = __numeric_traits<long double>::__max_exponent10 + 20; + return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, + L"%Lf", __val); + } +#endif +#endif + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif + +#if __cplusplus >= 201103L + +#include <bits/functional_hash.h> + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /// std::hash specialization for __vstring. + template<> + struct hash<__gnu_cxx::__vstring> + : public __hash_base<size_t, __gnu_cxx::__vstring> + { + size_t + operator()(const __gnu_cxx::__vstring& __s) const noexcept + { return std::_Hash_impl::hash(__s.data(), __s.length()); } + }; + +#ifdef _GLIBCXX_USE_WCHAR_T + /// std::hash specialization for __wvstring. + template<> + struct hash<__gnu_cxx::__wvstring> + : public __hash_base<size_t, __gnu_cxx::__wvstring> + { + size_t + operator()(const __gnu_cxx::__wvstring& __s) const noexcept + { return std::_Hash_impl::hash(__s.data(), + __s.length() * sizeof(wchar_t)); } + }; +#endif + +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 + /// std::hash specialization for __u16vstring. + template<> + struct hash<__gnu_cxx::__u16vstring> + : public __hash_base<size_t, __gnu_cxx::__u16vstring> + { + size_t + operator()(const __gnu_cxx::__u16vstring& __s) const noexcept + { return std::_Hash_impl::hash(__s.data(), + __s.length() * sizeof(char16_t)); } + }; + + /// std::hash specialization for __u32vstring. + template<> + struct hash<__gnu_cxx::__u32vstring> + : public __hash_base<size_t, __gnu_cxx::__u32vstring> + { + size_t + operator()(const __gnu_cxx::__u32vstring& __s) const noexcept + { return std::_Hash_impl::hash(__s.data(), + __s.length() * sizeof(char32_t)); } + }; +#endif + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif // C++11 + +#include "vstring.tcc" + +#endif /* _VSTRING_H */ diff --git a/gcc-4.9/libstdc++-v3/include/ext/vstring.tcc b/gcc-4.9/libstdc++-v3/include/ext/vstring.tcc new file mode 100644 index 0000000..ebc610d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/vstring.tcc @@ -0,0 +1,702 @@ +// Versatile string -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/vstring.tcc + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{ext/vstring.h} + */ + +#ifndef _VSTRING_TCC +#define _VSTRING_TCC 1 + +#pragma GCC system_header + +#include <bits/cxxabi_forced.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + const typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>::npos; + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + void + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + resize(size_type __n, _CharT __c) + { + const size_type __size = this->size(); + if (__size < __n) + this->append(__n - __size, __c); + else if (__n < __size) + this->_M_erase(__n, __size - __n); + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base>& + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + _M_append(const _CharT* __s, size_type __n) + { + const size_type __len = __n + this->size(); + + if (__len <= this->capacity() && !this->_M_is_shared()) + { + if (__n) + this->_S_copy(this->_M_data() + this->size(), __s, __n); + } + else + this->_M_mutate(this->size(), size_type(0), __s, __n); + + this->_M_set_length(__len); + return *this; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + template<typename _InputIterator> + __versa_string<_CharT, _Traits, _Alloc, _Base>& + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + _M_replace_dispatch(const_iterator __i1, const_iterator __i2, + _InputIterator __k1, _InputIterator __k2, + std::__false_type) + { + const __versa_string __s(__k1, __k2); + const size_type __n1 = __i2 - __i1; + return _M_replace(__i1 - _M_ibegin(), __n1, __s._M_data(), + __s.size()); + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base>& + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, + _CharT __c) + { + _M_check_length(__n1, __n2, "__versa_string::_M_replace_aux"); + + const size_type __old_size = this->size(); + const size_type __new_size = __old_size + __n2 - __n1; + + if (__new_size <= this->capacity() && !this->_M_is_shared()) + { + _CharT* __p = this->_M_data() + __pos1; + + const size_type __how_much = __old_size - __pos1 - __n1; + if (__how_much && __n1 != __n2) + this->_S_move(__p + __n2, __p + __n1, __how_much); + } + else + this->_M_mutate(__pos1, __n1, 0, __n2); + + if (__n2) + this->_S_assign(this->_M_data() + __pos1, __n2, __c); + + this->_M_set_length(__new_size); + return *this; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base>& + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + _M_replace(size_type __pos, size_type __len1, const _CharT* __s, + const size_type __len2) + { + _M_check_length(__len1, __len2, "__versa_string::_M_replace"); + + const size_type __old_size = this->size(); + const size_type __new_size = __old_size + __len2 - __len1; + + if (__new_size <= this->capacity() && !this->_M_is_shared()) + { + _CharT* __p = this->_M_data() + __pos; + + const size_type __how_much = __old_size - __pos - __len1; + if (_M_disjunct(__s)) + { + if (__how_much && __len1 != __len2) + this->_S_move(__p + __len2, __p + __len1, __how_much); + if (__len2) + this->_S_copy(__p, __s, __len2); + } + else + { + // Work in-place. + if (__len2 && __len2 <= __len1) + this->_S_move(__p, __s, __len2); + if (__how_much && __len1 != __len2) + this->_S_move(__p + __len2, __p + __len1, __how_much); + if (__len2 > __len1) + { + if (__s + __len2 <= __p + __len1) + this->_S_move(__p, __s, __len2); + else if (__s >= __p + __len1) + this->_S_copy(__p, __s + __len2 - __len1, __len2); + else + { + const size_type __nleft = (__p + __len1) - __s; + this->_S_move(__p, __s, __nleft); + this->_S_copy(__p + __nleft, __p + __len2, + __len2 - __nleft); + } + } + } + } + else + this->_M_mutate(__pos, __len1, __s, __len2); + + this->_M_set_length(__new_size); + return *this; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { + __versa_string<_CharT, _Traits, _Alloc, _Base> __str; + __str.reserve(__lhs.size() + __rhs.size()); + __str.append(__lhs); + __str.append(__rhs); + return __str; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(const _CharT* __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { + __glibcxx_requires_string(__lhs); + typedef __versa_string<_CharT, _Traits, _Alloc, _Base> __string_type; + typedef typename __string_type::size_type __size_type; + const __size_type __len = _Traits::length(__lhs); + __string_type __str; + __str.reserve(__len + __rhs.size()); + __str.append(__lhs, __len); + __str.append(__rhs); + return __str; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(_CharT __lhs, + const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) + { + __versa_string<_CharT, _Traits, _Alloc, _Base> __str; + __str.reserve(__rhs.size() + 1); + __str.push_back(__lhs); + __str.append(__rhs); + return __str; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + const _CharT* __rhs) + { + __glibcxx_requires_string(__rhs); + typedef __versa_string<_CharT, _Traits, _Alloc, _Base> __string_type; + typedef typename __string_type::size_type __size_type; + const __size_type __len = _Traits::length(__rhs); + __string_type __str; + __str.reserve(__lhs.size() + __len); + __str.append(__lhs); + __str.append(__rhs, __len); + return __str; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + __versa_string<_CharT, _Traits, _Alloc, _Base> + operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, + _CharT __rhs) + { + __versa_string<_CharT, _Traits, _Alloc, _Base> __str; + __str.reserve(__lhs.size() + 1); + __str.append(__lhs); + __str.push_back(__rhs); + return __str; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + copy(_CharT* __s, size_type __n, size_type __pos) const + { + _M_check(__pos, "__versa_string::copy"); + __n = _M_limit(__pos, __n); + __glibcxx_requires_string_len(__s, __n); + if (__n) + this->_S_copy(__s, this->_M_data() + __pos, __n); + // 21.3.5.7 par 3: do not append null. (good.) + return __n; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + find(const _CharT* __s, size_type __pos, size_type __n) const + { + __glibcxx_requires_string_len(__s, __n); + const size_type __size = this->size(); + const _CharT* __data = this->_M_data(); + + if (__n == 0) + return __pos <= __size ? __pos : npos; + + if (__n <= __size) + { + for (; __pos <= __size - __n; ++__pos) + if (traits_type::eq(__data[__pos], __s[0]) + && traits_type::compare(__data + __pos + 1, + __s + 1, __n - 1) == 0) + return __pos; + } + return npos; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + find(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT + { + size_type __ret = npos; + const size_type __size = this->size(); + if (__pos < __size) + { + const _CharT* __data = this->_M_data(); + const size_type __n = __size - __pos; + const _CharT* __p = traits_type::find(__data + __pos, __n, __c); + if (__p) + __ret = __p - __data; + } + return __ret; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + rfind(const _CharT* __s, size_type __pos, size_type __n) const + { + __glibcxx_requires_string_len(__s, __n); + const size_type __size = this->size(); + if (__n <= __size) + { + __pos = std::min(size_type(__size - __n), __pos); + const _CharT* __data = this->_M_data(); + do + { + if (traits_type::compare(__data + __pos, __s, __n) == 0) + return __pos; + } + while (__pos-- > 0); + } + return npos; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + rfind(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT + { + size_type __size = this->size(); + if (__size) + { + if (--__size > __pos) + __size = __pos; + for (++__size; __size-- > 0; ) + if (traits_type::eq(this->_M_data()[__size], __c)) + return __size; + } + return npos; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + find_first_of(const _CharT* __s, size_type __pos, size_type __n) const + { + __glibcxx_requires_string_len(__s, __n); + for (; __n && __pos < this->size(); ++__pos) + { + const _CharT* __p = traits_type::find(__s, __n, + this->_M_data()[__pos]); + if (__p) + return __pos; + } + return npos; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + find_last_of(const _CharT* __s, size_type __pos, size_type __n) const + { + __glibcxx_requires_string_len(__s, __n); + size_type __size = this->size(); + if (__size && __n) + { + if (--__size > __pos) + __size = __pos; + do + { + if (traits_type::find(__s, __n, this->_M_data()[__size])) + return __size; + } + while (__size-- != 0); + } + return npos; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const + { + __glibcxx_requires_string_len(__s, __n); + for (; __pos < this->size(); ++__pos) + if (!traits_type::find(__s, __n, this->_M_data()[__pos])) + return __pos; + return npos; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + find_first_not_of(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT + { + for (; __pos < this->size(); ++__pos) + if (!traits_type::eq(this->_M_data()[__pos], __c)) + return __pos; + return npos; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const + { + __glibcxx_requires_string_len(__s, __n); + size_type __size = this->size(); + if (__size) + { + if (--__size > __pos) + __size = __pos; + do + { + if (!traits_type::find(__s, __n, this->_M_data()[__size])) + return __size; + } + while (__size--); + } + return npos; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + find_last_not_of(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT + { + size_type __size = this->size(); + if (__size) + { + if (--__size > __pos) + __size = __pos; + do + { + if (!traits_type::eq(this->_M_data()[__size], __c)) + return __size; + } + while (__size--); + } + return npos; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + int + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + compare(size_type __pos, size_type __n, const __versa_string& __str) const + { + _M_check(__pos, "__versa_string::compare"); + __n = _M_limit(__pos, __n); + const size_type __osize = __str.size(); + const size_type __len = std::min(__n, __osize); + int __r = traits_type::compare(this->_M_data() + __pos, + __str.data(), __len); + if (!__r) + __r = this->_S_compare(__n, __osize); + return __r; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + int + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + compare(size_type __pos1, size_type __n1, const __versa_string& __str, + size_type __pos2, size_type __n2) const + { + _M_check(__pos1, "__versa_string::compare"); + __str._M_check(__pos2, "__versa_string::compare"); + __n1 = _M_limit(__pos1, __n1); + __n2 = __str._M_limit(__pos2, __n2); + const size_type __len = std::min(__n1, __n2); + int __r = traits_type::compare(this->_M_data() + __pos1, + __str.data() + __pos2, __len); + if (!__r) + __r = this->_S_compare(__n1, __n2); + return __r; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + int + __versa_string<_CharT, _Traits, _Alloc, _Base>:: + compare(const _CharT* __s) const + { + __glibcxx_requires_string(__s); + const size_type __size = this->size(); + const size_type __osize = traits_type::length(__s); + const size_type __len = std::min(__size, __osize); + int __r = traits_type::compare(this->_M_data(), __s, __len); + if (!__r) + __r = this->_S_compare(__size, __osize); + return __r; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + int + __versa_string <_CharT, _Traits, _Alloc, _Base>:: + compare(size_type __pos, size_type __n1, const _CharT* __s) const + { + __glibcxx_requires_string(__s); + _M_check(__pos, "__versa_string::compare"); + __n1 = _M_limit(__pos, __n1); + const size_type __osize = traits_type::length(__s); + const size_type __len = std::min(__n1, __osize); + int __r = traits_type::compare(this->_M_data() + __pos, __s, __len); + if (!__r) + __r = this->_S_compare(__n1, __osize); + return __r; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + int + __versa_string <_CharT, _Traits, _Alloc, _Base>:: + compare(size_type __pos, size_type __n1, const _CharT* __s, + size_type __n2) const + { + __glibcxx_requires_string_len(__s, __n2); + _M_check(__pos, "__versa_string::compare"); + __n1 = _M_limit(__pos, __n1); + const size_type __len = std::min(__n1, __n2); + int __r = traits_type::compare(this->_M_data() + __pos, __s, __len); + if (!__r) + __r = this->_S_compare(__n1, __n2); + return __r; + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __in, + __gnu_cxx::__versa_string<_CharT, _Traits, + _Alloc, _Base>& __str) + { + typedef basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + typedef __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base> + __string_type; + typedef typename __istream_type::int_type __int_type; + typedef typename __string_type::size_type __size_type; + typedef ctype<_CharT> __ctype_type; + typedef typename __ctype_type::ctype_base __ctype_base; + + __size_type __extracted = 0; + typename __ios_base::iostate __err = __ios_base::goodbit; + typename __istream_type::sentry __cerb(__in, false); + if (__cerb) + { + __try + { + // Avoid reallocation for common case. + __str.erase(); + _CharT __buf[128]; + __size_type __len = 0; + const streamsize __w = __in.width(); + const __size_type __n = __w > 0 ? static_cast<__size_type>(__w) + : __str.max_size(); + const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc()); + const __int_type __eof = _Traits::eof(); + __int_type __c = __in.rdbuf()->sgetc(); + + while (__extracted < __n + && !_Traits::eq_int_type(__c, __eof) + && !__ct.is(__ctype_base::space, + _Traits::to_char_type(__c))) + { + if (__len == sizeof(__buf) / sizeof(_CharT)) + { + __str.append(__buf, sizeof(__buf) / sizeof(_CharT)); + __len = 0; + } + __buf[__len++] = _Traits::to_char_type(__c); + ++__extracted; + __c = __in.rdbuf()->snextc(); + } + __str.append(__buf, __len); + + if (_Traits::eq_int_type(__c, __eof)) + __err |= __ios_base::eofbit; + __in.width(0); + } + __catch(__cxxabiv1::__forced_unwind&) + { + __in._M_setstate(__ios_base::badbit); + __throw_exception_again; + } + __catch(...) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 91. Description of operator>> and getline() for string<> + // might cause endless loop + __in._M_setstate(__ios_base::badbit); + } + } + // 211. operator>>(istream&, string&) doesn't set failbit + if (!__extracted) + __err |= __ios_base::failbit; + if (__err) + __in.setstate(__err); + return __in; + } + + template<typename _CharT, typename _Traits, typename _Alloc, + template <typename, typename, typename> class _Base> + basic_istream<_CharT, _Traits>& + getline(basic_istream<_CharT, _Traits>& __in, + __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str, + _CharT __delim) + { + typedef basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + typedef __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base> + __string_type; + typedef typename __istream_type::int_type __int_type; + typedef typename __string_type::size_type __size_type; + + __size_type __extracted = 0; + const __size_type __n = __str.max_size(); + typename __ios_base::iostate __err = __ios_base::goodbit; + typename __istream_type::sentry __cerb(__in, true); + if (__cerb) + { + __try + { + // Avoid reallocation for common case. + __str.erase(); + _CharT __buf[128]; + __size_type __len = 0; + const __int_type __idelim = _Traits::to_int_type(__delim); + const __int_type __eof = _Traits::eof(); + __int_type __c = __in.rdbuf()->sgetc(); + + while (__extracted < __n + && !_Traits::eq_int_type(__c, __eof) + && !_Traits::eq_int_type(__c, __idelim)) + { + if (__len == sizeof(__buf) / sizeof(_CharT)) + { + __str.append(__buf, sizeof(__buf) / sizeof(_CharT)); + __len = 0; + } + __buf[__len++] = _Traits::to_char_type(__c); + ++__extracted; + __c = __in.rdbuf()->snextc(); + } + __str.append(__buf, __len); + + if (_Traits::eq_int_type(__c, __eof)) + __err |= __ios_base::eofbit; + else if (_Traits::eq_int_type(__c, __idelim)) + { + ++__extracted; + __in.rdbuf()->sbumpc(); + } + else + __err |= __ios_base::failbit; + } + __catch(__cxxabiv1::__forced_unwind&) + { + __in._M_setstate(__ios_base::badbit); + __throw_exception_again; + } + __catch(...) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 91. Description of operator>> and getline() for string<> + // might cause endless loop + __in._M_setstate(__ios_base::badbit); + } + } + if (!__extracted) + __err |= __ios_base::failbit; + if (__err) + __in.setstate(__err); + return __in; + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif // _VSTRING_TCC diff --git a/gcc-4.9/libstdc++-v3/include/ext/vstring_fwd.h b/gcc-4.9/libstdc++-v3/include/ext/vstring_fwd.h new file mode 100644 index 0000000..666a51e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/vstring_fwd.h @@ -0,0 +1,89 @@ +// <vstring.h> Forward declarations -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/vstring_fwd.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{ext/vstring.h} + */ + +#ifndef _VSTRING_FWD_H +#define _VSTRING_FWD_H 1 + +#pragma GCC system_header + +#include <bits/c++config.h> +#include <bits/char_traits.h> +#include <bits/allocator.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template<typename _CharT, typename _Traits, typename _Alloc> + class __sso_string_base; + + template<typename _CharT, typename _Traits, typename _Alloc> + class __rc_string_base; + + template<typename _CharT, typename _Traits = std::char_traits<_CharT>, + typename _Alloc = std::allocator<_CharT>, + template + <typename, typename, typename> class _Base = __sso_string_base> + class __versa_string; + + typedef __versa_string<char> __vstring; + typedef __vstring __sso_string; + typedef + __versa_string<char, std::char_traits<char>, + std::allocator<char>, __rc_string_base> __rc_string; + +#ifdef _GLIBCXX_USE_WCHAR_T + typedef __versa_string<wchar_t> __wvstring; + typedef __wvstring __wsso_string; + typedef + __versa_string<wchar_t, std::char_traits<wchar_t>, + std::allocator<wchar_t>, __rc_string_base> __wrc_string; +#endif + +#if ((__cplusplus >= 201103L) \ + && defined(_GLIBCXX_USE_C99_STDINT_TR1)) + + typedef __versa_string<char16_t> __u16vstring; + typedef __u16vstring __u16sso_string; + typedef + __versa_string<char16_t, std::char_traits<char16_t>, + std::allocator<char16_t>, __rc_string_base> __u16rc_string; + + typedef __versa_string<char32_t> __u32vstring; + typedef __u32vstring __u32sso_string; + typedef + __versa_string<char32_t, std::char_traits<char32_t>, + std::allocator<char32_t>, __rc_string_base> __u32rc_string; + +#endif + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif /* _VSTRING_FWD_H */ diff --git a/gcc-4.9/libstdc++-v3/include/ext/vstring_util.h b/gcc-4.9/libstdc++-v3/include/ext/vstring_util.h new file mode 100644 index 0000000..2363f16 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/vstring_util.h @@ -0,0 +1,183 @@ +// Versatile string utility -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +/** @file ext/vstring_util.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{ext/vstring.h} + */ + +#ifndef _VSTRING_UTIL_H +#define _VSTRING_UTIL_H 1 + +#pragma GCC system_header + +#include <ext/vstring_fwd.h> +#include <debug/debug.h> +#include <bits/stl_function.h> // For less +#include <bits/functexcept.h> +#include <bits/localefwd.h> +#include <bits/ostream_insert.h> +#include <bits/stl_iterator.h> +#include <ext/numeric_traits.h> +#include <bits/move.h> +#include <bits/range_access.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template<typename _CharT, typename _Traits, typename _Alloc> + struct __vstring_utility + { + typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type; + + typedef _Traits traits_type; + typedef typename _Traits::char_type value_type; + typedef typename _CharT_alloc_type::size_type size_type; + typedef typename _CharT_alloc_type::difference_type difference_type; + typedef typename _CharT_alloc_type::pointer pointer; + typedef typename _CharT_alloc_type::const_pointer const_pointer; + + // For __sso_string. + typedef __gnu_cxx:: + __normal_iterator<pointer, __gnu_cxx:: + __versa_string<_CharT, _Traits, _Alloc, + __sso_string_base> > + __sso_iterator; + typedef __gnu_cxx:: + __normal_iterator<const_pointer, __gnu_cxx:: + __versa_string<_CharT, _Traits, _Alloc, + __sso_string_base> > + __const_sso_iterator; + + // For __rc_string. + typedef __gnu_cxx:: + __normal_iterator<pointer, __gnu_cxx:: + __versa_string<_CharT, _Traits, _Alloc, + __rc_string_base> > + __rc_iterator; + typedef __gnu_cxx:: + __normal_iterator<const_pointer, __gnu_cxx:: + __versa_string<_CharT, _Traits, _Alloc, + __rc_string_base> > + __const_rc_iterator; + + // NB: When the allocator is empty, deriving from it saves space + // (http://www.cantrip.org/emptyopt.html). + template<typename _Alloc1> + struct _Alloc_hider + : public _Alloc1 + { + _Alloc_hider(_CharT* __ptr) + : _Alloc1(), _M_p(__ptr) { } + + _Alloc_hider(const _Alloc1& __a, _CharT* __ptr) + : _Alloc1(__a), _M_p(__ptr) { } + + _CharT* _M_p; // The actual data. + }; + + // When __n = 1 way faster than the general multichar + // traits_type::copy/move/assign. + static void + _S_copy(_CharT* __d, const _CharT* __s, size_type __n) + { + if (__n == 1) + traits_type::assign(*__d, *__s); + else + traits_type::copy(__d, __s, __n); + } + + static void + _S_move(_CharT* __d, const _CharT* __s, size_type __n) + { + if (__n == 1) + traits_type::assign(*__d, *__s); + else + traits_type::move(__d, __s, __n); + } + + static void + _S_assign(_CharT* __d, size_type __n, _CharT __c) + { + if (__n == 1) + traits_type::assign(*__d, __c); + else + traits_type::assign(__d, __n, __c); + } + + // _S_copy_chars is a separate template to permit specialization + // to optimize for the common case of pointers as iterators. + template<typename _Iterator> + static void + _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) + { + for (; __k1 != __k2; ++__k1, ++__p) + traits_type::assign(*__p, *__k1); // These types are off. + } + + static void + _S_copy_chars(_CharT* __p, __sso_iterator __k1, __sso_iterator __k2) + { _S_copy_chars(__p, __k1.base(), __k2.base()); } + + static void + _S_copy_chars(_CharT* __p, __const_sso_iterator __k1, + __const_sso_iterator __k2) + { _S_copy_chars(__p, __k1.base(), __k2.base()); } + + static void + _S_copy_chars(_CharT* __p, __rc_iterator __k1, __rc_iterator __k2) + { _S_copy_chars(__p, __k1.base(), __k2.base()); } + + static void + _S_copy_chars(_CharT* __p, __const_rc_iterator __k1, + __const_rc_iterator __k2) + { _S_copy_chars(__p, __k1.base(), __k2.base()); } + + static void + _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) + { _S_copy(__p, __k1, __k2 - __k1); } + + static void + _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) + { _S_copy(__p, __k1, __k2 - __k1); } + + static int + _S_compare(size_type __n1, size_type __n2) + { + const difference_type __d = difference_type(__n1 - __n2); + + if (__d > __numeric_traits_integer<int>::__max) + return __numeric_traits_integer<int>::__max; + else if (__d < __numeric_traits_integer<int>::__min) + return __numeric_traits_integer<int>::__min; + else + return int(__d); + } + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif /* _VSTRING_UTIL_H */ |