Rebornbuddy
Loading...
Searching...
No Matches
Pathfinding.SortableList Class Reference

The SortableList allows to maintain a list sorted as long as needed. If no IComparer interface has been provided at construction, then the list expects the Objects to implement IComparer. If the list is not sorted it behaves like an ordinary list. When sorted, the list's "Add" method will put new objects at the right place. As well the "Contains" and "IndexOf" methods will perform a binary search. More...

Inheritance diagram for Pathfinding.SortableList:

Public Member Functions

 SortableList ()
 Default constructor. Since no IComparer is provided here, added objects must implement the IComparer interface.
 SortableList (int Capacity)
 Constructor. Since no IComparer is provided, added objects must implement the IComparer interface.
 SortableList (IComparer Comparer)
 Constructor.
 SortableList (IComparer Comparer, int Capacity)
 Constructor.
int Add (object O)
 IList implementation. If the KeepSorted property is set to true, the object will be added at the right place. Else it will be added at the end of the list.
bool Contains (object O)
 IList implementation. Search for a specified object in the list. If the list is sorted, a BinarySearch is performed using IComparer interface. Else the Object.Equals implementation is used.
int IndexOf (object O)
 IList implementation. Returns the index of the specified object in the list. If the list is sorted, a BinarySearch is performed using IComparer interface. Else the Object.Equals implementation of objects is used.
void Clear ()
 IList implementation. Idem ArrayList
void Insert (int Index, object O)
 IList implementation. Inserts an objects at a specified index. Cannot be used if the list has its KeepSorted property set to true.
void Remove (object Value)
 IList implementation. Idem ArrayList
void RemoveAt (int Index)
 IList implementation. Idem ArrayList
void CopyTo (Array array, int arrayIndex)
 IList.ICollection implementation. Idem ArrayList
IEnumerator GetEnumerator ()
 IList.IEnumerable implementation. Idem ArrayList
object Clone ()
 ICloneable implementation. Idem ArrayList
int IndexOf (object O, int Start)
 Idem IndexOf(object), but starting at a specified position in the list.
delegate bool Equality (object O1, object O2)
 Defines an equality for two objects.
int IndexOf (object O, Equality AreEqual)
 Idem IndexOf(object), but with a specified equality function.
int IndexOf (object O, int Start, Equality AreEqual)
 Idem IndexOf(object), but with a start index and a specified equality function.
override string ToString ()
 Object.ToString() override. Build a string to represent the list.
override bool Equals (object O)
 Object.Equals() override.
override int GetHashCode ()
 Object.GetHashCode() override.
void Sort ()
 Sorts the elements in the list using ArrayList.Sort. Does nothing if the list is already sorted.
void AddRange (ICollection C)
 If the KeepSorted property is set to true, the object will be added at the right place. Else it will be appended to the list.
void InsertRange (int Index, ICollection C)
 Inserts a collection of objects at a specified index. Should not be used if the list is the KeepSorted property is set to true.
void LimitNbOccurrences (object Value, int NbValuesToKeep)
 Limits the number of occurrences of a specified value. Same values are equals according to the Equals() method of objects in the list. The first occurrences encountered are kept.
void RemoveDuplicates ()
 Removes all duplicates in the list. Each value encountered will have only one representant.
int IndexOfMin ()
 Returns the object of the list whose value is minimum.
int IndexOfMax ()
 Returns the object of the list whose value is maximum.

Properties

bool IsSorted [get]
 'Get only' property that indicates if the list is sorted.
bool KeepSorted [get, set]
 Get : Indicates if the list must be kept sorted from now on. Set : Tells the list if it must stay sorted or not. Impossible to set to true if the list is not sorted. KeepSorted==true implies that IsSorted==true.
bool AddDuplicates [get, set]
 If set to true, it will not be possible to add an object to the list if its value is already in the list.
object this[int Index] [get, set]
 IList implementation. Gets - or sets - object's value at a specified index. The set operation is impossible if the KeepSorted property is set to true.
bool IsFixedSize [get]
 IList implementation. Idem ArrayList
bool IsReadOnly [get]
 IList implementation. Idem ArrayList
int Count [get]
 IList.ICollection implementation. Idem ArrayList
bool IsSynchronized [get]
 IList.ICollection implementation. Idem ArrayList
object SyncRoot [get]
 IList.ICollection implementation. Idem ArrayList
int Capacity [get, set]
 Idem ArrayList

Detailed Description

