subtract
Short summary
overwrites the content of this set with the set difference of this set and the given set Set difference: Elements present in one set but not in the other.
Example: Set A = 4 Set B = 4
Set difference (A - B): 2 Set difference (B - A): 6
Return: SUCCESS: if insert could made, error if object was already in the tree,
ABORTED: execute has a falling edge during insert,
BUSY: Insert is in Progress
ERROR: the passed collection where not valid / contained invalid Elements
IDLE: Currently no insert in progress
- Return type: CNM_ReturnTypes.SingleExecutionState
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| set | CNM_CollectionInterfaces.ISet | foreign set to construct substraction | input |
| execute | BOOL | If substract should be processed | input |
Code
Declaration
METHOD INTERNAL subtract :CNM_ReturnTypes.SingleExecutionState
VAR_INPUT
(*foreign set to construct substraction*)
set :CNM_CollectionInterfaces.ISet;
(*If substract should be processed*)
execute :BOOL;
END_VAR
VAR_INST
cycleManager :CNM_CycleManager.SimpleCycleManager;
changeIndex :__XWORD;
END_VAR
VAR
object :CNM_AbstractObject.IObject;
iterateState :CNM_ReturnTypes.SingleExecutionState;
insertOperationsThisCycle :__XWORD;
END_VAR
VAR CONSTANT
INIT :DINT := CNM_ReturnTypes.DefaultSteps.STEP.INIT;
PROCESSING :DINT := INIT + 1;
SUCCESS :DINT := CNM_ReturnTypes.DefaultSteps.STEP.SUCCESS;
ERROR :DINT := CNM_ReturnTypes.DefaultSteps.STEP.ERROR;
END_VAR
Implementation
IF THIS^.isObjectNull(set) THEN
subtract := CNM_ReturnTypes.SingleExecutionState.ERROR;
cycleManager.proceedWith(ERROR);
RETURN;
END_IF
insertOperationsThisCycle := 0;
REPEAT
cycleManager(execute := execute);
CASE cycleManager.step.current OF
INIT:
cycleManager.configuration.sequence.requireSuccessStep := FALSE;
IF ((THIS^.size = 0) OR_ELSE (set.size = 0)) THEN
cycleManager.proceedWith(SUCCESS);
subtract := CNM_ReturnTypes.SingleExecutionState.SUCCESS;
RETURN;
END_IF
IF THIS^.isObjectValid(THIS^.subtractIterator) THEN
THIS^.subtractIterator.destruct();
END_IF
IF (set.createNewIterator(iterator => THIS^.subtractIterator) <> CNM_ReturnTypes.SingleExecutionResult.SUCCESS)
THEN
cycleManager.proceedWith(ERROR);
subtract := CNM_ReturnTypes.SingleExecutionState.ERROR;
RETURN;
END_IF
THIS^.subtractIterator.iterate(execute := FALSE);
changeIndex := THIS^.changesToCollection;
cycleManager.proceed();
PROCESSING:
IF (changeIndex <> THIS^.changesToCollection) THEN
cycleManager.proceedWith(ERROR);
subtract := CNM_ReturnTypes.SingleExecutionState.ERROR;
RETURN;
END_IF
WHILE (( iterateState := THIS^.subtractIterator.iterate(execute := TRUE, object => object)) = CNM_ReturnTypes.SingleExecutionState.BUSY) DO
CASE THIS^.remove(object) OF
CNM_ReturnTypes.SingleExecutionResult.ERROR:
subtract := CNM_ReturnTypes.SingleExecutionState.ERROR;
cycleManager.proceedWith(ERROR);
RETURN;
END_CASE
insertOperationsThisCycle := (insertOperationsThisCycle + THIS^.treeHeight);
IF (insertOperationsThisCycle >= THIS^.maxCycleCompares) THEN
EXIT;
END_IF
END_WHILE
CASE iterateState OF
CNM_ReturnTypes.SingleExecutionState.SUCCESS:
THIS^.subtractIterator.destruct();
cycleManager.proceedWith(SUCCESS);
CNM_ReturnTypes.SingleExecutionState.ERROR:
THIS^.subtractIterator.destruct();
cycleManager.proceedWith(ERROR);
END_CASE
END_CASE
UNTIL
(insertOperationsThisCycle >= THIS^.maxCycleCompares) OR_ELSE
(cycleManager.state <> CNM_ReturnTypes.SingleExecutionState.BUSY)
END_REPEAT
subtract := cycleManager.state;