nodes: 0, module; 1, function_definition; 2, function_name:calculate_keys_by_mapreduce_state; 3, parameters; 4, block; 5, identifier:cls; 6, identifier:mapreduce_state; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, for_statement; 11, return_statement; 12, comment:"""Calculate all shard states keys for given mapreduce.
  
      Args:
        mapreduce_state: MapreduceState instance
  
      Returns:
        A list of keys for shard states, sorted by shard id.
        The corresponding shard states may not exist.
      """; 13, comparison_operator:mapreduce_state is None; 14, block; 15, assignment; 16, identifier:i; 17, call; 18, block; 19, identifier:keys; 20, identifier:mapreduce_state; 21, None; 22, return_statement; 23, identifier:keys; 24, list; 25, identifier:range; 26, argument_list; 27, expression_statement; 28, expression_statement; 29, list; 30, attribute; 31, assignment; 32, call; 33, attribute; 34, identifier:shard_count; 35, identifier:shard_id; 36, call; 37, attribute; 38, argument_list; 39, attribute; 40, identifier:mapper; 41, attribute; 42, argument_list; 43, identifier:keys; 44, identifier:append; 45, call; 46, identifier:mapreduce_state; 47, identifier:mapreduce_spec; 48, identifier:cls; 49, identifier:shard_id_from_number; 50, call; 51, identifier:i; 52, attribute; 53, argument_list; 54, attribute; 55, argument_list; 56, identifier:cls; 57, identifier:get_key_by_shard_id; 58, identifier:shard_id; 59, call; 60, identifier:name; 61, attribute; 62, argument_list; 63, identifier:mapreduce_state; 64, identifier:key
code: def calculate_keys_by_mapreduce_state(cls, mapreduce_state):
      """Calculate all shard states keys for given mapreduce.
  
      Args:
        mapreduce_state: MapreduceState instance
  
      Returns:
        A list of keys for shard states, sorted by shard id.
        The corresponding shard states may not exist.
      """
      if mapreduce_state is None:
        return []
  
      keys = []
      for i in range(mapreduce_state.mapreduce_spec.mapper.shard_count):
        shard_id = cls.shard_id_from_number(mapreduce_state.key().name(), i)
        keys.append(cls.get_key_by_shard_id(shard_id))
      return keys