📄 vector.html
字号:
<HTML><!-- -- Copyright (c) 1998,1999 -- University of Notre Dame -- -- Permission to use, copy, modify, distribute and sell this software -- and its documentation for any purpose is hereby granted without fee, -- provided that the above copyright notice appears in all copies and -- that both that copyright notice and this permission notice appear -- in supporting documentation. The University of Notre Dame makes no -- representations about the suitability of this software for any -- purpose. It is provided "as is" without express or implied warranty. -- --><HEAD><TITLE>Description of Vector</TITLE></HEAD><BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" ALINK="#ff0000"> <FONT FACE=Helvetica><!--end header--><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=100%><TR><TD><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><TR><TD Align=left valign=middle width=440 rowspan=2><FONT FACE=verdana,arial,helvetica SIZE=+3 COLOR=#110088><B>Vector</B></FONT></TD><TD valign=middle Align=right width=128 rowspan=2><A HREF="http://lsc.nd.edu/research/mtl"><IMG BORDER=0 SRC="./glossy-mtl-logo.jpg" height=48 ALT="[MTL Home]"></A></TD><TD Align=center width=280 nowrap><Font face=verdana,arial,helvetica size=+3><b>Programmers Guide</b></font></TD></TR><TR BGCOLOR='#2020b0'><TD HEIGHT=20 VALIGN='MIDDLE' NOWRAP align=center STYLE="font-family:verdana,arial,helvetica;font-weight:bold;"> <A STYLE="text-decoration:none;color:white;font-family:verdana,arial,helvetica;font-weight:bold;" HREF="./table_of_contents.html">Contents</A> | <A STYLE="text-decoration:none;color:white;font-family:verdana,arial,helvetica;font-weight:bold;" HREF="./mtl_index.html">Index</A> | <A STYLE="text-decoration:none;color:white;font-family:verdana,arial,helvetica;font-weight:bold;" HREF="http://lsc.nd.edu/research/mtl/search.html">Search</A> </TD></TR></TABLE></TD></TR><TR><TD><Table Border=0 CellPadding=0 CellSpacing=0 width=100% cols=2><TR><TD Align=left><BR><TABLE BORDER=0 CellSpacing=0 CellPadding=0><TR><TD><Img src = "containers.gif" Alt="" WIDTH = "194" HEIGHT = "38" ></TD></TR></TABLE></TD><TD Align=right><BR><TABLE BORDER=0 CellSpacing=0 CellPadding=0><TR><TD><Img src = "concept.gif" Alt="" WIDTH = "194" HEIGHT = "38" ></TD></TR></TABLE></TD></TR><TR><TD Align=left VAlign=top><b>Category</b>:containers</TD><TD Align=right VAlign=top><b>Component type</b>:concept</TD></TR></Table></TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="10" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>Description</B></FONT></TD></TR><TR><TD> Not to be confused with the std::vector class. The MTL <A HREF="Vector.html" >Vector</A> concept is a Container in which every element has a corresponding index. The elements do not have to be sorted by their index, and the indices do not necessarily have to start at 0. Also the indices do not have to form a contiguous range. The iterator type must be a model of <A HREF="IndexedIterator.html" >IndexedIterator</A>. <A HREF="Vector.html" >Vector</A> is not a refinement of RandomAccessContainer (even though <A HREF="Vector.html" >Vector</A> defines <tt>operator[]</tt>) because <A HREF="Vector.html" >Vector</A> does not guarantee amortized constant time for that operation (to allow fo sparse vectors). Note also that the invariant <TT>a[n] == advance(A.begin(), n)</tt> that applies to RandomAccessContainer does not apply to <A HREF="Vector.html" >Vector</A>, since the <tt>a[i]</tt> is defined for <A HREF="Vector.html" >Vector</A> to return the element with the ith index. So <tt>a[n] == *i</tt> if and only if <tt>i.index() == n</tt>. The indices of the elements in the subrange remain the same. For example, here is a vector written in terms of index-value pairs: x = [ (0,2), (1,5), (2,3), (3,1), (4,9) ] The subrange [1,3) of x can be obtained with y = x(1,3) which results in y = [ (1,5), (2,3) ] The subrange vector is a reference to a particular portion of the original vector. If you wish to have the subrange vector's starting index to be zero just do the following: y = x(1,3).adjust_index(-1); The adjust_index(delta) function does not affect the indexing of the original vector.</TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="10" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>Refinement of</B></FONT></TD></TR><TR><TD></TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="10" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>Associated types</B></FONT></TD></TR><TR><TD><TABLE BORDER><TR><TH>Concept</TH><TH>Type name</TH><TH>Description</TH></TR> <TR><TD VALIGN="TOP"> <TT><A HREF="IndexedIterator.html" >IndexedIterator</A> </TT> </TD> <TD VALIGN="TOP"> <TT>X::iterator</TT> </TD> <TD><FONT FACE=Times SIZE=3> </FONT></TD> </TR> <TR><TD VALIGN="TOP"> <TT>const <A HREF="IndexedIterator.html" >IndexedIterator</A> </TT> </TD> <TD VALIGN="TOP"> <TT>X::const_iterator</TT> </TD> <TD><FONT FACE=Times SIZE=3> </FONT></TD> </TR> <TR><TD VALIGN="TOP"> <TT>Tag </TT> </TD> <TD VALIGN="TOP"> <TT>X::dimension</TT> </TD> <TD><FONT FACE=Times SIZE=3> Marks this as 1-D </FONT></TD> </TR> <TR><TD VALIGN="TOP"> <TT>Tag </TT> </TD> <TD VALIGN="TOP"> <TT>X::sparsity</TT> </TD> <TD><FONT FACE=Times SIZE=3> <tt><A HREF="dense_tag.html" >dense_tag</A></tt> or <tt><A HREF="sparse_tag.html" >sparse_tag</A></tt> </FONT></TD> </TR> <TR><TD VALIGN="TOP"> <TT>const <A HREF="Vector.html" >Vector</A> </TT> </TD> <TD VALIGN="TOP"> <TT>X::scaled_type</TT> </TD> <TD><FONT FACE=Times SIZE=3> The vector scaled be a constant </FONT></TD> </TR> <TR><TD VALIGN="TOP"> <TT>size_type </TT> </TD> <TD VALIGN="TOP"> <TT>X::N</TT> </TD> <TD><FONT FACE=Times SIZE=3> the static size, 0 if dynamic </FONT></TD> </TR> <TR><TD VALIGN="TOP"> <TT>const Container </TT> </TD> <TD VALIGN="TOP"> <TT>X::IndexArray</TT> </TD> <TD><FONT FACE=Times SIZE=3> An <A HREF="array.html" >array</A> containing the indices of the elements in the vector. </FONT></TD> </TR> <TR><TD VALIGN="TOP"> <TT><A HREF="Vector.html" >Vector</A> </TT> </TD> <TD VALIGN="TOP"> <TT>X::subrange_type</TT> </TD> <TD><FONT FACE=Times SIZE=3> The sub-vector type </FONT></TD> </TR> <TR><TD VALIGN="TOP"> <TT>const <A HREF="Vector.html" >Vector</A> </TT> </TD> <TD VALIGN="TOP"> <TT>X::const_subrange_type</TT> </TD> <TD><FONT FACE=Times SIZE=3> The const sub-vector type </FONT></TD> </TR> </TABLE></TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="10" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>Notations</B></FONT></TD></TR><TR><TD><BR><TABLE BORDER><TR><TD><TT>X</TT></TD><TD>The type of a model of <A HREF="Vector.html" >Vector</A></TD></TR><TR><TD><TT>a</TT></TD><TD>An object of type X</TD></TR><TR><TD><TT>splits</TT></TD><TD>A container of integral objects</TD></TR></TABLE></TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="10" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>Definitions</B></FONT></TD></TR><TR><TD><UL></UL></TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="10" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>Expression semantics</B></FONT></TD></TR><TR><TD><TABLE BORDER><TR><TH>Description</TH><TH>Expression</TH><TH>Semantics</TH></TR> <TR> <TD><FONT FACE=Times SIZE=3> Element access </FONT></TD> <TD VALIGN="TOP"> <TT> a[n]</TT> </TD> <TD VALIGN="TOP"> <TT> </TT> </TD> </TR> <TR> <TD><FONT FACE=Times SIZE=3> Const element access </FONT></TD> <TD VALIGN="TOP"> <TT> a[n]</TT> </TD> <TD VALIGN="TOP"> <TT> </TT> </TD> </TR> <TR> <TD><FONT FACE=Times SIZE=3> Subrange access </FONT></TD> <TD VALIGN="TOP"> <TT> a(s,f)</TT> </TD> <TD VALIGN="TOP"> <TT> </TT> </TD> </TR> <TR> <TD><FONT FACE=Times SIZE=3> Subrange access </FONT></TD> <TD VALIGN="TOP"> <TT> a[r]</TT> </TD> <TD VALIGN="TOP"> <TT> </TT> </TD> </TR> <TR> <TD><FONT FACE=Times SIZE=3> Number of non-zero elements (actually the number of stored elements) </FONT></TD> <TD VALIGN="TOP"> <TT> a.nnz()</TT> </TD> <TD VALIGN="TOP"> <TT> </TT> </TD> </TR> <TR> <TD><FONT FACE=Times SIZE=3> Adjust the indices of the elements by delta </FONT></TD> <TD VALIGN="TOP"> <TT> x.adjust_index(delta);</TT> </TD> <TD VALIGN="TOP"> <TT> </TT> </TD> </TR> </TABLE></TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="10" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>Function specification</B></FONT></TD></TR><TR><TD><TABLE BORDER><TR><TH>Name</TH><TH>Function</TH><TH>Complexity</TH></TR> <TR> <TD><FONT FACE=Times SIZE=3> Element access </FONT></TD> <TD VALIGN="TOP"> <TT>reference operator[](size_type n)</TT> </TD> <TD><FONT FACE=Times SIZE=3> linear time </FONT></TD> </TR> <TR> <TD><FONT FACE=Times SIZE=3> Const element access </FONT></TD> <TD VALIGN="TOP"> <TT>const_reference operator[](size_type n)</TT> </TD> <TD><FONT FACE=Times SIZE=3> linear time </FONT></TD> </TR> <TR> <TD><FONT FACE=Times SIZE=3> Subrange access </FONT></TD> <TD VALIGN="TOP"> <TT>subrange operator()(size_type start, size_type finish)</TT> </TD> <TD><FONT FACE=Times SIZE=3> linear time </FONT></TD> </TR> <TR> <TD><FONT FACE=Times SIZE=3> Subrange access </FONT></TD> <TD VALIGN="TOP"> <TT>subrange operator()(range_type r)</TT> </TD> <TD><FONT FACE=Times SIZE=3> linear time </FONT></TD> </TR> <TR> <TD><FONT FACE=Times SIZE=3> Number of non-zero elements (actually the number of stored elements) </FONT></TD> <TD VALIGN="TOP"> <TT>size_type nnz()</TT> </TD> <TD><FONT FACE=Times SIZE=3> constant time </FONT></TD> </TR> <TR> <TD><FONT FACE=Times SIZE=3> Adjust the indices of the elements by delta </FONT></TD> <TD VALIGN="TOP"> <TT>self adjust_index(size_type delta)</TT> </TD> <TD><FONT FACE=Times SIZE=3> constant time </FONT></TD> </TR> </TABLE></TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="10" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>Invariants</B></FONT></TD></TR><TR><TD> a.nnz() <= a.size()</TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="10" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>Models</B></FONT></TD></TR><TR><TD><UL><LI> dense1D<LI> <A HREF="sparse1D.html" >sparse1D</A><LI> <A HREF="compressed1D.html" >compressed1D</A><LI> <A HREF="scaled1D.html" >scaled1D</A><LI> <A HREF="strided1D.html" >strided1D</A></UL></TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="15" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>Notes</B></FONT></TD></TR><TR><TD></TD></TR><TR><TD><IMG SRC="whitespace.gif" Alt="" WIDTH="32" HEIGHT="15" ALIGN="TOP"></TD></TR><TR BGCOLOR=#e0e0e0><TD VALIGN=BOTTOM><FONT FACE=arial,helvetica SIZE=+1><B>See also</B></FONT></TD></TR><TR><TD></TD></TR></TABLE><!--start footer--> <P><CENTER><CENTER><IMG SRC="./blue-bar.jpg" width=640></CENTER></CENTER><P><A HREF="http://www.nd.edu"><IMG BORDER=0 SRC="./ndtoclogo.gif" ALT="[MTL Home]" ALIGN=absmiddle></A></A><FONT SIZE="-2"><A HREF="../LICENSE.htm">Copyright ©1998,1999 University of Notre Dame. All Rights Reserved.</FONT></FONT></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -