Class TgoValueList
Unit
Grijjy.Collections
Declaration
type TgoValueList<T:record> = class(TObject)
Description
A light-weight list of value types (primitive types and records). Differs from TList<T> in the following regards:
You cannot store reference types (objects, interfaces, strings or dynamic arrays) in the list.
It is more light-weight since it doesn't support noticications, comparers and only checks bounds with assertions (which can be turned off).
When requesting an item (using Items, First, Last etc.), it returns a Pointer to the type instead of the actual type. This can be both more efficient, and it allows you to directly modify the item in the list.
It grows in increments of 16 instead of doubling its size.
The pointer is of type TgoPtr<T>.P. It may be easier to declare your own pointer type as in PFoo = TgoPtr<TFoo>.P .
Note that you should not cache these pointers for long-term use as they become invalid when you modify the list (add or remove items).
Hierarchy
Overview
Internal Types
Methods
Properties
|
property Count: Integer read FCount write SetCount; |
|
property Items[constAIndex:Integer]: P read GetItem; |
Description
Internal Types
|
P = TgoPtr<T>.P; |
The pointer type for referencing items in this list.
|
Methods
|
constructor Create; |
Creates a new list. The list is initially emtpy and will grow in increments of 16 items.
|
|
procedure Clear; |
Clears the list.
|
|
function Add(const AValue: T): Integer; |
Adds an item to the end of the list.
Parameters
- AValue
- the item to
add .
Returns
The index of the added item |
|
procedure Insert(const AIndex: Integer; const AValue: T); |
Inserts an item at a given index into the list.
Parameters
- AIndex
- the location to
insert the item. An assertion is used when the index is out of bounds.
- AValue
- the item to add.
|
|
procedure Delete(const AIndex: Integer); |
Deletes an item from the list.
Parameters
- AIndex
- the index of the item to
delete . An assertion is used when the index is out of bounds.
|
|
procedure DeleteRange(const AIndex, ACount: Integer); |
Deletes a range of items from the list.
Parameters
- AIndex
- the index of the first item to delete
- ACount
- the number of items to delete
|
|
function First: P; |
Returns a pointer to the first item in the list. An assertion is used when the list is empty.
Note: You should not cache the returned pointer for long-term use as it is only valid as long as you don't modify the list.
|
|
function Last: P; |
Returns a pointer to the last item in the list. An assertion is used when the list is empty.
Note: You should not cache the returned pointer for long-term use as it is only valid as long as you don't modify the list.
|
|
function GetEnumerator: TEnumerator; |
Allows for for..in enumeration of the list. Since the enumerator returns pointers to the items, you use it like this:
var
Items: TgoValueList<TFoo>;
Item: TgoPtr<TFoo>.P;
begin
for Item in Items do...
end;
|
Properties
|
property Count: Integer read FCount write SetCount; |
The number of items in the list
|
|
property Items[constAIndex:Integer]: P read GetItem; |
The items in the list. Returns a pointer to the requested item.
Note: You should not cache the returned pointer for long-term use as it is only valid as long as you don't modify the list.
Parameters
- Index
- the index of the requested item. An assertion is used when the index is out of bounds.
|
Generated by P2PasDoc 0.13.0 on 2017-04-25 12:54:26
|