3 typedef unsigned int size_t;
8 namespace std __attribute__ ((__visibility__ ("default"))) {
10 template<typename _Alloc>
13 template<class _CharT>
16 template<typename _CharT, typename _Traits = char_traits<_CharT>,
17 typename _Alloc = allocator<_CharT> >
20 template<> struct char_traits<char>;
22 typedef basic_string<char> string;
24 template<> struct char_traits<wchar_t>;
26 typedef basic_string<wchar_t> wstring;
29 namespace std __attribute__ ((__visibility__ ("default"))) {
31 __throw_bad_alloc(void) __attribute__((__noreturn__));
34 namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
35 template<typename _Iterator, typename _Container>
36 class __normal_iterator;
39 namespace std __attribute__ ((__visibility__ ("default"))) {
41 template<typename _Tp>
45 return reinterpret_cast<_Tp*>
46 (&const_cast<char&>(reinterpret_cast<const volatile char&>(__r)));
50 namespace std __attribute__ ((__visibility__ ("default"))) {
51 template<class _T1, class _T2>
54 typedef _T1 first_type;
55 typedef _T2 second_type;
61 : first(), second() { }
63 pair(const _T1& __a, const _T2& __b)
64 : first(__a), second(__b) { }
68 namespace std __attribute__ ((__visibility__ ("default"))) {
69 struct input_iterator_tag { };
71 struct output_iterator_tag { };
73 struct forward_iterator_tag : public input_iterator_tag { };
75 struct bidirectional_iterator_tag : public forward_iterator_tag { };
77 struct random_access_iterator_tag : public bidirectional_iterator_tag { };
78 template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t,
79 typename _Pointer = _Tp*, typename _Reference = _Tp&>
82 typedef _Category iterator_category;
83 typedef _Tp value_type;
84 typedef _Distance difference_type;
85 typedef _Pointer pointer;
86 typedef _Reference reference;
89 template<typename _Iterator>
90 struct iterator_traits
92 typedef typename _Iterator::iterator_category iterator_category;
93 typedef typename _Iterator::value_type value_type;
94 typedef typename _Iterator::difference_type difference_type;
95 typedef typename _Iterator::pointer pointer;
96 typedef typename _Iterator::reference reference;
100 namespace std __attribute__ ((__visibility__ ("default"))) {
101 template<typename _Iterator>
102 class reverse_iterator
103 : public iterator<typename iterator_traits<_Iterator>::iterator_category,
104 typename iterator_traits<_Iterator>::value_type,
105 typename iterator_traits<_Iterator>::difference_type,
106 typename iterator_traits<_Iterator>::pointer,
107 typename iterator_traits<_Iterator>::reference>
111 typedef iterator_traits<_Iterator> __traits_type;
117 typedef struct _IO_FILE FILE;
119 typedef struct _IO_FILE __FILE;
121 typedef __builtin_va_list __gnuc_va_list;
123 typedef unsigned int size_t;
124 typedef unsigned int wint_t;
137 typedef __mbstate_t mbstate_t;
139 namespace std __attribute__ ((__visibility__ ("default"))) {
143 namespace std __attribute__ ((__visibility__ ("default"))) {
144 typedef long long streamoff;
146 typedef ptrdiff_t streamsize;
147 template<typename _StateT>
157 : _M_off(0), _M_state() { }
158 fpos(streamoff __off)
159 : _M_off(__off), _M_state() { }
161 operator streamoff() const { return _M_off; }
165 typedef fpos<mbstate_t> streampos;
167 typedef fpos<mbstate_t> wstreampos;
170 namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
171 template<typename _CharT>
174 typedef unsigned long int_type;
175 typedef std::streampos pos_type;
176 typedef std::streamoff off_type;
177 typedef std::mbstate_t state_type;
179 template<typename _CharT>
182 typedef _CharT char_type;
183 typedef typename _Char_types<_CharT>::int_type int_type;
184 typedef typename _Char_types<_CharT>::pos_type pos_type;
185 typedef typename _Char_types<_CharT>::off_type off_type;
186 typedef typename _Char_types<_CharT>::state_type state_type;
188 static const char_type*
189 find(const char_type* __s, std::size_t __n, const char_type& __a);
193 namespace std __attribute__ ((__visibility__ ("default"))) {
194 template<class _CharT>
195 struct char_traits : public __gnu_cxx::char_traits<_CharT>
199 struct char_traits<char>
201 typedef char char_type;
202 typedef int int_type;
203 typedef streampos pos_type;
204 typedef streamoff off_type;
205 typedef mbstate_t state_type;
207 static const char_type*
208 find(const char_type* __s, size_t __n, const char_type& __a)
209 { return static_cast<const char_type*>(__builtin_memchr(__s, __a, __n)); }
213 namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
216 using std::ptrdiff_t;
217 template<typename _Tp>
221 typedef size_t size_type;
222 typedef ptrdiff_t difference_type;
223 typedef _Tp* pointer;
224 typedef const _Tp* const_pointer;
225 typedef _Tp& reference;
226 typedef const _Tp& const_reference;
227 typedef _Tp value_type;
229 new_allocator() throw() { }
231 new_allocator(const new_allocator&) throw() { }
233 template<typename _Tp1>
234 new_allocator(const new_allocator<_Tp1>&) throw() { }
236 ~new_allocator() throw() { }
239 allocate(size_type __n, const void* = 0)
241 if (__n > this->max_size())
242 std::__throw_bad_alloc();
244 return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
247 deallocate(pointer __p, size_type)
248 { ::operator delete(__p); }
251 destroy(pointer __p) { __p->~_Tp(); }
255 namespace std __attribute__ ((__visibility__ ("default"))) {
256 template<typename _Tp>
259 template<typename _Tp>
260 class allocator: public __gnu_cxx::new_allocator<_Tp>
263 typedef size_t size_type;
264 typedef ptrdiff_t difference_type;
265 typedef _Tp* pointer;
266 typedef const _Tp* const_pointer;
267 typedef _Tp& reference;
268 typedef const _Tp& const_reference;
269 typedef _Tp value_type;
271 template<typename _Tp1>
273 { typedef allocator<_Tp1> other; };
275 allocator() throw() { }
277 allocator(const allocator& __a) throw()
278 : __gnu_cxx::new_allocator<_Tp>(__a) { }
280 template<typename _Tp1>
281 allocator(const allocator<_Tp1>&) throw() { }
283 ~allocator() throw() { }
287 namespace std __attribute__ ((__visibility__ ("default"))) {
288 template<typename _Arg, typename _Result>
289 struct unary_function
291 typedef _Arg argument_type;
292 typedef _Result result_type;
295 template<typename _Arg1, typename _Arg2, typename _Result>
296 struct binary_function
298 typedef _Arg1 first_argument_type;
299 typedef _Arg2 second_argument_type;
300 typedef _Result result_type;
303 template<typename _Tp>
304 struct less : public binary_function<_Tp, _Tp, bool>
307 operator()(const _Tp& __x, const _Tp& __y) const
308 { return __x < __y; }
311 template<typename _Pair>
312 struct _Select1st : public unary_function<_Pair,
313 typename _Pair::first_type>
315 typename _Pair::first_type&
316 operator()(_Pair& __x) const
317 { return __x.first; }
319 const typename _Pair::first_type&
320 operator()(const _Pair& __x) const
321 { return __x.first; }
327 typedef int __sig_atomic_t;
331 unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
333 typedef __sigset_t sigset_t;
335 typedef unsigned long int pthread_t;
337 typedef struct __pthread_internal_slist
339 struct __pthread_internal_slist *__next;
344 struct __pthread_mutex_s
347 unsigned int __count;
351 unsigned int __nusers;
355 __pthread_slist_t __list;
363 typedef unsigned int pthread_key_t;
365 typedef int pthread_once_t;
367 extern int pthread_once (pthread_once_t *__once_control,
368 void (*__init_routine) (void)) __attribute__ ((__nonnull__ (1, 2)));
370 extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
371 throw () __attribute__ ((__nonnull__ (1)));
373 extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
374 throw () __attribute__ ((__nonnull__ (1)));
376 typedef pthread_t __gthread_t;
377 typedef pthread_key_t __gthread_key_t;
378 typedef pthread_once_t __gthread_once_t;
379 typedef pthread_mutex_t __gthread_mutex_t;
381 static __typeof(pthread_once) __gthrw_pthread_once __attribute__ ((__weakref__("pthread_once")));
383 static __typeof(pthread_mutex_lock) __gthrw_pthread_mutex_lock __attribute__ ((__weakref__("pthread_mutex_lock")));
385 static __typeof(pthread_mutex_unlock) __gthrw_pthread_mutex_unlock __attribute__ ((__weakref__("pthread_mutex_unlock")));
387 static volatile int __gthread_active = -1;
390 __gthread_trigger (void)
392 __gthread_active = 1;
396 __gthread_active_p (void)
398 static pthread_mutex_t __gthread_active_mutex = { { 0, 0, 0, 0, 0, { 0 } } };
399 static pthread_once_t __gthread_active_once = 0;
401 int __gthread_active_latest_value = __gthread_active;
403 if (__builtin_expect (__gthread_active_latest_value < 0, 0))
405 if (__gthrw_pthread_once)
407 __gthrw_pthread_mutex_lock (&__gthread_active_mutex);
408 __gthrw_pthread_once (&__gthread_active_once, __gthread_trigger);
409 __gthrw_pthread_mutex_unlock (&__gthread_active_mutex);
412 if (__gthread_active < 0)
413 __gthread_active = 0;
414 __gthread_active_latest_value = __gthread_active;
417 return __gthread_active_latest_value != 0;
420 typedef int _Atomic_word;
422 namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
424 static inline _Atomic_word
425 __exchange_and_add(volatile _Atomic_word* __mem, int __val)
426 { return __sync_fetch_and_add(__mem, __val); }
429 __atomic_add(volatile _Atomic_word* __mem, int __val)
430 { __sync_fetch_and_add(__mem, __val); }
431 static inline _Atomic_word
432 __exchange_and_add_single(_Atomic_word* __mem, int __val)
434 _Atomic_word __result = *__mem;
440 __atomic_add_single(_Atomic_word* __mem, int __val)
443 static inline _Atomic_word
444 __attribute__ ((__unused__))
445 __exchange_and_add_dispatch(_Atomic_word* __mem, int __val)
447 if (__gthread_active_p())
448 return __exchange_and_add(__mem, __val);
450 return __exchange_and_add_single(__mem, __val);
454 __attribute__ ((__unused__))
455 __atomic_add_dispatch(_Atomic_word* __mem, int __val)
457 if (__gthread_active_p())
458 __atomic_add(__mem, __val);
460 __atomic_add_single(__mem, __val);
464 namespace std __attribute__ ((__visibility__ ("default"))) {
465 template<typename _CharT, typename _Traits, typename _Alloc>
468 typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
471 typedef _Traits traits_type;
472 typedef typename _Traits::char_type value_type;
473 typedef _Alloc allocator_type;
474 typedef typename _CharT_alloc_type::size_type size_type;
475 typedef typename _CharT_alloc_type::difference_type difference_type;
476 typedef typename _CharT_alloc_type::reference reference;
477 typedef typename _CharT_alloc_type::const_reference const_reference;
478 typedef typename _CharT_alloc_type::pointer pointer;
479 typedef typename _CharT_alloc_type::const_pointer const_pointer;
480 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
481 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
483 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
484 typedef std::reverse_iterator<iterator> reverse_iterator;
490 size_type _M_capacity;
491 _Atomic_word _M_refcount;
494 struct _Rep : _Rep_base
497 typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
498 static const size_type _S_max_size;
499 static const _CharT _S_terminal;
501 static size_type _S_empty_rep_storage[];
506 void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage);
507 return *reinterpret_cast<_Rep*>(__p);
512 { return reinterpret_cast<_CharT*>(this + 1); }
515 _M_dispose(const _Alloc& __a)
517 if (__builtin_expect(this != &_S_empty_rep(), false))
520 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
530 _M_destroy(const _Alloc&) throw();
535 if (__builtin_expect(this != &_S_empty_rep(), false))
536 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
541 struct _Alloc_hider : _Alloc
543 _Alloc_hider(_CharT* __dat, const _Alloc& __a)
544 : _Alloc(__a), _M_p(__dat) { }
551 mutable _Alloc_hider _M_dataplus;
555 { return _M_dataplus._M_p; }
559 { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
567 { _M_rep()->_M_dispose(this->get_allocator()); }
572 get_allocator() const
573 { return _M_dataplus; }
577 namespace std __attribute__ ((__visibility__ ("default"))) {
578 enum _Rb_tree_color { _S_red = false, _S_black = true };
580 struct _Rb_tree_node_base
582 typedef _Rb_tree_node_base* _Base_ptr;
583 typedef const _Rb_tree_node_base* _Const_Base_ptr;
585 _Rb_tree_color _M_color;
591 _S_minimum(_Base_ptr __x)
593 while (__x->_M_left != 0) __x = __x->_M_left;
597 static _Const_Base_ptr
598 _S_minimum(_Const_Base_ptr __x)
600 while (__x->_M_left != 0) __x = __x->_M_left;
605 _S_maximum(_Base_ptr __x)
607 while (__x->_M_right != 0) __x = __x->_M_right;
611 static _Const_Base_ptr
612 _S_maximum(_Const_Base_ptr __x)
614 while (__x->_M_right != 0) __x = __x->_M_right;
619 template<typename _Val>
620 struct _Rb_tree_node : public _Rb_tree_node_base
622 typedef _Rb_tree_node<_Val>* _Link_type;
626 __attribute__ ((__pure__)) _Rb_tree_node_base*
627 _Rb_tree_increment(_Rb_tree_node_base* __x) throw ();
629 __attribute__ ((__pure__)) const _Rb_tree_node_base*
630 _Rb_tree_increment(const _Rb_tree_node_base* __x) throw ();
632 __attribute__ ((__pure__)) _Rb_tree_node_base*
633 _Rb_tree_decrement(_Rb_tree_node_base* __x) throw ();
635 __attribute__ ((__pure__)) const _Rb_tree_node_base*
636 _Rb_tree_decrement(const _Rb_tree_node_base* __x) throw ();
638 template<typename _Tp>
639 struct _Rb_tree_iterator
641 typedef _Tp value_type;
642 typedef _Tp& reference;
643 typedef _Tp* pointer;
645 typedef bidirectional_iterator_tag iterator_category;
646 typedef ptrdiff_t difference_type;
648 typedef _Rb_tree_iterator<_Tp> _Self;
649 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
650 typedef _Rb_tree_node<_Tp>* _Link_type;
656 _Rb_tree_iterator(_Link_type __x)
660 operator==(const _Self& __x) const
661 { return _M_node == __x._M_node; }
664 operator!=(const _Self& __x) const
665 { return _M_node != __x._M_node; }
670 template<typename _Tp>
671 struct _Rb_tree_const_iterator
673 typedef _Tp value_type;
674 typedef const _Tp& reference;
675 typedef const _Tp* pointer;
677 typedef _Rb_tree_iterator<_Tp> iterator;
679 typedef bidirectional_iterator_tag iterator_category;
680 typedef ptrdiff_t difference_type;
682 typedef _Rb_tree_const_iterator<_Tp> _Self;
683 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
684 typedef const _Rb_tree_node<_Tp>* _Link_type;
686 _Rb_tree_const_iterator()
690 _Rb_tree_const_iterator(_Link_type __x)
693 _Rb_tree_const_iterator(const iterator& __it)
694 : _M_node(__it._M_node) { }
698 { return std::__addressof(static_cast<_Link_type>
699 (_M_node)->_M_value_field); }
702 operator==(const _Self& __x) const
703 { return _M_node == __x._M_node; }
706 operator!=(const _Self& __x) const
707 { return _M_node != __x._M_node; }
712 template<typename _Key, typename _Val, typename _KeyOfValue,
713 typename _Compare, typename _Alloc = allocator<_Val> >
716 typedef typename _Alloc::template rebind<_Rb_tree_node<_Val> >::other
720 typedef _Rb_tree_node_base* _Base_ptr;
721 typedef const _Rb_tree_node_base* _Const_Base_ptr;
724 typedef _Key key_type;
725 typedef _Val value_type;
726 typedef value_type* pointer;
727 typedef const value_type* const_pointer;
728 typedef value_type& reference;
729 typedef const value_type& const_reference;
730 typedef _Rb_tree_node<_Val>* _Link_type;
731 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
732 typedef size_t size_type;
733 typedef ptrdiff_t difference_type;
734 typedef _Alloc allocator_type;
736 const _Node_allocator&
737 _M_get_Node_allocator() const
738 { return *static_cast<const _Node_allocator*>(&this->_M_impl); }
741 get_allocator() const
742 { return allocator_type(_M_get_Node_allocator()); }
746 _M_put_node(_Link_type __p)
747 { _M_impl._Node_allocator::deallocate(__p, 1); }
750 _M_destroy_node(_Link_type __p)
752 get_allocator().destroy(std::__addressof(__p->_M_value_field));
757 template<typename _Key_compare,
758 bool _Is_pod_comparator = __is_pod(_Key_compare)>
759 struct _Rb_tree_impl : public _Node_allocator
761 _Key_compare _M_key_compare;
762 _Rb_tree_node_base _M_header;
763 size_type _M_node_count;
769 this->_M_header._M_color = _S_red;
770 this->_M_header._M_parent = 0;
771 this->_M_header._M_left = &this->_M_header;
772 this->_M_header._M_right = &this->_M_header;
776 _Rb_tree_impl<_Compare> _M_impl;
782 { return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); }
786 { return static_cast<_Link_type>(&this->_M_impl._M_header); }
789 _S_left(_Base_ptr __x)
790 { return static_cast<_Link_type>(__x->_M_left); }
793 _S_right(_Base_ptr __x)
794 { return static_cast<_Link_type>(__x->_M_right); }
796 static const_reference
797 _S_value(_Const_Base_ptr __x)
798 { return static_cast<_Const_Link_type>(__x)->_M_value_field; }
801 _S_key(_Const_Base_ptr __x)
802 { return _KeyOfValue()(_S_value(__x)); }
805 typedef _Rb_tree_iterator<value_type> iterator;
806 typedef _Rb_tree_const_iterator<value_type> const_iterator;
811 _M_erase(_Link_type __x);
814 _M_lower_bound(_Link_type __x, _Link_type __y,
818 _M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
819 const _Key& __k) const;
824 { _M_erase(_M_begin()); }
828 { return iterator(static_cast<_Link_type>(&this->_M_impl._M_header)); }
833 return const_iterator(static_cast<_Const_Link_type>
834 (&this->_M_impl._M_header));
839 find(const key_type& __k);
842 template<typename _Key, typename _Val, typename _KeyOfValue,
843 typename _Compare, typename _Alloc>
845 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
846 _M_erase(_Link_type __x)
851 _M_erase(_S_right(__x));
852 _Link_type __y = _S_left(__x);
853 _M_destroy_node(__x);
858 template<typename _Key, typename _Val, typename _KeyOfValue,
859 typename _Compare, typename _Alloc>
860 typename _Rb_tree<_Key, _Val, _KeyOfValue,
861 _Compare, _Alloc>::iterator
862 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
863 _M_lower_bound(_Link_type __x, _Link_type __y,
867 if (!_M_impl._M_key_compare(_S_key(__x), __k))
868 __y = __x, __x = _S_left(__x);
871 return iterator(__y);
874 template<typename _Key, typename _Val, typename _KeyOfValue,
875 typename _Compare, typename _Alloc>
876 typename _Rb_tree<_Key, _Val, _KeyOfValue,
877 _Compare, _Alloc>::iterator
878 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
879 find(const _Key& __k)
881 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
883 || _M_impl._M_key_compare(__k,
884 _S_key(__j._M_node))) ? end() : __j;
890 template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
891 typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
895 typedef _Key key_type;
896 typedef _Tp mapped_type;
897 typedef std::pair<const _Key, _Tp> value_type;
898 typedef _Compare key_compare;
899 typedef _Alloc allocator_type;
903 typedef typename _Alloc::template rebind<value_type>::other
906 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
907 key_compare, _Pair_alloc_type> _Rep_type;
913 typedef typename _Rep_type::iterator iterator;
914 typedef typename _Rep_type::const_iterator const_iterator;
921 { return _M_t.end(); }
925 { return _M_t.key_comp(); }
928 find(const key_type& __x)
929 { return _M_t.find(__x); }
935 typedef std::map<int, std::string> Map;
938 Map::const_iterator it = m.find(0);
940 std::string s = it->second;