 (ns io.cyanite.engine.buckets
-  (:require [io.cyanite.utils :refer [nbhm keyset remove!]]
+  (:require [io.cyanite.utils      :refer [nbhm keyset remove!]]
             [clojure.tools.logging :refer [debug]])
   (:import java.util.concurrent.atomic.AtomicLong
            java.util.concurrent.atomic.AtomicLongArray
-           java.util.concurrent.atomic.AtomicReferenceArray))
+           java.util.concurrent.atomic.AtomicReferenceArray
+           io.cyanite.engine.rule.Resolution))
 
-(deftype MetricTuple [^String id ^String path]
+(deftype MetricTuple [^Resolution id ^String path]
   java.lang.Object
   (hashCode [this]
-    (.hashCode (str id ":" path)))
+    (.hashCode [id path]))
   (equals [this other]
     (and
      (= (.id this) (.id other))

    (assoc! time-slots k slot)
    slot))

(defrecord MetricKey [k resolution time-slots drift]
  Mutable
  (add! [this metric]
    (add! drift (:time metric))
    (let [slot (time-slot resolution (:time metric))
          k    (TimeSlotTuple. (:path metric) slot)
          mts  (or (get time-slots k)
                   (insert-slot! time-slots k resolution))]
      (add! mts metric)
      (snapshot! this)))
  Snapshotable
  (snapshot! [this]
    (let [now       (quot (System/currentTimeMillis) 1000)
          drift-ts  (- now @drift)
          low-slot  (time-slot resolution drift-ts)
          slots     (keyset time-slots)
          old-slots (filter #(< (.slot %) low-slot) slots)]
      (try

    (* p (quot now p))))

(defn insert-slot!
  [time-slots k]
  (let [slot (MetricTimeSlot.
              k
              (AtomicLong. 0)