The SortableList allows to maintain a list sorted as long as needed. If no IComparer interface has been provided at construction, then the list expects the Objects to implement IComparer. If the list is not sorted it behaves like an ordinary list. When sorted, the list's "Add" method will put new objects at the right place. As well the "Contains" and "IndexOf" methods will perform a binary search.

Constructor & Destructor Documentation

◆ SortableList() [1/4]

Pathfinding.SortableList.SortableList ( )

Default constructor. Since no IComparer is provided here, added objects must implement the IComparer interface.

◆ SortableList() [2/4]

Pathfinding.SortableList.SortableList ( int Capacity)

Constructor. Since no IComparer is provided, added objects must implement the IComparer interface.

Parameters
CapacityCapacity of the list (ArrayList.Capacity)

◆ SortableList() [3/4]

Pathfinding.SortableList.SortableList ( IComparer Comparer)

Constructor.

Parameters
ComparerWill be used to compare added elements for sort and search operations.

◆ SortableList() [4/4]

Pathfinding.SortableList.SortableList ( IComparer Comparer,
int Capacity )

Constructor.

Parameters
ComparerWill be used to compare added elements for sort and search operations.
CapacityCapacity of the list (ArrayList.Capacity)

Member Function Documentation

◆ Add()

int Pathfinding.SortableList.Add ( object O)

IList implementation. If the KeepSorted property is set to true, the object will be added at the right place. Else it will be added at the end of the list.

Parameters
OThe object to add.
Returns
The index where the object has been added.
Exceptions
ArgumentExceptionThe SortableList is set to use object's IComparable interface, and the specifed object does not implement this interface.

◆ AddRange()

void Pathfinding.SortableList.AddRange ( ICollection C)

If the KeepSorted property is set to true, the object will be added at the right place. Else it will be appended to the list.

Parameters
CThe object to add.
Returns
The index where the object has been added.
Exceptions
ArgumentExceptionThe SortableList is set to use object's IComparable interface, and the specifed object does not implement this interface.

◆ Clear()

void Pathfinding.SortableList.Clear ( )

IList implementation. Idem ArrayList

◆ Clone()

object Pathfinding.SortableList.Clone ( )

ICloneable implementation. Idem ArrayList

Returns
Cloned object.

◆ Contains()

bool Pathfinding.SortableList.Contains ( object O)

IList implementation. Search for a specified object in the list. If the list is sorted, a BinarySearch is performed using IComparer interface. Else the Object.Equals implementation is used.

Parameters
OThe object to look for
Returns
true if the object is in the list, otherwise false.

◆ CopyTo()

void Pathfinding.SortableList.CopyTo ( Array array,
int arrayIndex )

IList.ICollection implementation. Idem ArrayList

Parameters
array
arrayIndex

◆ Equality()

delegate bool Pathfinding.SortableList.Equality ( object O1,
object O2 )

Defines an equality for two objects.

◆ Equals()

override bool Pathfinding.SortableList.Equals ( object O)

Object.Equals() override.

Returns
true if object is equal to this, otherwise false.

◆ GetEnumerator()

IEnumerator Pathfinding.SortableList.GetEnumerator ( )

IList.IEnumerable implementation. Idem ArrayList

Returns
Enumerator on the list.

◆ GetHashCode()

override int Pathfinding.SortableList.GetHashCode ( )

Object.GetHashCode() override.

Returns
HashCode value.

◆ IndexOf() [1/4]

int Pathfinding.SortableList.IndexOf ( object O)

IList implementation. Returns the index of the specified object in the list. If the list is sorted, a BinarySearch is performed using IComparer interface. Else the Object.Equals implementation of objects is used.

Parameters
OThe object to locate.
Returns
If the object has been found, a positive integer corresponding to its position. If the objects has not been found, a negative integer which is the bitwise complement of the index of the next element.

◆ IndexOf() [2/4]

int Pathfinding.SortableList.IndexOf ( object O,
Equality AreEqual )

Idem IndexOf(object), but with a specified equality function.

Parameters
OThe object to locate.
AreEqualEquality function to use for the search.
Returns

◆ IndexOf() [3/4]

int Pathfinding.SortableList.IndexOf ( object O,
int Start )

Idem IndexOf(object), but starting at a specified position in the list.

Parameters
OThe object to locate.
StartThe index for start position.
Returns

◆ IndexOf() [4/4]

int Pathfinding.SortableList.IndexOf ( object O,
int Start,
Equality AreEqual )

Idem IndexOf(object), but with a start index and a specified equality function.

Parameters
OThe object to locate.
StartThe index for start position.
AreEqualEquality function to use for the search.
Returns

