code: def AddWeight(self, path_segment_index, weight):
      
      if path_segment_index not in self._weight_per_index:
        raise ValueError('Path segment index not set.')
  
      self._weight_per_index[path_segment_index] += weight
  
      if weight not in self._indexes_per_weight:
        self._indexes_per_weight[weight] = []
  
      self._indexes_per_weight[weight].append(path_segment_index)
docs: Adds a weight for a specific path segment index.
  
      Args:
        path_segment_index: an integer containing the path segment index.
        weight: an integer containing the weight.
  
      Raises:
        ValueError: if the path segment weights do not contain
                    the path segment index.