Ignore:
Timestamp:
Apr 24, 2025, 6:35:41 PM (5 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
6b33e89, f85de47
Parents:
f632bd50
Message:

proofreading intro and background chapters, capitalize section titles, update backtick calls to regular calls

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/mike_brooks_MMath/list.tex

    rf632bd50 rb195498  
    1515
    1616The doubly-linked list attaches links intrusively, supports multiple link directions, integrates with user code via the type system, treats its ends uniformly, and identifies a list using an explicit head.
    17 This design covers system and data management issues stated in Section~\ref{toc:lst:issue}.
    18 
    19 Figure~\ref{fig:lst-features-intro} continues the running @req@ example from Figure~\ref{fig:lst-issues-attach} using the \CFA list.
    20 The \CFA link attachment is intrusive so the resulting memory layout is per user node, as for the LQ version of Figure~\ref{f:Intrusive}.
     17This design covers system and data management issues stated in \VRef{toc:lst:issue}.
     18
     19\VRef[Figure]{fig:lst-features-intro} continues the running @req@ example from \VRef[Figure]{fig:lst-issues-attach} using the \CFA list.
     20The \CFA link attachment is intrusive so the resulting memory layout is per user node, as for the LQ version of \VRef[Figure]{f:Intrusive}.
    2121The \CFA framework provides generic type @dlink( T, T )@ for the two link fields (front and back).
    2222A user inserts the links into the @req@ structure via \CFA inline-inheritance from the Plan-9 C dialect~\cite[\S~3.3]{Thompson90new}.
     
    3434    \caption[Multiple link directions in \CFA list library]{
    3535        Demonstration of the running \lstinline{req} example, done using the \CFA list library.
    36         This example is equivalent to the three approaches in Figure~\ref{fig:lst-issues-attach}.
     36        This example is equivalent to the three approaches in \VRef[Figure]{fig:lst-issues-attach}.
    3737    }
    3838    \label{fig:lst-features-intro}
    3939\end{figure}
    4040
    41 Figure~\ref{fig:lst-features-multidir} shows how the \CFA library supports multi-inline links, so a node can be on one or more lists simultaneously.
     41\VRef[Figure]{fig:lst-features-multidir} shows how the \CFA library supports multi-inline links, so a node can be on one or more lists simultaneously.
    4242The declaration of @req@ has two inline-inheriting @dlink@ occurrences.
    4343The first of these gives a type named @req.by_pri@, @req@ inherits from it, and it inherits from @dlink@.
     
    4848The type of the variable @reqs_pri_global@ is @dlist(req, req.by_pri)@, meaning operations called on @reqs_pri_global@ are implicitly disambiguated.
    4949In the example, the calls @insert_first(reqs_pri_global, ...)@ imply, ``here, we are working by priority.''
    50 As in Figure~\ref{fig:lst-issues-multi-static}, three lists are constructed, a priority list containing all nodes, a list with only nodes containing the value 42, and a list with only nodes containing the value 17.
     50As in \VRef[Figure]{fig:lst-issues-multi-static}, three lists are constructed, a priority list containing all nodes, a list with only nodes containing the value 42, and a list with only nodes containing the value 17.
    5151
    5252\begin{figure}
     
    6363\caption{
    6464        Demonstration of multiple static link directions done in the \CFA list library.
    65         The right example is from Figure~\ref{fig:lst-issues-multi-static}.
     65        The right example is from \VRef[Figure]{fig:lst-issues-multi-static}.
    6666                The left \CFA example does the same job.
    6767    }
     
    7070
    7171The \CFA library also supports the common case, of single directionality, more naturally than LQ. 
    72 Figure~\ref{fig:lst-features-intro} shows a single-direction list done with no contrived name for the link direction,
    73 where Figure~\ref{f:Intrusive} adds the unnecessary field name, @d@.
    74 In \CFA, a user doing a single direction (Figure~\ref{fig:lst-features-intro}) sets up a simple inheritance with @dlink@, and declares a list head to have the simpler type @dlist( T )@.
    75 In contrast, (Figure~\ref{fig:lst-features-multidir}) sets up a diamond inheritance with @dlink@, and declares a list head to have the more-informed type @dlist( T, DIR )@.
     72\VRef[Figure]{fig:lst-features-intro} shows a single-direction list done with no contrived name for the link direction,
     73where \VRef[Figure]{f:Intrusive} adds the unnecessary field name, @d@.
     74In \CFA, a user doing a single direction (\VRef[Figure]{fig:lst-features-intro}) sets up a simple inheritance with @dlink@, and declares a list head to have the simpler type @dlist( T )@.
     75In contrast, (\VRef[Figure]{fig:lst-features-multidir}) sets up a diamond inheritance with @dlink@, and declares a list head to have the more-informed type @dlist( T, DIR )@.
    7676
    7777The directionality issue also has an advanced corner-case that needs treatment.
     
    118118By using a larger scope, a user can put code within that acts as if there is only one list direction.
    119119This boost is needed only when operating on a list with several directions, using operations that do not take the list head.
    120 Otherwise, the sole applicable list direction ``just works.''
     120Otherwise, the sole applicable list direction \emph{just works}.
    121121
    122122Unlike \CC templates container-types, the \CFA library works completely within the type system;
     
    138138@isEmpty@ returns true if the list has no nodes and false otherwise.
    139139\item
    140 @first@ returns a pointer to the first node of the list without removing it or @0p@ if the list is empty.
    141 \item
    142 @last@ returns a pointer to the last node of the list without removing it or @0p@ if the list is empty.
    143 \item
    144 @next@ returns a pointer to the next (successor, towards last) node after the specified node or @0p@ if the specified node is the last node in the list.
    145 \item
    146 @pred@ returns a pointer to the previous (predecessor, towards first) node before the specified node or @0p@ if the specified node is the first node in the list.
     140@first@ returns a reference to the first node of the list without removing it or @0p@ if the list is empty.
     141\item
     142@last@ returns a reference to the last node of the list without removing it or @0p@ if the list is empty.
    147143\item
    148144@insert_before@ adds a node before the specified node and returns the added node for cascading.
     
    150146@insert_after@ adds a node after the specified node and returns the added node for cascading.
    151147\item
    152 @remove@ removes the specified node from the list (any location) and returns a pointer to the node.
    153 \item
    154 @insert_first@ adds a node to the start of the list so it becomes the first node and returns a pointer to the node for cascading.
    155 \item
    156 @insert_last@ adds a node to the end of the list so it becomes the last node and returns returns a pointer to the node for cascading.
    157 \item
    158 @insert@ is a synonym for @insert_last@.
    159 \item
    160 @remove_first@ removes the first node and returns a pointer to it or @0p@ if the list is empty.
    161 \item
    162 @remove_last@ removes the last node and returns a pointer to it or @0p@ if the list is emptyy.
     148@remove@ removes the specified node from the list (any location) and returns a reference to the node.
     149\item
     150@iter@ create an iterator for the list.
     151\item
     152@recede@ returns true if the iterator cursor is advanced to the previous (predecessor, towards first) node before the prior cursor node and false otherwise.
     153\item
     154@advance@ returns true if the iterator cursor is advanced to the next (successor, towards last) node after the prior cursor node and false otherwise.
     155\item
     156@isFirst@ returns true if the node is the first node in the list and false otherwise.
     157\item
     158@isLast@ returns true if the node is the last node in the list and false otherwise.
     159\item
     160@pred@ returns a reference to the previous (predecessor, towards first) node before the specified node or @0p@ if the specified node is the first node in the list.
     161\item
     162@next@ returns a reference to the next (successor, towards last) node after the specified node or @0p@ if the specified node is the last node in the list.
     163\item
     164@insert_first@ adds a node to the start of the list so it becomes the first node and returns a reference to the node for cascading.
     165\item
     166@insert_last@ adds a node to the end of the list so it becomes the last node and returns returns a reference to the node for cascading.
     167\item
     168@remove_first@ removes the first node and returns a reference to it or @0p@ if the list is empty.
     169\item
     170@remove_last@ removes the last node and returns a reference to it or @0p@ if the list is empty.
    163171\item
    164172@transfer@ transfers all nodes from the @from@ list to the end of the @to@ list; the @from@ list is empty after the transfer.
     
    170178\begin{figure}
    171179\begin{cfa}
    172 E & ?`isEmpty( dlist( E ) & list );
    173 E & ?`isListed( E & node );
    174 E & ?`first( dlist( E ) & list );
    175 E & ?`last( dlist( E ) & list );
    176 E & ?`next( E & node );
    177 E & ?`prev( E & node );
     180E & isListed( E & node );
     181E & isEmpty( dlist( E ) & list );
     182E & first( dlist( E ) & list );
     183E & last( dlist( E ) & list );
    178184E & insert_before( E & before, E & node );
    179185E & insert_after( E & after, E & node );
    180186E & remove( E & node );
    181 E & ?`elems( dlist( E ) & list );
    182 E & ?`head( dlist( E ) & list );
    183 bool ?`moveNext( E && refx );
    184 bool ?`next( E && refx );                                                       // alternate name
    185 bool ?`movePrev( E && refx );
    186 bool ?`prev( E && refx );                                                       // alternate name
    187 bool ?`hasNext( E & node );
    188 bool ?`hasPrev( E & node );
     187E & iter( dlist( E ) & list );
     188bool advance( E && refx );
     189bool recede( E && refx );
     190bool isFirst( E & node );
     191bool isLast( E & node );
     192E & prev( E & node );
     193E & next( E & node );
    189194E & insert_first( dlist( E ) & list, E & node );
    190195E & insert_last( dlist( E ) & list, E & node );
    191 E & insert( dlist( E ) & list, E & node );              // alternate name
    192196E & remove_first( dlist( E ) & list );
    193197E & remove_last( dlist( E ) & list );
    194198void transfer( dlist( E ) & to, dlist( E ) & from ) {
    195199void split( dlist( E ) & to, dlist( E ) & from, E & node ) {
    196 E & try_pop_front( dlist( E ) & list );
    197 E & try_pop_back( dlist( E ) & list );
    198200\end{cfa}
    199201\caption{\CFA List API}
     
    205207
    206208It is possible to iterate through a list manually or using a set of standard macros.
    207 \VRef[Figure]{f:IteratorExample} shows the iterator template, managing a list of nodes, used throughout the following iterator examples.
     209\VRef[Figure]{f:IteratorTemple} shows the iterator template, managing a list of nodes, used throughout the following iterator examples.
    208210Each example assumes its loop body prints the value in the current node.
    209211
     
    222224        insert( list, n1 );   insert( list, n2 );   insert( list, n3 );   insert( list, n4 );
    223225        sout | nlOff;
    224         for ( node & it = list`first; &it; &it = &it`next ) @sout | it.v | ",";   sout | nl;@
    225         // other iterator examples
     226        for ( ... ) @sout | it.v | ",";   sout | nl;@ // iterator examples in text
    226227        remove( n1 );   remove( n2 );   remove( n3 );   remove( n4 );
    227228}
    228229\end{cfa}
    229 \caption{Iterator Example}
    230 \label{f:IteratorExample}
     230\caption{Iterator Temple}
     231\label{f:IteratorTemple}
    231232\end{figure}
    232233
     
    243244\begin{tabular}{@{}l|l@{}}
    244245\begin{cfa}
    245 for ( node & it = list`@first@; &it /* != 0p */ ; &it = &it`@next@ ) ...
    246 for ( node & it = list`@last@; &it; &it = &it`@prev@ ) ...
     246for ( node & it = @first@( list ); &it /* != 0p */ ; &it = &@next@( it ) ...
     247for ( node & it = @last@( list ); &it; &it = &@prev@( it ) ) ...
    247248\end{cfa}
    248249&
     
    258259\begin{tabular}{@{}l|l@{}}
    259260\begin{cfa}
    260 for ( node & it = @n2@; &it; &it = &it`@next@ ) ...
    261 for ( node & it = @n3@; &it; &it = &it`@prev@ ) ...
     261for ( node & it = @n2@; &it; &it = &@next@( it ) ) ...
     262for ( node & it = @n3@; &it; &it = &@prev@( it ) ) ...
    262263\end{cfa}
    263264&
     
    268269\end{tabular}
    269270\end{cquote}
    270 Iterating forward and reverse from a starting node to an ending node through the remaining list.
    271 \begin{cquote}
    272 \setlength{\tabcolsep}{15pt}
    273 \begin{tabular}{@{}l|l@{}}
    274 \begin{cfa}
    275 for ( node & it = @n2@; &it @!= &n4@; &it = &it`@next@ ) ...
    276 for ( node & it = @n4@; &it @!= &n2@; &it = &it`@prev@ ) ...
     271Iterating forward and reverse from a starting node to an ending node through the contained list.
     272\begin{cquote}
     273\setlength{\tabcolsep}{15pt}
     274\begin{tabular}{@{}l|l@{}}
     275\begin{cfa}
     276for ( node & it = @n2@; &it @!= &n4@; &it = &@next@( it ) ) ...
     277for ( node & it = @n4@; &it @!= &n2@; &it = &@prev@( it ) ) ...
    277278\end{cfa}
    278279&
     
    284285\end{cquote}
    285286Iterating forward and reverse through the entire list using the shorthand start at the list head and pick a direction.
    286 In this case, @next@ and @prev@ return a boolean, like \CC @while ( cin >> i )@.
    287 \begin{cquote}
    288 \setlength{\tabcolsep}{15pt}
    289 \begin{tabular}{@{}l|l@{}}
    290 \begin{cfa}
    291 for ( node & it = list`@head@; it`@next@; ) ...
    292 for ( node & it = list`@head@; it`@prev@; ) ...
     287In this case, @advance@ and @recede@ return a boolean, like \CC @while ( cin >> i )@.
     288\begin{cquote}
     289\setlength{\tabcolsep}{15pt}
     290\begin{tabular}{@{}l|l@{}}
     291\begin{cfa}
     292for ( node & it = @iter@( list ); @advance@( it ); ) ...
     293for ( node & it = @iter@( list ); @recede@( it ); ) ...
    293294\end{cfa}
    294295&
     
    330331\end{tabular}
    331332\end{cquote}
    332 The ability to provide a language-level @foreach@ is a future \CFA project.
     333Macros are not ideal, so future work is to provide a language-level @foreach@ statement, like \CC.
    333334Finally, a predicate can be added to any of the manual iteration loops.
    334335\begin{cquote}
     
    336337\begin{tabular}{@{}l|l@{}}
    337338\begin{cfa}
    338 for ( node & it = list`first; &it @&& !(it.v == 3)@; &it = &it`next ) ...
    339 for ( node & it = list`last; &it @&& !(it.v == 1)@; &it = &it`prev ) ...
    340 for ( node & it = list`head; it`next @&& !(it.v == 3)@; ) ...
    341 for ( node & it = list`head; it`prev @&& !(it.v == 1)@; ) ...
     339for ( node & it = first( list ); &it @&& !(it.v == 3)@; &it = &next( it ) ) ...
     340for ( node & it = last( list ); &it @&& !(it.v == 1)@; &it = &prev( it ) ) ...
     341for ( node & it = iter( list ); advance( it ) @&& !(it.v == 3)@; ) ...
     342for ( node & it = iter( list ); recede( it ) @&& !(it.v == 1)@; ) ...
    342343\end{cfa}
    343344&
     
    439440
    440441
    441 
    442442\section{Implementation}
    443 
    444 \subsection{Links}
    445443
    446444\VRef[Figure]{fig:lst-impl-links} continues the running @req@ example, now showing the \CFA list library's internal representation.
    447445The @dlink@ structure contains exactly two pointers: @next@ and @prev@, which are opaque to a user.
    448 Even though the user-facing list model is ordered (linear), the CFA library implements all listing as circular.
     446Even though the user-facing list model is linear, the CFA library implements all listing as circular.
    449447This choice helps achieve uniform end treatment and TODO finish summarizing benefit.
    450448A link pointer targets a neighbouring @dlink@ structure, rather than a neighbouring @req@.
     
    460458\end{figure}
    461459
    462 Link pointers are internally tagged according to whether the link is user-visible.
    463 Links among user-requested neighbours are left natural, with the tag bit not set.
    464 System-added links, which produce the circular implementation, have the tag bit set.
     460System-added link pointers (dashed lines) are internally tagged to indicate linear endpoints that are the circular pointers.
     461Links among neighbour nodes are not tagged.
    465462Iteration reports ``has more elements'' when crossing natural links, and ``no more elements'' upon reaching a tagged link.
    466463
    467464In a headed list, the list head (@dlist(req)@) acts as an extra element in the implementation-level circularly-linked list.
    468 The content of a @dlist@ is a (private) @dlink@, with the @next@ pointer purposed for the first element, and the @prev@ pointer purposed for the last element.
    469 Since the head wraps a @dlink@, since a @req@ does too, and since a link-pointer targets a @dlink@, the resulting cycle is among @dlink@ structures, situated inside of other things.
    470 The tags on the links say what the wrapper is: untagged (user link) means the targeted @dlink@ is within a @req@, while tagged (system link) means the targeted @dlink@ is within a list head.
    471 
    472 In a headless list, the circular backing list is only among @dlink@s within @req@s.  The tags are set on the links that a user cannot navigate.
    473 
    474 No distinction is made between an unlisted item under a headed model and a singleton list under a headless model.  Both are represented as an item referring to itself, with both tags set.
    475 
     465The content of a @dlist@ is a (private) @dlink@, with the @next@ pointer to the first element, and the @prev@ pointer to the last element.
     466Since the head wraps a @dlink@, as does a @req@ does too, and since a link-pointer targets a @dlink@, the resulting cycle is among @dlink@ structures, situated inside of header/node.
     467An untagged pointer points within a @req@, while a tagged pointer points within a list head.
     468In a headless list, the circular backing list is only among @dlink@s within @req@s.
     469The tags are set on the links that a user cannot navigate.
     470
     471No distinction is made between an unlisted item under a headed model and a singleton list under a headless model.
     472Both are represented as an item referring to itself, with both tags set.
    476473
    477474
Note: See TracChangeset for help on using the changeset viewer.