For anyone who might think it handy, I was helping
out Mark M with a way to delete an array element without resizing the array
after the deletion and came up with this solution
<cfscript>
function
ArrayDeleteAtPos(Array,Pos)
{
thisArrayLen =
ArrayLen(Array);
ArrayResize(Array,thisArrayLen+1);
ArraySwap(Array,Pos,thisArrayLen+1);
ArrayDeleteAt(Array,thisArrayLen+1);
return Array;
}
</cfscript>
An exmple
is
---------------------------------
<cfscript>
function
ArrayDeleteAtPos(Array,Pos)
{
thisArrayLen =
ArrayLen(Array);
ArrayResize(Array,thisArrayLen+1);
ArraySwap(Array,Pos,thisArrayLen+1);
ArrayDeleteAt(Array,thisArrayLen+1);
return
Array;
}
tmp = ArrayNew(1);
for (i=1; i LTE 1000;
i=i+1)
{tmp[i] = "item#i#";}
start = getTickCount();
tmp =
ArrayDeleteAtPos(tmp,4);
end =
getTickCount();
</cfscript>
<cfoutput>#Val(end-start)#</cfoutput>
<br>
<cfdump var="#tmp#">
---------------------------------
this will
delete the array element, but retain the array size
Have fun
Regards
Steve Onnis
Domain Concept Designs
+61 422
337 685
+61 3 9431 4249
| http://www.domainconceptdesigns.com
[EMAIL PROTECTED] |
http://www.cfcentral.com.au [EMAIL PROTECTED] |
http://www.devedit.com [EMAIL PROTECTED] | ||
("If you think it can't be done, you haven't asked me!") - Steve Onnis
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MX Downunder AsiaPac DevCon - http://mxdu.com/
