View Single Post
  #18  
Old 10-12-2008, 02:32 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Programmer View Post
Zzz...

PHP Code:
function onCreated()
{
    
temp.dataSet = {16425820100541000523};
    
    echo(
temp.dataSet);
    
temp.dataSet selectionSort(temp.dataSet);
    echo(
temp.dataSet);
    
    
temp.dataSet null;
    
temp.dataSet.destroy();
}

function 
selectionSort(temp.data)
{
    for (
0temp.data.size() - 1a++)
    {
        for (
1temp.data.size(); b++)
        {
            if (
temp.data[b] < temp.data[a])
            {
                
result temp.data[b];
                
temp.data[b] = temp.data[a];
                
temp.data[a] = result;
            }
        }
    }
    
    return 
temp.data;

That would cause an error because temp.dataSet is not an object with a destroy() function. And temp variables are destroyed automatically anyways when the function is over, no need to set it to null. Also, function parameters are automatically temp, you don't need to specify it. It's also less costly to send the array by reference using temp.dataSet.link() rather than duplicating it.
PHP Code:
function onCreated() {
  
temp.dataset = {16425820100541000523};

  echo(
dataset);
  
this.selectionsort(dataset.link());
  echo(
dataset);
}
function 
selectionsort(data) {
  
temp.0;
  
temp.0;
  
temp.tmp 0;

  for (
0data.size() - 1a++) {
    for (
1data.size(); b++) {
      if (
data[b] < data[a]) {
        
tmp data[b];
        
data[b] = data[a];
        
data[a] = tmp;
      }
    }
  }

Once a temp variable is initialized it can be referenced without using the temp prefix, however using the prefix is marginally faster.

Python is superior though.
__________________
Reply With Quote