⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 associativecontainer.html

📁 指导程序员合理、高效的进行标准模板库编程。
💻 HTML
📖 第 1 页 / 共 2 页
字号:
</TH>
<TH>
Expression
</TH>
<TH>
Precondition
</TH>
<TH>
Semantics
</TH>
<TH>
Postcondition
</TH>
</TR>
<TR>
<TD VAlign=top>
Default constructor
</TD>
<TD VAlign=top>
<pre>
X()
X a;
</pre>
</TD>
<TD VAlign=top>
&nbsp;
</TD>
<TD VAlign=top>
Creates an empty container.
</TD>
<TD VAlign=top>
The size of the container is <tt>0</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
Erase key
</TD>
<TD VAlign=top>
<tt>a.erase(k)</tt>
</TD>
<TD VAlign=top>
&nbsp;
</TD>
<TD VAlign=top>
Destroys all elements whose key is the same as <tt>k</tt>, and removes
   them from <tt>a</tt>. <A href="#2">[2]</A>  The return value is the number of elements that
   were erased, <i>i.e.</i> the old value of <tt>a.count(k)</tt>.
</TD>
<TD VAlign=top>
<tt>a.size()</tt> is decremented by <tt>a.count(k)</tt>.
   <tt>a</tt> contains no elements with key <tt>k</tt>.  
</TD>
</TR>
<TR>
<TD VAlign=top>
Erase element
</TD>
<TD VAlign=top>
<tt>a.erase(p)</tt>
</TD>
<TD VAlign=top>
<tt>p</tt> is a dereferenceable iterator in <tt>a</tt>.
</TD>
<TD VAlign=top>
Destroys the element pointed to by <tt>p</tt>, and removes it from <tt>a</tt>.
</TD>
<TD VAlign=top>
<tt>a.size()</tt> is decremented by 1.
</TD>
</TR>
<TR>
<TD VAlign=top>
Erase range
</TD>
<TD VAlign=top>
<tt>a.erase(p, q)</tt>
</TD>
<TD VAlign=top>
<tt>[p, q)</tt> is a valid range in <tt>a</tt>.
</TD>
<TD VAlign=top>
Destroys the elements in the range <tt>[p,q)</tt> and removes them from
   <tt>a</tt>. 
</TD>
<TD VAlign=top>
<tt>a.size()</tt> is decremented by the distance from <tt>i</tt> to <tt>j</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
Clear
</TD>
<TD VAlign=top>
<tt>a.clear()</tt>
</TD>
<TD VAlign=top>
&nbsp;
</TD>
<TD VAlign=top>
Equivalent to <tt>a.erase(a.begin(), a.end())</tt>
</TD>
<TD VAlign=top>
&nbsp;
</TD>
</TR>
<TR>
<TD VAlign=top>
Find
</TD>
<TD VAlign=top>
<tt>a.find(k)</tt>
</TD>
<TD VAlign=top>
&nbsp;
</TD>
<TD VAlign=top>
Returns an iterator pointing to an element whose key is the same
   as <tt>k</tt>, or <tt>a.end()</tt> if no such element exists.
</TD>
<TD VAlign=top>
Either the return value is <tt>a.end()</tt>, or else the return value has
   a key that is the same as <tt>k</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
Count
</TD>
<TD VAlign=top>
<tt>a.count(k)</tt>
</TD>
<TD VAlign=top>
&nbsp;
</TD>
<TD VAlign=top>
Returns the number of elements in <tt>a</tt> whose keys are the same as <tt>k</tt>.
</TD>
<TD VAlign=top>
&nbsp;
</TD>
</TR>
<TR>
<TD VAlign=top>
Equal range
</TD>
<TD VAlign=top>
<tt>a.equal_range(k)</tt>
</TD>
<TD VAlign=top>
&nbsp;
</TD>
<TD VAlign=top>
Returns a pair <tt>P</tt> such that <tt>[P.first, P.second)</tt> is a range
   containing all elements in <tt>a</tt> whose keys are the same as <tt>k</tt>. <A href="#3">[3]</A>
   If no elements have the same key as <tt>k</tt>, the return value is an empty
   range.
</TD>
<TD VAlign=top>
The distance between <tt>P.first</tt> and <tt>P.second</tt> is equal to
   <tt>a.count(k)</tt>.  If <tt>p</tt> is a dereferenceable iterator in <tt>a</tt>, then
   either <tt>p</tt> lies in the range <tt>[P.first, P.second)</tt>, or else
   <tt>*p</tt> has a key that is not the same as <tt>k</tt>.
</TD>
</tr>
</table>
<h3>Complexity guarantees</h3>
Average complexity for erase key is at most <tt>O(log(size()) + count(k))</tt>.
<P>
Average complexity for erase element is constant time.
<P>
Average complexity for erase range is at most 
   <tt>O(log(size()) + N)</tt>, where <tt>N</tt> is the number of elements in the range.
<P>
Average complexity for count is at most <tt>O(log(size()) + count(k))</tt>.
<P>
Average complexity for find is at most logarithmic.
<P>
Average complexity for equal range is at most logarithmic.
<h3>Invariants</h3>
<Table border>
<TR>
<TD VAlign=top>
Contiguous storage
</TD>
<TD VAlign=top>
All elements with the same key are adjacent to each other.  That
   is, if <tt>p</tt> and <tt>q</tt> are iterators that point to elements that have
   the same key, and if <tt>p</tt> precedes <tt>q</tt>, then every element in the
   range <tt>[p, q)</tt> has the same key as every other element.
