<commit_before>#!/bin/python3

import math
import os
import random
import re
import sys
from heapq import heappush, heappop

class MinHeap:
    """A lightweight wrapper around Python's Min heap implementation."""

    def __init__(self):
        self.store = []

    def heap_push(self, value):
        heappush(self.store, value)

    def heap_pop(self):
        return heappop(self.store)

    def peek(self):
        return self.store[0]

    def __len__(self):
        return len(self.store)

    def __str__(self):
        return str(self.store)

class MaxHeap:

    def __init__(self):
        self.store = []

    def heap_push(self, value):
        """Add value to the heap while maintaining the max heap property."""
        self.store.append(value)
        value_idx = len(self.store) - 1
        self.sift_up(self.get_parent_idx(value_idx), value_idx)

    def heap_pop(self):
        """Pop the value off the top of the heap while maintaining the heap property."""
        self.swap(0, len(self.store) - 1)
        result = self.store.pop()
        self.sift_down(0)
        return result

    def sift_up(self, parent_idx, child_idx):
        """Compare the values at parent_idx and child_idx
           If they are in the incorrect order, swap them and sift up with the new parent.
           If they are in the correct order then stop sifting up.
        """
        if (self.store[child_idx] > self.store[parent_idx]):
            self.swap(child_idx, parent_idx)
            return self.sift_up(self.get_parent_idx(parent_idx), parent_idx)

    def sift_down(self, idx):
        """Sift down the value at position idx.
           Compare value with it's larger child.
           If the child is larger than value, swap them.
           Repeat with swapped idx.
        """
        larger_child_idx = self.get_larger_child_idx(idx)
        if (larger_child_idx is None):
            return

        if(self.store[idx] < self.store[larger_child_idx]):
            self.swap(idx, larger_child_idx)
            return self.sift_down(larger_child_idx)

    def get_larger_child_idx(self, idx):
        """Gets the larger child for value at idx"""
        left_child_idx = self.get_left_child_idx(idx)
        right_child_idx = self.get_right_child_idx(idx)

        if(left_child_idx is None):
            return None
        elif(right_child_idx is None):
            return left_child_idx
        else:
            left_child = self.store[left_child_idx]
            right_child = self.store[right_child_idx]
            return left_child_idx if left_child > right_child else right_child_idx


    def get_left_child_idx(self, idx):
        """Returns the left child index for value if it exists.
           Returns None if the value at idx does not have a left child.
        """
        left_child_idx = 2 * idx + 1
        if(left_child_idx >= self.size()):
            return None
        return left_child_idx

    def get_right_child_idx(self, idx):
        """Returns the right child index for value if it exists.
           Returns None if the value at idx does not have a right child.
        """
        right_child_idx = 2 * idx + 2
        if(right_child_idx >= self.size()):
            return None
        return right_child_idx

    def get_parent_idx(self, idx):
        """Return the parent index for node at idx."""
        return idx // 2

    def swap(self, idx_1, idx_2):
        """Swap the values at position idx_1 and idx_2."""
        self.store[idx_1], self.store[idx_2] = self.store[idx_2], self.store[idx_1]<commit_msg>Fix bug with size()<commit_after>#!/bin/python3

import math
import os
import random
import re
import sys
from heapq import heappush, heappop

class MinHeap:
    """A lightweight wrapper around Python's Min heap implementation."""

    def __init__(self):
        self.store = []

    def heap_push(self, value):
        heappush(self.store, value)

    def heap_pop(self):
        return heappop(self.store)

    def peek(self):
        return self.store[0]

    def __len__(self):
        return len(self.store)

    def __str__(self):
        return str(self.store)

class MaxHeap:

    def __init__(self):
        self.store = []

    def heap_push(self, value):
        """Add value to the heap while maintaining the max heap property."""
        self.store.append(value)
        value_idx = len(self.store) - 1
        self.sift_up(self.get_parent_idx(value_idx), value_idx)

    def heap_pop(self):
        """Pop the value off the top of the heap while maintaining the heap property."""
        self.swap(0, len(self.store) - 1)
        result = self.store.pop()
        self.sift_down(0)
        return result

    def sift_up(self, parent_idx, child_idx):
        """Compare the values at parent_idx and child_idx
           If they are in the incorrect order, swap them and sift up with the new parent.
           If they are in the correct order then stop sifting up.
        """
        if (self.store[child_idx] > self.store[parent_idx]):
            self.swap(child_idx, parent_idx)
            return self.sift_up(self.get_parent_idx(parent_idx), parent_idx)

    def sift_down(self, idx):
        """Sift down the value at position idx.
           Compare value with it's larger child.
           If the child is larger than value, swap them.
           Repeat with swapped idx.
        """
        larger_child_idx = self.get_larger_child_idx(idx)
        if (larger_child_idx is None):
            return

        if(self.store[idx] < self.store[larger_child_idx]):
            self.swap(idx, larger_child_idx)
            return self.sift_down(larger_child_idx)

    def get_larger_child_idx(self, idx):
        """Gets the larger child for value at idx"""
        left_child_idx = self.get_left_child_idx(idx)
        right_child_idx = self.get_right_child_idx(idx)

        if(left_child_idx is None):
            return None
        elif(right_child_idx is None):
            return left_child_idx
        else:
            left_child = self.store[left_child_idx]
            right_child = self.store[right_child_idx]
            return left_child_idx if left_child > right_child else right_child_idx


    def get_left_child_idx(self, idx):
        """Returns the left child index for value if it exists.
           Returns None if the value at idx does not have a left child.
        """
        left_child_idx = 2 * idx + 1
        if(left_child_idx >= len(self.store)):
            return None
        return left_child_idx

    def get_right_child_idx(self, idx):
        """Returns the right child index for value if it exists.
           Returns None if the value at idx does not have a right child.
        """
        right_child_idx = 2 * idx + 2
        if(right_child_idx >= len(self.store)):
            return None
        return right_child_idx

    def get_parent_idx(self, idx):
        """Return the parent index for node at idx."""
        return idx // 2

    def swap(self, idx_1, idx_2):
        """Swap the values at position idx_1 and idx_2."""
        self.store[idx_1], self.store[idx_2] = self.store[idx_2], self.store[idx_1]
{'fraction_non_alphanumeric': 0.08772421524663677, 'fraction_numerical': 0.005325112107623318, 'mean_word_length': 2.310296846011132, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '235430', 'n_tokens_mistral': 2178, 'n_tokens_neox': 2115, 'n_words': 654}