◆ IndexOfMax()

int Pathfinding.SortableList.IndexOfMax ( )

Returns the object of the list whose value is maximum.

Returns
The maximum object in the list

◆ IndexOfMin()

int Pathfinding.SortableList.IndexOfMin ( )

Returns the object of the list whose value is minimum.

Returns
The minimum object in the list

◆ Insert()

void Pathfinding.SortableList.Insert ( int Index,
object O )

IList implementation. Inserts an objects at a specified index. Cannot be used if the list has its KeepSorted property set to true.

Parameters
IndexThe index before which the object must be added.
OThe object to add.
Exceptions
ArgumentExceptionThe SortableList is set to use object's IComparable interface, and the specifed object does not implement this interface.
ArgumentOutOfRangeExceptionIndex is less than zero or Index is greater than Count.
InvalidOperationExceptionIf the object is added at the specify index, the list will not be sorted any more and the KeepSorted property is set to true.

◆ InsertRange()

void Pathfinding.SortableList.InsertRange ( int Index,
ICollection C )

Inserts a collection of objects at a specified index. Should not be used if the list is the KeepSorted property is set to true.

Parameters
IndexThe index before which the objects must be added.
CThe object to add.
Exceptions
ArgumentExceptionThe SortableList is set to use objects's IComparable interface, and the specifed object does not implement this interface.
ArgumentOutOfRangeExceptionIndex is less than zero or Index is greater than Count.
InvalidOperationExceptionIf the object is added at the specify index, the list will not be sorted any more and the KeepSorted property is set to true.

◆ LimitNbOccurrences()

void Pathfinding.SortableList.LimitNbOccurrences ( object Value,
int NbValuesToKeep )

Limits the number of occurrences of a specified value. Same values are equals according to the Equals() method of objects in the list. The first occurrences encountered are kept.

Parameters
ValueValue whose occurrences number must be limited.
NbValuesToKeepNumber of occurrences to keep

◆ Remove()

void Pathfinding.SortableList.Remove ( object Value)

IList implementation. Idem ArrayList

Parameters
ValueThe object whose value must be removed if found in the list.

◆ RemoveAt()

void Pathfinding.SortableList.RemoveAt ( int Index)

IList implementation. Idem ArrayList

Parameters
IndexIndex of object to remove.

◆ RemoveDuplicates()

void Pathfinding.SortableList.RemoveDuplicates ( )

Removes all duplicates in the list. Each value encountered will have only one representant.

◆ Sort()

void Pathfinding.SortableList.Sort ( )

Sorts the elements in the list using ArrayList.Sort. Does nothing if the list is already sorted.

◆ ToString()

override string Pathfinding.SortableList.ToString ( )

Object.ToString() override. Build a string to represent the list.

Returns
The string refecting the list.

Property Documentation

◆ AddDuplicates

bool Pathfinding.SortableList.AddDuplicates
getset

If set to true, it will not be possible to add an object to the list if its value is already in the list.

◆ Capacity

int Pathfinding.SortableList.Capacity
getset

Idem ArrayList

◆ Count

int Pathfinding.SortableList.Count
get

IList.ICollection implementation. Idem ArrayList

◆ IsFixedSize

bool Pathfinding.SortableList.IsFixedSize
get

IList implementation. Idem ArrayList

◆ IsReadOnly

bool Pathfinding.SortableList.IsReadOnly
get

IList implementation. Idem ArrayList

◆ IsSorted

bool Pathfinding.SortableList.IsSorted
get

'Get only' property that indicates if the list is sorted.

◆ IsSynchronized

bool Pathfinding.SortableList.IsSynchronized
get

IList.ICollection implementation. Idem ArrayList

◆ KeepSorted

bool Pathfinding.SortableList.KeepSorted
getset

Get : Indicates if the list must be kept sorted from now on. Set : Tells the list if it must stay sorted or not. Impossible to set to true if the list is not sorted. KeepSorted==true implies that IsSorted==true.

Exceptions
InvalidOperationExceptionCannot be set to true if the list is not sorted yet.

◆ SyncRoot

object Pathfinding.SortableList.SyncRoot
get

IList.ICollection implementation. Idem ArrayList

◆ this[int Index]

object Pathfinding.SortableList.this[int Index]
getset

IList implementation. Gets - or sets - object's value at a specified index. The set operation is impossible if the KeepSorted property is set to true.

Exceptions
ArgumentOutOfRangeExceptionIndex is less than zero or Index is greater than Count.
InvalidOperationException[] operator cannot be used to set a value if KeepSorted property is set to true.