   "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)
+  ^BitSet [^PersistentVector element-vector ^PersistentHashSet hashset]
+  (let [nr-elements (int (count element-vector))
+        ^BitSet bs (BitSet. nr-elements)]
+    (loop [index nr-elements]
+      (if (zero? index)
+        bs
+        (let [dec-index (dec index)
+              elt (.get element-vector dec-index)]
+          (when (.contains hashset elt)
             (.set bs index))
-          (recur (next elements) (inc index)))
-        bs))))
+          (recur dec-index))))))
 
 (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]
+  [^PersistentVector 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))))))
+             (conj! result (.get element-vector pos))))))
 
 (defn to-binary-matrix
   "Converts the incidence-relation to a binary matrix (in the sense of

            [conexp.io.util :refer :all]
            [conexp.util.exec :refer :all])
  (:import conexp.fca.implications.Implication
           [java.util ArrayList BitSet LinkedList List ListIterator]))


;;; Helpers to convert to and from BitSets


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