Whatever message this page gives is out now! Go check it out!
structFind(structure, closure, [, parallel][, maxThreadCount] )Parameter | Description |
structure | Structure that contains the value to return. |
closure | Takes a callback function. You can use this instead of the key value. |
key | Key whose value to return. You can also use this instead of the callback. |
parallel | True if you want to enable parallel programming. Note: Parallelism is supported only when the second parameter is a closure. When the second parameter is a key, paralellism is not supported. |
maxThreadCount | The number of threads the function can execute. The number of threads must be between 1-50. If the value exceeds 50, there is an exception. |
<cfscript>
myStruct=StructNew();
myStruct={a:1,b:2,c:3,d:4,e:5}; //Define structure keys
WriteOutput("The values are: ");
for (key in myStruct){ //Find keys in the struct
WriteOutput(StructFind(myStruct,#key#) & " | "); //Display the value if key is found
}
// Try to search for the key "f" that does not exist in myStruct
// Since the key is not in the struct, an error message is displayed
try{
StructFind(myStruct,"f");
}
catch (any e)
{
WriteOutput(e.message);
}
</cfscript><cfscript>
myStruct={a:1,b:2,c:3,d:4,e:5}; //Define structure keys
myFind=myStruct.find("c");
WriteOutput(myFind); // Displays value of key c that is 3
</cfscript><cfscript>
mystruct= Structnew("ordered");
for(i=1;i<=10000;i++){
mystruct.insert("key#i#","val#i#")
}
function callback(key,val){
if(isSimplevalue(val) && key eq 'key889')
return true
return false
}
writeoutput("<br> mystruct.find(callback,false)" & mystruct.find(callback))
writeoutput("<br> mystruct.find(callback,true):" & mystruct.find(callback,true,5));
writeoutput( "<br> mystruct.find(callback,true,10):" & mystruct.find(callback,true,10))
writeoutput( "<br> mystruct.find(callback,true,20):" & structfind(struct=mystruct,callback=callback,parallel=true,maxthreadcount=20))
writeoutput( "<br> mystruct.find(callback,true,40):" & structfind(struct=mystruct,callback=callback,parallel=true,maxthreadcount=40))
try{
structfind(struct=mystruct,callback=callback,parallel=true,maxthreadcount=-40)
}
catch(any e){
writeoutput("<br>Type: " & e.type & " Message:" & e.message )
}
try{
structfind(struct=mystruct,callback=callback,parallel=true,maxthreadcount=400)
}
catch(any e){
writeoutput("<br>Type: " & e.type & " Message:" & e.message )
}
</cfscript>