ADTVector

The Vector module implements resizable container. It is fast to append to end of array. Insert data at random locations then this container is not suitable for.

WARNING: The VectorOfByte implementation is not type safe and the developer must ensure that no GC data is placed in the array. Any data can be pushed to this Vector. VectorOfByte should be extended with a concrete type safe interface.

The follow classes are defined
  • VectorOfByte (Ref. warning above.)

  • VectorOfLongInt

  • VectorOfLongReal

  • VectorOfString

Other types can be implemented by method of type extension without much overhead.

Const

INIT_SIZE* = 64;

Types

VectorValue* = RECORD END;
Vector* = POINTER TO VectorDesc;
VectorDesc* = RECORD
        last : LONGINT;
    END;
VectorByteValue* = RECORD (VectorValue) byte- : SYSTEM.BYTE END;
VectorOfByte* = POINTER TO VectorOfByteDesc;
VectorLongIntValue* = RECORD (VectorValue) longint- : LONGINT END;
VectorOfLongInt* = POINTER TO VectorOfLongIntDesc;
VectorLongRealValue* = RECORD (VectorValue) longreal- : LONGREAL END;
VectorOfLongReal* = POINTER TO VectorOfLongRealDesc;
VectorStringValue* = RECORD (VectorValue) string- : String.STRING END;
VectorOfString* = POINTER TO VectorOfStringDesc;

Procedures

Vector.Size

PROCEDURE (this : Vector) Size*(): LONGINT;

Vector.Capacity

Capacity of array. Must be reimplemented.

PROCEDURE (this : Vector) Capacity*(): LONGINT;

Vector.Reserve

Resize storage to accomodate capacity. Must be reimplemented.

PROCEDURE (this : Vector) Reserve*(capacity  : LONGINT);

Vector.Resize

Resize vector potential discarding data

PROCEDURE (this : Vector) Resize*(capacity  : LONGINT);

Vector.Shrink

Shrink storage. Must be reimplemented.

PROCEDURE (this : Vector) Shrink*();

Vector.Clear

Clear Vector to zero size

PROCEDURE (this : Vector) Clear*();

Vector.Reverse

Reverse array in-place

PROCEDURE (this : Vector) Reverse*();

Vector.Shuffle

Random shuffle array in-place

PROCEDURE (this : Vector) Shuffle*();

Vector.Sort

Sort array in-place (QuickSort)

PROCEDURE (this : Vector) Sort*;

VectorOfByte.InitRaw

Initialize

PROCEDURE (this : VectorOfByte) InitRaw*(size : LONGINT; itemSize := 1 : LONGINT);

VectorOfByte.Capacity

Item capacity of vector

PROCEDURE (this : VectorOfByte) Capacity*(): LONGINT;

VectorOfByte.Reserve

Resize storage to accomodate capacity

PROCEDURE (this : VectorOfByte) Reserve*(capacity  : LONGINT);

VectorOfByte.Shrink

Shrink storage

PROCEDURE (this : VectorOfByte) Shrink*();

VectorOfByte.FillRaw

Fill vector with capacity values, overwriting content and possible resize vector

PROCEDURE (this : VectorOfByte) FillRaw*(capacity : LONGINT; value := 0 : SYSTEM.BYTE);

VectorOfByte.GetRaw

Get raw data from array

PROCEDURE (this : VectorOfByte) GetRaw*(idx : LONGINT; VAR dst : ARRAY OF SYSTEM.BYTE);

VectorOfByte.SetRaw

Set raw data from src

PROCEDURE (this : VectorOfByte) SetRaw*(idx : LONGINT; src- : ARRAY OF SYSTEM.BYTE);

VectorOfByte.AppendRaw

Append raw data

PROCEDURE (this : VectorOfByte) AppendRaw*(src- : ARRAY OF SYSTEM.BYTE);

VectorOfLongInt.Init

Initialize

PROCEDURE (this : VectorOfLongInt) Init*(size := INIT_SIZE : LONGINT);

VectorOfLongInt.Capacity

Item capacity of vector

PROCEDURE (this : VectorOfLongInt) Capacity*(): LONGINT;

VectorOfLongInt.Reserve

Resize storage to accomodate capacity

PROCEDURE (this : VectorOfLongInt) Reserve*(capacity  : LONGINT);

VectorOfLongInt.Shrink

Shrink storage

PROCEDURE (this : VectorOfLongInt) Shrink*();

VectorOfLongInt.BinaryFind

