<commit_before>;(function($B){

eval($B.InjectBuiltins())

var $ObjectDict = _b_.object.$dict
var str_hash = _b_.str.$dict.__hash__

// dictionary
function $DictClass($keys,$values){
    this.iter = null
    this.__class__ = $DictDict
    $DictDict.clear(this)

    var setitem=$DictDict.__setitem__
    var i=$keys.length
    while(i--) setitem($keys[i], $values[i])
}

var $DictDict = {__class__:$B.$type,
    __name__ : 'dict',
    $native:true,
    __dir__:$ObjectDict.__dir__
}

var $key_iterator = function(d) {
    this.d = d
    this.current = 0
    this.iter = new $item_generator(d)
}
$key_iterator.prototype.length = function() { return this.iter.length }
$key_iterator.prototype.next = function() { return this.iter.next()[0] }

var $value_iterator = function(d) {
    this.d = d
    this.current = 0
    this.iter = new $item_generator(d)
}
$value_iterator.prototype.length = function() { return this.iter.length }
$value_iterator.prototype.next = function() { return this.iter.next()[1] }

var $item_generator = function(d) {
    
    this.i = 0

    if(d.$jsobj){
        this.items = []
        for(var attr in d.$jsobj){
            if(attr.charAt(0)!='$'){this.items.push([attr,d.$jsobj[attr]])}
        }
        this.length=this.items.length;
        return
    }
    
    var items=[]
    var pos=0
    for (var k in d.$numeric_dict) {
        items[pos++]=[parseFloat(k), d.$numeric_dict[k]]
    }

    for (var k in d.$string_dict) {
        items[pos++]=[k, d.$string_dict[k]]
    }

    for (var k in d.$object_dict) {
        var i=d.$object_dict[k].length
        while(i--) items[pos++]=d.$object_dict[k][i]
    }

    this.items=items
    this.length=items.length
}

$item_generator.prototype.next = function() {
    if (this.i < this.items.length) {
       return this.items[this.i++]
    }
    throw _b_.StopIteration("StopIteration")
}
$item_generator.prototype.as_list = function() {
    return this.items
}

var $item_iterator = function(d) {
    this.d = d
    this.current = 0
    this.iter = new $item_generator(d)
}
$item_iterator.prototype.length = function() {return this.iter.items.length }
$item_iterator.prototype.next = function() { return _b_.tuple(this.iter.next()) }

var $copy_dict = function(left, right) {
    var _l=new $item_generator(right).as_list()
    var si=$DictDict.__setitem__
    var i=_l.length
    while(i--) si(left, _l[i][0], _l[i][1])
}

$iterator_wrapper = function(items,klass){
    var res = {
        __class__:klass,
        __iter__:function(){items.iter.i=0; return res},
        __len__:function(){return items.length()},
        __next__:function(){
            //if (items.length() !== items.iter.used) {
            //    throw _b_.RuntimeError("dictionary changed size during iteration")
            //}
            return items.next()
            //return items[counter++]
        },
        //__repr__:function(){return "<"+klass.__name__+" object>"},
        __repr__:function(){return klass.__name__+'('+ new $item_generator(items).as_list().join(',') + ')'},
        //counter:0
    }
    res.__str__ = res.toString = res.__repr__
    return res
}


var $dict_keysDict = $B.$iterator_class('dict_keys')

$DictDict.keys = function(self){
    if (arguments.length > 1) {
       var _len=arguments.length - 1
       var _msg="keys() takes no arguments ("+_len+" given)"
       throw _b_.TypeError(_msg)
    }
    return $iterator_wrapper(new $key_iterator(self),$dict_keysDict)
}

var $dict_valuesDict = $B.$iterator_class('dict_values')

$DictDict.values = function(self){
    if (arguments.length > 1) {
       var _len=arguments.length - 1
       var _msg="values() takes no arguments ("+_len+" given)"
       throw _b_.TypeError(_msg)
    }
    return $iterator_wrapper(new $value_iterator(self), $dict_valuesDict)
}

$DictDict.__bool__ = function (self) {return $DictDict.__len__(self) > 0}

$DictDict.__contains__ = function(self,item){
    if(self.$jsobj) return self.$jsobj[item]!==undefined
    switch(typeof item) {
      case 'string':
        return self.$string_dict[item] !==undefined
      case 'number':
        return self.$numeric_dict[item] !==undefined
    }

    var _key=hash(item)
    if (self.$str_hash[_key]!==undefined &&
        _b_.getattr(item,'__eq__')(self.$str_hash[_key])){return true}
    if (self.$numeric_dict[_key]!==undefined &&
        _b_.getattr(item,'__eq__')(_key)){return true}
    if (self.$object_dict[_key] !== undefined) {
       var _eq = getattr(item, '__eq__')
       var i=self.$object_dict[_key].length
       while(i--) {
           if (_eq(self.$object_dict[_key][i][0])) return true
       }
    }
    return false
}

$DictDict.__delitem__ = function(self,arg){
    if(self.$jsobj){
        if(self.$jsobj[arg]===undefined){throw KeyError(arg)}
        delete self.$jsobj[arg]
        return
    }
    switch(typeof arg) {
      case 'string':
        if (self.$string_dict[arg] === undefined) throw KeyError(_b_.str(arg))
        delete self.$string_dict[arg]
        delete self.$str_hash[str_hash(arg)]
        return
      case 'number':
        if (self.$numeric_dict[arg] === undefined) throw KeyError(_b_.str(arg))
        delete self.$numeric_dict[arg]
        return
    }
    // go with defaults

    var _key=hash(arg)
    if (self.$object_dict[_key] !== undefined) {
       var _eq=getattr(arg, '__eq__')
       var i=self.$object_dict[_key].length
       while(i--) {
           if (_eq(self.$object_dict[_key][i][0])) {
              delete self.$object_dict[_key][i];
              break;
           }
       }
    }

    if(self.$jsobj) delete self.$jsobj[arg]
}

$DictDict.__eq__ = function(self,other){
    if(other===undefined){ // compare self to class "dict"
        return self===dict
    }
    if(!isinstance(other,dict)) return false
    
    if ($DictDict.__len__(self) != $DictDict.__len__(other)){return false}

    var _l = new $item_generator(self).as_list()
    var i=_l.length
    while(i--) {
        var key=_l[i][0]
        if (!$DictDict.__contains__(other, key)) {return false}
        var v1=_l[i][1]
        var v2=$DictDict.__getitem__(other, key)
        if (!getattr(v1, '__eq__')(v2)) {return false}
    }

    return true
}

$DictDict.__getitem__ = function(self,arg){

    if(self.$jsobj){
        if(self.$jsobj[arg]===undefined){return None}
        return self.$jsobj[arg]
    }

    switch(typeof arg) {
      case 'string':
        if (self.$string_dict[arg] !== undefined) return self.$string_dict[arg]
        break
      case 'number':
        if (self.$numeric_dict[arg] !== undefined) return self.$numeric_dict[arg]
    }

    // since the key is more complex use 'default' method of getting item

    var _key=hash(arg)
    var sk = self.$str_hash[_key]
    if (sk!==undefined && _b_.getattr(arg,'__eq__')(sk)){
        return self.$string_dict[sk]
    }
    if (self.$numeric_dict[_key]!==undefined &&
        _b_.getattr(arg,'__eq__')(_key)){
         return self.$numeric_dict[_key]   
    }
    if (self.$object_dict[_key] !== undefined) {
       var _eq=getattr(arg, '__eq__')
       var i=self.$object_dict[_key].length
       while(i--) {
           if (_eq(self.$object_dict[_key][i][0])) {
              return self.$object_dict[_key][i][1]
           }
       }
    }

    if(hasattr(self, '__missing__')) return getattr(self, '__missing__')(arg)

    throw KeyError(_b_.str(arg))
}

$DictDict.__hash__ = function(self) {
    if (self === undefined) {
       return $DictDict.__hashvalue__ || $B.$py_next_hash--  // for hash of dict type (not instance of dict)
    }
    throw _b_.TypeError("unhashable type: 'dict'");
}

$DictDict.__init__ = function(self){
    var args = [], pos=0
    for(var i=1;i<arguments.length;i++){args[pos++]=arguments[i]}
    $DictDict.clear(self)
    switch(args.length) {
      case 0:
        return
      case 1:
        var obj = args[0]
        if(Array.isArray(obj)){
            var i = obj.length
            var si = $DictDict.__setitem__
            while(i--) si(self, obj[i][0], obj[i][1])
            return
        }else if(isinstance(obj,dict)){
            $copy_dict(self, obj)
            return
        }

        if(obj.__class__===$B.JSObject.$dict){
            // convert a JSObject into a Python dictionary
            var si = $DictDict.__setitem__
            for(var attr in obj.js) si(self,attr,obj.js[attr])

            // Attribute $jsobj is used to update the original JS object
            // when the dictionary is modified
            self.$jsobj = obj.js
            return
        }
    } //switch

    var $ns=$B.$MakeArgs('dict',args,[],[],'args','kw')
    var args = $ns['args']
    var kw = $ns['kw']
    
    if (args.length>0) {
        if(isinstance(args[0],dict)){
            $B.$copy_dict(self, args[0])
            return
        }

        // format dict([(k1,v1),(k2,v2)...])
        
        if(Array.isArray(args[0])){
            var src = args[0]
            var i = src.length
            var si=$DictDict.__setitem__
            while(i--) si(self, src[i][0], src[i][1])
        }else{
            var iterable = iter(args[0])
            while(1){
                try{
                   var elt = next(iterable)
                   var key = getattr(elt,'__getitem__')(0)
                   var value = getattr(elt,'__getitem__')(1)
                   $DictDict.__setitem__(self, key, value)
                }catch(err){
                   if(err.__name__==='StopIteration'){break}
                   throw err
                }
            }
        }
    }//if
    if($DictDict.__len__(kw) > 0) $copy_dict(self, kw)
}

var $dict_iterator = $B.$iterator_class('dict iterator')
$DictDict.__iter__ = function(self) {
    return $DictDict.keys(self)
}<commit_msg>fix issues with dict, when an array of length 1 is passed in<commit_after>;(function($B){

eval($B.InjectBuiltins())

var $ObjectDict = _b_.object.$dict
var str_hash = _b_.str.$dict.__hash__

// dictionary
function $DictClass($keys,$values){
    this.iter = null
    this.__class__ = $DictDict
    $DictDict.clear(this)

    var setitem=$DictDict.__setitem__
    var i=$keys.length
    while(i--) setitem($keys[i], $values[i])
}

var $DictDict = {__class__:$B.$type,
    __name__ : 'dict',
    $native:true,
    __dir__:$ObjectDict.__dir__
}

var $key_iterator = function(d) {
    this.d = d
    this.current = 0
    this.iter = new $item_generator(d)
}
$key_iterator.prototype.length = function() { return this.iter.length }
$key_iterator.prototype.next = function() { return this.iter.next()[0] }

var $value_iterator = function(d) {
    this.d = d
    this.current = 0
    this.iter = new $item_generator(d)
}
$value_iterator.prototype.length = function() { return this.iter.length }
$value_iterator.prototype.next = function() { return this.iter.next()[1] }

var $item_generator = function(d) {
    
    this.i = 0

    if(d.$jsobj){
        this.items = []
        for(var attr in d.$jsobj){
            if(attr.charAt(0)!='$'){this.items.push([attr,d.$jsobj[attr]])}
        }
        this.length=this.items.length;
        return
    }
    
    var items=[]
    var pos=0
    for (var k in d.$numeric_dict) {
        items[pos++]=[parseFloat(k), d.$numeric_dict[k]]
    }

    for (var k in d.$string_dict) {
        items[pos++]=[k, d.$string_dict[k]]
    }

    for (var k in d.$object_dict) {
        var i=d.$object_dict[k].length
        while(i--) items[pos++]=d.$object_dict[k][i]
    }

    this.items=items
    this.length=items.length
}

$item_generator.prototype.next = function() {
    if (this.i < this.items.length) {
       return this.items[this.i++]
    }
    throw _b_.StopIteration("StopIteration")
}
$item_generator.prototype.as_list = function() {
    return this.items
}

var $item_iterator = function(d) {
    this.d = d
    this.current = 0
    this.iter = new $item_generator(d)
}
$item_iterator.prototype.length = function() {return this.iter.items.length }
$item_iterator.prototype.next = function() { return _b_.tuple(this.iter.next()) }

var $copy_dict = function(left, right) {
    var _l=new $item_generator(right).as_list()
    var si=$DictDict.__setitem__
    var i=_l.length
    while(i--) si(left, _l[i][0], _l[i][1])
}

$iterator_wrapper = function(items,klass){
    var res = {
        __class__:klass,
        __iter__:function(){items.iter.i=0; return res},
        __len__:function(){return items.length()},
        __next__:function(){
            //if (items.length() !== items.iter.used) {
            //    throw _b_.RuntimeError("dictionary changed size during iteration")
            //}
            return items.next()
            //return items[counter++]
        },
        //__repr__:function(){return "<"+klass.__name__+" object>"},
        __repr__:function(){return klass.__name__+'('+ new $item_generator(items).as_list().join(',') + ')'},
        //counter:0
    }
    res.__str__ = res.toString = res.__repr__
    return res
}


var $dict_keysDict = $B.$iterator_class('dict_keys')

$DictDict.keys = function(self){
    if (arguments.length > 1) {
       var _len=arguments.length - 1
       var _msg="keys() takes no arguments ("+_len+" given)"
       throw _b_.TypeError(_msg)
    }
    return $iterator_wrapper(new $key_iterator(self),$dict_keysDict)
}

var $dict_valuesDict = $B.$iterator_class('dict_values')

$DictDict.values = function(self){
    if (arguments.length > 1) {
       var _len=arguments.length - 1
       var _msg="values() takes no arguments ("+_len+" given)"
       throw _b_.TypeError(_msg)
    }
    return $iterator_wrapper(new $value_iterator(self), $dict_valuesDict)
}

$DictDict.__bool__ = function (self) {return $DictDict.__len__(self) > 0}

$DictDict.__contains__ = function(self,item){
    if(self.$jsobj) return self.$jsobj[item]!==undefined
    switch(typeof item) {
      case 'string':
        return self.$string_dict[item] !==undefined
      case 'number':
        return self.$numeric_dict[item] !==undefined
    }

    var _key=hash(item)
    if (self.$str_hash[_key]!==undefined &&
        _b_.getattr(item,'__eq__')(self.$str_hash[_key])){return true}
    if (self.$numeric_dict[_key]!==undefined &&
        _b_.getattr(item,'__eq__')(_key)){return true}
    if (self.$object_dict[_key] !== undefined) {
       var _eq = getattr(item, '__eq__')
       var i=self.$object_dict[_key].length
       while(i--) {
           if (_eq(self.$object_dict[_key][i][0])) return true
       }
    }
    return false
}

$DictDict.__delitem__ = function(self,arg){
    if(self.$jsobj){
        if(self.$jsobj[arg]===undefined){throw KeyError(arg)}
        delete self.$jsobj[arg]
        return
    }
    switch(typeof arg) {
      case 'string':
        if (self.$string_dict[arg] === undefined) throw KeyError(_b_.str(arg))
        delete self.$string_dict[arg]
        delete self.$str_hash[str_hash(arg)]
        return
      case 'number':
        if (self.$numeric_dict[arg] === undefined) throw KeyError(_b_.str(arg))
        delete self.$numeric_dict[arg]
        return
    }
    // go with defaults

    var _key=hash(arg)
    if (self.$object_dict[_key] !== undefined) {
       var _eq=getattr(arg, '__eq__')
       var i=self.$object_dict[_key].length
       while(i--) {
           if (_eq(self.$object_dict[_key][i][0])) {
              delete self.$object_dict[_key][i];
              break;
           }
       }
    }

    if(self.$jsobj) delete self.$jsobj[arg]
}

$DictDict.__eq__ = function(self,other){
    if(other===undefined){ // compare self to class "dict"
        return self===dict
    }
    if(!isinstance(other,dict)) return false
    
    if ($DictDict.__len__(self) != $DictDict.__len__(other)){return false}

    var _l = new $item_generator(self).as_list()
    var i=_l.length
    while(i--) {
        var key=_l[i][0]
        if (!$DictDict.__contains__(other, key)) {return false}
        var v1=_l[i][1]
        var v2=$DictDict.__getitem__(other, key)
        if (!getattr(v1, '__eq__')(v2)) {return false}
    }

    return true
}

$DictDict.__getitem__ = function(self,arg){

    if(self.$jsobj){
        if(self.$jsobj[arg]===undefined){return None}
        return self.$jsobj[arg]
    }

    switch(typeof arg) {
      case 'string':
        if (self.$string_dict[arg] !== undefined) return self.$string_dict[arg]
        break
      case 'number':
        if (self.$numeric_dict[arg] !== undefined) return self.$numeric_dict[arg]
    }

    // since the key is more complex use 'default' method of getting item

    var _key=hash(arg)
    var sk = self.$str_hash[_key]
    if (sk!==undefined && _b_.getattr(arg,'__eq__')(sk)){
        return self.$string_dict[sk]
    }
    if (self.$numeric_dict[_key]!==undefined &&
        _b_.getattr(arg,'__eq__')(_key)){
         return self.$numeric_dict[_key]   
    }
    if (self.$object_dict[_key] !== undefined) {
       var _eq=getattr(arg, '__eq__')
       var i=self.$object_dict[_key].length
       while(i--) {
           if (_eq(self.$object_dict[_key][i][0])) {
              return self.$object_dict[_key][i][1]
           }
       }
    }

    if(hasattr(self, '__missing__')) return getattr(self, '__missing__')(arg)

    throw KeyError(_b_.str(arg))
}

$DictDict.__hash__ = function(self) {
    if (self === undefined) {
       return $DictDict.__hashvalue__ || $B.$py_next_hash--  // for hash of dict type (not instance of dict)
    }
    throw _b_.TypeError("unhashable type: 'dict'");
}

$DictDict.__init__ = function(self){
    var args = [], pos=0
    for(var i=1;i<arguments.length;i++){args[pos++]=arguments[i]}
    $DictDict.clear(self)

    switch(args.length) {
      case 0:
        return
      case 1:
        var obj = args[0]
        if(Array.isArray(obj)){
            var i = obj.length
            var si = $DictDict.__setitem__
            while(i-->0) si(self, obj[i-1][0], obj[i-1][1])
            return
        }else if(isinstance(obj,dict)){
            $copy_dict(self, obj)
            return
        }

        if(obj.__class__===$B.JSObject.$dict){
            // convert a JSObject into a Python dictionary
            var si = $DictDict.__setitem__
            for(var attr in obj.js) si(self,attr,obj.js[attr])

            // Attribute $jsobj is used to update the original JS object
            // when the dictionary is modified
            self.$jsobj = obj.js
            return
        }
    } //switch

    var $ns=$B.$MakeArgs('dict',args,[],[],'args','kw')
    var args = $ns['args']
    var kw = $ns['kw']
    
    if (args.length>0) {
        if(isinstance(args[0],dict)){
            $B.$copy_dict(self, args[0])
            return
        }

        // format dict([(k1,v1),(k2,v2)...])
        
        if(Array.isArray(args[0])){
            var src = args[0]
            var i = src.length -1
            var si=$DictDict.__setitem__
            while(i-->0) si(self, src[i-1][0], src[i-1][1])
        }else{
            var iterable = iter(args[0])
            while(1){
                try{
                   var elt = next(iterable)
                   var key = getattr(elt,'__getitem__')(0)
                   var value = getattr(elt,'__getitem__')(1)
                   $DictDict.__setitem__(self, key, value)
                }catch(err){
                   if(err.__name__==='StopIteration'){break}
                   throw err
                }
            }
        }
    }//if
    if($DictDict.__len__(kw) > 0) $copy_dict(self, kw)
}

var $dict_iterator = $B.$iterator_class('dict iterator')
$DictDict.__iter__ = function(self) {
    return $DictDict.keys(self)
}
{'fraction_non_alphanumeric': 0.1580857917071425, 'fraction_numerical': 0.005521754690935119, 'mean_word_length': 2.457051961823966, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '7014587', 'n_tokens_mistral': 6548, 'n_tokens_neox': 6524, 'n_words': 1233}