</TD>
</TR>
<TR>
<TD VAlign=top>
Immutability of keys
</TD>
<TD VAlign=top>
Every element of an Associative Container has an immutable key.
   Objects may be inserted and erased, but an element in an 
   Associative Container may not be modified in such a way as to change
   its key.
</TD>
</tr>
</table>
<h3>Models</h3>
<UL>
<LI>
<tt><A href="set.html">set</A></tt>
<LI>
<tt><A href="multiset.html">multiset</A></tt>
<LI>
<tt><A href="hash_set.html">hash_set</A></tt>
<LI>
<tt><A href="hash_multiset.html">hash_multiset</A></tt>
<LI>
<tt><A href="Map.html">map</A></tt>
<LI>
<tt><A href="Multimap.html">multimap</A></tt>
<LI>
<tt><A href="hash_map.html">hash_map</A></tt>
<LI>
<tt><A href="hash_multimap.html">hash_multimap</A></tt>
</UL>
<h3>Notes</h3>
<P><A name="1">[1]</A>
The reason there is no such mechanism is that the way in which
elements are arranged in an associative container is typically a class
invariant; elements in a <A href="SortedAssociativeContainer.html">Sorted Associative Container</A>, for
example, are always stored in ascending order, and elements in a 
<A href="HashedAssociativeContainer.html">Hashed Associative Container</A> are always stored according to the
hash function.  It would make no sense to allow the position of an
element to be chosen arbitrarily.
<P><A name="2">[2]</A>
Keys are not required to be <A href="EqualityComparable.html">Equality Comparable</A>: associative
containers do not necessarily use <tt>operator==</tt> to determine whether two
keys are the same.  In <A href="SortedAssociativeContainer.html">Sorted Associative Containers</A>, for example,
where keys are ordered by a comparison function, two keys are considered
to be the same if neither one is less than the other.
<P><A name="3">[3]</A>
Note the implications of this member function: it means that if
two elements have the same key, there must be no elements with
different keys in between them.  The requirement that elements with
the same key be stored contiguously is an associative container
invariant.
<h3>See also</h3>
<A href="SimpleAssociativeContainer.html">Simple Associative Container</A>, <A href="PairAssociativeContainer.html" tppabs="http://www.sgi.com/Technology/STL/PairAssociativeContainer.shtml">Pair Associative Container</A>,
<A href="UniqueAssociativeContainer.html">Unique Associative Container</A>, <A href="MultipleAssociativeContainer.html" tppabs="http://www.sgi.com/Technology/STL/MultipleAssociativeContainer.shtml">Multiple Associative Container</A>,
<A href="SortedAssociativeContainer.html">Sorted Associative Container</A>, 
<A href="UniqueSortedAssociativeContainer.html">Unique Sorted Associative Container</A>, 
<A href="MultipleSortedAssociativeContainer.html">Multiple Sorted Associative Container</A>,
<A href="HashedAssociativeContainer.html">Hashed Associative Container</A>,
<A href="UniqueHashedAssociativeContainer.html">Unique Hashed Associative Container</A>, 
<A href="MultipleHashedAssociativeContainer.html">Multiple Hashed Associative Container</A>.

<HR SIZE="6"> <FONT SIZE="-2"> Copyright &copy; 1996 Silicon Graphics, Inc.
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="index.html" >
STL</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; Copyright 1997-1998 CodeGuru</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact : <A HREF="mailto:webmaster@codeguru.com">webmaster@codeguru.com</A>&nbsp;</FONT></DIV>
</TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript" ><!--
var adurl = "/cgi-bin/doubleclick.cgi?";

if( self.adcategory )
	adurl += adcategory;
else
	adurl += "mfc";

if( self.parent.norefreshad )
	parent.norefreshad = false;
else if( validframes )
	parent.frames['ad'].location = adurl;



if( !validframes && nfrm == -1)
{
	var dclkPage = "www.codeguru.com/";
	if( self.adcategory )
		dclkPage += adcategory;
	else 
		dclkPage += "mfc";
//	var random = Math.random();
	document.write('<nolayer><center>');
	document.write('<iframe src="http://ad.doubleclick.net/adi/' + dclkPage + ';ord='
	 + random + '" width=470 height=62 marginwidth=0 marginheight=0 hspace=0 vspace=0 '
	 + 'frameborder=0 scrolling=no bordercolor="#000000">');
	document.write('<a href="http://ad.doubleclick.net/jump/' + dclkPage + ';ord='
	 + random + '">');
	document.write('<img src="http://ad.doubleclick.net/ad/' + dclkPage + ';ord='
	 + random + '" height=60 width=468>' + '</a>');
	document.write('</iframe>');
	document.write('</center></nolayer>');
	document.write('<layer  src="http://ad.doubleclick.net/adl/' + dclkPage + 
	 ';ord=' + random + '"></layer>');
	document.write('<ilayer visibility=hide width=468 height=83></ilayer>');
}

// -->
</SCRIPT> 
<!-- SCRIPT LANGUAGE="JavaScript" SRC="/global/fscript.js">
//
</SCRIPT --> 

<noscript>
<p align="center">
<a href="http://ad.doubleclick.net/jump/www.codeguru.com/cpp;ord=NupaF9FCY34AAHX54JI">
<img src="http://ad.doubleclick.net/ad/www.codeguru.com/cpp;ord=NupaF9FCY34AAHX54JI"></a>
</p>
</noscript>





</BODY>
</HTML>


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -