📄 hash_set.html
字号:
<HTML><HEAD><TITLE><hash_set></TITLE></HEAD><BODY><H1><A NAME="<hash_set>"><CODE><hash_set></CODE></A></H1><HR><P>Include the <A HREF="index.html#STL">STL</A>standard header <B><CODE><hash_set></CODE></B> to define the<A HREF="lib_cont.html#Containers">container</A>template classes <CODE>hash_set</CODE> and<CODE>hash_multiset</CODE>, and their supportingtemplates.</P><PRE>namespace std {template<class Key, class Tr, class Alloc> class <B><A HREF="#hash_set">hash_set</A></B>;template<class Key, class Tr, class Alloc> class <B><A HREF="#hash_multiset">hash_multiset</A></B>; // TEMPLATE FUNCTIONStemplate<class Key, class Tr, class Alloc> bool <B><A HREF="#operator==">operator==</A></B>( const hash_set<Key, Tr, Alloc>& left, const hash_set<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator==">operator==</A></B>( const hash_multiset<Key, Tr, Alloc>& left, const hash_multiset<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator!=">operator!=</A></B>( const hash_set<Key, Tr, Alloc>& left, const hash_set<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator!=">operator!=</A></B>( const hash_multiset<Key, Tr, Alloc>& left, const hash_multiset<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator<">operator<</A></B>( const hash_set<Key, Tr, Alloc>& left, const hash_set<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator<">operator<</A></B>( const hash_multiset<Key, Tr, Alloc>& left, const hash_multiset<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator>">operator></A></B>( const hash_set<Key, Tr, Alloc>& left, const hash_set<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator>">operator></A></B>( const hash_multiset<Key, Tr, Alloc>& left, const hash_multiset<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator<=">operator<=</A></B>( const hash_set<Key, Tr, Alloc>& left, const hash_set<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator<=">operator<=</A></B>( const hash_multiset<Key, Tr, Alloc>& left, const hash_multiset<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator>=">operator>=</A></B>( const hash_set<Key, Tr, Alloc>& left, const hash_set<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> bool <B><A HREF="#operator>=">operator>=</A></B>( const hash_multiset<Key, Tr, Alloc>& left, const hash_multiset<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> void <B><A HREF="#swap">swap</A></B>( hash_set<Key, Tr, Alloc>& left, hash_set<Key, Tr, Alloc>& right);template<class Key, class Tr, class Alloc> void <B><A HREF="#swap">swap</A></B>( hash_multiset<Key, Tr, Alloc>& left, hash_multiset<Key, Tr, Alloc>& right); };</PRE><H2><A NAME="hash_multiset"><CODE>hash_multiset</CODE></A></H2><HR><P><B><CODE><A HREF="#hash_multiset::allocator_type">allocator_type</A>· <A HREF="#hash_multiset::begin">begin</A>· <A HREF="#hash_multiset::clear">clear</A>· <A HREF="#hash_multiset::const_iterator">const_iterator</A>· <A HREF="#hash_multiset::const_pointer">const_pointer</A>· <A HREF="#hash_multiset::const_reference">const_reference</A>· <A HREF="#hash_multiset::const_reverse_iterator">const_reverse_iterator</A>· <A HREF="#hash_multiset::count">count</A>· <A HREF="#hash_multiset::difference_type">difference_type</A>· <A HREF="#hash_multiset::empty">empty</A>· <A HREF="#hash_multiset::end">end</A>· <A HREF="#hash_multiset::equal_range">equal_range</A>· <A HREF="#hash_multiset::erase">erase</A>· <A HREF="#hash_multiset::find">find</A>· <A HREF="#hash_multiset::get_allocator">get_allocator</A>· <A HREF="#hash_multiset::insert">insert</A>· <A HREF="#hash_multiset::iterator">iterator</A>· <A HREF="#hash_multiset::key_comp">key_comp</A>· <A HREF="#hash_multiset::key_compare">key_compare</A>· <A HREF="#hash_multiset::key_type">key_type</A>· <A HREF="#hash_multiset::lower_bound">lower_bound</A>· <A HREF="#hash_multiset::max_size">max_size</A>· <A HREF="#hash_multiset::hash_multiset">hash_multiset</A>· <A HREF="#hash_multiset::pointer">pointer</A>· <A HREF="#hash_multiset::rbegin">rbegin</A>· <A HREF="#hash_multiset::reference">reference</A>· <A HREF="#hash_multiset::rend">rend</A>· <A HREF="#hash_multiset::reverse_iterator">reverse_iterator</A>· <A HREF="#hash_multiset::size">size</A>· <A HREF="#hash_multiset::size_type">size_type</A>· <A HREF="#hash_multiset::swap">swap</A>· <A HREF="#hash_multiset::upper_bound">upper_bound</A>· <A HREF="#hash_multiset::value_comp">value_comp</A>· <A HREF="#hash_multiset::value_compare">value_compare</A>· <A HREF="#hash_multiset::value_type">value_type</A></CODE></B></P><HR><PRE>template<class Key, class Tr = hash_compare<Key, less<Key> >, class Alloc = allocator<Key> > class <B>hash_multiset</B> {public: typedef Key <B><A HREF="#hash_multiset::key_type">key_type</A></B>; typedef Tr <B><A HREF="#hash_multiset::key_compare">key_compare</A></B>; typedef Key <B><A HREF="#hash_multiset::value_type">value_type</A></B>; typedef Tr <B><A HREF="#hash_multiset::value_compare">value_compare</A></B>; typedef Alloc <B><A HREF="#hash_multiset::allocator_type">allocator_type</A></B>; typedef Alloc::pointer <B><A HREF="#hash_multiset::pointer">pointer</A></B>; typedef Alloc::const_pointer <B><A HREF="#hash_multiset::const_pointer">const_pointer</A></B>; typedef Alloc::reference <B><A HREF="#hash_multiset::reference">reference</A></B>; typedef Alloc::const_reference <B><A HREF="#hash_multiset::const_reference">const_reference</A></B>; typedef T0 <B><A HREF="#hash_multiset::iterator">iterator</A></B>; typedef T1 <B><A HREF="#hash_multiset::const_iterator">const_iterator</A></B>; typedef T2 <B><A HREF="#hash_multiset::size_type">size_type</A></B>; typedef T3 <B><A HREF="#hash_multiset::difference_type">difference_type</A></B>; typedef reverse_iterator<const_iterator> <B><A HREF="#hash_multiset::const_reverse_iterator">const_reverse_iterator</A></B>; typedef reverse_iterator<iterator> <B><A HREF="#hash_multiset::reverse_iterator">reverse_iterator</A></B>; <B><A HREF="#hash_multiset::hash_multiset">hash_multiset</A></B>(); explicit <B><A HREF="#hash_multiset::hash_multiset">hash_multiset</A></B>(const Tr& traits); <B><A HREF="#hash_multiset::hash_multiset">hash_multiset</A></B>(const Tr& traits, const Alloc& al); <B><A HREF="#hash_multiset::hash_multiset">hash_multiset</A></B>(const hash_multiset& right); template<class InIt> <B><A HREF="#hash_multiset::hash_multiset">hash_multiset</A></B>(InIt first, InIt last); template<class InIt> <B><A HREF="#hash_multiset::hash_multiset">hash_multiset</A></B>(InIt first, InIt last, const Tr& traits); template<class InIt> <B><A HREF="#hash_multiset::hash_multiset">hash_multiset</A></B>(InIt first, InIt last, const Tr& traits, const Alloc& al); const_iterator <B><A HREF="#hash_multiset::begin">begin</A></B>() const; const_iterator <B><A HREF="#hash_multiset::end">end</A></B>() const; const_reverse_iterator <B><A HREF="#hash_multiset::rbegin">rbegin</A></B>() const; const_reverse_iterator <B><A HREF="#hash_multiset::rend">rend</A></B>() const; size_type <B><A HREF="#hash_multiset::size">size</A></B>() const; size_type <B><A HREF="#hash_multiset::max_size">max_size</A></B>() const; bool <B><A HREF="#hash_multiset::empty">empty</A></B>() const; Alloc <B><A HREF="#hash_multiset::get_allocator">get_allocator</A></B>() const; iterator <B><A HREF="#hash_multiset::insert">insert</A></B>(const value_type& val); iterator <B><A HREF="#hash_multiset::insert">insert</A></B>(iterator where, const value_type& val); template<class InIt> void <B><A HREF="#hash_multiset::insert">insert</A></B>(InIt first, InIt last); iterator <B><A HREF="#hash_multiset::erase">erase</A></B>(iterator where); iterator <B><A HREF="#hash_multiset::erase">erase</A></B>(iterator first, iterator last); size_type <B><A HREF="#hash_multiset::erase">erase</A></B>(const Key& keyval); void <B><A HREF="#hash_multiset::clear">clear</A></B>(); void <B><A HREF="#hash_multiset::swap">swap</A></B>(hash_multiset& right); key_compare <B><A HREF="#hash_multiset::key_comp">key_comp</A></B>() const; value_compare <B><A HREF="#hash_multiset::value_comp">value_comp</A></B>() const; const_iterator <B><A HREF="#hash_multiset::find">find</A></B>(const Key& keyval) const; size_type <B><A HREF="#hash_multiset::count">count</A></B>(const Key& keyval) const; const_iterator <B><A HREF="#hash_multiset::lower_bound">lower_bound</A></B>(const Key& keyval) const; const_iterator <B><A HREF="#hash_multiset::upper_bound">upper_bound</A></B>(const Key& keyval) const; pair<const_iterator, const_iterator> <B><A HREF="#hash_multiset::equal_range">equal_range</A></B>(const Key& keyval) const; };</PRE><P>The template class describes an object that controls avarying-length sequence of elements of type<CODE>const Key</CODE>.The sequence is<A HREF="lib_stl.html#sequence ordering">ordered by</A> the<A HREF="hash_map.html#hash traits">hash traits</A> object<CODE>Tr</CODE>, which includes both a two-operand function for imposing a<A HREF="lib_stl.html#strict weak ordering">strict weak ordering</A>and a one-operand <A HREF="hash_map.html#hash function">hash function</A>.Each element serves as both a <B>sort key</B> and a <B>value</B>.The sequence is represented in a way that permits lookup, insertion,and removal of an arbitrary element with a number of operations that can beindependent of the number of elements in the sequence (constant time).In the worst case, the number of operations isproportional to the number of elementsin the sequence (linear time). Moreover, inserting an elementinvalidates no iterators, and removing an elementinvalidates only those iterators which point at the removed element.</P><P>The object orders the sequence it controls by calling a stored<A HREF="hash_map.html#hash traits">hash traits</A> object of type <CODE>Tr</CODE>.You access this stored object by calling the member function<CODE><A HREF="#hash_multiset::key_comp">key_comp</A>()</CODE>.Such a traits object must behave the same as an object of class<CODE><A HREF="hash_map.html#hash_compare">hash_compare</A><Key, Pr></CODE>.Specifically, for all values <CODE>keyval</CODE> of type <CODE>Key</CODE>,the call <CODE>Tr(keyval)</CODE> yields a distributionof values of type <CODE>size_t</CODE>.Moreover, class <CODE>Pr</CODE> imposes a<A HREF="lib_stl.html#strict weak ordering">strict weak ordering</A>on sort keys of type <CODE>Key</CODE>.For any element <CODE>X</CODE> that precedes<CODE>Y</CODE> in the sequence and has the same hash value,<CODE>key_comp()(Y, X)</CODE> is false. (For the default function object<CODE><A HREF="functio2.html#less">less</A><Key></CODE>,sort keys never decrease in value.)Unlike template class <CODE><A HREF="#hash_set">hash_set</A></CODE>,an object of template class <CODE>hash_multiset</CODE> does not ensure that<CODE>key_comp()(X, Y)</CODE> is true.(Keys need not be unique.)</P><P>The actual order of elements in the controlled sequence depends on thehash function, the ordering function, and the current size of the hashtable stored in the container object. You cannot determine the current sizeof the hash table, so you cannot in general predict the order of elementsin the controlled sequence. You can always be assured, however, that anysubset of elements that have<A HREF="lib_stl.html#equivalent ordering">equivalent ordering</A>are adjacent in the controlled sequence.</P><P>The object allocates and frees storage for the sequence it controlsthrough a stored <A HREF="memory.html#allocator object">allocator object</A>of class <CODE>Alloc</CODE>. Such an allocator object must havethe same external interface as an object of template class<A HREF="memory.html#allocator"><CODE>allocator</CODE></A>.Note that the stored allocator object is <I>not</I> copied when the containerobject is assigned.</P><H3><CODE><A NAME="hash_multiset::allocator_type">hash_multiset::allocator_type</A></CODE></H3><PRE>typedef Alloc <B>allocator_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Alloc</CODE>.</P><H3><CODE><A NAME="hash_multiset::begin">hash_multiset::begin</A></CODE></H3><PRE>const_iterator <B>begin</B>() const;</PRE><P>The member function returns a bidirectional iterator that points atthe first element of the sequence (or just beyond the end of an emptysequence).</P><H3><CODE><A NAME="hash_multiset::clear">hash_multiset::clear</A></CODE></H3><PRE>void <B>clear</B>();</PRE><P>The member function calls<CODE><A HREF="#hash_multiset::erase">erase</A>(<A HREF="#hash_multiset::begin">begin</A>(),<A HREF="#hash_multiset::end">end</A>())</CODE>.</P><H3><CODE><A NAME="hash_multiset::const_iterator">hash_multiset::const_iterator</A></CODE></H3><PRE>typedef T1 <B>const_iterator</B>;</PRE><P>The type describes an object that can serve as a constantbidirectional iterator for the controlled sequence.It is described here as asynonym for the implementation-defined type <CODE>T1</CODE>.</P><H3><CODE><A NAME="hash_multiset::const_pointer">hash_multiset::const_pointer</A></CODE></H3><PRE>typedef Alloc::const_pointer <B>const_pointer</B>;</PRE><P>The type describes an object that can serve as a constant pointerto an element of the controlled sequence.</P><H3><CODE><A NAME="hash_multiset::const_reference">hash_multiset::const_reference</A></CODE></H3><PRE>typedef Alloc::const_reference <B>const_reference</B>;</PRE><P>The type describes an object that can serve as a constant referenceto an element of the controlled sequence.</P><H3><CODE><A NAME="hash_multiset::const_reverse_iterator">hash_multiset::const_reverse_iterator</A></CODE></H3><PRE>typedef reverse_iterator<const_iterator> <B>const_reverse_iterator</B>;</PRE><P>The type describes an object that can serve as a constant reversebidirectional iterator for the controlled sequence.</P><H3><CODE><A NAME="hash_multiset::count">hash_multiset::count</A></CODE></H3><PRE>size_type <B>count</B>(const Key& keyval) const;</PRE><P>The member function returns the number of elements in the range<CODE>[<A HREF="#hash_multiset::lower_bound">lower_bound</A>(keyval),<A HREF="#hash_multiset::upper_bound">upper_bound</A>(keyval)).</CODE></P><H3><CODE><A NAME="hash_multiset::difference_type">hash_multiset::difference_type</A></CODE></H3><PRE>typedef T3 <B>difference_type</B>;</PRE><P>The signed integer type describes an object that can represent thedifference between the addresses of any two elements in the controlledsequence. It is described here as asynonym for the implementation-defined type <CODE>T3</CODE>.</P><H3><CODE><A NAME="hash_multiset::empty">hash_multiset::empty</A></CODE></H3><PRE>bool <B>empty</B>() const;</PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -