Not part of build, a=leaf

Added the get(int) method, for accessing via index. It's not recommended using
this method unless on very small lists. This will help save on overhead so we don't have to create an iterator on lists with only a couple elements.
This commit is contained in:
kvisco%ziplink.net 2000-05-29 07:14:03 +00:00
parent bc6648f2e1
commit 98d6c009df
2 changed files with 33 additions and 3 deletions

View File

@ -23,7 +23,7 @@
* Bob Miller, kbob@oblix.com
* -- plugged core leak.
*
* $Id: List.cpp,v 1.3 1999/11/25 03:03:02 kvisco%ziplink.net Exp $
* $Id: List.cpp,v 1.4 2000/05/29 07:14:03 kvisco%ziplink.net Exp $
*/
#include "List.h"
@ -36,7 +36,7 @@
/**
* Default constructor for a List;
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.3 $ $Date: 1999/11/25 03:03:02 $
* @version $Revision: 1.4 $ $Date: 2000/05/29 07:14:03 $
**/
List::List() {
@ -75,6 +75,29 @@ void List::add(void* objPtr) {
insert(itemCount, objPtr);
} //-- add
/**
* Returns the object located at the given index. This may
* be slow or fast depending on the implementation.
* Note:
* Currently this list is implemented via a linked list, so
* this method will be slow (unless the list only has a couple
* members) as it will need traverse the links each time
* @return the object located at the given index
**/
void* List::get(int index) {
if ((index < 0) || (index >= itemCount)) return 0;
int c = 0;
ListItem* item = firstItem;
while (c != index) {
item = item->nextItem;
++c;
}
return item->objPtr;
} //-- get(int)
List::ListItem* List::getFirstItem() {
return firstItem;
} //-- getFirstItem

View File

@ -21,7 +21,7 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: List.h,v 1.5 2000/04/12 10:53:21 kvisco%ziplink.net Exp $
* $Id: List.h,v 1.6 2000/05/29 07:14:03 kvisco%ziplink.net Exp $
*/
#include "baseutils.h"
@ -48,6 +48,13 @@ public:
**/
virtual ~List();
/**
* Returns the object located at the given index. This may
* be slow or fast depending on the implementation.
* @return the object located at the given index
**/
void* get(int index);
/**
* Returns the number of items in this List
**/