Find position in array. Expect array to be sorted in ascending order. Return -1 if not found.

PROCEDURE (this : VectorOfLongInt) BinaryFind*(value : LONGINT): LONGINT;

VectorOfLongInt.BinarySearch

Find position in array where value should be inserted to keep array sorted.

Expect array to be sorted in ascending order.

PROCEDURE (this : VectorOfLongInt) BinarySearch*(value : LONGINT): LONGINT;

VectorOfLongInt.Fill

Fill vector with capacity values, overwriting content and possible resize vector

PROCEDURE (this : VectorOfLongInt) Fill*(capacity : LONGINT; value := 0 : LONGINT);

VectorOfLongInt.Append

Append raw data

PROCEDURE (this : VectorOfLongInt) Append*(value : LONGINT);

VectorOfLongInt.At

Return value at idx

PROCEDURE (this : VectorOfLongInt) At*(idx : LONGINT) : LONGINT;

VectorOfLongInt.Set

Set value at idx

PROCEDURE (this : VectorOfLongInt) Set*(idx, value : LONGINT);

VectorOfLongInt.Pop

Pop last value

PROCEDURE (this : VectorOfLongInt) Pop*(VAR value : LONGINT) : BOOLEAN;

VectorOfLongReal.Init

Initialize

PROCEDURE (this : VectorOfLongReal) Init*(size := INIT_SIZE : LONGINT);

VectorOfLongReal.Capacity

Item capacity of vector

PROCEDURE (this : VectorOfLongReal) Capacity*(): LONGINT;

VectorOfLongReal.Reserve

Resize storage to accomodate capacity

PROCEDURE (this : VectorOfLongReal) Reserve*(capacity  : LONGINT);

VectorOfLongReal.Shrink

Shrink storage

PROCEDURE (this : VectorOfLongReal) Shrink*();

VectorOfLongReal.BinarySearch

Find position in array where value should be inserted to keep array sorted. Expect array to be sorted in ascending order.

PROCEDURE (this : VectorOfLongReal) BinarySearch*(value : LONGREAL): LONGINT;

VectorOfLongReal.Fill

Fill vector with capacity values, overwriting content and possible resize vector

PROCEDURE (this : VectorOfLongReal) Fill*(capacity : LONGINT; value := 0.0 : LONGREAL);

VectorOfLongReal.Append

Append value to end of vector

PROCEDURE (this : VectorOfLongReal) Append*(value : LONGREAL);

VectorOfLongReal.At

Return value at idx

PROCEDURE (this : VectorOfLongReal) At*(idx : LONGINT) : LONGREAL;

VectorOfLongReal.Set

Set value at idx

PROCEDURE (this : VectorOfLongReal) Set*(idx : LONGINT; value : LONGREAL);

VectorOfLongReal.Pop

Pop last value

PROCEDURE (this : VectorOfLongReal) Pop*(VAR value : LONGREAL) : BOOLEAN;

VectorOfString.Init

Initialize

PROCEDURE (this : VectorOfString) Init*(size := INIT_SIZE : LONGINT);

VectorOfString.Capacity

Item capacity of vector

PROCEDURE (this : VectorOfString) Capacity*(): LONGINT;

VectorOfString.Reserve

Resize storage to accomodate capacity

PROCEDURE (this : VectorOfString) Reserve*(capacity  : LONGINT);

VectorOfString.Shrink

Shrink storage

PROCEDURE (this : VectorOfString) Shrink*();

VectorOfString.BinarySearch

Find position in array where value should be inserted to keep array sorted. Expect array to be sorted in ascending order.

PROCEDURE (this : VectorOfString) BinarySearch*(value : ARRAY OF CHAR): LONGINT;

VectorOfString.Fill

Fill vector with capacity values, overwriting content and possible resize vector

PROCEDURE (this : VectorOfString) Fill*(capacity : LONGINT; value : ARRAY OF CHAR);

VectorOfString.Append

Append string to end of vector

PROCEDURE (this : VectorOfString) Append*(value : ARRAY OF CHAR);

VectorOfString.At

Return value at idx

PROCEDURE (this : VectorOfString) At*(idx : LONGINT) : String.STRING;

VectorOfString.Set

Set value at idx

PROCEDURE (this : VectorOfString) Set*(idx : LONGINT; value : ARRAY OF CHAR);

VectorOfString.Pop

Pop last value

PROCEDURE (this : VectorOfString) Pop*(VAR value : String.STRING) : BOOLEAN;