<commit_before>/****************************************************************************
 * Copyright (c) 2012-2018 by the DataTransferKit authors                   *
 * All rights reserved.                                                     *
 *                                                                          *
 * This file is part of the DataTransferKit library. DataTransferKit is     *
 * distributed under a BSD 3-clause license. For the licensing terms see    *
 * the LICENSE file in the top-level directory.                             *
 *                                                                          *
 * SPDX-License-Identifier: BSD-3-Clause                                    *
 ****************************************************************************/
#ifndef DTK_DETAILS_PRIORITY_QUEUE_HPP
#define DTK_DETAILS_PRIORITY_QUEUE_HPP

#include <Kokkos_Macros.hpp>

#include <cassert>
#include <cstdlib>
#include <utility>

namespace DataTransferKit
{
namespace Details
{

template <typename T>
struct Less
{
  public:
    KOKKOS_INLINE_FUNCTION bool operator()( T const &x, T const &y )
    {
        return x < y;
    }
};

template <typename T, typename Compare = Less<T>>
class PriorityQueue
{
  public:
    using SizeType = size_t;

    KOKKOS_FUNCTION PriorityQueue() = default;

    KOKKOS_INLINE_FUNCTION bool empty() const { return _size == 0; }

    template <typename... Args>
    KOKKOS_INLINE_FUNCTION void push( Args &&... args )
    {
        // ensure the heap is not already full
        assert( _size < _max_size );

        // add the element to the bottom level of the heap
        SizeType pos = _size;
        T elem{std::forward<Args>( args )...};

        // perform up-heap operation
        while ( pos > 0 )
        {
            // compare the added element with its parent
            // if they are in correct order, stop
            // if not, swap them and continue
            SizeType const parent = ( pos - 1 ) / 2;
            if ( !_compare( _heap[parent], elem ) )
                break;
            _heap[pos] = _heap[parent];
            pos = parent;<commit_msg>Add ValueType alias and size() to PriorityQueue<commit_after>/****************************************************************************
 * Copyright (c) 2012-2018 by the DataTransferKit authors                   *
 * All rights reserved.                                                     *
 *                                                                          *
 * This file is part of the DataTransferKit library. DataTransferKit is     *
 * distributed under a BSD 3-clause license. For the licensing terms see    *
 * the LICENSE file in the top-level directory.                             *
 *                                                                          *
 * SPDX-License-Identifier: BSD-3-Clause                                    *
 ****************************************************************************/
#ifndef DTK_DETAILS_PRIORITY_QUEUE_HPP
#define DTK_DETAILS_PRIORITY_QUEUE_HPP

#include <Kokkos_Macros.hpp>

#include <cassert>
#include <cstdlib>
#include <utility>

namespace DataTransferKit
{
namespace Details
{

template <typename T>
struct Less
{
  public:
    KOKKOS_INLINE_FUNCTION bool operator()( T const &x, T const &y )
    {
        return x < y;
    }
};

template <typename T, typename Compare = Less<T>>
class PriorityQueue
{
  public:
    using SizeType = size_t;
    using ValueType = T;

    KOKKOS_FUNCTION PriorityQueue() = default;

    KOKKOS_INLINE_FUNCTION bool empty() const { return _size == 0; }

    KOKKOS_INLINE_FUNCTION IndexType size() const { return _size; }

    template <typename... Args>
    KOKKOS_INLINE_FUNCTION void push( Args &&... args )
    {
        // ensure the heap is not already full
        assert( _size < _max_size );

        // add the element to the bottom level of the heap
        SizeType pos = _size;
        T elem{std::forward<Args>( args )...};

        // perform up-heap operation
        while ( pos > 0 )
        {
            // compare the added element with its parent
            // if they are in correct order, stop
            // if not, swap them and continue
            SizeType const parent = ( pos - 1 ) / 2;
            if ( !_compare( _heap[parent], elem ) )
                break;
            _heap[pos] = _heap[parent];
            pos = parent;
{'fraction_non_alphanumeric': 0.14483227561196735, 'fraction_numerical': 0.006346328195829556, 'mean_word_length': 1.7615769712140175, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7056151', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1075, 'n_words': 358}