<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.jackrabbit.oak.util;

import java.util.Random;
import java.util.UUID;

import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;

/**
 * An approximate counter algorithm.
 */
public class ApproximateCounter {
    
    public static final String COUNT_PROPERTY_PREFIX = ":count_";
    public static final int COUNT_RESOLUTION = 100;
    public static final int COUNT_MAX = 10000000;

    private static final Random RANDOM = new Random();
    
    /**
     * Calculate the approximate offset from a given offset. The offset is the
     * number of added or removed entries. The result is 0 in most of the cases,
     * but sometimes it is a (positive or negative) multiple of the resolution,
     * such that on average, the sum of the returned value matches the sum of
     * the passed offsets.
     * 
     * @param offset the high-resolution input offset
     * @param resolution the resolution
     * @return the low-resolution offset (most of the time 0)
     */
    public static long calculateOffset(long offset, int resolution) {
        if (offset == 0 || resolution <= 1) {
            return offset;
        }
        int add = resolution;<commit_msg>OAK-6078 : oak.util.ApproximateCounter must have private constructor<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.jackrabbit.oak.util;

import java.util.Random;
import java.util.UUID;

import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;

/**
 * An approximate counter algorithm.
 */
public class ApproximateCounter {
    
    public static final String COUNT_PROPERTY_PREFIX = ":count_";
    public static final int COUNT_RESOLUTION = 100;
    public static final int COUNT_MAX = 10000000;

    private static final Random RANDOM = new Random();

    private ApproximateCounter() {
    }

    /**
     * Calculate the approximate offset from a given offset. The offset is the
     * number of added or removed entries. The result is 0 in most of the cases,
     * but sometimes it is a (positive or negative) multiple of the resolution,
     * such that on average, the sum of the returned value matches the sum of
     * the passed offsets.
     * 
     * @param offset the high-resolution input offset
     * @param resolution the resolution
     * @return the low-resolution offset (most of the time 0)
     */
    public static long calculateOffset(long offset, int resolution) {
        if (offset == 0 || resolution <= 1) {
            return offset;
        }
        int add = resolution;
{'fraction_non_alphanumeric': 0.07235494880546076, 'fraction_numerical': 0.00955631399317406, 'mean_word_length': 3.3225172074729596, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '3525853', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1116, 'n_words': 508}