|
@@ -219,4 +219,85 @@ abstract Vector<T>(VectorData<T>) {
|
|
return vec;
|
|
return vec;
|
|
#end
|
|
#end
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Returns a shallow copy of `this` Vector.
|
|
|
|
+
|
|
|
|
+ The elements are not copied and retain their identity, so
|
|
|
|
+ `a[i] == a.copy()[i]` is true for any valid `i`. However,
|
|
|
|
+ `a == a.copy()` is always false.
|
|
|
|
+ **/
|
|
|
|
+ public inline function copy<T>():Vector<T> {
|
|
|
|
+ var r = new Vector<T>(length);
|
|
|
|
+ Vector.blit(cast this, 0, r, 0, length);
|
|
|
|
+ return r;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Returns a string representation of `this` Vector, with `sep` separating
|
|
|
|
+ each element.
|
|
|
|
+
|
|
|
|
+ The result of this operation is equal to `Std.string(this[0]) + sep +
|
|
|
|
+ Std.string(this[1]) + sep + ... + sep + Std.string(this[this.length-1])`
|
|
|
|
+
|
|
|
|
+ If `this` Vector has length 0, the result is the empty String `""`.
|
|
|
|
+ If `this` has exactly one element, the result is equal to a call to
|
|
|
|
+ `Std.string(this[0])`.
|
|
|
|
+
|
|
|
|
+ If `sep` is null, the result is unspecified.
|
|
|
|
+ **/
|
|
|
|
+ public inline function join<T>(sep:String):String {
|
|
|
|
+ #if (flash||cpp)
|
|
|
|
+ return this.join(sep);
|
|
|
|
+ #else
|
|
|
|
+ var b = new StringBuf();
|
|
|
|
+ var i = 0;
|
|
|
|
+ var len = length;
|
|
|
|
+ for(i in 0...len) {
|
|
|
|
+ b.add( Std.string(get(i)) );
|
|
|
|
+ if(i < len-1) {
|
|
|
|
+ b.add(sep);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return b.toString();
|
|
|
|
+ #end
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Creates a new Vector by applying function `f` to all elements of `this`.
|
|
|
|
+
|
|
|
|
+ The order of elements is preserved.
|
|
|
|
+
|
|
|
|
+ If `f` is null, the result is unspecified.
|
|
|
|
+ **/
|
|
|
|
+ //public function map<S>(f:T->S):Vector<S> {
|
|
|
|
+ //var r = new Vector<S>(length);
|
|
|
|
+ //var i = 0;
|
|
|
|
+ //var len = length;
|
|
|
|
+ //for(i in 0...len) {
|
|
|
|
+ //var v = f(get(i));
|
|
|
|
+ //r.set(i, v);
|
|
|
|
+ //}
|
|
|
|
+ //return r;
|
|
|
|
+ //}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ Sorts `this` Vector according to the comparison function `f`, where
|
|
|
|
+ `f(x,y)` returns 0 if x == y, a positive Int if x > y and a
|
|
|
|
+ negative Int if x < y.
|
|
|
|
+
|
|
|
|
+ This operation modifies `this` Vector in place.
|
|
|
|
+
|
|
|
|
+ The sort operation is not guaranteed to be stable, which means that the
|
|
|
|
+ order of equal elements may not be retained.
|
|
|
|
+
|
|
|
|
+ If `f` is null, the result is unspecified.
|
|
|
|
+ **/
|
|
|
|
+ public inline function sort<T>(f:T->T->Int):Void {
|
|
|
|
+ #if (neko || cs || java)
|
|
|
|
+ throw "not yet supported";
|
|
|
|
+ #else
|
|
|
|
+ this.sort(f);
|
|
|
|
+ #end
|
|
|
|
+ }
|
|
}
|
|
}
|