Implement timelines (sorted map of timestamps to values)
This commit is contained in:
parent
29409585e9
commit
fcc86c782c
17
src/hottub/timeline.clj
Normal file
17
src/hottub/timeline.clj
Normal 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))
|
||||
|
Loading…
Reference in a new issue