                (let [dirtied-rules (aget kind->name->rules kind name)]
                  (dotimes [j (alength dirtied-rules)]
                    (aset rule->dirty? (aget dirtied-rules j) true)))))))))
-
-(deftype AggregateFlow [prefix-len input-index output-kind output-name output-fields aggregate-function]
-  Object
-  (run [this kn rule->dirty? kind->name->rules]
-       (let [current-key nil
-             inputs #js []
-             output-facts&vals #js []]
-         (.foreach input-index
-                   (fn [key]
-                     (when (nil? current-key)
-                       (set!! current-key key))
-                     (when (btree/prefix-not= key current-key prefix-len)
-                       (let [outputs (aggregate-function inputs)]
-                         (dotimes [i (alength outputs)]
-                           (let [output-key (.slice current-key 0 prefix-len)]
-                             (aset output-key prefix-len (aget outputs i))
-                             (apush output-facts&vals output-key)
-                             (apush output-facts&vals 1)))
-                         (set!! current-key key)
-                         (aclear inputs)))
-                     (apush inputs (.slice key prefix-len))))
-         (when (> (alength inputs) 0)
-           (let [outputs (aggregate-function inputs)]
-             (dotimes [i (alength outputs)]
-               (let [output-key (.slice current-key 0 prefix-len)]
-                 (aset output-key prefix-len (aget outputs i))
-                 (apush output-facts&vals output-key)
-                 (apush output-facts&vals 1)))
-             (set!! current-key key)
-             (aclear inputs)))
-         (when (true? (.update-facts kn output-kind output-name output-fields output-facts&vals))
-           (let [dirtied-rules (aget kind->name->rules output-kind output-name)]
-             (dotimes [j (alength dirtied-rules)]
-               (aset rule->dirty? (aget dirtied-rules j) true)))))))
 
 (deftype Flows [rules rule->flow rule->dirty? kind->name->rules name->transient?]
   Object

(.get-or-create-index kn "know" "foo" #js ["x" "y"])

(.get-or-create-index kn "know" "bar" #js ["z"])

(.get-or-create-index kn "know" "quux" #js ["x" "y" "z"])
)

                                                                                                    #js ["overlap" "when" "some-interval" "interval"]
                                                                                                    #js ["overlap" "remember" "rem-bar" "bar"]])

(.add-facts kn "know" "clause-fields" #js ["clause-id" "constant|variable" "key" "val"] #js [#js ["get-foos" "variable" "x" "xx"]
                                                                                             #js ["get-foos" "variable" "y" "yy"]
                                                                                             #js ["some-interval" "variable" "lo" "xx"]
                                                                                             #js ["some-interval" "variable" "hi" "yy"]
                                                                                             #js ["some-interval" "variable" "in" "zz"]
                                                                                             #js ["rem-bar" "variable" "z" "zz"]])

(def flows (compile kn))

(set! (.-rules flows) #js ["single-edge" "transitive-edge" "function-edge" "-function-edge" "overlap"])

(enable-console-print!)

