code: function( cy, elements, options ){
    if( cy === undefined || !is.core( cy ) ){
      util.error( 'A collection must have a reference to the core' );
      return;
    }
  
    let map = new Map();
    let createdElements = false;
  
    if( !elements ){
      elements = [];
    } else if( elements.length > 0 && is.plainObject( elements[0] ) && !is.element( elements[0] ) ){
      createdElements = true;
  
      // make elements from json and restore all at once later
      let eles = [];
      let elesIds = new Set();
  
      for( let i = 0, l = elements.length; i < l; i++ ){
        let json = elements[ i ];
  
        if( json.data == null ){
          json.data = {};
        }
  
        let data = json.data;
  
        // make sure newly created elements have valid ids
        if( data.id == null ){
          data.id = idFactory.generate( cy, json );
        } else if( cy.hasElementWithId( data.id ) || elesIds.has( data.id ) ){
          continue; // can't create element if prior id already exists
        }
  
        let ele = new Element( cy, json, false );
        eles.push( ele );
        elesIds.add( data.id );
      }
  
      elements = eles;
    }
  
    this.length = 0;
  
    for( let i = 0, l = elements.length; i < l; i++ ){
      let element = elements[i][0]; // [0] in case elements is an array of collections, rather than array of elements
      if( element == null ){  continue; }
  
      let id = element._private.data.id;
  
      if( options == null || ( options.unique && !map.has(id) ) ){
        map.set( id, {
          index: this.length,
          ele: element
        } );
  
        this[ this.length ] = element;
        this.length++;
      }
    }
  
    this._private = {
      cy: cy,
      map: map
    };
  
    // restore the elements if we created them from json
    if( createdElements ){
      this.restore();
    }
  }
docs: represents a set of nodes, edges, or both together