Object TPointerView

Unit

Declaration

type generic TPointerView<TElement> = object(TObject)

Description

An array view representing a slice (subsequence) of an array.

The view is read-only and can only shrink. Methods with pointer arguments are safe, such that pointers outside the view either yield an empty view or keep the view unchanged.

Methods Move* remove elements from the beginning, methods Cut* remove elements from the end, i.e.:

|----------leftOf(x)---------||--------------------rightWith(x)-----------------|
ppppppppppppppppppppppppppppppxxxxxxxxxxxxxxxxxxxxxxsssssssssssssssssssssssssssss  <- the initial array view
|-------------------leftWith(x)--------------------||---------rightOf(x)--------|

Methods View* return a new view. To and From are inclusive, while Until and After are exclusive, i.e.:

|--------viewLeftOf(x)-------||------------------viewRightWith(x)---------------|
ppppppppppppppppppppppppppppppxxxxxxxxxxxxxxxxxxxxxxsssssssssssssssssssssssssssss  <- the initial array view
|-------------------viewLeftWith(x)----------------||---------rightOf(x)--------|

To avoid confusion, whether indices should be 0-based or 1-based, signed or unsigned, most methods of this view are specified without refering to indices. Rather they use pointers or an amount of elements. E.g. rather than getting a slice of all elements after index k, you use moveBy to remove the first k elements.

Hierarchy

Overview

Nested Types

Public PElement = ˆTElement;
Published TElementToString = function (const e: TElement): string;

Fields

Public data: pelement;
Public dataend: pelement;

Methods

Public procedure init(firstelement: PElement; length: sizeint);
Public procedure init(firstelement, behindlastelement: PElement);
Public procedure init(const a: array of TElement);
Public function length: SizeInt;
Public function isEmpty: boolean; inline;
Public function isEqual(const other: TPointerView): boolean;
Public function isEqual(const other: array of telement): boolean;
Public function isInBounds(target: PElement): boolean; inline;
Public function isOnBounds(target: PElement): boolean; inline;
Public function getEnumerator: TPointerViewEnumerator; inline;
Public function rightOfFirst(delta: SizeUInt): boolean;
Public function rightWithLast(alength: SizeUInt): boolean;
Public procedure rightWith(target: PElement);
Public procedure rightOf(target: PElement);
Public function leftOfLast(delta: SizeUInt): boolean;
Public function leftWithFirst(alength: SizeUInt): boolean;
Public procedure leftOf(target: PElement);
Public procedure leftWith(target: PElement);
Public function count(const e: TElement): SizeUInt;
Public function joinToString(elementMap: TElementToString; const sep: string): string;
Public function viewLeftWith(newLast: PElement): TPointerView;
Public function viewLeftOf(newEnd: PElement): TPointerView;
Public function viewRightWith(newStart: PElement): TPointerView;
Public function viewRightOf(newStartSkip: PElement): TPointerView;

Description

Nested Types

Public PElement = ˆTElement;
 
Published TElementToString = function (const e: TElement): string;
 

Fields

Public data: pelement;
 
Public dataend: pelement;
 

Methods

Public procedure init(firstelement: PElement; length: sizeint);

Creates a view starting with an element of certain length.

Public procedure init(firstelement, behindlastelement: PElement);

Creates a view starting with an element (inclusive) until another element (exclusive).

Public procedure init(const a: array of TElement);

Creates a view for a (dynamic) array.

Public function length: SizeInt;

Number of elements in the view.

Public function isEmpty: boolean; inline;

Tests whether the length zero.

Public function isEqual(const other: TPointerView): boolean;

Tests whether this view is equal to another view (same length and elements) (currently undefined if element is a string).

Public function isEqual(const other: array of telement): boolean;

Tests whether this view is equal to another view (same length and elements) (currently undefined if element is a string).

Public function isInBounds(target: PElement): boolean; inline;

Tests whether an element is in the view (0 <= index < length).

Public function isOnBounds(target: PElement): boolean; inline;

Tests whether an element is on the view (0 <= index <= length).

Public function getEnumerator: TPointerViewEnumerator; inline;

Enumerates all elements, copying each.

Public function rightOfFirst(delta: SizeUInt): boolean;

Removes delta many elements from the beginning.

Public function rightWithLast(alength: SizeUInt): boolean;

Take the last length elements

Public procedure rightWith(target: PElement);

Removes all elements before the target element.

Public procedure rightOf(target: PElement);

Removes all elements before the target element and the target element.

Public function leftOfLast(delta: SizeUInt): boolean;

Removes delta many elements from the end.

Public function leftWithFirst(alength: SizeUInt): boolean;

Set the length to length

Public procedure leftOf(target: PElement);

Removes all elements after the target element and the target element.

Public procedure leftWith(target: PElement);

Removes all elements after the target element.

Public function count(const e: TElement): SizeUInt;

Count how often an element occurs.

Public function joinToString(elementMap: TElementToString; const sep: string): string;
 
Public function viewLeftWith(newLast: PElement): TPointerView;

copy and leftWith.

Public function viewLeftOf(newEnd: PElement): TPointerView;

copy and leftOf.

Public function viewRightWith(newStart: PElement): TPointerView;

copy and rightWith.

Public function viewRightOf(newStartSkip: PElement): TPointerView;

copy and rightOf.


Generated by PasDoc 0.16.0.