parameters: (self, elements, typed, fixed, keys=None)
return_statement: return Value(loc, type_, bit_width)
docstring: Writes vector elements to the underlying buffer.
docstring_summary: Writes vector elements to the underlying buffer.
docstring_tokens: Writes vector elements to the underlying buffer .
function: def _CreateVector(self, elements, typed, fixed, keys=None):
      """Writes vector elements to the underlying buffer."""
      length = len(elements)
  
      if fixed and not typed:
        raise ValueError('fixed vector must be typed')
  
      # Figure out smallest bit width we can store this vector with.
      bit_width = max(self._force_min_bit_width, BitWidth.U(length))
      prefix_elems = 1  # Vector size
      if keys:
        bit_width = max(bit_width, keys.ElemWidth(len(self._buf)))
        prefix_elems += 2  # Offset to the keys vector and its byte width.
  
      vector_type = Type.KEY
      # Check bit widths and types for all elements.
      for i, e in enumerate(elements):
        bit_width = max(bit_width, e.ElemWidth(len(self._buf), prefix_elems + i))
  
        if typed:
          if i == 0:
            vector_type = e.Type
          else:
            if vector_type != e.Type:
              raise RuntimeError('typed vector elements must be of the same type')
  
      if fixed and not Type.IsFixedTypedVectorElementType(vector_type):
        raise RuntimeError('must be fixed typed vector element type')
  
      byte_width = self._Align(bit_width)
      # Write vector. First the keys width/offset if available, and size.
      if keys:
        self._WriteOffset(keys.Value, byte_width)
        self._Write(U, 1 << keys.MinBitWidth, byte_width)
  
      if not fixed:
        self._Write(U, length, byte_width)
  
      # Then the actual data.
      loc = len(self._buf)
      for e in elements:
        self._WriteAny(e, byte_width)
  
      # Then the types.
      if not typed:
        for e in elements:
          self._buf.append(e.StoredPackedType(bit_width))
  
      if keys:
        type_ = Type.MAP
      else:
        if typed:
          type_ = Type.ToTypedVector(vector_type, length if fixed else 0)
        else:
          type_ = Type.VECTOR
  
      return Value(loc, type_, bit_width)
function_tokens: def _CreateVector ( self , elements , typed , fixed , keys = None ) : length = len ( elements ) if fixed and not typed : raise ValueError ( 'fixed vector must be typed' ) # Figure out smallest bit width we can store this vector with. bit_width = max ( self . _force_min_bit_width , BitWidth . U ( length ) ) prefix_elems = 1 # Vector size if keys : bit_width = max ( bit_width , keys . ElemWidth ( len ( self . _buf ) ) ) prefix_elems += 2 # Offset to the keys vector and its byte width. vector_type = Type . KEY # Check bit widths and types for all elements. for i , e in enumerate ( elements ) : bit_width = max ( bit_width , e . ElemWidth ( len ( self . _buf ) , prefix_elems + i ) ) if typed : if i == 0 : vector_type = e . Type else : if vector_type != e . Type : raise RuntimeError ( 'typed vector elements must be of the same type' ) if fixed and not Type . IsFixedTypedVectorElementType ( vector_type ) : raise RuntimeError ( 'must be fixed typed vector element type' ) byte_width = self . _Align ( bit_width ) # Write vector. First the keys width/offset if available, and size. if keys : self . _WriteOffset ( keys . Value , byte_width ) self . _Write ( U , 1 << keys . MinBitWidth , byte_width ) if not fixed : self . _Write ( U , length , byte_width ) # Then the actual data. loc = len ( self . _buf ) for e in elements : self . _WriteAny ( e , byte_width ) # Then the types. if not typed : for e in elements : self . _buf . append ( e . StoredPackedType ( bit_width ) ) if keys : type_ = Type . MAP else : if typed : type_ = Type . ToTypedVector ( vector_type , length if fixed else 0 ) else : type_ = Type . VECTOR return Value ( loc , type_ , bit_width )