private EntitiesOfTypeIterator(
     @NotNull final EntitiesOfTypeRangeIterable iterable, @NotNull final Cursor index) {
   super(iterable);
   setCursor(index);
   final ByteIterable key = LongBinding.longToCompressedEntry(min);
   checkHasNext(getCursor().getSearchKeyRange(key) != null);
 }
 @Override
 protected long countImpl(@NotNull final PersistentStoreTransaction txn) {
   final Cursor cursor = openCursor(txn);
   if (cursor == null) {
     return 0;
   }
   try {
     final ByteIterable key = LongBinding.longToCompressedEntry(min);
     long result = 0;
     boolean success = cursor.getSearchKeyRange(key) != null;
     while (success) {
       if (max > LongBinding.compressedEntryToLong(cursor.getKey())) {
         break;
       }
       result++;
       success = cursor.getNextNoDup();
     }
     return result;
   } finally {
     cursor.close();
   }
 }