<commit_before>package tink.collections;
import tink.lang.Cls;

/**
 * ...
 * @author back2dos
 */

private class StringRepMap<T> extends tink.collections.abstract.StringIDMap < Dynamic, T > {
	override function transform(k:Dynamic) {
		return Std.string(k); 
	}
}
 
class AnyMap<V> implements Map<Dynamic,V>, implements Cls {
	var ints:IntHash<V>;
	var strings:Hash<V>;
	var objs:ObjectMap<Dynamic, V>;
	var misc:StringRepMap<V>;
	var funcs:FunctionMap<Dynamic, V>;
	public function new() {
		this.ints = new IntHash();
		this.strings = new Hash();
		this.objs = new ObjectMap();
		this.misc = new StringRepMap();
		this.funcs = new FunctionMap();
	}
	public function get(k:Dynamic):Null<V> {
		return
			switch (Type.typeof(k)) {
				case TNull, TBool, TFloat, TUnknown: misc.get(k);
				case TInt: ints.get(k);
				case TClass(c):
					if (c == String) strings.get(k);
					else objs.get(k);
				case TObject, TEnum(_): objs.get(k);
				case TFunction: funcs.get(k);
			}
	}
	public function set(k:Dynamic, v:V):V {
		switch (Type.typeof(k)) {
			case TNull, TBool, TFloat, TUnknown: misc.set(k, v);
			case TInt: ints.set(k, v);
			case TClass(c):
				if (c == String) strings.set(k, v);
				else objs.set(k, v);
			case TObject, TEnum(_): objs.set(k, v);
			case TFunction: funcs.set(k, v);
		}		
		return v;
	}
	public function exists(k:Dynamic):Bool {
		return
			switch (Type.typeof(k)) {
				case TNull, TBool, TFloat, TUnknown: misc.exists(k);
				case TInt: ints.exists(k);
				case TClass(c):
					if (c == String) strings.exists(k);
					else objs.exists(k);
				case TObject, TEnum(_): objs.exists(k);
				case TFunction: funcs.exists(k);
			}
	}
	public function remove(k:Dynamic):Bool {
		return
			switch (Type.typeof(k)) {
				case TNull, TBool, TFloat, TUnknown: misc.remove(k);
				case TInt: ints.remove(k);
				case TClass(c):
					if (c == String) strings.remove(k);
					else objs.remove(k);
				case TObject, TEnum(_): objs.remove(k);
				case TFunction: funcs.remove(k);
			}
	}
	public function keys():Iterator<Dynamic> {
		return group([ints.keys(), strings.keys(), objs.keys(), misc.keys(), funcs.keys()]);
	}
	public function iterator():Iterator<V> {
		return group([ints.iterator(), strings.iterator(), objs.iterator(), misc.iterator(), funcs.iterator()]);		
	}
	function group<A>(a:Iterable<Iterator<A>>) {//TODO: it might make sense extracting this
		var i = a.iterator();
		return 
			if (i.hasNext()) {
				var cur = i.next();
				{
					hasNext: function () return cur.hasNext() || i.hasNext(),
					next: function () {
						if (!cur.hasNext()) cur = i.next();
						return cur.next();
					}
				}
			}
			else [].iterator();//TODO: unlazify<commit_msg>Fixed a bug in iterator.<commit_after>package tink.collections;
import tink.lang.Cls;

/**
 * ...
 * @author back2dos
 */

private class StringRepMap<T> extends tink.collections.abstract.StringIDMap < Dynamic, T > {
	override function transform(k:Dynamic) {
		return Std.string(k); 
	}
}
 
class AnyMap<V> implements Map<Dynamic,V>, implements Cls {
	var ints:IntHash<V>;
	var strings:Hash<V>;
	var objs:ObjectMap<Dynamic, V>;
	var misc:StringRepMap<V>;
	var funcs:FunctionMap<Dynamic, V>;
	public function new() {
		this.ints = new IntHash();
		this.strings = new Hash();
		this.objs = new ObjectMap();
		this.misc = new StringRepMap();
		this.funcs = new FunctionMap();
	}
	public function get(k:Dynamic):Null<V> {
		return
			switch (Type.typeof(k)) {
				case TNull, TBool, TFloat, TUnknown: misc.get(k);
				case TInt: ints.get(k);
				case TClass(c):
					if (c == String) strings.get(k);
					else objs.get(k);
				case TObject, TEnum(_): objs.get(k);
				case TFunction: funcs.get(k);
			}
	}
	public function set(k:Dynamic, v:V):V {
		switch (Type.typeof(k)) {
			case TNull, TBool, TFloat, TUnknown: misc.set(k, v);
			case TInt: ints.set(k, v);
			case TClass(c):
				if (c == String) strings.set(k, v);
				else objs.set(k, v);
			case TObject, TEnum(_): objs.set(k, v);
			case TFunction: funcs.set(k, v);
		}		
		return v;
	}
	public function exists(k:Dynamic):Bool {
		return
			switch (Type.typeof(k)) {
				case TNull, TBool, TFloat, TUnknown: misc.exists(k);
				case TInt: ints.exists(k);
				case TClass(c):
					if (c == String) strings.exists(k);
					else objs.exists(k);
				case TObject, TEnum(_): objs.exists(k);
				case TFunction: funcs.exists(k);
			}
	}
	public function remove(k:Dynamic):Bool {
		return
			switch (Type.typeof(k)) {
				case TNull, TBool, TFloat, TUnknown: misc.remove(k);
				case TInt: ints.remove(k);
				case TClass(c):
					if (c == String) strings.remove(k);
					else objs.remove(k);
				case TObject, TEnum(_): objs.remove(k);
				case TFunction: funcs.remove(k);
			}
	}
	public function keys():Iterator<Dynamic> {
		return group([ints.keys(), strings.keys(), objs.keys(), misc.keys(), funcs.keys()]);
	}
	public function iterator():Iterator<V> {
		return group([ints.iterator(), strings.iterator(), objs.iterator(), misc.iterator(), funcs.iterator()]);		
	}
	function group<A>(a:Iterable<Iterator<A>>) {//TODO: it might make sense extracting this
		var i = Lambda.filter(a, function (iter) return iter.hasNext()).iterator();
		return 
			if (i.hasNext()) {
				var cur = i.next();
				{
					hasNext: function () return cur.hasNext() || i.hasNext(),
					next: function () {
						if (!cur.hasNext()) cur = i.next();
						return cur.next();
					}
				}
			}
			else [].iterator();//TODO: unlazify
{'fraction_non_alphanumeric': 0.17000183587295759, 'fraction_numerical': 0.00036717459151826694, 'mean_word_length': 3.4802631578947367, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '2622329', 'n_tokens_mistral': 2328, 'n_tokens_neox': 1989, 'n_words': 475}