diff options
author | Daniel Solano Gómez <clojure@sattvik.com> | 2011-02-25 16:09:06 -0600 |
---|---|---|
committer | Stuart Halloway <stu@Orolo-2.local> | 2011-03-20 09:34:28 -0400 |
commit | 0245f15c9c7bd2d043f0f6e59fff0a692d7466b1 (patch) | |
tree | a637d0aba0625b0228c7b6e9d87f11193417d950 /src | |
parent | 8c783f1c1a6fb0cf9c50e4737596e92bceb8012b (diff) |
Add (vector a b c ...) like functionality to vector-of, plus tests
Signed-off-by: Stuart Halloway <stu@Orolo-2.local>
Diffstat (limited to 'src')
-rw-r--r-- | src/clj/clojure/gvec.clj | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/src/clj/clojure/gvec.clj b/src/clj/clojure/gvec.clj index fa1ba03e..6aabd1eb 100644 --- a/src/clj/clojure/gvec.clj +++ b/src/clj/clojure/gvec.clj @@ -453,8 +453,43 @@ "Creates a new vector of a single primitive type t, where t is one of :int :long :float :double :byte :short :char or :boolean. The resulting vector complies with the interface of vectors in general, - but stores the values unboxed internally." - {:added "1.2"} - [t] - (let [am ^clojure.core.ArrayManager (ams t)] - (Vec. am 0 5 EMPTY-NODE (.array am 0) nil))) + but stores the values unboxed internally. + + Optionally takes one or more elements to populate the vector." + {:added "1.2" + :arglists '([t] [t & elements])} + ([t] + (let [am ^clojure.core.ArrayManager (ams t)] + (Vec. am 0 5 EMPTY-NODE (.array am 0) nil))) + ([t x1] + (let [am ^clojure.core.ArrayManager (ams t) + arr (.array am 1)] + (.aset am arr 0 x1) + (Vec. am 1 5 EMPTY-NODE arr nil))) + ([t x1 x2] + (let [am ^clojure.core.ArrayManager (ams t) + arr (.array am 2)] + (.aset am arr 0 x1) + (.aset am arr 1 x2) + (Vec. am 2 5 EMPTY-NODE arr nil))) + ([t x1 x2 x3] + (let [am ^clojure.core.ArrayManager (ams t) + arr (.array am 3)] + (.aset am arr 0 x1) + (.aset am arr 1 x2) + (.aset am arr 2 x3) + (Vec. am 3 5 EMPTY-NODE arr nil))) + ([t x1 x2 x3 x4] + (let [am ^clojure.core.ArrayManager (ams t) + arr (.array am 4)] + (.aset am arr 0 x1) + (.aset am arr 1 x2) + (.aset am arr 2 x3) + (.aset am arr 3 x4) + (Vec. am 4 5 EMPTY-NODE arr nil))) + ([t x1 x2 x3 x4 & xn] + (loop [v (vector-of t x1 x2 x3 x4) + xn xn] + (if xn + (recur (.cons v (first xn)) (next xn)) + v)))) |