Array.hx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. #if !macro
  23. import python.internal.ArrayImpl;
  24. import python.NativeIterator;
  25. #end
  26. import haxe.iterators.ArrayKeyValueIterator;
  27. @:native("list")
  28. @:coreApi
  29. extern class Array<T> implements ArrayAccess<T> {
  30. var length(default, null):Int;
  31. function new():Void;
  32. inline function concat(a:Array<T>):Array<T> {
  33. return ArrayImpl.concat(this, a);
  34. }
  35. inline function copy():Array<T> {
  36. return ArrayImpl.copy(this);
  37. }
  38. @:runtime inline function iterator():haxe.iterators.ArrayIterator<T> {
  39. return new haxe.iterators.ArrayIterator(this);
  40. }
  41. @:runtime inline public function keyValueIterator():ArrayKeyValueIterator<T> {
  42. return new ArrayKeyValueIterator(this);
  43. }
  44. inline function insert(pos:Int, x:T):Void {
  45. ArrayImpl.insert(this, pos, x);
  46. }
  47. @:runtime inline function join(sep:String):String {
  48. return ArrayImpl.join(this, sep);
  49. }
  50. inline function toString():String {
  51. return ArrayImpl.toString(this);
  52. }
  53. @:runtime inline function pop():Null<T> {
  54. return ArrayImpl.pop(this);
  55. }
  56. @:runtime inline function push(x:T):Int {
  57. return ArrayImpl.push(this, x);
  58. }
  59. inline function unshift(x:T):Void {
  60. ArrayImpl.unshift(this, x);
  61. }
  62. inline function indexOf(x:T, ?fromIndex:Int):Int {
  63. return ArrayImpl.indexOf(this, x, fromIndex);
  64. }
  65. inline function lastIndexOf(x:T, ?fromIndex:Int):Int {
  66. return ArrayImpl.lastIndexOf(this, x, fromIndex);
  67. }
  68. inline function remove(x:T):Bool {
  69. return ArrayImpl.remove(this, x);
  70. }
  71. inline function contains(x:T):Bool {
  72. return ArrayImpl.contains(this,x);
  73. }
  74. inline function reverse():Void {
  75. ArrayImpl.reverse(this);
  76. }
  77. @:runtime inline function shift():Null<T> {
  78. return ArrayImpl.shift(this);
  79. }
  80. inline function slice(pos:Int, ?end:Int):Array<T> {
  81. return ArrayImpl.slice(this, pos, end);
  82. }
  83. inline function sort(f:T->T->Int):Void {
  84. ArrayImpl.sort(this, f);
  85. }
  86. inline function splice(pos:Int, len:Int):Array<T> {
  87. return ArrayImpl.splice(this, pos, len);
  88. }
  89. @:runtime inline function map<S>(f:T->S):Array<S> {
  90. return ArrayImpl.map(this, f);
  91. }
  92. @:runtime inline function filter(f:T->Bool):Array<T> {
  93. return ArrayImpl.filter(this, f);
  94. }
  95. inline function resize(len:Int):Void {
  96. ArrayImpl.resize(this, len);
  97. }
  98. @:keep private inline function _get(idx:Int):T {
  99. return ArrayImpl._get(this, idx);
  100. }
  101. @:keep private inline function _set(idx:Int, val:T):T {
  102. return ArrayImpl._set(this, idx, val);
  103. }
  104. @:keep private inline function unsafeGet(idx:Int):T {
  105. return ArrayImpl.unsafeGet(this, idx);
  106. }
  107. @:keep private inline function unsafeSet(idx:Int, val:T):T {
  108. return ArrayImpl.unsafeSet(this, idx, val);
  109. }
  110. @:noCompletion private function __iter__():NativeIterator<T>;
  111. }