 ;;    I.e., live decrease -50 to -49, now blocked sibling becomes best; above is -50 TDB;
 ;; TODO: smarter summary updates (i.e., pass child)
 ;; TODO: smarter choose-leaf?
+;; TODO: conspiracy number, weighted, etc.
 
 ;;;;; SP caching
 ;; TODO: tail (i.e., pair) caching? -- Only help for >2 len refs...


(defn atomic-name-fs [n] (assert (= :Atomic (first n))) (second n))
(defn log-input [fs inp-set] (if *state-abstraction* (fs/get-logger fs inp-set) inp-set))

(defn get-input-key [fs inp-set] (if *state-abstraction* (fs/extract-context fs inp-set) inp-set))
(defn get-cache-key [atomic-n inp-set] [atomic-n (get-input-key (atomic-name-fs atomic-n) inp-set)])

;; Input-key caching not necessary, but speeds things up a lot on, e.g., d-m.
(defn- make-output-collecting-subproblem [fs inp-key inner-sp]

(def *decreases* (ArrayList.))
(def *subsumes* (ArrayList.))

(defn schedule-increase! [sp] (.add ^ArrayList *increases* sp))
(defn schedule-decrease! [sp] (.add ^ArrayList *decreases* sp))
(defn schedule-subsumption! [ts subsumed-ts] (.add ^ArrayList *subsumes* [ts subsumed-ts]))

(defn do-changes! [^ArrayList a f] (doseq [sp a] (f sp)) (.clear a))

(declare evaluate!)

(defn evaluate-and-update! [s]
  (evaluate! s)
  (do-changes! *increases* summaries/summary-increased!) ;; Must go first for correctness.
