summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorchatty1994-02-24 10:33:41 +0000
committerchatty1994-02-24 10:33:41 +0000
commit1ed65383fc2b49e22929862dd5705c93f79a60c2 (patch)
treede9faf90901884dd19819462430a119ce88a216d /utils
parentd9d4dc11af0b9f6863b6cd14c85ef1b0ea8f98a5 (diff)
downloadivy-league-1ed65383fc2b49e22929862dd5705c93f79a60c2.zip
ivy-league-1ed65383fc2b49e22929862dd5705c93f79a60c2.tar.gz
ivy-league-1ed65383fc2b49e22929862dd5705c93f79a60c2.tar.bz2
ivy-league-1ed65383fc2b49e22929862dd5705c93f79a60c2.tar.xz
Added rank arg to Find
Fixed doc
Diffstat (limited to 'utils')
-rw-r--r--utils/List.cc53
1 files changed, 32 insertions, 21 deletions
diff --git a/utils/List.cc b/utils/List.cc
index f55b1be..4c4db23 100644
--- a/utils/List.cc
+++ b/utils/List.cc
@@ -169,9 +169,11 @@ CcuList :: operator = (const CcuList& l)
#ifdef DOC
/*?
-Get the status flag of a list. This can be one of \var{NoError, WasEmpty, TooEarly, TooFar} or
-\var{BadIterator}. The status flag is modified by most operations on lists. Those which
-modify it when errors are encountered also set it to \var{NoError} when there is no error.
+Get the status flag of a list. This can be one of \var{CcuList::NoError, CcuList::WasEmpty,
+CcuList::TooEarly, CcuList::TooFar} or \var{CcuList::BadIterator}.
+The status flag is modified by most operations on lists. Those which
+modify it when errors are encountered also set it to \var{CcuList::NoError}
+when there is no error.
?*/
list_status
CcuList :: GetStatus () const
@@ -195,7 +197,7 @@ CcuList :: First ()
Return the first (resp. last) element in the list, or 0 if the list was empty.
The case of a null element can be distinguished from the case
when the list is empty with the function \fun{GetStatus}: the status flag is
-set to \var{WasEmpty} in the latter case.
+set to \var{CcuList::WasEmpty} in the latter case.
?*/
CcuListItem*
CcuList :: Last ()
@@ -210,8 +212,8 @@ CcuList :: Last ()
/*?
Get the \var{n}-th element of a list. If \var{n} is greater than the length of the list
-this function returns 0 and sets the status to \var{TooFar}. If \var{n} is negative,
-this function returns 0 but sets the status to \var{NoError}.
+this function returns 0 and sets the status to \var{CcuList::TooFar}. If \var{n} is negative,
+this function returns 0 but sets the status to \var{CcuList::NoError}.
?*/
CcuListItem*
CcuList :: Nth (int n)
@@ -241,16 +243,25 @@ CcuList :: Length () const
}
/*?
-Check whether an item is present in a list.
+Check whether an item is present in a list. If \var{rank} is not null, it is filled with the
+rank of the first occurence of \var{e} in the list.
?*/
int
-CcuList :: Find (CcuListItem* e) const
+CcuList :: Find (CcuListItem* e, int* rank) const
{
+ int rk = 0;
+ int ret = 0;
+
CcuListIter li (*this);
- while (++li)
- if (*li == e)
- return 1;
- return 0;
+ while (++rk, ++li)
+ if (*li == e) {
+ ret = 1;
+ break;
+ }
+
+ if (rank)
+ *rank = ret ? rk : 0;
+ return ret;
}
/*?nextdoc?*/
@@ -278,7 +289,7 @@ CcuList :: Append (CcuListItem* e)
/*?
Remove the first element of a list and return it. The status flag is set to
-\var{WasEmpty} when the list was empty.
+\var{CcuList::WasEmpty} when the list was empty.
?*/
CcuListItem*
CcuList :: RemoveFirst ()
@@ -307,7 +318,7 @@ CcuList :: RemoveFirst ()
/*?
Remove the last element of a list and return it. The status flag is set to
-\var{WasEmpty} when the list was empty. This function has to locate the last
+\var{CcuList::WasEmpty} when the list was empty. This function has to locate the last
element, and hence has a linear cost.
?*/
CcuListItem*
@@ -461,7 +472,7 @@ These functions are both equivalent to \fun{CcuList::Prepend} if the iterator is
beginning of the list (ie. before the first element).
\fun{InsertAfter} is performed in a constant time, while \fun{InsertBefore}
has a linear cost. If \var{li} is not an iterator on this list, the status flag of the list
-is set to \var{BadIterator}.
+is set to \var{CcuList::BadIterator}.
?*/
void
CcuList :: InsertBefore (const CcuListIter& li, CcuListItem* e)
@@ -488,10 +499,10 @@ CcuList :: InsertBefore (const CcuListIter& li, CcuListItem* e)
/*?
Remove the element after the current element of the iterator \var{li}.
If \var{li} points before the beginning of the list, the first element is removed.
-If \var{li} points at the last element, the status flag is set to \var{TooFar}.
-If the list is empty, the flag is set to \var{EmptyList}. In both cases, the
+If \var{li} points at the last element, the status flag is set to \var{CcuList::TooFar}.
+If the list is empty, the flag is set to \var{CcuList::EmptyList}. In both cases, the
return value is null. If \var{li} is not an iterator
-on this list, the flag is set to \var{BadIterator}.
+on this list, the flag is set to \var{CcuList::BadIterator}.
This function may be used
when one wants to iterate through a list and remove some elements:
\begin{ccode}
@@ -553,8 +564,8 @@ CcuListIter :: CcuListIter (const CcuList& l)
}
/*?
-Get the status of an iterator. The status may be one of \var{Normal, StartOfList}, or
-\var{EndOfList}
+Get the status of an iterator. The status may be one of \var{CcuListIter::Normal,
+CcuListIter::StartOfList}, or \var{CcuListIter::EndOfList}
?*/
listiter_status
CcuListIter :: GetStatus () const
@@ -585,7 +596,7 @@ CcuListIter :: operator * () const
#ifdef DOC
/*?
-Check whether the status of an iterator is \var{Normal}.
+Check whether the status of an iterator is \var{CcuListIter::Normal}.
?*/
CcuListIter :: operator int () const
{