Class are destined to control of sorted data.
tSortedArrayNew() --> SortedArray object tSortedArray() --> SortedArray object
ADD | Add new element to sorted array. |
DEL | Removes some data from SORTEDARRAY. |
DELITEM | Delete element from sorted array by index. |
GETDATA | Get element data by index in sorted array. |
GETFIRST | Get first item data are sorted array. |
GETITEM | Get item are sorted array by index. |
GETKEY | Get element keys by index in sorted array. |
GETLAST | Get last item data are sorted array. |
HARDSEEK | Hard seek element in sorted array. |
LEN | Returns count items into SORTEDARRAY. |
SEEK | Seek element in sorted array. |
SOFTSEEK | Soft seek element in sorted array. |
TSORTEDARRAYNEW | SORTEDARRAY constructor. |
sArr := tSortedArrayNew() sArr:Add("January" , {1 , "January" }) sArr:Add("February" , {2 , "February" }) sArr:Add("March" , {3 , "March" }) sArr:Add("April" , {4 , "April" }) sArr:Add("May" , {5 , "May" }) sArr:Add("June" , {6 , "June" }) sArr:Add("July" , {7 , "July" }) sArr:Add("August" , {8 , "August" }) sArr:Add("September", {9 , "September"}) sArr:Add("October" , {10, "October" }) sArr:Add("November" , {11, "November" }) sArr:Add("December" , {12, "December" }) ? sArr:Len() // 12 ? sArr:GetFirst() // { 4, April} ? sArr:GetLast() // { 9, September} ? sArr:Seek("May") // 9 ? sArr:Seek("Monday") // 13 ? sArr:SoftSeek("Monday") // 10 ? sArr:HardSeek("Monday") // 13 ? sArr:GetItem(3) // {December, { 12, December}} ? sArr:GetData(3) // { 12, December} ? sArr:DelItem(3) // .T. ? sArr:Len() // 11 ? sArr:GetItem(3) // {February, { 2, February}} ? sArr:GetData(3) // { 2, February}
No dependies of platform.
Add new element to sorted array.
Add(<nKey>, <Value>) --> .T./.F.
If adding is success then returns value is TRUE , else is FALSE
Add() is added new item to class SortedArray with key <nKey> and value <Value>. Every item of sorted array is array containes only two elements: key (<nKey>) and value (<Value>). Items with low keys <nKey> are sorted toward the top of the array. If <nKey> or <Value> not specified then attribute <Error> will be contain error description.
You can add several items with identical keys. In this case class SortedArray will contain all these items and item can be inserted at suitable place.
Removes some data from SORTEDARRAY.
Del(<nKey>, <Value>) --> .T. || .F. Delete(<nKey>, <Value>) --> .T. || .F. DelKey(<nKey>, <Value>) --> .T. || .F.
In successfully returns value is TRUE else is FALSE.
Del(), Delete(), DelKey() is deleted item from sorted array by key and value.
If parameters <nKey> or <Value> not spacified then methods returns FALSE and write error description to attribute <Error>.
When element with <nKey> and <Value> not found methods returns FALSE and write error description to attribute <Error>.
Delete element from sorted array by index.
DelItem(<nPos>) --> .T. || .F.
In successfully returns value is TRUE else FALSE.
DelItem() is removed item from sorted array by index and returns TRUE.
If <nPos> without of bound sorted array then method return FALSE and write to attribute <Error> error descriptions.
Get element data by index in sorted array.
GetData(<nPos>) --> data
Is returns data value by item index.
GetData() gets data value by item index in sorted array and returns it if found, otherwise it returns NIL. If index is without of bound sorted array or is NIL then attribute <Error> to be keep error description.
Get first item data are sorted array.
GetFirst() --> data value
No arguments
Is returns data value of first item sorted array.
GetFirst() gets data value first items sorted array and returns it.
If no items in sorted array it returns NIL.
Get item are sorted array by index.
GetItem(<nPos>) --> aItem
Is returns array that contain key value and data value.
GetItem() gets key value and data value by item index in sorted array and returns array containes it. In other case it returns NIL. If index is without of bound sorted array or is NIL then attribute <Error> to be keep error description.
Get element keys by index in sorted array.
GetKey(<nPos>) --> nKeyValue
Is returns key value by item index.
GetKey() gets key value by item index in sorted array and returns it if found, otherwise it returns NIL. If index is without of bound sorted array or is NIL then attribute <Error> to be keep error description.
Get last item data are sorted array.
GetLast() --> data value
No arguments
Is returns data value of last item sorted array.
GetLast() gets data value last added items in to sorted array and returns it. If no items in sorted array it returns NIL.
Hard seek element in sorted array.
HardSeek(<nKey>) --> nPos
Is returns item index whose key value is equal <nKey> if specified key value was found, otherwise it returns Len()+1.
HardSeek() calls method Seek() as Seek(<nKey>, .F.)
Returns count items into SORTEDARRAY.
Len() --> nCount
No arguments
Returns sorted array length.
Len() is returned sorted array length what equal lenght of <Items>.
If sorted array is empty, then method returns zero.
Seek element in sorted array.
Seek(<nKey>[, <lSoft>]) --> nPos
Is returns item index whose key value is equal <nKey> if specified key value was found, otherwise it returns Len()+1.
Seek() moves to the first item whose key is equal to <nKey>. If such a item is found, it becomes to current item and Seek() returns item index in sorted array, attribute <Found> sets to TRUE, otherwise it returns Len() +1 position and attribute <Found> sets to FALSE The positioning in sorted array is as followes: for normal (hard) seek (lSoft is .F.), the sorted array is positioned to Len() + 1; for a soft seek, the sorted array positioned to the first item whose key value is greather than specified key <nKey>. If no such item exist, the sorted array positioned to Len()+1 and returns Len() + 1 and sets attribute <Found> sets to FALSE.
Soft seek element in sorted array.
SoftSeek(<nKey>) --> nPos
Is returns item index whose key value is equal <nKey> if specified key value was found, otherwise it returns the first item whose key value is greather than specified key <nKey>.
SoftSeek() calls method Seek() as Seek(<nKey>, .T.)
SORTEDARRAY constructor.
tSortedArrayNew() --> SortedArray object tSortedArray() --> SortedArray object
No arguments
Returns new SORTEDARRAY object
tSortedArrayNew() is constructs and returns new sorted array object. That class can be used to storage, access, control sorted data.