Parameter
You can also set the maximum thread count in ColdFusion Administrator. Click Server Settings > Settings and specify the number of threads in Default Maximum Thread Count For Parallel Functions.
Determines the value associated with a key in a structure.
The value associated with a key in a structure; if a structure does not exist, the function throws an exception.
ColdFusion (2021 release): Introduced the following parameters:
structFind(structure, closure, [, parallel][, maxThreadCount] )
Structure functions; Structure functions in the Developing ColdFusion Applications
|
Parameter |
Description |
|
structure |
Structure that contains the value to return. |
|
key |
Key whose value to return. |
|
parallel |
True if you want to enable parallel programming. Note: Parallelism is supported only when the second parameter is closure . When the second parameter is 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>
The values are: 1 | 2 | 3 | 4 | 5 |
Cannot find f key in structure.
<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>
Sign in to your account