<commit_before>function GraphDatabase(_name, ds){
  /*
  *  ToDo: implement hashCode to get true unique identifier
  *  --- for now it simply checks if there is a hashCode already
  *  --- and if not then it creates one that simply returns the string
  */
  window.String.prototype.hashCode = window.String.prototype.hashCode || function(){
    return this;
  }
  
  /*
  *  Gets hashCode based on entity type & name
  */
  var _getHash = function(o){ return (o.type && o.name) ? (o.type + o.name).hashCode() : null; }

  /*
  *  Checks if user supplied datasource
  *  --- if so, make it the datasource
  *  --- if not, create blank datasource
  *  Note: datasource is an Object with 2 properties
  *  --- entities & edges. Both are arrays of objects
  */
  var _datasource = ds || {entities:[], edges:[]};
  
  var byKey = function(key, value){
    var result = {},
        dups = [];
    for (e in this){
      if (this[e][key] && !result[this[e][key]])
        result[this[e][key]] = this[e];
      else if (this[e][key] && $.inArray(this[e][key], dups) > -1)
        result[this[e][key]][this[e].uid] = this[e];
      else if (this[e][key]){
        var first = result[this[e][key]];
        delete result[this[e][key]];
        result[this[e][key]] = {};
        result[this[e][key]]['byKey'] = byKey;
        result[this[e][key]][first.uid] = first;
        result[this[e][key]][this[e].uid] = this[e];
        dups.push(this[e][key]);
      }
    }
    return typeof value === 'undefined' ? result : result[value];
  }
  
  /*
  *  Parses entities to object
  *  --- indexed by Unique Identifier
  *  @Params:
  *  --- @e: array of objects
  */
  var _parseEntities = function(e){
        var data = { uid: {}, name: {}, types: {}};
        for (var j = 0; j < e.length; j++){
          e[j].uid = _getHash(e[j]);
          data[e[j].uid] = e[j];
        }
        data.read = byKey;
        return data;
      },
  /*
  *  Sets private entities to returned object
  */
      _entities = _parseEntities(_datasource.entities),
  /*
  *  Parses edges to object
  *  --- indexed by Source and Target
  *  @Params:
  *  --- @e: array of objects
  */
      _parseEdges = function(e){
        var edges = {ins: {}, outs: {}};
        for (var i = 0; i < e.length; i++){
          var tid = _getHash(e[i].target),
              sid = _getHash(e[i].source);
          if (!edges.ins[tid]) edges.ins[tid] = [];
          edges.ins[tid].push({source: _entities[sid], rel: e[i].rel});
          if (!edges.outs[sid]) edges.outs[sid] = [];
          edges.outs[sid].push({target: _entities[tid], rel: e[i].rel});
        }
        return edges;
      },
      _edges = _parseEdges(_datasource.edges),
      _read = function(name){
        if (!localStorage || !localStorage[name]) return false
        _datasource = $.parseJSON(localStorage[name]);
        _entities =_parseEntities(_datasource.entities);
        _edges = _parseEdges(_datasource.edges);
      },
      _write = function(name){localStorage[name] = JSON.stringify(_datasource); };
      
  if (typeof ds === 'undefined') _read(_name);
  
  this.entities = function(){return _entities; };
  this.edges = function(){ return _edges; }; 
  this.create = function(o){
    //o.uid = _datasource.entities.length; _getHash(e[j])
    //add to datasource entities
    if (!o.name || !o.type) return -1;
    o.uid = _getHash(o);
    if ($.grep(_datasource.entities, function(e){ return e.uid == o.uid; }).length > 0) return -1;
    _datasource.entities.push(o);
    
    //add to _entities    
    _entities[o.uid] = o;
    
    //return success
    _write(_name);
    return o.uid;
    
  };
  this.read = function(key, value){
    var matches = _entities.read(key, value);
    return matches;
  }
  this.update = function (uid, o){<commit_msg>Update GraphDatabase.js<commit_after>function GraphDatabase(_name, ds){
  /*
  *  ToDo: implement hashCode to get true unique identifier
  *  --- for now it simply checks if there is a hashCode already
  *  --- and if not then it creates one that simply returns the string
  */
  window.String.prototype.hashCode = window.String.prototype.hashCode || function(){
    return this;
  }
  
  /*
  *  Gets hashCode based on entity type & name
  */
  var _getHash = function(o){ return (o.type && o.name) ? (o.type + o.name).hashCode() : null; }

  /*
  *  Checks if user supplied datasource
  *  --- if so, make it the datasource
  *  --- if not, create blank datasource
  *  Note: datasource is an Object with 2 properties
  *  --- entities & edges. Both are arrays of objects
  */
  var _datasource = ds || {entities:[], edges:[]};
  
  var byKey = function(key, value){
    var result = {},
        dups = [];
    for (e in this){
      if (this[e][key] && !result[this[e][key]])
        result[this[e][key]] = this[e];
      else if (this[e][key] && $.inArray(this[e][key], dups) > -1)
        result[this[e][key]][this[e].uid] = this[e];
      else if (this[e][key]){
        var first = result[this[e][key]];
        delete result[this[e][key]];
        result[this[e][key]] = {};
        result[this[e][key]]['byKey'] = byKey;
        result[this[e][key]][first.uid] = first;
        result[this[e][key]][this[e].uid] = this[e];
        dups.push(this[e][key]);
      }
    }
    return typeof value === 'undefined' ? result : result[value];
  }
  
  /*
  *  Parses entities to object
  *  --- indexed by Unique Identifier
  *  @Params:
  *  --- @e: array of objects
  */
  var _parseEntities = function(e){
        var data = { uid: {}, name: {}, types: {}};
        for (var j = 0; j < e.length; j++){
          e[j].uid = _getHash(e[j]);
          data[e[j].uid] = e[j];
        }
        data.read = byKey;
        return data;
      },
  /*
  *  Sets private entities to returned object
  */
      _entities = _parseEntities(_datasource.entities),
  /*
  *  Parses edges to object
  *  --- indexed by Source and Target
  *  @Params:
  *  --- @e: array of objects
  */
      _parseEdges = function(e){
        var edges = {ins: {}, outs: {}};
        for (var i = 0; i < e.length; i++){
          var tid = _getHash(e[i].target),
              sid = _getHash(e[i].source);
          if (!edges.ins[tid]) edges.ins[tid] = [];
          edges.ins[tid].push({source: _entities[sid], rel: e[i].rel});
          if (!edges.outs[sid]) edges.outs[sid] = [];
          edges.outs[sid].push({target: _entities[tid], rel: e[i].rel});
        }
        return edges;
      },
      _edges = _parseEdges(_datasource.edges),
      _read = function(name){
        if (!localStorage || !localStorage[name]) return false
        _datasource = $.parseJSON(localStorage[name]);
        _entities =_parseEntities(_datasource.entities);
        _edges = _parseEdges(_datasource.edges);
      },
      _write = function(name){localStorage[name] = JSON.stringify(_datasource); };
      
  if (typeof ds === 'undefined') _read(_name);
  
  this.entities = function(){return _entities; };
  this.edges = function(){ return _edges; }; 
  this.create = function(o){
    //o.uid = _datasource.entities.length; _getHash(e[j])
    //add to datasource entities
    if (!o.name || !o.type) return -1;
    o.uid = _getHash(o);
    if ($.grep(_datasource.entities, function(e){ return e.uid == o.uid; }).length > 0) return -1;
    _datasource.entities.push(o);
    
    //add to _entities    
    _entities[o.uid] = o;
    
    //return success
    _write(_name);
    return o.uid;
    
  };
  this.read = function(key, value){
    var matches = _entities.read(key, value);
    for (e in matches){
      matches[e].ins = _edges.ins[ matches[e].uid];
      matches[e].outs = _edges.outs[ matches[e].uid];
    }
    return matches;
  }
  this.update = function (uid, o){
{'fraction_non_alphanumeric': 0.16864822951667097, 'fraction_numerical': 0.001809253036960455, 'mean_word_length': 2.43040780141844, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '756755', 'n_tokens_mistral': 2622, 'n_tokens_neox': 2609, 'n_words': 628}