class Hamster::Vector

def replace_suffix(from, suffix)

def replace_suffix(from, suffix)
  # new suffix can go directly after existing elements
  raise IndexError if from > @size
  root, levels = @root, @levels
  if (from >> (BITS_PER_LEVEL * (@levels + 1))) != 0
    # index where new suffix goes doesn't fall within current tree
    # we will need to deepen tree
    root = [root].freeze
    levels += 1
  end
  new_size = from + suffix.size
  root = replace_node_suffix(root, levels * BITS_PER_LEVEL, from, suffix)
  if !suffix.empty?
    levels.times { suffix = suffix.each_slice(32).to_a }
    root.concat(suffix)
    while root.size > 32
      root = root.each_slice(32).to_a
      levels += 1
    end
  else
    while root.size == 1 && levels > 0
      root = root[0]
      levels -= 1
    end
  end
  self.class.alloc(root.freeze, new_size, levels)
end