|
| 1 | +package haxe.ds; |
| 2 | + |
| 3 | +@:coreApi |
| 4 | +class Int64Map<T> implements haxe.Constraints.IMap<haxe.Int64, T> { |
| 5 | + var hashMap:java.util.HashMap<haxe.Int64, T>; |
| 6 | + |
| 7 | + @:overload |
| 8 | + public function new():Void { |
| 9 | + hashMap = new java.util.HashMap(); |
| 10 | + } |
| 11 | + |
| 12 | + @:overload |
| 13 | + function new(hashMap:java.util.HashMap<haxe.Int64, T>):Void { |
| 14 | + this.hashMap = hashMap; |
| 15 | + } |
| 16 | + |
| 17 | + public function set(key:haxe.Int64, value:T):Void { |
| 18 | + hashMap.put(key, value); |
| 19 | + } |
| 20 | + |
| 21 | + public function get(key:haxe.Int64):Null<T> { |
| 22 | + return hashMap.get(key); |
| 23 | + } |
| 24 | + |
| 25 | + public function exists(key:haxe.Int64):Bool { |
| 26 | + return hashMap.containsKey(key); |
| 27 | + } |
| 28 | + |
| 29 | + public function remove(key:haxe.Int64):Bool { |
| 30 | + var has = exists(key); |
| 31 | + hashMap.remove(key); |
| 32 | + return has; |
| 33 | + } |
| 34 | + |
| 35 | + public inline function keys():Iterator<haxe.Int64> { |
| 36 | + return hashMap.keySet().iterator(); |
| 37 | + } |
| 38 | + |
| 39 | + @:runtime public inline function keyValueIterator():KeyValueIterator<haxe.Int64, T> { |
| 40 | + return new haxe.iterators.MapKeyValueIterator(this); |
| 41 | + } |
| 42 | + |
| 43 | + public inline function iterator():Iterator<T> { |
| 44 | + return hashMap.values().iterator(); |
| 45 | + } |
| 46 | + |
| 47 | + public function copy():Int64Map<T> { |
| 48 | + return new Int64Map(hashMap.clone()); |
| 49 | + } |
| 50 | + |
| 51 | + public function toString():String { |
| 52 | + var s = new StringBuf(); |
| 53 | + s.add("["); |
| 54 | + var it = keys(); |
| 55 | + for (i in it) { |
| 56 | + s.add(i.toString()); |
| 57 | + s.add(" => "); |
| 58 | + s.add(Std.string(get(i))); |
| 59 | + if (it.hasNext()) |
| 60 | + s.add(", "); |
| 61 | + } |
| 62 | + s.add("]"); |
| 63 | + return s.toString(); |
| 64 | + } |
| 65 | + |
| 66 | + public function clear():Void { |
| 67 | + hashMap.clear(); |
| 68 | + } |
| 69 | + |
| 70 | + public function size():Int { |
| 71 | + return hashMap.size(); |
| 72 | + } |
| 73 | +} |
0 commit comments