 
   addArray: ->
    n = lastArr.length
-   n *= 2
-   if n * struct.bytes > MAX_SIZE
-    n = Math.floor MAX_SIZE / struct.bytes
-
+   if n isnt MAX_SIZE
+    n = n << 1
+
+   capacity += n
    lastArr = TDS.Array struct, n
    lastViews = lastArr.views
    arrays.push lastArr



INT_SIZE = 16
MAX_SIZE = (1<<30) - (1<<3)


ITER_CHANGE_VIEW = 1
ITER_SUCCESS = 0
ITER_FAIL = -1

ArrayList = (struct) ->
 capacity = null
 arrays = null
 allViews = null
 sum = null

   @length = 0
   @struct = struct

   if capacity?
    @length = capacity
    n = capacity
    size = INT_SIZE
    ls = 0
    while true
     console.log 'creating ', size
     lastArr = TDS.Array struct, size
     lastViews = lastArr.views
     arrays.push lastArr
     allViews.push lastViews
     ls += size
     sum.push ls

     if n <= size
      i_lastArr = arrays.length-1
      i_lastPos = n
      i_lla = i_lastArr
      i_llp = n-1
      break

     n -= size
     if size isnt MAX_SIZE
      size = size << 1
   else
    capacity = INT_SIZE
    lastArr = TDS.Array struct, capacity
    lastViews = lastArr.views
    arrays.push lastArr
    allViews.push lastViews
    sum.push capacity

  begin: ->
   if @length is 0
