Implement timelines (sorted map of timestamps to values)

This commit is contained in:
Jeremy Penner 2013-03-14 11:04:49 -05:00
parent 29409585e9
commit fcc86c782c

17
src/hottub/timeline.clj Normal file
View file

@ -0,0 +1,17 @@
(ns hottub.timeline)
(defn timeline-create [& [fncomparison]]
(clojure.lang.PersistentTreeMap/create (or fncomparison #(- %1 %2)) nil))
(defn timeline-insert [tln clock val]
(let [queue (or (tln clock) [])]
(assoc tln clock (conj queue val))))
(defn timeline-after [tln clock]
(if-let [kvFirst (first tln)]
(let [clockFirst (kvFirst 0)]
(if (>= (.compare (.comp tln) clock clockFirst) 0)
(recur (dissoc tln clockFirst) clock)
tln))
tln))