-(ns
-    ^{:doc "ID allocator system. Used to return new unique integer IDs in a threadsafe manner. IDs may be freed and therefore reused. Allows action fns to be executed in synchronisation with allocation and deallocation."
+(ns ^{:doc "ID allocator system. Used to return new unique integer IDs
+            in a threadsafe manner. IDs may be freed and therefore
+            reused. Allows action fns to be executed in synchronisation
+            with allocation and deallocation."
       :author "Sam Aaron"}
   overtone.sc.machinery.allocator
   (:use [overtone.sc defaults]

   :control-bus  (ref (mk-bitset (sc-arg-default :max-control-bus)))})

(defn- fill-gaps
  "Returns a new vector similar to bs except filled with with size consecutive vals from idx

  example: (fill with 3 from idx 1 for 2 vals)
  (fill-gaps [1 0 0 0 1] 1 2 3) ;=> [1 3 3 0 1]"
  [bs idx size val]
  (loop [bs bs
         idx idx

(defonce _root-group_ (alloc-id :node))

(defn free-id
  "Free the ID of type key. Takes an optional action-fn which it will
   evaluate in transaction with the freeing of the id. (Evaluation
   happens within an agent so there's no need to worry about the
   transaction retrying multiple times).  Therefore there is no
   possibility of interleaving concurrent freeing of ids and execution
   of associated action-fns. Execution of action-fn is also synchronised
   with the execution of alloc-id action-fns (they all use the same
   agent)."
  ([k id] (free-id k id 1 nil))
  ([k id size] (free-id k id size nil))
  ([k id size action-fn]
