<commit_before>// Dep: [KadOH]/core/class
// Dep: [KadOH]/peer
// Dep: [KadOH]/util/crypto

(function(exports) {
  
  var KadOH = exports;
  var Class = KadOH.core.Class;
  var Peer = KadOH.Peer;
  var Crypto = KadOH.util.Crypto;

  var PeerArray = KadOH.PeerArray = Class({

    initialize: function(peers) {
      this._PEERS = [];

      if (peers instanceof this.constructor)
        this._PEERS = peers.getRawArray().slice(0);
      else if (peers)
        this.add(peers);
    },

    getRawArray: function() {
      return this._PEERS;
    },

    getTripleArray: function() {
      return this._PEERS.map(function(peer) {
        return peer.getTriple();
      });
    },

    getPeer: function(index) {
      if (index instanceof Peer) {
        index = this.find(index);
        if (index === -1)
          throw new ReferenceError('this peer does not exist');
      } else {
        if (index < 0 || index >= this.length())
          throw new RangeError(index + ' out of range');
      }
      return this._PEERS[index];
    },

    length: function() {
      return this._PEERS.length;
    },

// TRANSFORMing methods : these methods applly on the instance

    add: function(peers) {
      var self = this;
      peers.forEach(function(peer) {
        self.addPeer(peer);
      });
      return this;
    },

    addPeer: function(peer) {
      peer = (peer instanceof Peer) ? peer : new Peer(peer);

      if(!this.contains(peer)) {
        this._PEERS.push(peer);
      }
      return this;
    },

    remove: function(rm_peers) {
      this._PEERS = this._PEERS.filter(function(peer) {
        return rm_peers.every(function(rm_peer) {
          return !(rm_peer.equals(peer));
        });
      });
      return this;
    },

    removePeer: function (rm_peer) {
      rm_peer = (rm_peer instanceof Peer) ? rm_peer : new Peer(rm_peer);
      
      var index = this.find(rm_peer);
      if (index !== -1)
        this._PEERS.splice(index, 1);
      
      return this;
    },

    find: function(peer) {
      var i = this._PEERS.indexOf(peer);

      if (i !== -1) {
        return i;
      } else {
        for (i = 0, l = this.length(); i < l; i++)
          if (peer.equals(this._PEERS[i]))
            return i;
      }
      return -1;
    },

    contains: function(sample) {
      if (sample instanceof Peer) {
        return (this.find(sample) !== -1);
      }

      var self = this;
      return sample.every(function(sample_peer) {
        return self._PEERS.some(function(peer) {
          return peer.equals(sample_peer);
        });
      });
    },

    equals: function(peers) {
      peers = (peers instanceof PeerArray) ? peers : (new PeerArray(peers));
      return this.contains(peers) && peers.contains(this);
    },

//NON-TRANSFORMing methods : these methodes return a new instance of PeerArray

    clone: function() {
      return new this.constructor(this);
    },

    union: function(peers) {
      return this.clone().add(peers);
    },
    
    filterOut: function(peers) {
      return this.clone().remove(peers);
    },

    pickOutFirst: function(number) {
      number = Math.max(0, Math.min(number, this.length()));

      if (number < this.length()) {
        var clone = new this.clone();
        clone._PEERS = this._PEERS.slice(0, number);
        return clone;
      }
      return this;
    },

// Extends Array.prototype

    forEach: function() {
      Array.prototype.forEach.apply(this._PEERS, arguments);
      return this;
    },

    sort: function() {
      Array.prototype.sort.apply(this._PEERS, arguments);
      return this;
    },<commit_msg>fixing regression in peerarray<commit_after>// Dep: [KadOH]/core/class
// Dep: [KadOH]/peer
// Dep: [KadOH]/util/crypto

(function(exports) {
  
  var KadOH = exports;
  var Class = KadOH.core.Class;
  var Peer = KadOH.Peer;
  var Crypto = KadOH.util.Crypto;

  var PeerArray = KadOH.PeerArray = Class({

    initialize: function(peers) {
      this._PEERS = [];

      if (peers instanceof this.constructor)
        this._PEERS = peers.getRawArray().slice(0);
      else if (peers)
        this.add(peers);
    },

    getRawArray: function() {
      return this._PEERS;
    },

    getTripleArray: function() {
      return this._PEERS.map(function(peer) {
        return peer.getTriple();
      });
    },

    getPeer: function(index) {
      if (index instanceof Peer) {
        index = this.find(index);
        if (index === -1)
          throw new ReferenceError('this peer does not exist');
      } else {
        if (index < 0 || index >= this.length())
          throw new RangeError(index + ' out of range');
      }
      return this._PEERS[index];
    },

    length: function() {
      return this._PEERS.length;
    },

// TRANSFORMing methods : these methods applly on the instance

    add: function(peers) {
      var self = this;
      peers.forEach(function(peer) {
        self.addPeer(peer);
      });
      return this;
    },

    addPeer: function(peer) {
      peer = (peer instanceof Peer) ? peer : new Peer(peer);

      if(!this.contains(peer)) {
        this._PEERS.push(peer);
      }
      return this;
    },

    remove: function(rm_peers) {
      this._PEERS = this._PEERS.filter(function(peer) {
        return rm_peers.every(function(rm_peer) {
          return !(rm_peer.equals(peer));
        });
      });
      return this;
    },

    removePeer: function (rm_peer) {
      rm_peer = (rm_peer instanceof Peer) ? rm_peer : new Peer(rm_peer);
      
      var index = this.find(rm_peer);
      if (index !== -1)
        this._PEERS.splice(index, 1);
      
      return this;
    },

    find: function(peer) {
      var i = this._PEERS.indexOf(peer);

      if (i !== -1) {
        return i;
      } else {
        for (i = 0, l = this.length(); i < l; i++)
          if (peer.equals(this._PEERS[i]))
            return i;
      }
      return -1;
    },

    contains: function(sample) {
      if (sample instanceof Peer) {
        return (this.find(sample) !== -1);
      }

      var self = this;
      return sample.every(function(sample_peer) {
        return self._PEERS.some(function(peer) {
          return peer.equals(sample_peer);
        });
      });
    },

    equals: function(peers) {
      peers = (peers instanceof PeerArray) ? peers : (new PeerArray(peers));
      return this.contains(peers) && peers.contains(this);
    },

//NON-TRANSFORMing methods : these methodes return a new instance of PeerArray

    clone: function() {
      return new this.constructor(this);
    },

    union: function(peers) {
      return this.clone().add(peers);
    },
    
    filterOut: function(peers) {
      return this.clone().remove(peers);
    },

    pickOutFirst: function(number) {
      number = Math.max(0, Math.min(number, this.length()));

      if (number < this.length()) {
        var clone = this.clone();
        clone._PEERS = this._PEERS.slice(0, number);
        return clone;
      }
      return this;
    },

// Extends Array.prototype

    forEach: function() {
      Array.prototype.forEach.apply(this._PEERS, arguments);
      return this;
    },

    sort: function() {
      Array.prototype.sort.apply(this._PEERS, arguments);
      return this;
    },
{'fraction_non_alphanumeric': 0.13940648723257418, 'fraction_numerical': 0.003036576949620428, 'mean_word_length': 2.1032119914346894, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3707332', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2266, 'n_words': 512}