/* --[HeaderFile:Start] QUICK SUMMARY: Non-Recursively tracks downstream through linked-list and returns an array of node#'s that are ordered by tier. USAGE: Allows for updating a section of a tree where the downstream child nodes DEPEND on the upstream parent nodes being EVALUATED FIRST. Function Summary: Input: An array representing a linked-list. Example: arr[10] = #(13,14); Node#10 has children nodes #13 and #14; Input: Starting Position to re-evaluate tree from. Output: An array with all downstream children ordered from lowest level to highest level: Example: Say we want to re-evaluate the tree below starting at node#10: The array returned would be: #(10, 13,14, 17,19, 16,15, 08); L4 __L5__ __L6__ __L7__ L8 Note: 13&14's position can be swapped. Any number on the SAME LEVEL can be in any order. Just as long as the results are outputted so that nodes belonging to the same level are grouped together. Diagram of node linkage. Say your start index number was 3 the function would return the array #(3,1,5) since that is as far as it takes to get to all the termination points when starting at node 3. ********************************************* || || || L L L L L L L L || || E E E E E E E E || || V V V V V V V V || || E E E E E E E E || || L L L L L L L L || || # # # # # # # # || || 1 2 3 4 5 6 7 8 || || : : : : : : : : || || : : : [01] : : : : || || : : : / : : : : || || : : [03]-[05] : : : : || || : : / : : : : || || : [2] [06] [13] : : : || || : / \ / / : : : || || [7] [04]-[10]--< [17] : : || || : \ : \ / : : || || : [8]-[09] : [14] [16] : || || : : \ : : \ / : || || : : [11] : : [19] : || || : : : : : : \ : || || : : : : : : [15]-[18] || || : : : : : : : : || || || ********************************************* This tree above is the one used in the debug function. */ --[HeaderFile:End] function collectDownStream childrenPointerArray --Array :An array where item[1] stores an array of all children of item[1]. startPoint --Integer:What node are you starting from? levelsDown --Integer:How many levels below the startPoint root will you go. Zero will return nothing. getAll --Boolean:If true, update ALL that is downstream from the point you are updating. &resortedArr --Array :Items extracted from childrenPointerArray in order you wished for. -- collectDownStream (cpAr) (sPnt) (lDwn) (gAll) (&srtA); --Function call for quick grab. =( --Function Summary: --Formats information stored in a linked list (childrenPointerArray) --Into a more useable format that allows me to update the linked-list tree --using the array outputted by this function. --childrenPointerArray (chip) Structure: --chip[1] = #(2,3,4); --This means that node#1 has children nodes 2,3,4. --Collectively, the entire "chip" array creates a linked-list. --This function is used to collect the objects to update in the correct order. local chip = childrenPointerArray; --for ease of coding. local cArr = #(); --Array of collected children. local lp01 = 1; --points at the FIRST full spot of the currently collected level. local lp02 = 1; --points at the LAST full spot of the currently collected level. local cDex = 0; --The child-index collected from the array. local jump = 0; --used to jump to next level after previous level is collected. local king = true; --keep looping when true. local subA = #(); --sub-array that we loop through. local curL = 0; --current level you are on. 0 is base level. --Start collecting from start value given: cArr[1] = startPoint; do( if( (levelsDown>curL)or(getAll) )then( curL = curL + 1; jump = 0; for LG = lp01 to lp02 do( subA = chip[ cArr[LG] ]; if(subA!=undefined)then( for cDex in subA do( jump=jump+1; append cArr cDex; ) ) ) if(jump>0)then( lp01 = lp02+1; --get first object of NEXT level just collected. lp02 = lp02+jump; --get last object of NEXT level just collected. )else( king = false; ); )else( king = false; ); )while(king); --Return what you have gathered. resortedArr = cArr; )--[FN:collectDownStream:] function debug_collectDownStream =( --test the function: --Harder Test: pcar = #(); --TOP OF TREE: pcar[7] = #(2,8); --root of tree is node #7. --LEVEL #2: pcar[2] = #(3,4); pcar[8] = #(9,11); --LEVEL #3: pcar[3 ] = #(1,5); pcar[4 ] = #(6,10); pcar[9 ] = undefined; pcar[11] = undefined; --LEVEL #4: pcar[1 ] = undefined; pcar[5 ] = undefined; pcar[6 ] = undefined; pcar[10] = #(13,14); --LEVEL #5: pcar[13] = undefined; pcar[14] = #(17,19); --LEVEL #6 pcar[17] = undefined; pcar[19] = #(15,16); --LEVEL #7 pcar[16] = undefined; pcar[15] = #(18); --MUST be in array even if just one value. --LEVEL #8 pcar[18] = undefined; local cpAr = pcar; local sPnt = 4; --the start point. 7 is the ROOT of the tree. local lDwn = 2; local gAll = true; local srtA = #(); collectDownStream (cpAr) (sPnt) (lDwn) (gAll) (&srtA); --print out results: for i = 1 to srtA.count do( print("srtA[" + i as string + "]==" + srtA[i] as string); )--[x] )--[x] debug_collectDownStream();
Goodbye to All That (2014)
9 years ago