<commit_before>package com.quantiply.samza.util;

import org.apache.kafka.common.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.ByteBuffer;

public class Partitioner {

    private static Logger logger = LoggerFactory.getLogger(Partitioner.class);

    public static int getPartitionIdForCamus(byte[] camusMsg, int numPartitions) {
        return Partitioner.getPartitionId(new CamusFrame(camusMsg).getBody(), numPartitions);
    }

    public static int getPartitionId(byte[] key, int numPartitions) {
        return getPartitionId(key, 0, key.length, numPartitions);
    }

    public static int getPartitionId(byte[] buffer, int start, int length, int numPartitions) {
        return Utils.abs(murmur2(buffer, start, length)) % numPartitions;
    }

    public static int getPartitionId(ByteBuffer buffer, int numPartitions) {
        if (!buffer.hasArray()) {
            throw new IllegalArgumentException("Buffer is not backed by an array");
        }
        int start = buffer.arrayOffset() + buffer.position();
        int length = buffer.remaining();
        if (logger.isTraceEnabled()) {
            logger.trace(String.format("Buffer arrayOffset %d, position %d, remaining %d, array length %d, start %d, length %d",
                    buffer.arrayOffset(),
                    buffer.position(),
                    buffer.remaining(),
                    buffer.array().length,
                    start,
                    length
            ));
        }
        return getPartitionId(buffer.array(), start, length, numPartitions);
    }

    /**
     * Generates 32 bit murmur2 hash from byte array
     * @param data byte array to hash
     * @return 32 bit hash of the given array
     */
    public static int murmur2(final byte[] data) {
        return murmur2(data, 0, data.length);
    }

    /**
     * Generates 32 bit murmur2 hash from byte array
     * @param data ByteBuffer source
     * @param start start offset
     * @param length number of bytes to use
     * @return 32 bit hash of the given array
     *
     * Adapted from Apache Kafka client utils to support ByteBuffer
     */<commit_msg>Removed log<commit_after>package com.quantiply.samza.util;

import org.apache.kafka.common.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.ByteBuffer;

public class Partitioner {

    private static Logger logger = LoggerFactory.getLogger(Partitioner.class);

    public static int getPartitionIdForCamus(byte[] camusMsg, int numPartitions) {
        return Partitioner.getPartitionId(new CamusFrame(camusMsg).getBody(), numPartitions);
    }

    public static int getPartitionId(byte[] key, int numPartitions) {
        return getPartitionId(key, 0, key.length, numPartitions);
    }

    public static int getPartitionId(byte[] buffer, int start, int length, int numPartitions) {
        return Utils.abs(murmur2(buffer, start, length)) % numPartitions;
    }

    public static int getPartitionId(ByteBuffer buffer, int numPartitions) {
        if (!buffer.hasArray()) {
            throw new IllegalArgumentException("Buffer is not backed by an array");
        }
        int start = buffer.arrayOffset() + buffer.position();
        int length = buffer.remaining();
        return getPartitionId(buffer.array(), start, length, numPartitions);
    }

    /**
     * Generates 32 bit murmur2 hash from byte array
     * @param data byte array to hash
     * @return 32 bit hash of the given array
     */
    public static int murmur2(final byte[] data) {
        return murmur2(data, 0, data.length);
    }

    /**
     * Generates 32 bit murmur2 hash from byte array
     * @param data ByteBuffer source
     * @param start start offset
     * @param length number of bytes to use
     * @return 32 bit hash of the given array
     *
     * Adapted from Apache Kafka client utils to support ByteBuffer
     */
{'fraction_non_alphanumeric': 0.09174311926605505, 'fraction_numerical': 0.008664627930682976, 'mean_word_length': 2.748806112702961, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4154060', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1067, 'n_words': 341}