On 12/08/2010, at 2:34 PM, Seona Bellamy wrote:
> <cffunction name="downTree" hint="Returns the details of everything needed to 
> make an item" access="public" returntype="array" output="no">
>         <cfargument name="aItems" type="array" required="no" default="">
>         
>         <cfscript>
>             var result = arrayNew(1);
>             var i = 1;
>             var qItem = "";
>             
>             qItem = getItemMadeBy(aItems[1].id);
>             
>             if (qItem.recordcount) {
>                 result[1] = structNew();
>                 result[1].id = qItem.id;
>                 result[1].item = qItem.item;
>                 result[1].skill = qItem.skillname;
>                 result[1].makes = arguments.aItems;
>                 
>                 downTree(result);
>             }
>         </cfscript>
>         
>         <cfreturn result>
>     </cffunction>

I'm sure Geoff would have something like this for Eve by now. You can see with 
the function above that no matter how deep you recurse there is only ever going 
to be an item in the first position in the array, so there's definitely a 
problem. You could make a build tree like this (pseudocode):

function makeBuildTree() : struct {

        stDependencies = structNew();

        for all nextItem in allItems {
                if not structKeyExists(stDependencies, nextItem.id)
                        stDependencies[nextItem.id] = structNew();

                for all nextMadeThing in getItemsMadeBy(nextItem.id) {
                        if not structKeyExists(stDependencies, nextMadeThing.id)
                                stDependencies[nextMadeThing.id] = structNew();

                        stDependencies[nextMadeThing.id][nextItem.id] = 
stDependencies[nextItem.id];
                }
        }

        return stDependencies;
}

If you then cfdump a key in stDependencies you'd see a tree of ids showing what 
built what. You might then use the little known but usefuly recursive CF 
function structFindValue(returnValue[id], "", "all") to get an array of all the 
keys under a branch of the result.

HTH,
Robin (who should get back to some project work)

                 
        ROBIN HILLIARD
Chief Technology Officer
ro...@rocketboots.com.au

RocketBoots Pty Ltd
Level 11
189 Kent Street
Sydney NSW 2001
Australia
Phone +61 2 9323 2507
Facsimile +61 2 9323 2501
Mobile +61 418 414 341
www.rocketboots.com.au   
                 


-- 
You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To post to this group, send email to cfaus...@googlegroups.com.
To unsubscribe from this group, send email to 
cfaussie+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/cfaussie?hl=en.

Reply via email to