<commit_before>#ifndef EVENT_PAGE_2_HPP_
#define EVENT_PAGE_2_HPP_

#include "memory_page.h"

#include "event_page_walker.2.hpp"

#include <ostream>
#include <iostream>
#include <cstring>

#include <boost/pool/object_pool.hpp>

// PAGE_SIZE == 4096
// HEADER_SIZE == 24 ( next pointer + free_start pointer + free_end pointer)
// BLOCK_SIZE = PAGE_SIZE - HEADER_SIZE
// sizeof(event_node) = 16
// sizeof(object_node) = 24
//
// E[ events/object ] = 250 => Max 1 object/page;
// ...
// E[ event/object ] = 1 => Max 100 object/page;
template < class EVT, class OBJ >
class EventPage {
public:
    typedef EVT event_t;
    typedef OBJ object_t;

    typedef boost::object_pool< EventPage< EVT, OBJ > > manager_t;

    struct event_node {
        event_t *   p_event;
        event_node * next;
        event_node( event_t * e = NULL, event_node * n = NULL ) : p_event(e), next(n) {}
        event_node( const event_node & en ) : p_event(en.p_event), next( en.next ) {}

        event_node & operator=( const event_node & en ) {
            p_event = en.p_event;
            next = en.next;
            return *this;
        }
    };

    struct object_node {
        object_t object_id;
        event_node * events;
        object_node(object_t id = object_t(), event_node * n = NULL ) : object_id(id), events(n) {}
        object_node( const object_node & onode ) : object_id( onode.object_id ), events( onode.events ) {}

        object_node & operator=( const object_node & rhs ) {
            object_id = rhs.object_id;
            events = rhs.events;
            return *this;
        }
    };


    enum rb_state { RED, BLACK };

    struct rb_node {
        rb_node * parent, * left, * right;
        object_node onode;
        rb_state state;

        rb_node( rb_node * p = NULL, rb_node * l = NULL, rb_node * r = NULL, object_node o = object_node() ) :
            parent(p),
            left(l),
            right(r),
            onode(o),
            state(RED) {
        }
    };

    struct event_page_header {
        EventPage< EVT, OBJ > * next;
        rb_node     *m_root;
        size_t      m_nObjects, m_nEvents;

        event_page_header( EventPage<EVT,OBJ> * n = NULL, rb_node * r = NULL ) :
            next(n),
            m_root(r),
            m_nObjects(0),
            m_nEvents(0) {
        }
    };

    enum {  HEADER_SIZE = sizeof( event_page_header ) + sizeof( void * ), // additional pointer for virtual table
            BLOCK_SIZE = PAGE_SIZE - HEADER_SIZE,
            EXP_EVENTS_PER_NODE = 3,
            OBJECT_COUNT = (BLOCK_SIZE) / (sizeof(rb_node) + (EXP_EVENTS_PER_NODE - 1) * sizeof(event_node) ),
            EVENT_COUNT = OBJECT_COUNT * (EXP_EVENTS_PER_NODE - 1)
         };

    typedef EventPageWalker<  EventPage< EVT, OBJ > > iterator;
    friend iterator;

    typedef std::pair< iterator, iterator > iterator_range;

    EventPage( EventPage< EVT, OBJ > * n = NULL ) : m_header( n ) {}

    bool hasFreeObjects() {
        return m_header.m_nObjects < OBJECT_COUNT;
    }

    bool isFull() const {
        return (m_header.m_nEvents >= EVENT_COUNT);
    }
<commit_msg>Hard coded the number of objects per page to be 50<commit_after>#ifndef EVENT_PAGE_2_HPP_
#define EVENT_PAGE_2_HPP_

#include "event_page_walker.2.hpp"

#include <ostream>
#include <iostream>
#include <cstring>

#include <boost/pool/object_pool.hpp>

// PAGE_SIZE == 4096
// HEADER_SIZE == 24 ( next pointer + free_start pointer + free_end pointer)
// BLOCK_SIZE = PAGE_SIZE - HEADER_SIZE
// sizeof(event_node) = 16
// sizeof(object_node) = 24
//
// E[ events/object ] = 250 => Max 1 object/page;
// ...
// E[ event/object ] = 1 => Max 100 object/page;
template < class EVT, class OBJ >
class EventPage {
public:
    typedef EVT event_t;
    typedef OBJ object_t;

    typedef boost::object_pool< EventPage< EVT, OBJ > > manager_t;

    struct event_node {
        event_t *   p_event;
        event_node * next;
        event_node( event_t * e = NULL, event_node * n = NULL ) : p_event(e), next(n) {}
        event_node( const event_node & en ) : p_event(en.p_event), next( en.next ) {}

        event_node & operator=( const event_node & en ) {
            p_event = en.p_event;
            next = en.next;
            return *this;
        }
    };

    struct object_node {
        object_t object_id;
        event_node * events;
        object_node(object_t id = object_t(), event_node * n = NULL ) : object_id(id), events(n) {}
        object_node( const object_node & onode ) : object_id( onode.object_id ), events( onode.events ) {}

        object_node & operator=( const object_node & rhs ) {
            object_id = rhs.object_id;
            events = rhs.events;
            return *this;
        }
    };


    enum rb_state { RED, BLACK };

    struct rb_node {
        rb_node * parent, * left, * right;
        object_node onode;
        rb_state state;

        rb_node( rb_node * p = NULL, rb_node * l = NULL, rb_node * r = NULL, object_node o = object_node() ) :
            parent(p),
            left(l),
            right(r),
            onode(o),
            state(RED) {
        }
    };

    struct event_page_header {
        EventPage< EVT, OBJ > * next;
        rb_node     *m_root;
        size_t      m_nObjects, m_nEvents;

        event_page_header( EventPage<EVT,OBJ> * n = NULL, rb_node * r = NULL ) :
            next(n),
            m_root(r),
            m_nObjects(0),
            m_nEvents(0) {
        }
    };

    enum { // HEADER_SIZE = sizeof( event_page_header ) + sizeof( void * ), // additional pointer for virtual table
//            BLOCK_SIZE = PAGE_SIZE - HEADER_SIZE,
            EXP_EVENTS_PER_NODE = 3,
            OBJECT_COUNT = 50,
//            OBJECT_COUNT = (BLOCK_SIZE) / (sizeof(rb_node) + (EXP_EVENTS_PER_NODE - 1) * sizeof(event_node) ),
            EVENT_COUNT = OBJECT_COUNT * EXP_EVENTS_PER_NODE
         };

    typedef EventPageWalker<  EventPage< EVT, OBJ > > iterator;
    friend iterator;

    typedef std::pair< iterator, iterator > iterator_range;

    EventPage( EventPage< EVT, OBJ > * n = NULL ) : m_header( n ) {}

    bool hasFreeObjects() {
        return m_header.m_nObjects < OBJECT_COUNT;
    }

    bool isFull() const {
        return (m_header.m_nEvents >= EVENT_COUNT);
    }

{'fraction_non_alphanumeric': 0.11473583704646721, 'fraction_numerical': 0.008752387014640357, 'mean_word_length': 2.1662468513853903, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 35, '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': '3844128', 'n_tokens_mistral': 2164, 'n_tokens_neox': 2063, 'n_words': 495}