Skip to content

Commit

Permalink
small performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Mar 15, 2016
1 parent db7bf9c commit 1da3805
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/nal/deriver.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns nal.deriver
(:require
[nal.deriver.utils :refer [walk]]
[nal.deriver.key-path :refer [mall-paths all-paths path mpath-invariants]]
[nal.deriver.key-path :refer [mall-paths all-paths mpath-invariants
path-with-max-level]]
[nal.deriver.rules :refer [rule]]))

(defn get-matcher [rules p1 p2]
Expand All @@ -15,7 +16,7 @@
(fn [t1 t2] (mapcat #(% t1 t2) matchers)))))

(def mget-matcher (memoize get-matcher))
(def mpath (memoize path))
(def mpath (memoize path-with-max-level))
(defn generate-conclusions
[rules {p1 :statement :as t1} {p2 :statement :as t2}]
(let [matcher (mget-matcher rules (mpath p1) (mpath p2))]
Expand Down
12 changes: 12 additions & 0 deletions src/nal/deriver/key_path.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
(conj (map path tail) fst))
:any))

(defn path-with-max-level
([statement] (path-with-max-level 0 statement))
([level statement]
(if (coll? statement)
(let [[fst & tail] statement]
(cons fst
(if (> 1 level)
(let [next-level (if (= 'conj fst) level (inc level))]
(map #(path-with-max-level next-level %) tail))
(repeat (count tail) :any))))
:any)))

(defn rule-path
"Generates detailed pattern for the rule."
[p1 p2]
Expand Down

0 comments on commit 1da3805

Please sign in to comment.