chromium/components/language/content/browser/ulp_language_code_locator/ulp_language_code_locator_helper.h.tmpl

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <bitset>
#include <vector>

namespace {

template <size_t numbits>
static void GetTreeSerialized(std::bitset<numbits>& bitset, const std::vector<uint32_t>& serialized_tree) {
  for(size_t index_word = 0; index_word < serialized_tree.size(); index_word++) {
    const uint32_t word = serialized_tree.at(index_word);
    for(size_t index_bit = 0; index_bit < 32; index_bit++) {
      const size_t index = index_word*32 + index_bit;
      bitset.set(index, (word >> index_bit) & 1);
    }
  }
}

// Instantiating data as static function variables to avoid initializers.

{% for languages, tree_serialized in models -%}
std::vector<std::string> GetLanguagesRank{{loop.index0}}() {
  const std::vector<std::string> kLanguages = {
    {% for language in languages -%}
      "{{language}}",
    {% endfor -%}
  };
  return kLanguages;
}
const size_t kNumBits{{loop.index0}} = {{tree_serialized|length * 32}};
std::bitset<kNumBits{{loop.index0}}> GetTreeSerializedRank{{loop.index0}}() {
  const std::vector<uint32_t> kTreeSerialized = {
    {% for tree_word in tree_serialized -%}
      {{tree_word}},
    {% endfor -%}
  };
  std::bitset<kNumBits{{loop.index0}}> bitset;
  GetTreeSerialized(bitset, kTreeSerialized);
  return bitset;
}

{% endfor -%}
}  // namespace