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

📄 swarm.collections.index.protocol.html

📁 set for Swarm2.1是圣菲研究院的开发人员对Swarm的特性及其使用描述的最为完备的指南性文档。从这里可以获得最细致的平台说明。
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>Index</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.53"><LINKREL="HOME"TITLE="Documentation Set for Swarm 2.1.1"HREF="set.html"><LINKREL="UP"TITLE="Collections Library"HREF="swarm.collections.sgml.reference.html"><LINKREL="PREVIOUS"TITLE="ForEachKey"HREF="swarm.collections.foreachkey.protocol.html"><LINKREL="NEXT"TITLE="InputStream"HREF="swarm.collections.inputstream.protocol.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Documentation Set for Swarm 2.1.1</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="swarm.collections.foreachkey.protocol.html">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Reference II. Collections Library</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="swarm.collections.inputstream.protocol.html">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="SWARM.COLLECTIONS.INDEX.PROTOCOL">Index</A></H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN6792"></A><H2>Name</H2>Index&nbsp;--&nbsp; Reference into the enumeration sequence for a collection.</DIV><DIVCLASS="REFSECT1"><ANAME="AEN6795"></A><H2>Description</H2><P> An index is a reference into an enumeration sequence of a collection. Such an enumeration sequence contains all members of the collection in some order.  This order will always be consistent with ordering of members in the collection, assuming there is such an ordering. Otherwise, the sequence will still contain all members in some order that remains fixed provided that new members are not added or removed from the collection.</P><P> An index is created by a begin: or createIndex: message against a collection.  Each major collection type has its own corresponding index type, which supports specialized types of processing against the valid contents of that kind of collection.  Once created, an index is a separate object from the collection itself, but it remains valid only so long as the collection itself still exists.  Multiple indexes may exist at the same time against the same collection, and each index maintains its own position within an enumeration sequence for the collection.</P><P> Many indexes provde the ability modify the collection they refer to, in addition to simply traversing members.  An index often provides the complete means for maintaining the contents of a collection, more than could otherwise be performed on the collection itself.  The position or other status of the index is automatically updated to reflect any changes made through the index itself.</P><P> If changes to a collection are made while other indexes exist, those other indexes could be affected in potentially catastrophic ways. Each collection type documents which kinds of changes can be made without affecting or invalidating existing indexes.  The IndexSafety option of Collection provides additional ways to protect indexes against possible effects of independent updates.</P><P> Each index is a stand-alone object allocated within a zone passed as an argument in the message that created it.  This zone need not match the zone of a collection.  It is common for index lifetimes to be shorter than their collection.  For example, indexes can be created in a temporary scratch zone for use only within a local loop.</P><P> Because messages to a collection are the only valid way to create an index, create messages and create-time options are not used with index types.  All valid processing on an index is determined by characteristics of the collection from which it is created.  Index types are typically named after the type of collection they are created from, and serve principally to define the specific messages valid for an index on that type of collection.</P><P> Index objects support the universal messages of the top-level DefinedObject supertype, along with the standard drop: and getZone messages.  Even though they cannot be created except from a collection, new index objects can be created from an existing index using the standard copy: message.  Each copy refers to the same collection as the initial index, and starts at the same position in its enumeration sequence.  In all other respects, however, the new copy is an independent index that maintains its own position under any further processing.</P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN6804"></A><H2>Protocols adopted by Index</H2><P> <AHREF="swarm.defobj.definedobject.protocol.html">DefinedObject</A> <AHREF="swarm.defobj.drop.protocol.html">Drop</A> <AHREF="swarm.defobj.returnable.protocol.html">RETURNABLE</A></P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN6810"></A><H2>Methods</H2><DIVCLASS="REFSECT2"><ANAME="AEN6812"></A><H3>Phase: Using</H3><P></P><UL><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.COLLECTIONS.INDEX.METHOD.PU.M336"></A><P></P>- <BCLASS="FUNCPROTOTYPE">getCollection</B><BR> getCollection returns the collection referred to by an index.  This collection never changes during the lifetime of the index.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.COLLECTIONS.INDEX.METHOD.PU.M584"></A><P></P>- <BCLASS="FUNCPROTOTYPE">next</B><BR> The next message positions the index to the next valid member after its current position, or to a special position after the end of all valid members.  In addition to repositioning the index, both messages return the new member value to which they are positioned, or nil if there is no such member.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.COLLECTIONS.INDEX.METHOD.PU.M604"></A><P></P>- <BCLASS="FUNCPROTOTYPE">prev</B><BR> The prev message works similarly, but positions to a valid member preceding the current position, or to a special position preceding all valid members. <P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.COLLECTIONS.INDEX.METHOD.PU.M280"></A><P></P>- <BCLASS="FUNCPROTOTYPE">findNext:</B> <VARCLASS="PDPARAM">anObject</VAR> <BR> findNext: repeatedly performs next until the member value of the index matches the argument.  nil is returned if the index reaches the end of valid members without matching the argument.  <P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.COLLECTIONS.INDEX.METHOD.PU.M281"></A><P></P>- <BCLASS="FUNCPROTOTYPE">findPrev:</B> <VARCLASS="PDPARAM">anObject</VAR> <BR> findPrev: repeatedly performs prev until the member value of the index matches the argument.  nil is returned if the index reaches the end of valid members without matching the argument. <P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.COLLECTIONS.INDEX.METHOD.PU.M294"></A><P></P>- <BCLASS="FUNCPROTOTYPE">get</B><BR> get returns the member value at which the index is currently positioned, or nil if the index is not positioned at a member.<BR> The get message provides an alternate way to obtain the current member value in a loop that traverses a collection; its return value is the same as next or prev would return when first positioning to a new member.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.COLLECTIONS.INDEX.METHOD.PU.M613"></A><P></P>- <BCLASS="FUNCPROTOTYPE">put:</B> <VARCLASS="PDPARAM">anObject</VAR> <BR> The put: message replaces the member value at the current index position with its argument.  An InvalidIndexLoc error is raised if the index is not positioned at a current member.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.COLLECTIONS.INDEX.METHOD.PU.M635"></A><P></P>- <BCLASS="FUNCPROTOTYPE">remove</B><BR> The remove message removes the member at the current location of an index, and returns the member value removed.  The index position is set to a special position between the members which previously preceded and followed the removed member.  If there is no preceding or following member, the index is set to the special location before the start or after the end of all members.  After a current member is removed, there is no member at the current index location, but a subsequent next or prev message will continue with the same member that would have been accessed had the current member not been removed. An InvalidIndexLoc error is raised if the index is not positioned at a current member.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.COLLECTIONS.INDEX.METHOD.PU.M413"></A><P></P>- (id &lt;Symbol&gt;)<BCLASS="FUNCPROTOTYPE">getLoc</B><BR> The getLoc message returns a symbol constant which indicates the type of location at which an index is currently positioned.  This index location symbol has one of the following values: Start, End, <BR> and Member.<BR> The Start symbol indicates the special position preceding all members in the enumeration sequence for the collection.  This is the location at which an index is positioned when it is first created.  The End symbol indicates the special position following all members in the collection.  This is the location at which an index is positioned just after a next message has returned nil, as a result of moving beyond the last member.   The Member symbol indicates that the index is positioned at some current member in the enumeration sequence of a collection.<BR> The getLoc message is needed to traverse a collection which could contain nil values for its members.  Without getLoc, there would be no way to distinguish a nil value returned by next as either a valid member value or the special value returned at the end of members. With getLoc, a loop that traverses a collection can test specifically for the end (or start) of members.<P></P></DIV><DIVCLASS="EXAMPLE"><ANAME="SWARM.COLLECTIONS.INDEX.-GETLOC.1.EXAMPLE"></A><P><B>Example collections/Index/-getLoc/1. </B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> Following is a simple loop which illustrates such usage:</PRE></TD></TR></TABLE><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> {   id &#60;Index&#62; index = [aCollection begin: aZone];   id member;   for (member = [index next]; [index getLoc] == Member; member = [index next])     {      // do something with member ...     }   [index drop]; }</PRE></TD></TR></TABLE></DIV></LI><LI><DIV

⌨️ 快捷键说明

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