ArrayListMergeSorter
Short summary
This FB sorts the list using a mergesort, which has O(n*log(n)) runtime. For random data it is a bit faster than Timsort, else Timsort should be used. Needs to allocate extra memory while sorting, same size as currentContainerSize.
Caution: Due to the characteristics of a merge, a merge must be performed atomically. As a merge of two lists l1 and l2 can take up to l1.size compares. That implies that at the last cycle of the merge, an atomic operation that requires up to list.size/2 compares must be performed. Therefore the maxCycleCompares may be exceeded and set the maxCycleCompares to a value smaller than list.size/2 may not have the desired effect.
| Access | Abstract | Final | Extends | Implements |
|---|---|---|---|---|
| No | Yes | AbstractMergeBasedSorter | - |
UML Diagram
Parameters
none
Properties
className
Type: CNM_AbstractObject.ClassName
This abstract property returns the class name of the concrete object, …
Methods
clone
- Return type: CNM_AbstractObject.CNM_ReturnTypes.CloneResult
This method is used to create a new instance…
FB_Exit
- Parameters:
bInCopyCode(BOOL): TRUE: the exit method is called in order to leave the instance which will be copied afterwards (online change).
- Return type:
BOOL
Mark the object as deleted, as it staiys in the memory.…
instantSort
- Parameters:
size(UDINT): The size of the list to be sortedcontainer(POINTER TO CNM_CollectionInterfaces.CNM_AbstractObject.IObject): the container, that contains the list elementscomparator(CNM_CollectionInterfaces.CNM_AbstractObject.IComparator): the comparator that should be used for the sort. Must not be changed while sort is in processcurrentListVersion(__XWORD): the current version of the list, must change when the data in the list changes
- Return type: CNM_CollectionInterfaces.CNM_ReturnTypes.SingleExecutionResult
This method sorts the data structure instantly within one call. …
sort
- Parameters:
execute(BOOL): control bit to start or abort the sorting, needs to be active until the ExecutionState is SUCCESSsize(UDINT): The size of the list to be sortedcontainer(POINTER TO CNM_AbstractObject.IObject): the container, that contains the list elementscomparator(CNM_AbstractObject.IComparator): the comparator that should be used for the sort. Must not be changed while sort is in processcurrentListVersion(__XWORD): the current version of the list, must change when the data in the list changes
- Return type: CNM_ReturnTypes.SingleExecutionState
This method sorts the data structure. …
Code
Declaration
{attribute 'enable_dynamic_creation'}
FUNCTION_BLOCK FINAL ArrayListMergeSorter EXTENDS AbstractMergeBasedSorter
VAR
sortBuffer :POINTER TO CNM_AbstractObject.IObject;
END_VAR