Skip to content

Commit

Permalink
big perf boost to hard0 sudoku by implementing Object equals for Fini…
Browse files Browse the repository at this point in the history
…teDomain
  • Loading branch information
David Nolen authored and David Nolen committed Oct 14, 2012
1 parent 8d08726 commit 6129019
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/main/clojure/clojure/core/logic.clj
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@

(declare domain sorted-set->domain
difference* intersection* disjoint?*
unify-with-domain*)
unify-with-domain* finite-domain?)

;; FiniteDomain
;; -----
Expand All @@ -306,6 +306,13 @@
;; max - the maximum value, an optimization

(deftype FiniteDomain [s min max]
Object
(equals [this that]
(if (finite-domain? that)
(if (= (member-count this) (member-count that))
(= s (:s that))
false)
false))
clojure.lang.ILookup
(valAt [this k]
(.valAt this k nil))
Expand Down Expand Up @@ -366,6 +373,9 @@
IIntervals
(intervals [_] (seq s)))

(defn finite-domain? [x]
(instance? FiniteDomain x))

(defn sorted-set->domain [s]
(let [c (count s)]
(cond
Expand Down
2 changes: 1 addition & 1 deletion src/main/clojure/clojure/core/logic/bench.clj
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@

(dotimes [_ 5]
(time
(dotimes [_ 10]
(dotimes [_ 1]
(sudokufd hard0))))

;; from GeCode test suite
Expand Down

0 comments on commit 6129019

Please sign in to comment.