namespace sys.core.lang
class ReadSlice
Represents a read-only block of memory given by address of the block and a size. Implements common block algorithms that work on immutable data. After the algorithm is finished, the Length property is adjusted in accordance to the actions taken by the algorithm, often the extent of the read. The final Length can't be greater than the initial Length: Length can only shrink.
A `ReadSlice` can only be instantiated based on persistent object whose lifetime must exceed the lifetime of the slice. Freeing the data is an error.
this{} = null;
this{ref const p: CArray};
this{ref const p: CArray, length: PtrSize};
this{ref const p: CArray, start: PtrSize, end: PtrSize};
this{ref const p: Vector};
this{ref const p: Vector, length: PtrSize};
this{ref const p: Vector, start: PtrSize, end: PtrSize};
this{ref const p: Small};
this{ref const p: Small, length: PtrSize};
this{ref const p: Short};
this{ref const p: Short, length: PtrSize};
this{ref const p: Byte};
this{ref const p: Byte, length: PtrSize};
this{ref const p: Word};
this{ref const p: Word, length: PtrSize};
this{ref const p: Int};
this{ref const p: Int, length: PtrSize};
this{ref const p: Long};
this{ref const p: Long, length: PtrSize};
this{ref const p: DWord};
this{ref const p: DWord, length: PtrSize};
this{ref const p: QWord};
this{ref const p: QWord, length: PtrSize};
this{ref const p: Float};
this{ref const p: Float, length: PtrSize};
this{ref const p: Double};
this{ref const p: Double, length: PtrSize};
this{ref const p: Char};
this{ref const p: Char, length: PtrSize};
this{ref const p: String};
this{ref const p: ReadSlice, length: PtrSize};
this{ref const p: ReadSlice, offset: PtrSize, length: PtrSize};
Constructs a new slice based on a persistent readable memory location and an optional size.
The size can't be greater than the size of the memory location and the size is not allowed to grow after creation, only shrink.
The provided memory location must not be freed before the slice is destroyed.
p | a vector of items |
---|---|
length | the length of the slice |
start | the start index |
end | the end index |
offset | an offset to use |
func FindIndex(item: T): PtrSize;
func FindIndex(item: T, start: PtrSize): PtrSize;
Searches for an item in the array and returns the first index at which it was found or -1 if the item was not found.
The search starts on an index given by the `start` parameter if present or from index 0 otherwise.
item | the item to search for |
---|---|
start | the start index for the search |
the index where the item was found
func FindFirst(b: CArray): PtrSize;
func FindFirst(b: Vector): PtrSize;
func FindFirst(b: CArray, start: PtrSize): PtrSize;
func FindFirst(b: Vector, start: PtrSize): PtrSize;
Searches for first occurrence of any of the input items from `b` in the array and returns the first index at which it was found or -1 if the item was not found.
The search starts on an index given by the `start` parameter if present or from index 0 otherwise.
b | the array of items to search for |
---|---|
start | the start position |
the index where the item was found
func RFindIndex(item: T): PtrSize;
func RFindIndex(item: T, val start: PtrSize): PtrSize;
Searches for an item or items in the array in reverse order and returns the first index from the back at which it was found or -1 if the item was not found.
The search starts on an index given by the `start` parameter if present or from index 0 otherwise.
item | the item to search for |
---|---|
start | the start index for the search |
the index where the item was found
func RFindFirst(b: CArray): PtrSize;
func RFindFirst(b: Vector): PtrSize;
func RFindFirst(b: CArray, val start: PtrSize): PtrSize;
func RFindFirst(b: Vector, val start: PtrSize): PtrSize;
Searches for first occurrence of any of the input items from `b` in the array in reverse order and returns the first index at which it was found or -1 if the item was not found.
The search starts on an index given by the `start` parameter if present or from index 0 otherwise.
b | the array of items to search for |
---|---|
start | the start position |
the index where the item was found
func BinaryIndex(item: T): PtrSize;
func BinaryIndex(item: T, start: PtrSize): PtrSize;
Searches for an item in the array and returns the first index at which it was found or -1 if the item was not found. It uses a binary search algorithm and the contents of the container must be sorted in ascending order. If the elements are not sorted, the result is unpredictable.
The search starts on an index given by the `start` parameter if present or from index 0 otherwise.
item | the item to search for |
---|---|
start | the start index for the search |
the index where the item was found
func Sum(): T;
Returns the sum of all the items in the array.
the sum
property Length: PtrSize
Reads and writes the length of the slice. Can not grow, only decrease.
property @index: T
Reads and writes a given index from the slice.
property SysDataPointer: Ptr; get;
Returns a pointer to the data from the slice.