<commit_before>/*
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.chrishantha.sample.highcpu;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

public class HashingWorker implements Runnable {

    private final String algorithm;
    private final long length;

    public HashingWorker(long length, String algorithm) {
        this.length = length;
        this.algorithm = algorithm;
    }

    @Override
    public void run() {
        while (true) {
            String data = "";

            // Some random data
            for (int i = 0; i < length; i++) {
                data += UUID.randomUUID().toString();
            }

            MessageDigest digest;
            try {
                digest = MessageDigest.getInstance(algorithm);
            } catch (NoSuchAlgorithmException e) {
                throw new RuntimeException(e);
            }

            // Hash
            digest.update(data.getBytes());
        }
    }
}
<commit_msg>Make sure the computed hash is used.<commit_after>/*
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.chrishantha.sample.highcpu;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

public class HashingWorker implements Runnable {

    private final String algorithm;
    private final long length;

    private byte[] lastComputedHash;

    public HashingWorker(long length, String algorithm) {
        this.length = length;
        this.algorithm = algorithm;
    }

    @Override
    public void run() {
        while (true) {
            String data = "";

            // Some random data
            for (int i = 0; i < length; i++) {
                data += UUID.randomUUID().toString();
            }

            MessageDigest digest;
            try {
                digest = MessageDigest.getInstance(algorithm);
            } catch (NoSuchAlgorithmException e) {
                throw new RuntimeException(e);
            }

            // Hash
            digest.update(data.getBytes());
            byte[] computedHash = digest.digest();
            if (lastComputedHash != null && computedHash.length != lastComputedHash.length) {
                throw new IllegalStateException("Is the hash computation correct??");
            }
            lastComputedHash = computedHash;
        }
    }
}

{'fraction_non_alphanumeric': 0.08531348411107931, 'fraction_numerical': 0.005153163469796736, 'mean_word_length': 2.324452901998097, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6963871', 'n_tokens_mistral': 885, 'n_tokens_neox': 852, 'n_words': 316}