2
0

Array.hx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (C)2005-2017 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. @:native("list")
  27. @:coreApi
  28. extern class Array<T> implements ArrayAccess<T> {
  29. public var length(default,null) : Int;
  30. public function new() : Void;
  31. public inline function concat( a : Array<T>) : Array<T> {
  32. return ArrayImpl.concat(this, a);
  33. }
  34. public inline function copy() : Array<T> {
  35. return ArrayImpl.copy(this);
  36. }
  37. @:runtime public inline function iterator() : Iterator<T> {
  38. return ArrayImpl.iterator(this);
  39. }
  40. public inline function insert( pos : Int, x : T ) : Void {
  41. ArrayImpl.insert(this, pos, x);
  42. }
  43. @:runtime public inline function join( sep : String ) : String {
  44. return ArrayImpl.join(this, sep);
  45. }
  46. public inline function toString() : String {
  47. return ArrayImpl.toString(this);
  48. }
  49. @:runtime public inline function pop() : Null<T> {
  50. return ArrayImpl.pop(this);
  51. }
  52. @:runtime public inline function push(x:T) : Int {
  53. return ArrayImpl.push(this,x);
  54. }
  55. public inline function unshift(x : T) : Void {
  56. ArrayImpl.unshift(this,x);
  57. }
  58. public inline function indexOf(x : T, ?fromIndex:Int) : Int {
  59. return ArrayImpl.indexOf(this,x, fromIndex);
  60. }
  61. public inline function lastIndexOf(x : T, ?fromIndex:Int) : Int {
  62. return ArrayImpl.lastIndexOf(this,x, fromIndex);
  63. }
  64. public inline function remove(x : T) : Bool {
  65. return ArrayImpl.remove(this,x);
  66. }
  67. public inline function reverse() : Void {
  68. ArrayImpl.reverse(this);
  69. }
  70. @:runtime public inline function shift() : Null<T> {
  71. return ArrayImpl.shift(this);
  72. }
  73. public inline function slice( pos : Int, ?end : Int ) : Array<T> {
  74. return ArrayImpl.slice(this, pos, end);
  75. }
  76. public inline function sort(f:T->T->Int) : Void {
  77. ArrayImpl.sort(this, f);
  78. }
  79. public inline function splice( pos : Int, len : Int ) : Array<T> {
  80. return ArrayImpl.splice(this, pos, len);
  81. }
  82. @:runtime public inline function map<S>( f : T -> S ) : Array<S> {
  83. return ArrayImpl.map(this, f);
  84. }
  85. @:runtime public inline function filter( f : T -> Bool ) : Array<T> {
  86. return ArrayImpl.filter(this,f);
  87. }
  88. @:keep private inline function _get(idx:Int):T
  89. {
  90. return ArrayImpl._get(this, idx);
  91. }
  92. @:keep private inline function _set(idx:Int, val:T):T
  93. {
  94. return ArrayImpl._set(this, idx,val);
  95. }
  96. @:keep private inline function unsafeGet(idx:Int):T
  97. {
  98. return ArrayImpl.unsafeGet(this, idx);
  99. }
  100. @:keep private inline function unsafeSet(idx:Int, val:T):T
  101. {
  102. return ArrayImpl.unsafeSet(this, idx,val);
  103. }
  104. @:noCompletion private function __iter__ ():NativeIterator<T>;
  105. }