Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,100 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.ds;
@:coreApi class IntMap<T> implements haxe.Constraints.IMap<Int, T> {
private var h:Dynamic;
public inline function new():Void {
h = {};
}
public inline function set(key:Int, value:T):Void {
h[key] = value;
}
public inline function get(key:Int):Null<T> {
return h[key];
}
public inline function exists(key:Int):Bool {
return (cast h).hasOwnProperty(key);
}
public function remove(key:Int):Bool {
if (!(cast h).hasOwnProperty(key))
return false;
js.Syntax.delete(h, key);
return true;
}
public function keys():Iterator<Int> {
var a = [];
js.Syntax.code("for( var key in {0} ) if({0}.hasOwnProperty(key)) {1}.push(+key)", h, a);
return a.iterator();
}
public function iterator():Iterator<T> {
return untyped {
ref: h,
it: keys(),
hasNext: function() {
return __this__.it.hasNext();
},
next: function() {
var i = __this__.it.next();
return __this__.ref[i];
}
};
}
@:runtime public inline function keyValueIterator():KeyValueIterator<Int, T> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():IntMap<T> {
var copied = new IntMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
var s = new StringBuf();
s.add("{");
var it = keys();
for (i in it) {
s.add(i);
s.add(" => ");
s.add(Std.string(get(i)));
if (it.hasNext())
s.add(", ");
}
s.add("}");
return s.toString();
}
public inline function clear():Void {
h = {};
}
}

View File

@ -0,0 +1,132 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of h software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and h permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.ds;
import js.Syntax;
import js.Lib;
@:coreApi
class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
static var count:Int;
// initialize count through __init__ magic, because these are generated
// before normal static initializations for which ObjectMap should be ready to use
// see https://github.com/HaxeFoundation/haxe/issues/6792
static inline function __init__():Void
count = 0;
static inline function assignId(obj:{}):Int {
return Syntax.code('({0}.__id__ = {1})', obj, Lib.getNextHaxeUID());
}
static inline function getId(obj:{}):Int {
return untyped obj.__id__;
}
var h:{__keys__:{}};
public function new():Void {
h = {__keys__: {}};
}
public function set(key:K, value:V):Void {
var id = getId(key);
if(id == null) {
id = assignId(key);
}
Syntax.code('{0}[{1}] = {2}', h, id, value);
Syntax.code('{0}[{1}] = {2}', h.__keys__, id, key);
}
public inline function get(key:K):Null<V> {
return untyped h[getId(key)];
}
public inline function exists(key:K):Bool {
return untyped h.__keys__[getId(key)] != null;
}
public function remove(key:K):Bool {
var id = getId(key);
if (untyped h.__keys__[id] == null)
return false;
js.Syntax.delete(h, id);
js.Syntax.delete(h.__keys__, id);
return true;
}
public function keys():Iterator<K> {
var a = [];
untyped {
js.Syntax.code("for( var key in this.h.__keys__ ) {");
if (h.hasOwnProperty(key))
a.push(h.__keys__[key]);
js.Syntax.code("}");
}
return a.iterator();
}
public function iterator():Iterator<V> {
return untyped {
ref: h,
it: keys(),
hasNext: function() {
return __this__.it.hasNext();
},
next: function() {
var i = __this__.it.next();
return __this__.ref[getId(i)];
}
};
}
@:runtime public inline function keyValueIterator():KeyValueIterator<K, V> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():ObjectMap<K, V> {
var copied = new ObjectMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
var s = new StringBuf();
s.add("{");
var it = keys();
for (i in it) {
s.add(Std.string(i));
s.add(" => ");
s.add(Std.string(get(i)));
if (it.hasNext())
s.add(", ");
}
s.add("}");
return s.toString();
}
public inline function clear():Void {
h = {__keys__: {}};
}
}

View File

