<commit_before><commit_msg>Added a BoolMap - mostly for speed.<commit_after>package tink.collections.maps;

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

class BoolMap<V> implements Map<Bool, V> {
	var hasTrue:Bool;
	var hasFalse:Bool;
	var trueVal:Null<V>;
	var falseVal:Null<V>;
	public function new() {
		hasTrue = hasFalse = false;//for dynamic platforms
	}
	public inline function get(k:Bool):Null<V> {
		return k ? trueVal : falseVal;
	}
	public inline function set(k:Bool, v:V):V {
		if (k) {
			hasTrue = true;
			trueVal = v;
		}
		else {
			hasFalse = true;
			falseVal = v;
		}
		return v;
	}
	public inline function exists(k:Bool):Bool {
		return k ? hasTrue : hasFalse;
	}
	public function remove(k:Bool):Bool {
		return
			if (k) 
				if (hasTrue) {
					trueVal = null;
					hasTrue = false;
					true;
				}
				else false;
			else 
				if (hasFalse) {
					falseVal = null;
					hasFalse = false;
					false;
				}
				else true;
	}
	public inline function keys():Iterator<Bool> {
		var ret = [];
		if (hasTrue) ret.push(true);
		if (hasFalse) ret.push(false);
		return ret.iterator();
	}
	public inline function iterator():Iterator<V> {		
		var ret = [];
		if (hasTrue) ret.push(trueVal);
		if (hasFalse) ret.push(falseVal);
		return ret.iterator();
	}
}
{'fraction_non_alphanumeric': 0.1386687797147385, 'fraction_numerical': 0.000792393026941363, 'mean_word_length': 3.0095238095238095, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '1541962', 'n_tokens_mistral': 535, 'n_tokens_neox': 459, 'n_words': 117}