summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchatty1996-03-11 15:53:09 +0000
committerchatty1996-03-11 15:53:09 +0000
commit0a5546f5807ec2214846231358170a3debee524f (patch)
treef3760ea74e5315e8419a713f34eb35467da000bf
parent2bfbaf62b9455049fae91b73a1784a4499f951df (diff)
downloadivy-league-0a5546f5807ec2214846231358170a3debee524f.zip
ivy-league-0a5546f5807ec2214846231358170a3debee524f.tar.gz
ivy-league-0a5546f5807ec2214846231358170a3debee524f.tar.bz2
ivy-league-0a5546f5807ec2214846231358170a3debee524f.tar.xz
Added experimental CcuListIndex
-rw-r--r--utils/List.cc54
1 files changed, 40 insertions, 14 deletions
diff --git a/utils/List.cc b/utils/List.cc
index 7d47157..37c11eb 100644
--- a/utils/List.cc
+++ b/utils/List.cc
@@ -265,7 +265,7 @@ CcuList :: Find (CcuListItem* e, int* rank) const
}
/*?nextdoc?*/
-void
+CcuListIndex
CcuList :: Prepend (CcuListItem* e)
{
if (LastLink)
@@ -273,18 +273,20 @@ CcuList :: Prepend (CcuListItem* e)
LastLink->Next = new CcuListLink (e, LastLink->Next);
else
LastLink = new CcuListLink (e);
+ return LastLink;
}
/*?
Add an element at the beginning (resp. end) of a list.
?*/
-void
+CcuListIndex
CcuList :: Append (CcuListItem* e)
{
if (LastLink) {
LastLink = LastLink->Next = new CcuListLink (e, LastLink->Next);
} else
LastLink = new CcuListLink (e);
+ return LastLink;
}
/*?
@@ -354,12 +356,13 @@ CcuList :: RemoveLast ()
Insert an element before the link \var{l}. This function has a linear cost.
!*/
/*?hidden?*/
-void
+CcuListIndex
CcuList :: InsertBeforeLink (CcuListLink* l, CcuListItem* e)
{
CcuListLink* prev = l->Previous ();
CcuListLink* newlink = new CcuListLink (e, l);
prev->Next = newlink;
+ return newlink;
}
@@ -367,13 +370,14 @@ CcuList :: InsertBeforeLink (CcuListLink* l, CcuListItem* e)
Insert an element after the link \var{l}.
!*/
/*?hidden?*/
-void
+CcuListIndex
CcuList :: InsertAfterLink (CcuListLink* l, CcuListItem* e)
{
CcuListLink* newlink = new CcuListLink (e, l->Next);
l->Next = newlink;
if (LastLink == l)
LastLink = newlink;
+ return newlink;
}
/*!
@@ -444,26 +448,28 @@ CcuList :: Remove (int (*p) (CcuListItem*), int num)
/*?nextdoc?*/
-void
+CcuListIndex
CcuList :: InsertAfter (const CcuListIter& li, CcuListItem* e)
{
if (li.TheList != this) {
StatusFlag = BadIterator;
- return;
+ return 0;
}
StatusFlag = NoError;
+ CcuListIndex idx = 0;
if (!li.CurLink) {
if (li.StatusFlag == CcuListIter::StartOfList) {
- Prepend (e);
+ idx = Prepend (e);
} else {
fprintf (stderr, "abnormal status in CcuList::InsertAfter\n");
abort ();
}
} else if (li.StatusFlag == CcuListIter::EndOfList) {
- Append (e);
+ idx = Append (e);
} else {
- InsertAfterLink (li.CurLink, e);
+ idx = InsertAfterLink (li.CurLink, e);
}
+ return idx;
}
/*?
@@ -474,26 +480,28 @@ beginning of the list (ie. before the first element).
has a linear cost. If \var{li} is not an iterator on this list, the status flag of the list
is set to \var{CcuList::BadIterator}.
?*/
-void
+CcuListIndex
CcuList :: InsertBefore (const CcuListIter& li, CcuListItem* e)
{
if (li.TheList != this) {
StatusFlag = BadIterator;
- return;
+ return 0;
}
StatusFlag = NoError;
+ CcuListIndex idx = 0;
if (!li.CurLink) {
if (li.StatusFlag == CcuListIter::StartOfList) {
- Prepend (e);
+ idx = Prepend (e);
} else {
fprintf (stderr, "abnormal status in CcuList::InsertAfter\n");
abort ();
}
} else if (li.StatusFlag == CcuListIter::EndOfList) {
- Append (e);
+ idx = Append (e);
} else {
- InsertBeforeLink (li.CurLink, e);
+ idx = InsertBeforeLink (li.CurLink, e);
}
+ return idx;
}
/*?
@@ -562,8 +570,26 @@ of the list, {\em before} the first element.
CcuListIter :: CcuListIter (const CcuList& l)
{
}
+#endif /* DOC */
/*?
+Build an iterator on list \var{l}, pointing at the element denoted by \var{idx}. No check is done on whether
+\var{idx} is a valid index of list \var{l}.
+?*/
+CcuListIter :: CcuListIter (const CcuList& l, CcuListIndex idx)
+ : TheList (&l),
+#ifdef CPLUS_BUG20
+ CurLink ((CcuListLink*) idx),
+#else
+ CurLink ((CcuList::CcuListLink*) idx),
+#endif
+ StatusFlag (idx ? Normal : StartOfList)
+{
+}
+
+
+#ifdef DOC
+/*?
Get the status of an iterator. The status may be one of \var{CcuListIter::Normal,
CcuListIter::StartOfList}, or \var{CcuListIter::EndOfList}
?*/