Changeset 1794
- Timestamp:
- Sep 10, 2004, 4:34:50 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/doc/pslib/psLibSDRS.tex (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/pslib/psLibSDRS.tex
r1770 r1794 1 %%% $Id: psLibSDRS.tex,v 1.12 1 2004-09-10 00:33:54price Exp $1 %%% $Id: psLibSDRS.tex,v 1.122 2004-09-11 02:34:50 price Exp $ 2 2 \documentclass[panstarrs,spec]{panstarrs} 3 3 … … 1419 1419 \label{sec:psList} 1420 1420 1421 \PS{} s upportsdoubly linked lists through a type \code{psList}:1421 \PS{} shall support doubly linked lists through a type \code{psList}: 1422 1422 % 1423 1423 \begin{verbatim} … … 1426 1426 psListElem *head; ///< first element on list (may be NULL) 1427 1427 psListElem *tail; ///< last element on list (may be NULL) 1428 psListElem *iter; ///< iteration cursor1429 unsigned int iterIndex; ///< the numeric position of the iteration cursor in the list1428 unsigned int nIter; ///< number of iterators 1429 psListIterator **iter; ///< iteration cursors 1430 1430 pthread_mutex_t lock; ///< mutex to lock a node during changes 1431 1431 } psList; 1432 1432 \end{verbatim} 1433 1433 % 1434 The type \code{psList} represents the container of the list. It has 1435 apointer to the first element in the linked list (\code{head}), a1434 The type \code{psList} represents the container of the list. It has a 1435 pointer to the first element in the linked list (\code{head}), a 1436 1436 pointer to the last element in the list (\code{tail}), an entry for 1437 1437 the current cursor location (\code{iter}), and an entry to define the 1438 number of elements in the list (\code{n}). 1438 number of elements in the list (\code{size}). Iteration on the list 1439 is achieved by means of an array of \code{nIter} iteration cursors, 1440 \code{iter}. The \code{lock} should be applied during changes to the 1441 list to maintain thread safety. 1439 1442 1440 1443 The elements of the list are defined by the type \code{psListElem}: … … 1461 1464 \code{psList.head} and \code{psList.tail}. If the data entry is 1462 1465 \code{NULL}, then an empty list, with both pointers are set to 1463 \code{NULL} should be created. 1464 1465 The destructor function for \code{psList} must free the data 1466 associated with the entire list. 1466 \code{NULL} should be created. The number of iterators in the list is 1467 initially set to zero. 1468 1469 The destructor function for \code{psList} must call \code{psFree} for 1470 all the the data associated with the list. 1471 1472 All data items placed onto lists must have their reference counters 1473 (section \ref{secMemRefcounter}) incremented. When elements are 1474 removed from a list, they must have their reference counters 1475 decremented. The action of retrieving data from a list (with one of 1476 the three \code{psListGet} functions) also increments the reference 1477 counter. 1478 1479 Iteration on the list shall be achieved by means of a list iterator 1480 type: 1481 \begin{verbatim} 1482 typedef struct { 1483 psList *list; ///< List iterator works on 1484 unsigned int num; ///< Iterator number 1485 psListElem *cursor; ///< The current iterator cursor 1486 bool offEnd; ///< Is the iterator off the end? 1487 } psListIterator; 1488 \end{verbatim} 1489 The \code{psListIterator} keeps track of which list element the 1490 iterator \code{cursor} is currently pointing at. \code{num} is the 1491 number of the list iterator in the parent \code{list}'s array of 1492 iterators, so \code{list->iter[num]} points to the list iterator. The 1493 boolean member, \code{offEnd}, indicates whether the iterator has 1494 progressed off the end of the list (i.e., beyond the last item). 1495 1496 The corresponding constructor shall be: 1497 \begin{verbatim} 1498 psListIterator *psListIteratorAlloc(psList *list, int location); 1499 \end{verbatim} 1500 Here, \code{list} is the \code{psList} on which the iterator will 1501 iterate, and \code{location} is the initial starting point, and may be 1502 a numerical index or it may be one of the special values: 1503 \code{PS_LIST_HEAD} or \code{PS_LIST_TAIL}, which are defined as 1504 negative integers. Of course, the \code{psListElem} pointed to by the 1505 iterator shall have its \code{refCounter} incremented. 1506 1507 The destructor for \code{psListIterator} shall, after freeing the 1508 \code{psListIterator} and decrementing the \code{refCounter} of the 1509 \code{psListElem} that it pointed to, also reorganise the \code{iter} 1510 array (replacing the element being removed with the last element) and 1511 resizing the array appropriately. 1512 1513 A list \code{iterator} shall be set to a specific \code{location} on 1514 the list upon calling \code{psListIteratorSet}: 1515 \begin{verbatim} 1516 bool psListIteratorSet(psListIterator *iterator, int location); 1517 \end{verbatim} 1518 Again, the \code{location} may be a numerical index or it may be one 1519 of the special values: \code{PS_LIST_HEAD} or \code{PS_LIST_TAIL}, 1520 which are defined as negative integers. The function shall return 1521 \code{true} if the reset was successful, or \code{false} otherwise. 1467 1522 1468 1523 \begin{verbatim} 1469 1524 bool psListAdd(psList *list, int location, void *data); 1470 \end{verbatim} 1471 Add an entry to the list with this function, which takes a pointer to 1472 the list and returns a boolean giving the success or failure of the 1473 operation. The value of \code{location} specifies if the specified 1474 data item should be placed on the front of the list 1475 (\code{PS_LIST_HEAD}), at the end of the list (\code{PS_LIST_TAIL}), 1476 to add after (\code{PS_LIST_NEXT}) or before (\code{PS_LIST_PREV}) the 1477 current element (specified by the iteration cursor), or an index that 1478 the new \code{data} should inhabit. 1525 bool psListAddAfter(psListIterator *iterator, void *data); 1526 bool psListAddBefore(psListIterator *iterator, void *data); 1527 \end{verbatim} 1528 the first function, \code{psListAdd}, adds an entry to the \code{list} 1529 and returns a boolean giving the success or failure of the 1530 operation. The value of \code{location} may be a numerical index the 1531 \code{data} is to inhabit (if \code{location} is greater than the 1532 number of items on the list, then the function shall generate a 1533 warning and add the \code{data} to the tail) or it may be one of the 1534 special values: \code{PS_LIST_HEAD} or \code{PS_LIST_TAIL}, which are 1535 defined as negative integers. The other two functions, 1536 \code{psListAddAfter} and \code{psListAddBefore} specify that the 1537 \code{data} shall be added after or before (respectively) the current 1538 cursor position of the \code{iterator}. 1479 1539 1480 1540 \begin{verbatim} 1481 1541 void *psListGet(psList *list, int location); 1482 \end{verbatim} 1483 A data item may be retrieved from the list with this function. The 1484 value of \code{location} may be the numerical index or it may be one 1485 of the special values: \code{PS_LIST_HEAD}, \code{PS_LIST_TAIL}, 1486 \code{PS_LIST_PREV}, and \code{PS_LIST_NEXT}, all of which are defined 1487 as negative integers, allowing \code{location} to also be the index of 1488 one of the data items. 1489 1490 \begin{verbatim} 1491 bool psListRemove(psList *list, int location, void *data); 1492 \end{verbatim} 1493 A data item may be removed from the list with this function. The 1494 value of \code{location} may be the numerical index or it may be one 1495 of the special values: \code{PS_LIST_HEAD}, \code{PS_LIST_TAIL}, 1496 \code{PS_LIST_PREV}, \code{PS_LIST_UNKNOWN}, and \code{PS_LIST_NEXT}, 1497 all of which are defined as negative integers. If the value of 1498 \code{location} is \code{PS_LIST_UNKNOWN}, then the data item is 1499 identified by matching the pointer value with \code{void *data}. The 1500 function returns a value of \code{true} if the operation was 1501 successful, and \code{false} otherwise. 1502 1503 All data items placed onto lists (\code{psListAdd}) must have their 1504 reference counters (section \ref{secMemRefcounter}) incremented. When 1505 elements are removed from a list with \code{psListRemove}, they must 1506 have their reference counters decremented. The action of retrieving 1507 data from a list (with \code{psListGet}) also increments the reference 1508 counter. 1542 void *psListGetNext(psListIterator *iterator); 1543 void *psListGetPrevious(psListIterator *iterator); 1544 \end{verbatim} 1545 A data item may be retrieved from the list with these functions. The 1546 first function, \code{psListGet} simply returns the value specified 1547 by its \code{location}, which may be a numerical index or it may be 1548 one of the special values: \code{PS_LIST_HEAD} or \code{PS_LIST_TAIL}, 1549 which are defined as negative integers, allowing \code{location} to 1550 also be the index of one of the data items. The other two functions, 1551 \code{psListGetNext} and \code{psListGetPrevious} return the item 1552 under the iteration cursor before advancing to the next or previous 1553 item, respectively. 1554 1555 In the event that the iteration cursor is at the tail of the list, 1556 \code{psListGetNext} shall return the tail item and then set the 1557 \code{cursor} to \code{NULL} and \code{offEnd} to \code{true}. In the 1558 event that the iteration cursor is at the head of the list, 1559 \code{psListGetPrevious} shall return the head item and then set the 1560 \code{cursor} to \code{NULL} (and \code{offEnd} should already be 1561 \code{false}). In the event that the iteration \code{cursor} is 1562 \code{NULL}, \code{psListGetNext} and \code{psListGetPrevious} shall 1563 return \code{NULL}, and advance the iteration \code{cursor} only if 1564 the intended direction places the cursor back on the list; otherwise a 1565 warning shall be generated, and no change shall be made. If 1566 \code{psListGetPrevious} was called with \code{offEnd} as \code{true}, 1567 then \code{offEnd} shall also be toggled back to \code{false} to 1568 indicate that the \code{cursor} is no longer off the end of the list. 1569 When setting the \code{cursor}, the appropriate \code{refCounter}s 1570 shall be incremented and decremented. 1571 1572 \begin{verbatim} 1573 bool psListRemove(psList *list, int location) 1574 bool psListRemoveData(psList *list, void *data); 1575 bool psListRemoveAfter(psListIterator *iterator); 1576 bool psListRemoveBefore(psListIterator *iterator); 1577 \end{verbatim} 1578 A data item may be removed from the list with these functions. For 1579 \code{psListRemove}, the value of \code{location} may be the numerical 1580 index or it may be one of the special values: \code{PS_LIST_HEAD} or 1581 \code{PS_LIST_TAIL}, which are defined as negative integers. For 1582 \code{psListRemoveData}, the data item to be removed is identified by 1583 matching the pointer value with \code{void *data}. The functions 1584 return a value of \code{true} if the operation was successful, and 1585 \code{false} otherwise. The other two functions, 1586 \code{psListRemoveBefore} and \code{psListRemoveAfter} remove the item 1587 before or after (respectively) the iteration cursor. In all cases, if 1588 any iterators are currently pointing at the item to be removed, or the 1589 item to be removed is not on the list, an error shall be generated, 1590 the item shall not be removed, and the function shall return 1591 \code{false}. 1592 1509 1593 1510 1594 \begin{verbatim} … … 1516 1600 free the elements or destroy the input collection. Rather, they 1517 1601 increment the reference counter for each of the elements. 1518 1519 \begin{verbatim}1520 void psListSetIterator(psList *list, int iterator, int location);1521 void *psListGetNext(psList *list, int iterator);1522 void *psListGetPrevious(psList *list, int iterator);1523 \end{verbatim}1524 Iteration over all elements of the list using the iteration cursor1525 \code{iter} is provided by these functions. The first of these1526 functions uses the value of \code{location} to set the iteration1527 cursor for the given list to the beginning \code{PS_LIST_HEAD} or the1528 end \code{PS_LIST_TAIL} for the iterator specified by \code{iterator}.1529 The next two functions move the iteration cursor forward or backwards,1530 returning the data item from the resulting list entry, or returning1531 \code{NULL} at the end of the list. Explicit traversal of the list1532 using the \code{psListElem}s \code{prev} and \code{next} pointers is1533 also supported.1534 1602 1535 1603 \begin{verbatim}
Note:
See TracChangeset
for help on using the changeset viewer.