@ -0,0 +1,312 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.ds;
import js.lib.Object;
import haxe.Constraints.IMap;
import haxe.DynamicAccess;
#if (js_es >= 5)
@:coreApi class StringMap<T> implements IMap<String, T> {
var h:Dynamic;
public inline function new() {
h = Object.create(null);
}
public inline function exists(key:String):Bool {
return Object.prototype.hasOwnProperty.call(h, key);
}
public inline function get(key:String):Null<T> {
return h[cast key];
}
public inline function set(key:String, value:T):Void {
h[cast key] = value;
}
public inline function remove(key:String):Bool {
return if (exists(key)) {
js.Syntax.delete(h, key); true;
} else {
false;
}
}
public inline function keys():Iterator<String> {
return new StringMapKeyIterator(h);
}
public inline function iterator():Iterator<T> {
return new StringMapValueIterator(h);
}
public inline function keyValueIterator():KeyValueIterator<String, T> {
return new StringMapKeyValueIterator(h);
}
public inline function copy():StringMap<T> {
return createCopy(h);
}
public inline function clear():Void {
h = Object.create(null);
}
public inline function toString():String {
return stringify(h);
}
// impl
static function createCopy<T>(h:Dynamic):StringMap<T> {
var copy = new StringMap();
js.Syntax.code("for (var key in {0}) {1}[key] = {0}[key]", h, copy.h);
return copy;
}
@:analyzer(no_optimize)
static function stringify(h:Dynamic):String {
var s = "{", first = true;
js.Syntax.code("for (var key in {0}) {", h);
js.Syntax.code("\tif ({0}) {0} = false; else {1} += ',';", first, s);
js.Syntax.code("\t{0} += key + ' => ' + {1}({2}[key]);", s, Std.string, h);
js.Syntax.code("}");
return s + "}";
}
}
private class StringMapKeyIterator {
final h:Dynamic;
final keys:Array<String>;
final length:Int;
var current:Int;
public inline function new(h:Dynamic) {
this.h = h;
keys = Object.keys(h);
length = keys.length;
current = 0;
}
public inline function hasNext():Bool {
return current < length;
}
public inline function next():String {
return keys[current++];
}
}
private class StringMapValueIterator<T> {
final h:Dynamic;
final keys:Array<String>;
final length:Int;
var current:Int;
public inline function new(h:Dynamic) {
this.h = h;
keys = Object.keys(h);
length = keys.length;
current = 0;
}
public inline function hasNext():Bool {
return current < length;
}
public inline function next():T {
return h[cast keys[current++]];
}
}
private class StringMapKeyValueIterator<T> {
final h:Dynamic;
final keys:Array<String>;
final length:Int;
var current:Int;
public inline function new(h:Dynamic) {
this.h = h;
keys = Object.keys(h);
length = keys.length;
current = 0;
}
public inline function hasNext():Bool {
return current < length;
}
public inline function next():{key:String, value:T} {
var key = keys[current++];
return {key: key, value: h[cast key]};
}
}
#else
private class StringMapIterator<T> {
var map:StringMap<T>;
var keys:Array<String>;
var index:Int;
var count:Int;
public inline function new(map:StringMap<T>, keys:Array<String>) {
this.map = map;
this.keys = keys;
this.index = 0;
this.count = keys.length;
}
public inline function hasNext() {
return index < count;
}
public inline function next() {
return map.get(keys[index++]);
}
}
@:coreApi class StringMap<T> implements haxe.Constraints.IMap<String, T> {
private var h:Dynamic;
private var rh:Dynamic;
public inline function new():Void {
h = {};
}
inline function isReserved(key:String):Bool {
return js.Syntax.code("__map_reserved[{0}]", key) != null;
}
public inline function set(key:String, value:T):Void {
if (isReserved(key))
setReserved(key, value);
else
h[cast key] = value;
}
public inline function get(key:String):Null<T> {
if (isReserved(key))
return getReserved(key);
return h[cast key];
}
public inline function exists(key:String):Bool {
if (isReserved(key))
return existsReserved(key);
return h.hasOwnProperty(key);
}
function setReserved(key:String, value:T):Void {
if (rh == null)
rh = {};
rh[cast "$" + key] = value;
}
function getReserved(key:String):Null<T> {
return rh == null ? null : rh[cast "$" + key];
}
function existsReserved(key:String):Bool {
if (rh == null)
return false;
return (cast rh).hasOwnProperty("$" + key);
}
public function remove(key:String):Bool {
if (isReserved(key)) {
key = "$" + key;
if (rh == null || !rh.hasOwnProperty(key))
return false;
js.Syntax.delete(rh, key);
return true;
} else {
if (!h.hasOwnProperty(key))
return false;
js.Syntax.delete(h, key);
return true;
}
}
public function keys():Iterator<String> {
return arrayKeys().iterator();
}
function arrayKeys():Array<String> {
var out = [];
untyped {
js.Syntax.code("for( var key in this.h ) {");
if (h.hasOwnProperty(key))
out.push(key);
js.Syntax.code("}");
}
if (rh != null)
untyped {
js.Syntax.code("for( var key in this.rh ) {");
if (key.charCodeAt(0) == "$".code)
out.push(key.substr(1));
js.Syntax.code("}");
}
return out;
}
public inline function iterator():Iterator<T> {
return new StringMapIterator(this, arrayKeys());
}
@:runtime public inline function keyValueIterator():KeyValueIterator<String, T> {
return new haxe.iterators.MapKeyValueIterator(this);
}
public function copy():StringMap<T> {
var copied = new StringMap();
for (key in keys())
copied.set(key, get(key));
return copied;
}
public function toString():String {
var s = new StringBuf();
s.add("{");
var keys = arrayKeys();
for (i in 0...keys.length) {
var k = keys[i];
s.add(k);
s.add(" => ");
s.add(Std.string(get(k)));
if (i < keys.length - 1)
s.add(", ");
}
s.add("}");
return s.toString();
}
public inline function clear():Void {
h = {};
rh = null;
}
static function __init__():Void {
js.Syntax.code("var __map_reserved = {};");
}
}
#end