📄 hash_map.html
字号:
<A HREF="#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_map::key_comp">key_comp</A>()</CODE>.Such a traits object must behave the same as an object of class<CODE><A HREF="#hash_compare">hash_compare</A><Key, Pr></CODE>.Specifically, for all values <CODE>keyval</CODE> of type <CODE>Key</CODE>,the call <CODE>key_comp()(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.<A HREF="utility.html#pair::first">first</A>,X.first)</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_multimap">hash_multimap</A></CODE>,an object of template class <CODE>hash_map</CODE> ensures that<CODE>key_comp()(X.first, Y.first)</CODE> is true.(Each key is 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.</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_map::allocator_type">hash_map::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_map::begin">hash_map::begin</A></CODE></H3><PRE>const_iterator <B>begin</B>() const;iterator <B>begin</B>();</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_map::clear">hash_map::clear</A></CODE></H3><PRE>void <B>clear</B>();</PRE><P>The member function calls<CODE><A HREF="#hash_map::erase">erase</A>(<A HREF="#hash_map::begin">begin</A>(),<A HREF="#hash_map::end">end</A>())</CODE>.</P><H3><CODE><A NAME="hash_map::const_iterator">hash_map::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_map::const_pointer">hash_map::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_map::const_reference">hash_map::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_map::const_reverse_iterator">hash_map::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_map::count">hash_map::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_map::lower_bound">lower_bound</A>(keyval),<A HREF="#hash_map::upper_bound">upper_bound</A>(keyval)).</CODE></P><H3><CODE><A NAME="hash_map::difference_type">hash_map::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_map::empty">hash_map::empty</A></CODE></H3><PRE>bool <B>empty</B>() const;</PRE><P>The member function returns true for an empty controlled sequence.</P><H3><CODE><A NAME="hash_map::end">hash_map::end</A></CODE></H3><PRE>const_iterator <B>end</B>() const;iterator <B>end</B>();</PRE><P>The member function returns a bidirectional iterator that pointsjust beyond the end of the sequence.</P><H3><CODE><A NAME="hash_map::equal_range">hash_map::equal_range</A></CODE></H3><PRE>pair<iterator, iterator> <B>equal_range</B>(const Key& keyval);pair<const_iterator, const_iterator> <B>equal_range</B>(const Key& keyval) const;</PRE><P>The member function returns a pair of iterators <CODE>X</CODE>such that <CODE>X.<A HREF="utility.html#pair::first">first</A> ==<A HREF="#hash_map::lower_bound">lower_bound</A>(keyval)</CODE>and <CODE>X.<A HREF="utility.html#pair::second">second</A> ==<A HREF="#hash_map::upper_bound">upper_bound</A>(keyval)</CODE>.</P><H3><CODE><A NAME="hash_map::erase">hash_map::erase</A></CODE></H3><PRE>iterator <B>erase</B>(iterator where);iterator <B>erase</B>(iterator first, iterator last);size_type <B>erase</B>(const Key& keyval);</PRE><P>The first member function removes the element of the controlledsequence pointed to by <CODE>where</CODE>.The second member function removes the elementsin the interval <CODE>[first, last)</CODE>.Both return an iterator that designates the first element remainingbeyond any elements removed, or<CODE><A HREF="#hash_map::end">end</A>()</CODE> if no such element exists.</P><P>The third member function removesthe elements with sort keys in the range<CODE>[<A HREF="#hash_map::lower_bound">lower_bound</A>(keyval),<A HREF="#hash_map::upper_bound">upper_bound</A>(keyval)).</CODE>It returns the number of elements it removes.</P><P>The member functions never throw an exception.</P><H3><CODE><A NAME="hash_map::find">hash_map::find</A></CODE></H3><PRE>iterator <B>find</B>(const Key& keyval);const_iterator <B>find</B>(const Key& keyval) const;</PRE><P>The member function returns<CODE><A HREF="#hash_map::lower_bound">lower_bound</A>(keyval)</CODE>.</P><H3><CODE><A NAME="hash_map::get_allocator">hash_map::get_allocator</A></CODE></H3><PRE>Alloc <B>get_allocator</B>() const;</PRE><P>The member function returns the stored<A HREF="memory.html#allocator object">allocator object</A>.</P><H3><CODE><A NAME="hash_map::hash_map">hash_map::hash_map</A></CODE></H3><PRE><B>hash_map</B>();explicit <B>hash_map</B>(const Tr& traits);<B>hash_map</B>(const Tr& traits, const Alloc& al);<B>hash_map</B>(const hash_map& right);template<class InIt> <B>hash_map</B>(InIt first, InIt last);template<class InIt> <B>hash_map</B>(InIt first, InIt last, const Tr& traits);template<class InIt> <B>hash_map</B>(InIt first, InIt last, const Tr& traits, const Alloc& al);</PRE><P>All constructors store an<A HREF="memory.html#allocator object">allocator object</A> andinitialize the controlled sequence. The allocator object is the argument<CODE>al</CODE>, if present. For the copy constructor, it is<CODE>right.<A HREF="#hash_map::get_allocator">get_allocator</A>()</CODE>.Otherwise, it is <CODE>Alloc()</CODE>.</P><P>All constructors also store a<A HREF="#hash traits">hash traits</A> object that can laterbe returned by calling<CODE><A HREF="#hash_map::key_comp">key_comp</A>()</CODE>.The hash traits object is the argument <CODE>traits</CODE>, if present.For the copy constructor, it is<CODE>right.<A HREF="#hash_map::key_comp">key_comp</A>()</CODE>).Otherwise, it is <CODE>Tr()</CODE>.</P><P>The first three constructors specify anempty initial controlled sequence. The fourth constructor specifiesa copy of the sequence controlled by <CODE>right</CODE>.The last three constructors specify the sequence of element values<CODE>[first, last)</CODE>.</P><H3><CODE><A NAME="hash_map::insert">hash_map::insert</A></CODE></H3><PRE>pair<iterator, bool> <B>insert</B>(const value_type& val);iterator <B>insert</B>(iterator where, const value_type& val);template<class InIt> void <B>insert</B>(InIt first, InIt last);</PRE><P>The first member function determines whether an element <CODE>X</CODE>exists in the sequence whose key has<A HREF="lib_stl.html#equivalent ordering">equivalent ordering</A>to that of <CODE>val</CODE>. If not, it creates suchan element <CODE>X</CODE> and initializes it with <CODE>val</CODE>.The function then determines the iterator <CODE>where</CODE> thatdesignates <CODE>X</CODE>. If an insertion occurred, the functionreturns <CODE><A HREF="utility.html#pair">pair</A>(iter, true)</CODE>.Otherwise, it returns <CODE>pair(where, false)</CODE>.</P><P>The second member function returns <CODE>insert(val).first</CODE>,using <CODE>where</CODE> as a starting place within the controlledsequence to search for the insertion point. (Insertion canpossibly occur somewhat faster, if theinsertion point immediately precedes or follows <CODE>where</CODE>.)The third member functioninserts the sequence of element values,for each <CODE>where</CODE> in the range <CODE>[first, last)</CODE>,by calling <CODE>insert(*where)</CODE>.</P><P>If an exception is thrown during theinsertion of a single element, the container is left unalteredand the exception is rethrown.If an exception is thrown during theinsertion of multiple elements, the container is left in a stablebut unspecified state and the exception is rethrown.</P><H3><CODE><A NAME="hash_map::iterator">hash_map::iterator</A></CODE></H3><PRE>typedef T0 <B>iterator</B>;</PRE><P>The type describes an object that can serve as a bidirectionaliterator for the controlled sequence.It is described here as asynonym for the implementation-defined type <CODE>T0</CODE>.</P><H3><CODE><A NAME="hash_map::key_comp">hash_map::key_comp</A></CODE></H3><PRE>key_compare <B>key_comp</B>() const;</PRE><P>The member function returns the stored<A HREF="#hash traits">hash traits</A> object thatdetermines the order of elements in the controlled sequence.In particular, the stored object defines the member function:</P><PRE>bool operator()(const Key& left, const Key& right);</PRE><P>which returns true if <CODE>left</CODE> strictlyprecedes <CODE>right</CODE> in the sort order.</P><H3><CODE><A NAME="hash_map::key_compare">hash_map::key_compare</A></CODE></H3><PRE>typedef Tr <B>key_compare</B>;</PRE><P>The type describes a traits object that behaves much like an object of class<CODE><A HREF="#hash_compare">hash_compare</A><Key, Pr></CODE>.In particular, it can compare twosort keys to determine the relative order of twoelements in the controlled sequence.</P><H3><CODE><A NAME="hash_map::key_type">hash_map::key_type</A></CODE></H3><PRE>typedef Key <B>key_type</B>;</PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -