<commit_before>import numpy as np


ctypedef struct Pair:
    int key
    double value


cdef class Heap:
    cdef int[:] index_by_key
    cdef int[:] key_by_index
    cdef double[:] values
    cdef int size

    def __init__(self, double[:] values):
        self.size = values.shape[0]
        self.index_by_key = np.arange(self.size, dtype=np.intc)
        self.key_by_index = np.arange(self.size, dtype=np.intc)
        self.values = values.copy()
        cdef int i
        for i in reversed(range(self.size / 2)):
            self.sift_down(i)

    cpdef Pair get_min(self):
        return Pair(self.key_by_index[0], self.values[0])

    cpdef void remove_min(self):
        self.swap(0, self.size - 1)
        self.size -= 1
        self.sift_down(0)
<commit_msg>DOC: Add short description of Heap class<commit_after>import numpy as np


ctypedef struct Pair:
    int key
    double value


cdef class Heap:
    """Binary heap.

    Heap stores values and keys. Values are passed explicitly, whereas keys
    are assigned implicitly to natural numbers (from 0 to n - 1).

    The supported operations (all have O(log n) time complexity):

        * Return the current minimum value and the corresponding key.
        * Remove the current minimum value.
        * Change the value of the given key. Note that the key must be still
          in the heap.
    """
    cdef int[:] index_by_key
    cdef int[:] key_by_index
    cdef double[:] values
    cdef int size

    def __init__(self, double[:] values):
        self.size = values.shape[0]
        self.index_by_key = np.arange(self.size, dtype=np.intc)
        self.key_by_index = np.arange(self.size, dtype=np.intc)
        self.values = values.copy()
        cdef int i
        for i in reversed(range(self.size / 2)):
            self.sift_down(i)

    cpdef Pair get_min(self):
        return Pair(self.key_by_index[0], self.values[0])

    cpdef void remove_min(self):
        self.swap(0, self.size - 1)
        self.size -= 1
        self.sift_down(0)

{'fraction_non_alphanumeric': 0.0981169474727453, 'fraction_numerical': 0.008919722497522299, 'mean_word_length': 2.370617696160267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4125804', 'n_tokens_mistral': 684, 'n_tokens_neox': 649, 'n_words': 198}