<commit_before>/*
 * Copyright 2015-present Facebook, Inc.
 *
 * 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.
 */

#pragma once

#include <array>

#include <glog/logging.h>

#include <folly/Portability.h>
#include <folly/experimental/Instructions.h>

namespace folly {

namespace detail {

//  kSelectInByte
//
//  Described in:
//    http://dsiutils.di.unimi.it/docs/it/unimi/dsi/bits/Fast.html#selectInByte
//
//  A precomputed table containing in position (j, i), for integers i in
//  [0, 256) and j in [0, 8), the position of the j-th set bit in the binary
//  representation of i, or 8 if it has fewer than j set bits.
extern std::array<std::array<std::uint8_t, 256>, 8> const kSelectInByte;

} // namespace detail

/**
 * Returns the position of the k-th 1 in the 64-bit word x.
 * k is 0-based, so k=0 returns the position of the first 1.
 *<commit_msg>Revise the kSelectInByte comments<commit_after>/*
 * Copyright 2015-present Facebook, Inc.
 *
 * 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.
 */

#pragma once

#include <array>

#include <glog/logging.h>

#include <folly/Portability.h>
#include <folly/experimental/Instructions.h>

namespace folly {

namespace detail {

//  kSelectInByte
//
//  Described in:
//    http://dsiutils.di.unimi.it/docs/it/unimi/dsi/bits/Fast.html#selectInByte
//
//  A precomputed tabled containing the positions of the set bits in the binary
//  representations of all 8-bit unsigned integers.
//
//  For i: [0, 256) ranging over all 8-bit unsigned integers and for j: [0, 8)
//  ranging over all 0-based bit positions in an 8-bit unsigned integer, the
//  table entry kSelectInByte[i][j] is the 0-based bit position of the j-th set
//  bit in the binary representation of i, or 8 if it has fewer than j set bits.
//
//  Example: i: 17 (b00010001), j: [0, 8)
//    kSelectInByte[b00010001][0] = 0
//    kSelectInByte[b00010001][1] = 4
//    kSelectInByte[b00010001][2] = 8
//    ...
//    kSelectInByte[b00010001][7] = 8
extern std::array<std::array<std::uint8_t, 256>, 8> const kSelectInByte;

} // namespace detail

/**
 * Returns the position of the k-th 1 in the 64-bit word x.
 * k is 0-based, so k=0 returns the position of the first 1.
 *
{'fraction_non_alphanumeric': 0.10881801125703565, 'fraction_numerical': 0.034083802376485305, 'mean_word_length': 3.4430555555555555, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2241868', 'n_tokens_mistral': 1067, 'n_tokens_neox': 984, 'n_words': 401}