<commit_before>package net.openhft.chronicle.queue.impl.single;

import net.openhft.chronicle.core.Maths;
import net.openhft.chronicle.core.values.LongValue;
import net.openhft.chronicle.wire.Sequence;


class RollCycleEncodeSequence implements Sequence {
    private final LongValue sequenceValue;
    private int cycleShift = 0;
    private long sequenceMask = 0;

    RollCycleEncodeSequence(LongValue sequenceValue, int indexCount, int indexSpacing) {
        this.sequenceValue = sequenceValue;
        cycleShift = Math.max(32, Maths.intLog2(indexCount) * 2 + Maths.intLog2(indexSpacing));
        sequenceMask = (1L << cycleShift) - 1;
    }

    @Override
    public void setSequence(long sequence, long position) {
        if (sequenceValue == null)
            return;
        long value = toLongValue((int) position, sequence);
        sequenceValue.setValue(value);
    }

    @Override
    public long toIndex(long headerNumber, long sequence) {
        int cycle = Maths.toUInt31(headerNumber >> cycleShift);
        return toLongValue(cycle, sequence);
    }

    /**
     * gets the sequence for a writePosition<commit_msg>changed to setOrdered<commit_after>package net.openhft.chronicle.queue.impl.single;

import net.openhft.chronicle.core.Maths;
import net.openhft.chronicle.core.values.LongValue;
import net.openhft.chronicle.wire.Sequence;


class RollCycleEncodeSequence implements Sequence {
    private final LongValue sequenceValue;
    private int cycleShift = 0;
    private long sequenceMask = 0;

    RollCycleEncodeSequence(LongValue sequenceValue, int indexCount, int indexSpacing) {
        this.sequenceValue = sequenceValue;
        cycleShift = Math.max(32, Maths.intLog2(indexCount) * 2 + Maths.intLog2(indexSpacing));
        sequenceMask = (1L << cycleShift) - 1;
    }

    @Override
    public void setSequence(long sequence, long position) {
        if (sequenceValue == null)
            return;
        long value = toLongValue((int) position, sequence);
        sequenceValue.setOrderedValue(value);
    }

    @Override
    public long toIndex(long headerNumber, long sequence) {
        int cycle = Maths.toUInt31(headerNumber >> cycleShift);
        return toLongValue(cycle, sequence);
    }

    /**
     * gets the sequence for a writePosition
{'fraction_non_alphanumeric': 0.0907108591365024, 'fraction_numerical': 0.009594417793283908, 'mean_word_length': 3.3695238095238094, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6991109', 'n_tokens_mistral': 672, 'n_tokens_neox': 640, 'n_words': 157}