Question: How do I swap two tables/Arrays in constant time?

Is there a way to swap the names of two Arrays without creating unnecessary copies?

 

The scenario is as follows. I want to repeatedly apply a function to a large Array. The new value in each cell depends on seveal cells of the old Array.  So on each iteration I need to keep track of two Arrays: A_old and A_new. At the end of the iteration I would like to swap A_old and A_new efficiently. This way I will only need the memory for two Arrays and will not need to spend the extra time copying.  

 

Michael

Please Wait...