Array.hx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) 2005, The haXe Project Contributors
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * - Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * - Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  23. * DAMAGE.
  24. */
  25. /**
  26. An Array is a storage for values. You can access it using indexes or
  27. with its API. On the server side, it's often better to use a [List] which
  28. is less memory and CPU consuming, unless you really need indexed access.
  29. **/
  30. extern class Array<T> {
  31. /**
  32. The length of the Array
  33. **/
  34. var length(default,null) : Int;
  35. /**
  36. Creates a new Array.
  37. **/
  38. function new() : Void;
  39. /**
  40. Returns a new Array by appending [a] to [this].
  41. **/
  42. function concat( a : Array<T> ) : Array<T>;
  43. /**
  44. Returns a representation of an array with [sep] for separating each element.
  45. **/
  46. function join( sep : String ) : String;
  47. /**
  48. Removes the last element of the array and returns it.
  49. **/
  50. function pop() : Null<T>;
  51. /**
  52. Adds the element [x] at the end of the array.
  53. **/
  54. function push(x : T) : Int;
  55. /**
  56. Reverse the order of elements of the Array.
  57. **/
  58. function reverse() : Void;
  59. /**
  60. Removes the first element and returns it.
  61. **/
  62. function shift() : Null<T>;
  63. /**
  64. Copies the range of the array starting at [pos] up to,
  65. but not including, [end]. Both [pos] and [end] can be
  66. negative to count from the end: -1 is the last item in
  67. the array.
  68. **/
  69. function slice( pos : Int, ?end : Int ) : Array<T>;
  70. /**
  71. Sort the Array according to the comparison function [f].
  72. [f(x,y)] should return [0] if [x == y], [>0] if [x > y]
  73. and [<0] if [x < y].
  74. **/
  75. function sort( f : T -> T -> Int ) : Void;
  76. /**
  77. Removes [len] elements starting from [pos] an returns them.
  78. **/
  79. function splice( pos : Int, len : Int ) : Array<T>;
  80. /**
  81. Returns a displayable representation of the Array content.
  82. **/
  83. function toString() : String;
  84. /**
  85. Adds the element [x] at the start of the array.
  86. **/
  87. function unshift( x : T ) : Void;
  88. /**
  89. Inserts the element [x] at the position [pos].
  90. All elements after [pos] are moved one index ahead.
  91. **/
  92. function insert( pos : Int, x : T ) : Void;
  93. /**
  94. Removes the first occurence of [x].
  95. Returns false if [x] was not present.
  96. Elements are compared by using standard equality.
  97. **/
  98. function remove( x : T ) : Bool;
  99. /**
  100. Returns a copy of the Array. The values are not
  101. copied, only the Array structure.
  102. **/
  103. function copy() : Array<T>;
  104. /**
  105. Returns an iterator of the Array values.
  106. **/
  107. function iterator() : Iterator<Null<T>>;
  108. }