BRL.LinkedList: Functions Types Modinfo Source  

Lists

A linked list allows you to efficiently add and remove objects to a collection of objects.

To create a linked list, use the CreateList command.

You add objects to a linked list using ListAddFirst or ListAddLast. Both commands return a link object which can be used to later remove the added object with the RemoveLink command. You can also remove objects with the ListRemove command. However this is not as efficient as using RemoveLink because the list must first be searched for the object to be removed.

To visit all the objects in a linked list, you can use a For...EachIn loop.

Functions

Function ClearList( list:TList )
DescriptionClear a linked list.
InformationRemoves all objects from list.

Function CountList( list:TList )
ReturnsThe numbers of objects in list.
DescriptionCount list length.

Function CreateList:TList()
ReturnsA new linked list object.
DescriptionCreate a linked list.
Example
' createlist.bmx

' create a list to hold some objects

list:TList=createlist()

' add some string objects to the list

listaddlast list,"one"
listaddlast list,"two"
listaddlast list,"three"

' enumerate all the strings in the list

for a$=eachin list
	print a$
next

Function ListAddFirst:TLink( list:TList,value:Object )
ReturnsA link object.
DescriptionAdd an object to a linked list.

Function ListAddLast:TLink( list:TList,value:Object )
ReturnsA link object.
DescriptionAdd an object to a linked list.

Function ListContains( list:TList,value:Object )
ReturnsTrue if list contains value, else false.
DescriptionCheck if list contains a value.


Function ListFromArray:TList( arr:Object[] )
ReturnsA new linked list.
DescriptionCreate a list from an array.

Function ListIsEmpty( list:TList )
ReturnsTrue if list is empty, else false.
DescriptionCheck if list is empty.

Function ListRemove( list:TList,value:Object )
DescriptionRemove an object from a linked list.
InformationListRemove scans a list for the specified value and removes its link.

Function ListToArray:Object[]( list:TList )
ReturnsAn array of objects.
Descriptionconvert a list to an array.


Function ReverseList( list:TList )
DescriptionReverse the order of elements of a list.

Function SortList( list:TList,ascending=True,compareFunc( o1:Object,o2:Object )=CompareObjects )
DescriptionSort a list.

Function SwapLists( list_x:TList,list_y:TList )
DescriptionSwap the contents of 2 lists.

Types

Method Remove()
DescriptionRemoves the link from the List.
Method Value:Object()
DescriptionReturns the Object associated with this Link.

Type TList Extends TData
DescriptionLinked List.
Method AddFirst:TLink( value:Object )
ReturnsA link object.
DescriptionAdd an object to the start of the list.
Method AddLast:TLink( value:Object )
ReturnsA link object.
DescriptionAdd an object to the end of the list.
Method Clear()
DescriptionClear a linked list.
InformationRemoves all objects from list.
Method Contains( value:Object )
ReturnsTrue if list contains value, else false.
DescriptionCheck if list contains a value.
Method Copy:TList()
DescriptionCreates an identical copy of the list.
Method Count()
ReturnsThe numbers of objects in list.
DescriptionCount list length.
Method First:Object()
DescriptionReturns the first object in the list.
InformationThrows an exception if the list is empty.
Method IndexOfValue( value:Object )
DescriptionReturns the index position of the given value.
InformationReturns -1 if value not found in the list.
Method IsEmpty()
ReturnsTrue if list is empty, else false.
DescriptionCheck if list is empty.
Method Last:Object()
DescriptionReturns the last object in the list.
InformationThrows an exception if the list is empty.
Method Remove( value:Object )
DescriptionRemove an object from a linked list.
InformationRemove scans a list for the specified value and removes its link.
Method RemoveFirst:Object()
DescriptionRemoves and returns the first object in the list.
InformationThrows an exception if the list is empty.
Method RemoveLast:Object()
DescriptionRemoves and returns the last object in the list.
InformationThrows an exception if the list is empty.
Method Reverse()
DescriptionReverse the order of the list.
Method Reversed:TList()
DescriptionCreates a new list that is the reversed version of this list.
Method Sort( ascending=True,compareFunc( o1:Object,o2:Object )=CompareObjects )
DescriptionSort a list in either ascending (default) or decending order.
InformationUser types should implement a Compare method in order to be sorted.
Method Swap( list:TList )
DescriptionSwap contents with the list specified.
Method ToArray:Object[]()
ReturnsAn array of objects.
Descriptionconvert a list to an array.
Method ValueAtIndex:Object( index )
DescriptionReturns the value of the link at the given index.
InformationThrows an exception if the index is out of range (must be 0..list.Count()-1 inclusive).
Function FromArray:TList( arr:Object[] )
ReturnsA new linked list.
DescriptionCreate a list from an array.

Type TListEnum
DescriptionEnumerator Object use by TList in order to implement Eachin support.

Module Information

Version1.07
AuthorMark Sibly
LicenseBlitz Shared Source Code
CopyrightBlitz Research Ltd
ModserverBRL
Version1.07
VersionIndexOfValue method added to TList
History1.06 Release
HistoryAdded optional CompareFunc parameter to Sort
History1.05 Release
HistorySort now swaps links instead of values