Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Properties | Protected Member Functions | List of all members
Loyc.Collections.WListProtected< T > Class Template Reference

WList implementation in which the WList operations are only accessible to a derived class. More...


Source file:
Inheritance diagram for Loyc.Collections.WListProtected< T >:
Loyc.Collections.WListBase< T > Loyc.Collections.FWList< T > Loyc.Collections.WList< T >

Remarks

WList implementation in which the WList operations are only accessible to a derived class.

Template Parameters
TThe type of elements in the list

This base class is used in the same way one would use protected inheritance in C++: it provides the derived class with access to a FWList/WList, but it does not allow users of the derived class to access the list.

I had planned to use this base class as an optimization to help implement Loyc trees, but I didn't end up using it. Still, it could be useful someday as a base class of a memory-critical class that wants a mutable WList.

By default, the list will act like a FWList. If you want the list to act like an WList instead, override AdjustWListIndex and GetWListEnumerator as follows:

protected override int AdjustWListIndex(int index, int size)
{ return Count - size - index; }
protected virtual IEnumerator&lt;T> GetWListEnumerator()
{ return GetRVListEnumerator(); }

Properties

byte UserByte [get, set]
 An additional byte that the derived class can optionally use. More...
 
int BlockChainLength [get]
 Gets the number of blocks used by this list. More...
 

Protected Member Functions

virtual int AdjustWListIndex (int index, int size)
 This method implements the difference between FWList and WList: In FWList it returns index, but in WList it returns Count-size-index. More...
 
 WListProtected (WListProtected< T > original, bool takeOwnership)
 
GetAt (int index)
 Gets an item from a FWList or WList at the specified index. More...
 
void SetAt (int index, T value)
 Sets an item in a FWList or WList at the specified index. More...
 
void Add (T item)
 Inserts an item at the "front" of the list, which is index 0 for FWList, or Count for WList. More...
 
void Insert (int index, T item)
 
void RemoveAt (int index)
 
int IndexOf (T item)
 Searches for the specified object and returns the zero-based index of the first occurrence (lowest index) within the entire FVList. More...
 
bool Contains (T item)
 
void CopyTo (T[] array, int arrayIndex)
 
bool Remove (T item)
 
virtual IEnumerator< T > GetIEnumerator ()
 
FVList< T >.Enumerator GetVListEnumerator ()
 
VList< T >.Enumerator GetRVListEnumerator ()
 
void AddRange (IEnumerator< T > items)
 
void RemoveAtDff (int distanceFromFront)
 
void RemoveRangeBase (int distanceFromFront, int count)
 
void AddRangeBase (IList< T > items, bool isRWList)
 
void InsertRangeAtDff (int distanceFromFront, IList< T > items, bool isRWList)
 
void InsertAtDff (int distanceFromFront, T item)
 
GetAtDff (int distanceFromFront)
 Gets an item WITHOUT doing a range check More...
 
void SetAtDff (int distanceFromFront, T item)
 Sets an item WITHOUT doing a range or mutability check More...
 
FVList< T > ToFVList ()
 Returns this list as a FVList; if this is a WList, the order of the elements is reversed at the same time. More...
 
VList< T > ToVList ()
 Returns this list as a VList; if this is a FWList, the order of the elements is reversed at the same time. More...
 

Member Function Documentation

void Loyc.Collections.WListProtected< T >.Add ( item)
inlineprotected

Inserts an item at the "front" of the list, which is index 0 for FWList, or Count for WList.

virtual int Loyc.Collections.WListProtected< T >.AdjustWListIndex ( int  index,
int  size 
)
inlineprotectedvirtual

This method implements the difference between FWList and WList: In FWList it returns index, but in WList it returns Count-size-index.

Parameters
indexIndex to adjust
sizeNumber of elements being accessed or removed

Solely as an optimization, FWList and WList also have separate versions of this[], InsertAt and RemoveAt.

Reimplemented in Loyc.Collections.WList< T >, and Loyc.Collections.FWList< T >.

T Loyc.Collections.WListProtected< T >.GetAt ( int  index)
inlineprotected

Gets an item from a FWList or WList at the specified index.

T Loyc.Collections.WListProtected< T >.GetAtDff ( int  distanceFromFront)
inlineprotected

Gets an item WITHOUT doing a range check

int Loyc.Collections.WListProtected< T >.IndexOf ( item)
inlineprotected

Searches for the specified object and returns the zero-based index of the first occurrence (lowest index) within the entire FVList.

Parameters
itemItem to locate (can be null if T can be null)
Returns
Index of the item, or -1 if it was not found.

This method determines equality using the default equality comparer EqualityComparer.Default for T, the type of values in the list.

This method performs a linear search; therefore, this method is an O(n) operation, where n is Count.

void Loyc.Collections.WListProtected< T >.SetAt ( int  index,
value 
)
inlineprotected

Sets an item in a FWList or WList at the specified index.

void Loyc.Collections.WListProtected< T >.SetAtDff ( int  distanceFromFront,
item 
)
inlineprotected

Sets an item WITHOUT doing a range or mutability check

FVList<T> Loyc.Collections.WListProtected< T >.ToFVList ( )
inlineprotected

Returns this list as a FVList; if this is a WList, the order of the elements is reversed at the same time.

This operation marks the items of the FWList or WList as immutable. You can still modify the list afterward, but some or all of the list may have to be copied.

VList<T> Loyc.Collections.WListProtected< T >.ToVList ( )
inlineprotected

Returns this list as a VList; if this is a FWList, the order of the elements is reversed at the same time.

This operation marks the items of the FWList or WList as immutable. You can still modify the list afterward, but some or all of the list may have to be copied.

Property Documentation

int Loyc.Collections.WListProtected< T >.BlockChainLength
getprotected

Gets the number of blocks used by this list.

You might look at this property when optimizing your program, because the runtime of some operations increases as the chain length increases. This property runs in O(BlockChainLength) time. Ideally, BlockChainLength is proportional to log_2(Count), but if you produced the FWList by converting it from a FVList, certain FVList usage patterns can produce long chains.

byte Loyc.Collections.WListProtected< T >.UserByte
getsetprotected

An additional byte that the derived class can optionally use.

Used by Loyc.