 
 (defprotocol Mutable
   (add! [this metric]))
-
 
 (defprotocol Snapshotable
   (snapshot! [this]))

(ns io.cyanite.engine.buckets
  (: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))

(deftype MetricTuple [^String id ^String path]
  java.lang.Object
  (hashCode [this]
    (.hashCode (str id ":" path)))
  (equals [this other]
    (and
     (= (.id this) (.id other))

          (debug e "exception while snapshotting"))))))

(defn metric-key
  [^MetricTuple k]
  (MetricKey. k (nbhm) (drift-slot)))

(defn tuple
  [^Resolution id ^String path]
  (MetricTuple. id path))

(comment
  (let [k   (tuple (Resolution. 5 3600) "foo")
        mk  (metric-key k)
        now (quot (System/currentTimeMillis) 1000)]
    (add! mk {:time (- now 5) :metric 1.0 :path "bar"})
    (add! mk {:time (- now 5) :metric 1.0 :path "bar"})
