nodes: 0, module; 1, function_definition; 2, function_name:insert_graph; 3, parameters; 4, block; 5, identifier:cur; 6, identifier:nodelist; 7, identifier:edgelist; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, if_statement; 12, if_statement; 13, if_statement; 14, expression_statement; 15, expression_statement; 16, identifier:encoded_data; 17, None; 18, comment:"""Insert a graph into the cache.
  
      A graph is stored by number of nodes, number of edges and a
      json-encoded list of edges.
  
      Args:
          cur (:class:`sqlite3.Cursor`): An sqlite3 cursor. This function
              is meant to be run within a :obj:`with` statement.
          nodelist (list): The nodes in the graph.
          edgelist (list): The edges in the graph.
          encoded_data (dict, optional): If a dictionary is provided, it
              will be populated with the serialized data. This is useful for
              preventing encoding the same information many times.
  
      Notes:
          This function assumes that the nodes are index-labeled and range
          from 0 to num_nodes - 1.
  
          In order to minimize the total size of the cache, it is a good
          idea to sort the nodelist and edgelist before inserting.
  
      Examples:
          >>> nodelist = [0, 1, 2]
          >>> edgelist = [(0, 1), (1, 2)]
          >>> with pmc.cache_connect(':memory:') as cur:
          ...     pmc.insert_graph(cur, nodelist, edgelist)
  
          >>> nodelist = [0, 1, 2]
          >>> edgelist = [(0, 1), (1, 2)]
          >>> encoded_data = {}
          >>> with pmc.cache_connect(':memory:') as cur:
          ...     pmc.insert_graph(cur, nodelist, edgelist, encoded_data)
          >>> encoded_data['num_nodes']
          3
          >>> encoded_data['num_edges']
          2
          >>> encoded_data['edges']
          '[[0,1],[1,2]]'
  
      """; 19, comparison_operator:encoded_data is None; 20, block; 21, comparison_operator:'num_nodes' not in encoded_data; 22, block; 23, comparison_operator:'num_edges' not in encoded_data; 24, block; 25, comparison_operator:'edges' not in encoded_data; 26, block; 27, assignment; 28, call; 29, identifier:encoded_data; 30, None; 31, expression_statement; 32, string; 33, identifier:encoded_data; 34, expression_statement; 35, string; 36, identifier:encoded_data; 37, expression_statement; 38, string; 39, identifier:encoded_data; 40, expression_statement; 41, identifier:insert; 42, comment:"""
          INSERT OR IGNORE INTO graph(num_nodes, num_edges, edges)
          VALUES (:num_nodes, :num_edges, :edges);
          """; 43, attribute; 44, argument_list; 45, assignment; 46, string_content:num_nodes; 47, assignment; 48, string_content:num_edges; 49, assignment; 50, string_content:edges; 51, assignment; 52, identifier:cur; 53, identifier:execute; 54, identifier:insert; 55, identifier:encoded_data; 56, identifier:encoded_data; 57, dictionary; 58, subscript; 59, call; 60, subscript; 61, call; 62, subscript; 63, call; 64, identifier:encoded_data; 65, string; 66, identifier:len; 67, argument_list; 68, identifier:encoded_data; 69, string; 70, identifier:len; 71, argument_list; 72, identifier:encoded_data; 73, string; 74, attribute; 75, argument_list; 76, string_content:num_nodes; 77, identifier:nodelist; 78, string_content:num_edges; 79, identifier:edgelist; 80, string_content:edges; 81, identifier:json; 82, identifier:dumps; 83, identifier:edgelist; 84, keyword_argument; 85, identifier:separators; 86, tuple; 87, string; 88, string; 89, string_content:,; 90, string_content::
code: def insert_graph(cur, nodelist, edgelist, encoded_data=None):
      """Insert a graph into the cache.
  
      A graph is stored by number of nodes, number of edges and a
      json-encoded list of edges.
  
      Args:
          cur (:class:`sqlite3.Cursor`): An sqlite3 cursor. This function
              is meant to be run within a :obj:`with` statement.
          nodelist (list): The nodes in the graph.
          edgelist (list): The edges in the graph.
          encoded_data (dict, optional): If a dictionary is provided, it
              will be populated with the serialized data. This is useful for
              preventing encoding the same information many times.
  
      Notes:
          This function assumes that the nodes are index-labeled and range
          from 0 to num_nodes - 1.
  
          In order to minimize the total size of the cache, it is a good
          idea to sort the nodelist and edgelist before inserting.
  
      Examples:
          >>> nodelist = [0, 1, 2]
          >>> edgelist = [(0, 1), (1, 2)]
          >>> with pmc.cache_connect(':memory:') as cur:
          ...     pmc.insert_graph(cur, nodelist, edgelist)
  
          >>> nodelist = [0, 1, 2]
          >>> edgelist = [(0, 1), (1, 2)]
          >>> encoded_data = {}
          >>> with pmc.cache_connect(':memory:') as cur:
          ...     pmc.insert_graph(cur, nodelist, edgelist, encoded_data)
          >>> encoded_data['num_nodes']
          3
          >>> encoded_data['num_edges']
          2
          >>> encoded_data['edges']
          '[[0,1],[1,2]]'
  
      """
      if encoded_data is None:
          encoded_data = {}
  
      if 'num_nodes' not in encoded_data:
          encoded_data['num_nodes'] = len(nodelist)
      if 'num_edges' not in encoded_data:
          encoded_data['num_edges'] = len(edgelist)
      if 'edges' not in encoded_data:
          encoded_data['edges'] = json.dumps(edgelist, separators=(',', ':'))
  
      insert = \
          """
          INSERT OR IGNORE INTO graph(num_nodes, num_edges, edges)
          VALUES (:num_nodes, :num_edges, :edges);
          """
  
      cur.execute(insert, encoded_data)