<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Roton.Emulation
{
    sealed internal class Heap
    {
        public Heap()
        {
            Entries = new Dictionary<int, byte[]>();
            NextEntry = 1;
        }

        public byte[] this[int index]
        {
            get
            {
                if (Entries.ContainsKey(index))
                {
                    return Entries[index];
                }
                return null;
            }
            set
            {
                if (Entries.ContainsKey(index))
                {
                    // only allow in-place replacement
                    var entry = Entries[index];
                    Array.Resize(ref entry, value.Length);
                    Array.Copy(value, entry, value.Length);
                    Entries[index] = entry;
                }
            }
        }

        public int Allocate(byte[] data)
        {
            byte[] dataCopy = new byte[data.Length];
            Array.Copy(data, dataCopy, dataCopy.Length);
            Entries[NextEntry++] = dataCopy;
            return NextEntry - 1;
        }

        public bool Contains(int index)
        {
            return Entries.ContainsKey(index);
        }

        private Dictionary<int, byte[]> Entries
        {
            get;
            set;
        }

        public bool Free(int index)
        {
            if (Entries.ContainsKey(index))
            {
                Entries.Remove(index);
                return true;
            }
            return false;
        }

        private int NextEntry
        {
            get;
            set;
        }
    }
}<commit_msg>Make Heap reference generator more robust<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Roton.Emulation
{
    sealed internal class Heap
    {
        public Heap()
        {
            Entries = new Dictionary<int, byte[]>();
            SetNextEntry();
        }

        public byte[] this[int index]
        {
            get
            {
                if (Entries.ContainsKey(index))
                {
                    return Entries[index];
                }
                return null;
            }
            set
            {
                if (Entries.ContainsKey(index))
                {
                    // only allow in-place replacement
                    var entry = Entries[index];
                    Array.Resize(ref entry, value.Length);
                    Array.Copy(value, entry, value.Length);
                    Entries[index] = entry;
                }
            }
        }

        public int Allocate(byte[] data)
        {
            byte[] dataCopy = new byte[data.Length];
            Array.Copy(data, dataCopy, dataCopy.Length);
            int index = NextEntry;
            Entries[index] = dataCopy;
            SetNextEntry();
            return index;
        }

        public bool Contains(int index)
        {
            return Entries.ContainsKey(index);
        }

        private Dictionary<int, byte[]> Entries
        {
            get;
            set;
        }

        public bool Free(int index)
        {
            if (Entries.ContainsKey(index))
            {
                Entries.Remove(index);
                return true;
            }
            return false;
        }

        private int NextEntry
        {
            get;
            set;
        }

        private void SetNextEntry()
        {
            while (NextEntry == 0 || Contains(NextEntry))
            {
                NextEntry++;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08616047388260635, 'fraction_numerical': 0.0008077544426494346, 'mean_word_length': 1.0311645708037178, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6923522', 'n_tokens_mistral': 937, 'n_tokens_neox': 886, 'n_words': 205}