<commit_before>'use strict'

let _edges = new WeakSet();

/*
 * A class for a Vertex data structure containing a key, data and edges
 *
 * @author <NAME>
 * @version 0.5.0
 *
 * @class
 */
class Vertex {

  /*
   * A static method that compares two vertexes for equality.
   * @returns {boolean} true if they are equal, false otherwise
   */
  static equal(n1, n2){
    n1 = JSON.stringify(n1);
    n2 = JSON.stringify(n2);
    return n1 === n2;
  }

  /* Creates an instance of Vertex.
   *
   * @constructor
   * @this {Vertex}
   * @param {string|number} key - The key of the Vertex, used as a reference
   * @param {object} data - The data of the Vertex, can be any object
   */
  constructor(key = null, data = null){
    this.key = key;
    this.data = data;
    this.degree = 0;
  }

  addEdgeTo(target){
    if(!_edges.has(target)){
      _edges.add(target);
      this.degree += _edges.has(target)? 1 : 0;
    }
  }

  hasEdgeTo(target){
    return _edges.has(target)
  }

  deleteEdgeTo(target){
    if(_edges.has(target)){
      _edges.delete(target);
      this.degree -= _edges.has(target)? 0 : 1;
    }
  }

  /*
   * Returns a string representing the vertex.
   * @returns {string} The string representing the vertex.
   */
  toString(){ return JSON.stringify(this); }

  static fromString(str){ return JSON.parse(str); }

  serialize(){ return `${this.key}=${JSON.stringify(this.data)}`; }

  static deserialize(str){
    let [key, data] = str.split("=");
    let deserialized =  new Vertex(key, JSON.parse(data))
    return deserialized;
  }


  /*
   * Deletes the vertex neighbours, and nullifies key data. It also ensures
   * proper garbage collection by deallocating references to WeakMaps
   */
  clear(){
    this.data = null;
    this.key = null;
  }

}

module.exports = Vertex;
<commit_msg>Better memory managment. Now, we clear WeakMap when calling #clear()<commit_after>'use strict'

let _edges = new WeakSet();

/*
 * A class for a Vertex data structure containing a key, data and edges
 *
 * @author <NAME>
 * @version 0.5.0
 *
 * @class
 */
class Vertex {

  /*
   * A static method that compares two vertexes for equality.
   * @returns {boolean} true if they are equal, false otherwise
   */
  static equal(n1, n2){
    n1 = JSON.stringify(n1);
    n2 = JSON.stringify(n2);
    return n1 === n2;
  }

  /* Creates an instance of Vertex.
   *
   * @constructor
   * @this {Vertex}
   * @param {string|number} key - The key of the Vertex, used as a reference
   * @param {object} data - The data of the Vertex, can be any object
   */
  constructor(key = null, data = null){
    this.key = key;
    this.data = data;
    this.degree = 0;
  }

  addEdgeTo(target){
    if(!_edges.has(target)){
      _edges.add(target);
      this.degree += _edges.has(target)? 1 : 0;
    }
  }

  hasEdgeTo(target){
    return _edges.has(target)
  }

  deleteEdgeTo(target){
    if(_edges.has(target)){
      _edges.delete(target);
      this.degree -= _edges.has(target)? 0 : 1;
    }
  }

  /*
   * Returns a string representing the vertex.
   * @returns {string} The string representing the vertex.
   */
  toString(){ return JSON.stringify(this); }

  static fromString(str){ return JSON.parse(str); }

  serialize(){ return `${this.key}=${JSON.stringify(this.data)}`; }

  static deserialize(str){
    let [key, data] = str.split("=");
    let deserialized =  new Vertex(key, JSON.parse(data))
    return deserialized;
  }


  /*
   * Deletes the vertex neighbours, and nullifies key data. It also ensures
   * proper garbage collection by deallocating references to WeakMaps
   */
  clear(){
    _edges = new WeakSet();
    this.data = null;
    this.key = null;
    this.degree = 0;
  }

}

module.exports = Vertex;

{'fraction_non_alphanumeric': 0.1348314606741573, 'fraction_numerical': 0.00882825040128411, 'mean_word_length': 2.8036622583926754, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '578549', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1228, 'n_words': 364}