<commit_before>'use strict';

var util = require('../util');
var is = require('../is');

var Element = require('./element');

// factory for generating edge ids when no id is specified for a new element
var idFactory = {
  prefix: {
    nodes: 'n',
    edges: 'e'
  },
  id: {
    nodes: 0,
    edges: 0
  },
  generate: function(cy, element, tryThisId){
    var json = is.element( element ) ? element._private : element;
    var group = json.group;
    var id = tryThisId != null ? tryThisId : this.prefix[group] + this.id[group];

    if( cy.getElementById(id).empty() ){
      this.id[group]++; // we've used the current id, so move it up
    } else { // otherwise keep trying successive unused ids
      while( !cy.getElementById(id).empty() ){
        id = this.prefix[group] + ( ++this.id[group] );
      }
    }

    return id;
  }
};

// represents a set of nodes, edges, or both together
var Collection = function(cy, elements, options){
  if( !(this instanceof Collection) ){
    return new Collection(cy, elements, options);
  }

  if( cy === undefined || !is.core(cy) ){
    util.error('A collection must have a reference to the core');
    return;
  }

  var ids = {};
  var indexes = {};
  var createdElements = false;
<commit_msg>fixes autogenerated ids with inferred group<commit_after>'use strict';

var util = require('../util');
var is = require('../is');

var Element = require('./element');

// factory for generating edge ids when no id is specified for a new element
var idFactory = {
  prefix: 'ele',
  id: 0,
  generate: function(cy, element, tryThisId){
    var json = is.element( element ) ? element._private : element;
    var id = tryThisId != null ? tryThisId : this.prefix + this.id;

    if( cy.getElementById(id).empty() ){
      this.id++; // we've used the current id, so move it up
    } else { // otherwise keep trying successive unused ids
      while( !cy.getElementById(id).empty() ){
        id = this.prefix + ( ++this.id );
      }
    }

    return id;
  }
};

// represents a set of nodes, edges, or both together
var Collection = function(cy, elements, options){
  if( !(this instanceof Collection) ){
    return new Collection(cy, elements, options);
  }

  if( cy === undefined || !is.core(cy) ){
    util.error('A collection must have a reference to the core');
    return;
  }

  var ids = {};
  var indexes = {};
  var createdElements = false;

{'fraction_non_alphanumeric': 0.1465553235908142, 'fraction_numerical': 0.0012526096033402922, 'mean_word_length': 2.9472817133443163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7114583', 'n_tokens_mistral': 735, 'n_tokens_neox': 717, 'n_words': 250}