                                                                  weight-calculator op-binding
                                                                  cell constr-lkp)]
                                (if (not full?)
-                                 ; using up an empty slot
+                                 ;; using up an empty slot
                                  (-> plans
-                                     ; yuck. the set might not even exist at this point.
+                                     ;; yuck. the set might not even exist at this point.
                                      (update-in [index :ordered-cells]
                                                 #(conj (if (nil? %1) (sorted-set-by compare-search-plan-cell-by-cost) %1) cell))
                                      (assoc-in [index :cells-by-free free] cell))
-                                 ; replacing the worst
+                                 ;; replacing the worst
                                  (let [evicted (-> ordered-cells first)]
                                    (-> plans
-                                       ; get rid of it from the cells-by-free map
+                                       ;; get rid of it from the cells-by-free map
                                        (update-in [index :cells-by-free] #(dissoc %1 (-> evicted :constr-lkp (lookup/lookup :free))))
-                                       ; get rid of it from the ordered cells set
+                                       ;; get rid of it from the ordered cells set
                                        (update-in [index :ordered-cells] #(disj %1 evicted))
-                                       ; add new item to ordered cells set
+                                       ;; add new item to ordered cells set
                                        (update-in [index :ordered-cells] #(conj %1 cell))
-                                       ; add new item to cells-be-free map
+                                       ;; add new item to cells-be-free map
                                        (assoc-in [index :cells-by-free free] cell)))))
                   :else plans)))
             plans

                                                                             (constraint/->ConstraintBinding type bindings))
                                                                           (:done present-binding)))
                    free (lookup/lookup constr-lkp :free)
                    ; determine duplicate (if any)
                    dupe (get-in column [:cells-by-free free])
                    ; determine whether it fits into the k best or not (only needed if not a dupe actually)
                    full? (>= (count ordered-cells) k)]
                (cond
                  (some? dupe) (if (< (compare cost-calculator (:cost-calculator dupe)) 0)
                                 ; this is better, evict dupe
                                 (let [cell (create-search-plan-cell index cost-calculator
                                                                     weight-calculator op-binding
                                                                     cell constr-lkp)]
                                   (-> plans
                                       (update-in [index :ordered-cells] #(-> %1 (disj dupe) (conj cell)))
                                       (assoc-in [index :cells-by-free free] cell)))
                                 ; existing is better, so don't modify the plan
                                 plans)
                  ; we can fit it in somehow, either by consuming an empty slot, or replacing the worst
                  (or (not full?)
                      (< (compare cost-calculator
                                  (-> ordered-cells first :cost-calculator))

  [op var-lkp constr-lkp condition-types]
  (let [conditions (map #(case %1 :free [:satisfies :free]
                                  :bound [:requires :bound]) condition-types)]
    ;; this check is not required, it serves as an optimization
    ;; for exiting as early as possible in this highly likely situation
    (if-not (reduce #(and %1 (subset?
                               (keys (get op (nth %2 0)))
                               (into #{} (keys (lookup/lookup-by-type constr-lkp (nth %2 1)))))) conditions)
      ()
      (let [sorted-constr (apply union (map #(build-match-list op
                                                               ;; this is shady but we only replace the constraints with their counts
                                                               ;; on the respective map
                                                               (fmap count (lookup/lookup-by-type constr-lkp (nth %1 1)))
                                                               %1) conditions))]
        (loop [open (list (map->BindingBranchNode {:op      op
