>Hmm, doing   name=: p{name   in O(1) space and O(n) time

Since you can do   name=:name,new_data   in  O(1) space it is possible to do  
name =: new_data , name  in O(1) space and O(n) time.  

The idea is to "shift in" the new data.  That is, append the data using the 
optimized appending code, then rotate the array by  >:#new_data  .

           name =: 'abcd'       
           name =: name , '123'  NB.  O(1)  
           name =: 4 |. name     NB. 4 -: >: # '123'
           name
        123abcd

I don't know how this scheme compares to the current implementation.  I suspect 
that's a question which must be answered empirically.  

If the scheme is superior, I suggest special casing each of:

           name =: name     ,  new_data
           name =: name     ,~ new_data

           name =: new_data ,  name
           name =: new_data ,~ name

-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to