<commit_before>package org.roaringbitmap;

import java.util.Arrays;
import java.util.BitSet;

public class BitSetUtil {
	// a block consists has a maximum of 1024 words, each representing 64 bits, thus representing at maximum 65536 bits
	static final int BLOCK_LENGTH = 1024; 

	/**
	 * Generate RoaringBitmap out of the bitSet
	 * 
	 * @param bitSet
	 * @return roaring bitmap
	 */
	static RoaringBitmap bitmapOf(final BitSet bitSet) {
		final int cardinality = bitSet.cardinality();
		if (cardinality == 0) {
			return new RoaringBitmap();
		} else if (cardinality <= ArrayContainer.DEFAULT_MAX_SIZE) {
			// if it is a tiny bitSet, we can directly build a arrayContainer, without an extra bitSet#toLongArray
			final RoaringBitmap bitmap = new RoaringBitmap();
			bitmap.highLowContainer.append((short)0, arrayContainerOf(cardinality, bitSet));
			return bitmap;
		} else {
			return bitmapOf(cardinality, bitSet.toLongArray());
		}
	}

	/**
	 * Generate RoaringBitmap out of a long[], each long using little-endian representation of its bits <commit_msg>add toLongArray workaround for jdk version < 1.7<commit_after>package org.roaringbitmap;

import java.util.Arrays;
import java.util.BitSet;

public class BitSetUtil {
	// a block consists has a maximum of 1024 words, each representing 64 bits, thus representing at maximum 65536 bits
	static final int BLOCK_LENGTH = 1024; 

	/**
	 * Generate RoaringBitmap out of the bitSet
	 * 
	 * @param bitSet
	 * @return roaring bitmap
	 */
	static RoaringBitmap bitmapOf(final BitSet bitSet) {
		final int cardinality = bitSet.cardinality();
		if (cardinality == 0) {
			return new RoaringBitmap();
		} else if (cardinality <= ArrayContainer.DEFAULT_MAX_SIZE) {
			// if it is a tiny bitSet, we can directly build a arrayContainer, without an extra bitSet#toLongArray
			final RoaringBitmap bitmap = new RoaringBitmap();
			bitmap.highLowContainer.append((short)0, arrayContainerOf(cardinality, bitSet));
			return bitmap;
		} else {
			// before jdk 1.7
			return bitmapOf(cardinality, toLongArray(cardinality, bitSet));
			// starting with jdk.17
			//return bitmapOf(cardinality, bitSet.toLongArray());
		}
	}
	
	private static long[] toLongArray(final int cardinality, final BitSet bitSet) {		
		final long[] words = new long[(bitSet.length() + 63) / 64];
	    for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i+1)) {
            if (i == Integer.MAX_VALUE) {
                break;
            }
            words[i / 64] |= (1L << i % 64); 
	    }
	    return words;
   }

	/**
	 * Generate RoaringBitmap out of a long[], each long using little-endian representation of its bits 
{'fraction_non_alphanumeric': 0.09739524348810873, 'fraction_numerical': 0.01963004907512269, 'mean_word_length': 3.6006944444444446, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6263852', 'n_tokens_mistral': 899, 'n_tokens_neox': 786, 'n_words': 265}