Here's the problem:
We have two linked lists and two update procedures, for an example:
Code: Select all
Structure first_struct
x.b
y.b
something.w
EndStructure
Structure second_struct
x.b
y.b
other.i
EndStructure
Global NewList first_list.first_struct()
Global NewList second_list.second_struct()
Procedure create_new_second_list_element(x.b, y.b, info.w)
;do something
EndProcedure
Procedure update_first_list()
ForEach first_list()
If condition
create_new_second_list_element(first_list()\x, first_list()\y, info)
EndIf
;do something (calculate new values)
;update x, y
first_list()\x = new_x_value
first_list()\y = new_y_value
;check if the element has to be destroyed
If condition
DeleteElement(first_list())
EndIf
Next first_list()
EndProcedure
Procedure update_second_list()
ForEach second_list()
; *******************************************************************
; <problem start>
; *******************************************************************
; If x or y values of the element from the first_list() from which
; was created very this element of the second_list() have changed,
; update the x and y values of this element in the second_list()
; according To the new x And y values of the first_list()'s element
; from which it was created
; If the element from the first_list() from which was created very
; this element of the second_list() has been meanwhile destroyed,
; destroy ALL corresponding elements from the second_list() too
; *******************************************************************
; <problem end>
; *******************************************************************
; NOTE:
; Since during each call of the update_first_list() there is a
; possibility of creating new second_list() elements,
; it is possible that many elements from the second_list() are
; created upon the same element from the first_list()
; So, if for the example one of the elements from the first_list()
; 'created' 4 elements in the second_list(), if that element from
; the first_list() has been destroyed, we have to destoy all 4
; elements from the second_list() created upon the element from
; the first_list()
; Or to say in a more simple way:
; The elements from the second_list() must 'know' to which element
; from the first_list() they belong
;do something
Next second_list()
EndProcedure
;main control loop
Repeat
;process window events etc.
update_first_list()
update_second_list()
ForEver
Is maybe possible to pass the pointer to the element from the first_list() when creating the new element from the second_list()? That way, every element from the second_list() would have the pointer to his corresponding element upon which it was created.
However I am not sure what happens when some element from the first_list() is destroyed? Do all remaining elements keep their adresses unchanged (so we don't have to change the pointers) or can, after deleting an element from the linked list, some other elements' addresses change?
And even if above could be done - what to do after some element from the first_list() is destroyed? How to identify all corresponding elements from the second_list() that have to be destroyed too? :-/
I hope I've managed to explain the problem in more or less understandable way.


