 
 (defn filter-bitset
   "Returns a new bitset of all bits in bitset for which predicate returns true."
-  [predicate, ^BitSet bitset]
+  [^IFn predicate, ^BitSet bitset]
   (let [result (BitSet.)]
     (dobits [i bitset]
       (when (predicate i)

  "Converts hashset to a BitSet. Elements are associated with indices
  as given by element-vector (i.e. the order in this vector is the
  order of the elements in the resulting BitSet."
  [element-vector hashset]
  (let [^BitSet bs (BitSet. (count element-vector))]
    (loop [elements (seq element-vector)
           index    0]
      (if elements
        (let [elt (first elements)]
          (when (contains? hashset elt)
            (.set bs index))
          (recur (next elements) (inc index)))
        bs))))

(defn to-hashset
  "Converts given bitset to a set, where element-vector gives the
  actual objects to be collected, i.e. element v at position p in
  element-vector is included in the result iff p is set in bitset."
  [element-vector, ^BitSet bitset]
  (loop [pos    (int (.nextSetBit bitset 0)),
         result (transient #{})]
    (if (== -1 pos)
      (persistent! result)
      (recur (.nextSetBit bitset (inc pos))
             (conj! result (nth element-vector pos))))))

(defn to-binary-matrix
  "Converts the incidence-relation to a binary matrix (in the sense of

    A))

(defn next-closed-set
  "Computes the next closed set of closure after A.
  Returns nil if there is none."
  [^long attribute-count, closure, ^BitSet A]
  (let [^BitSet B (.clone A)]
    (loop [i (dec attribute-count)]
      (cond
        (== -1 i)
        nil,
        (.get B i)
        (do (.clear B i)
            (recur (dec i))),
        :else
        (do (.set B i)
            (let [^BitSet A_i (closure B)]
              (if (loop [j (long (dec i))]
                    (cond
                      (< j 0)
                      true,
                      (not= (.get A j) (.get A_i j))
                      false,
                      :else
                      (recur (dec j))))
                A_i
                (do (.clear B i)
                    (recur (dec i))))))))))


;;; Computing Canonical Base efficiently
