Skip to content

Commit

Permalink
Abandon plumbing.clojure-core idea, revert to x-fast
Browse files Browse the repository at this point in the history
  • Loading branch information
w01fe committed Jan 25, 2013
1 parent 3bed835 commit d665c1d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 71 deletions.
20 changes: 0 additions & 20 deletions src/plumbing/clojure_core.clj

This file was deleted.

20 changes: 19 additions & 1 deletion src/plumbing/core.clj
@@ -1,7 +1,6 @@
(ns plumbing.core
"Utility belt for Clojure in the wild"
(:require
plumbing.clojure-core
[plumbing.fnk.schema :as schema]
[plumbing.fnk.pfnk :as pfnk]
[plumbing.fnk.impl :as fnk-impl]))
Expand Down Expand Up @@ -103,6 +102,25 @@
:when v]
[k v])))

(defn frequencies-fast
"Like clojure.core/frequencies, but faster.
Uses Java's equal/hash, so may produce incorrect results if
given values that are = but not .equal"
[xs]
(let [res (java.util.HashMap.)]
(doseq [x xs]
(.put res x (unchecked-inc (int (or (.get res x) 0)))))
(into {} res)))

(defn distinct-fast
"Like clojure.core/distinct, but faster.
Uses Java's equal/hash, so may produce incorrect results if
given values that are = but not .equal"
[xs]
(let [s (java.util.HashSet.)]
(filter #(when-not (.contains s %) (.add s %) true) xs)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Seqs

Expand Down
50 changes: 0 additions & 50 deletions test/plumbing/clojure_core_test.clj

This file was deleted.

19 changes: 19 additions & 0 deletions test/plumbing/core_test.clj
Expand Up @@ -88,6 +88,25 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Seqs

(deftest frequencies-fast-test
(is (= {\p 2, \s 4, \i 4, \m 1}
(frequencies-fast "mississippi")))
(is (= {1 3 2 2 3 1}
(frequencies-fast [1 2 3 1 2 1])))
;; We don't return the right thing on = but not .equals things,
;; because of the difference between Java Maps and Clojure maps.
(is (= {1 1}
(frequencies-fast [1 (BigInteger. "1")]))))

(deftest distinct-fast-test
(is (= [1 2 3]
(distinct-fast [1 2 3])))
(is (= [1 2 3]
(distinct-fast [1 2 3 2 1 2 3 2 2])))
(is (= []
(distinct-fast []))))


(deftest aconcat-test
(is (= [1 2 3 4 5 6] (aconcat [[1 2 3] [4 5 6]]))))

Expand Down

0 comments on commit d665c1d

Please sign in to comment.