Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.5 KiB

  1. #if _MSC_VER > 1000
  2. #pragma once
  3. #endif // _MSC_VER > 1000
  4. template< class Key, class T, class Compare= less<Key>,
  5. class Allocator= allocator<pair<const Key,T> > >
  6. class map:
  7. public RBTree< Key, pair<const Key,T>, select1st<pair<const Key,T> >,
  8. Compare, Allocator>
  9. {
  10. public: // Types
  11. typedef map< Key, T, Compare, Allocator> map_type;
  12. typedef RBTree< Key, pair<const Key,T>, select1st<pair<const Key,T> >,
  13. Compare, Allocator> tree_type;
  14. typedef tree_type::key_type key_type;
  15. typedef Allocator::rebind< T>::other mapped_type;
  16. typedef tree_type::value_type value_type;
  17. typedef tree_type::key_compare key_compare;
  18. struct value_compare:
  19. public binary_function< value_type, value_type, bool>
  20. {
  21. key_compare m_key_compare;
  22. explicit value_compare( const key_compare& KC): m_key_compare( KC)
  23. { }
  24. result_type operator()( const first_argument_type& Arg1,
  25. const second_argument_type& Arg2) const
  26. {
  27. return m_key_compare( Arg1.first, Arg2.first);
  28. }
  29. };
  30. typedef tree_type::pointer pointer;
  31. typedef tree_type::const_pointer const_pointer;
  32. typedef tree_type::reference reference;
  33. typedef tree_type::const_reference const_reference;
  34. typedef tree_type::size_type size_type;
  35. typedef tree_type::difference_type difference_type;
  36. typedef tree_type::iterator iterator;
  37. typedef tree_type::const_iterator const_iterator;
  38. typedef tree_type::reverse_iterator reverse_iterator;
  39. typedef tree_type::const_reverse_iterator const_reverse_iterator;
  40. typedef tree_type::allocator_type allocator_type;
  41. public: // Functions
  42. using tree_type::begin;
  43. using tree_type::end;
  44. using tree_type::rbegin;
  45. using tree_type::rend;
  46. using tree_type::size;
  47. using tree_type::max_size;
  48. using tree_type::empty;
  49. using tree_type::key_comp;
  50. value_compare value_comp() const
  51. { return value_compare( key_comp()); }
  52. explicit map( const Compare& comp= Compare(),
  53. const Allocator& A= Allocator()): tree_type( comp,
  54. select1st<pair<const Key,T> >(), A)
  55. { }
  56. template< class InputIterator>
  57. map( InputIterator f, InputIterator l, const Compare comp= Compare(),
  58. const Allocator& A= Allocator()): tree_type( comp,
  59. select1st<pair<const Key,T> >(), A)
  60. {
  61. insert_unique( f, l);
  62. }
  63. map( const map_type& Other): tree_type( Other)
  64. { }
  65. ~map()
  66. { }
  67. map_type& operator=( const map_type& Other)
  68. {
  69. tree_type::operator=( Other);
  70. return *this;
  71. }
  72. using tree_type::get_allocator;
  73. void swap( const map_type& Other)
  74. { tree_type::swap( Other); }
  75. pair< iterator, bool> insert( const value_type& x)
  76. { return insert_unique( x); }
  77. iterator insert( iterator pos, const value_type& x)
  78. { return insert_unique( x); }
  79. template< class InputIterator>
  80. void insert( InputIterator f, InputIterator l)
  81. { insert_unique( f, l); }
  82. using tree_type::erase;
  83. using tree_type::find;
  84. using tree_type::count;
  85. using tree_type::lower_bound;
  86. using tree_type::upper_bound;
  87. using tree_type::equal_range;
  88. mapped_type& operator[]( const key_type& k)
  89. {
  90. iterator itEntry( insert( value_type( k, mapped_type())));
  91. return itEntry->second;
  92. }
  93. };
  94. template< class Key, class T, class Compare, class Allocator> inline
  95. bool operator==( const map< Key, T, Compare, Allocator>& x,
  96. const map< Key, T, Compare, Allocator>& y)
  97. {
  98. return x.size()== y.size()&& equal( x.begin(), x.end(), y.begin());
  99. }
  100. template< class Key, class T, class Compare, class Allocator> inline
  101. bool operator!=( const map< Key, T, Compare, Allocator>& x,
  102. const map< Key, T, Compare, Allocator>& y)
  103. {
  104. return !(x== y);
  105. }
  106. template< class Key, class T, class Compare, class Allocator> inline
  107. bool operator<( const map< Key, T, Compare, Allocator>& x,
  108. const map< Key, T, Compare, Allocator>& y)
  109. {
  110. return lexicographical_compare( x.begin(), x.end(), y.begin(), y.end());
  111. }
  112. template< class Key, class T, class Compare, class Allocator> inline
  113. bool operator>( const map< Key, T, Compare, Allocator>& x,
  114. const map< Key, T, Compare, Allocator>& y)
  115. {
  116. return y< x;
  117. }
  118. template< class Key, class T, class Compare, class Allocator> inline
  119. bool operator<=( const map< Key, T, Compare, Allocator>& x,
  120. const map< Key, T, Compare, Allocator>& y)
  121. {
  122. return !(y< x);
  123. }
  124. template< class Key, class T, class Compare, class Allocator> inline
  125. bool operator>=( const map< Key, T, Compare, Allocator>& x,
  126. const map< Key, T, Compare, Allocator>& y)
  127. {
  128. return !(x< y);
  129. }