 
 
 ;;; Making final maps.  TODO: precompile?
-(defn make-permuter [args var-ordering]
-  (let [arg-positions (map vector (iterate inc 1) (map #(util/position % var-ordering) args))
-	arg-permutation (map first (sort-by second arg-positions))]
-    (fn permute [#^clojure.lang.APersistentVector tuple] 
-      (map (fn [ind] (.get tuple ind)) arg-permutation))))
+;(defn make-permuter [args var-ordering]
+;  (let [arg-positions (map vector (iterate inc 1) (map #(util/position % var-ordering) args))
+;	arg-permutation (map first (sort-by second arg-positions))]
+;    (fn permute [#^clojure.lang.APersistentVector tuple] 
+;      (util/vec-map (fn [ind] (.get tuple ind)) arg-permutation))))
+
+(defn get-permutation [args var-ordering]
+  (let [arg-positions (map vector (iterate inc 1) (map #(util/position % var-ordering) args))]
+    (vec (map first (sort-by second arg-positions)))))
+
+
+; TODO: be smarter about map sizes?
+(defn my-assoc-in [#^HashMap m #^clojure.lang.APersistentVector key-vec #^clojure.lang.APersistentVector perm ind]
+;  (println m key-vec perm ind)
+  (if (< (inc ind) (count perm))
+      (let [key (.get key-vec (.get perm ind))
+	    #^HashMap m2 
+             (or (.get m key) 
+		 (let [#^HashMap m2 (HashMap.)]
+		   (.put m key m2)
+		   m2))]
+	(recur m2 key-vec perm (inc ind)))
+    (.put m (.get key-vec (.get perm ind)) true)))
 
   
 ;; TODO: filter based on domains?

(ns edu.berkeley.ai.search.smart-csps
 (:refer-clojure)
 (:import [java.util HashMap])
 (:require [edu.berkeley.ai.util :as util] 
	   [edu.berkeley.ai.util.propositions :as props]
	   )

	       pred
	       (rest (util/safe-get pred-instance-map pred-gen)) 
	       var-ordering
	       dummy-unary-var dummy-unary-val)])
	sz (count map-makers)
	bigsz (int (inc (* 1.12 sz)))]
    (fn pred-map-maker [[true-tuple-map poss-tuple-map]]
      (let [#^HashMap m (HashMap. bigsz 0.9)]
	(doseq [[pn map-maker] map-makers]
	  (.put m pn (list (map-maker true-tuple-map poss-tuple-map))))
	m))))
;      (HashMap.
;      (util/map-map
;       (fn [[pn map-maker]] [pn (map-maker true-tuple-map poss-tuple-map)])
;       map-makers)))))



