<commit_before>//
//  seglist.h
//
//  Created by <NAME> on 23/10/2014.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//


#ifndef SEGLIST_H
#define SEGLIST_H


/*
    A write-only container which is used to build a list of elements by
    appending them to the end.
*/


#include <assert.h>
#include <iterator>
#include <limits>
#include <new>


template < typename element_t >
class seglist
{
private:

    static const size_t ELEMENT_COUNT = 250;

    struct segment
    {
        segment*    next;
        segment*    prev;
        element_t   elements[];
    };

    template < typename value_t >
    class basic_iterator
        :   public std::iterator< std::forward_iterator_tag, value_t >
    {
    public:
    
        basic_iterator( const basic_iterator< const element_t >& iterator );
    
        bool operator != ( const basic_iterator& b ) const;

        basic_iterator& operator ++ ();
        basic_iterator operator ++ ( int );
        
        value_t& operator * () const;
        value_t* operator -> () const;
    
    private:
    
        friend class seglist;
        
        basic_iterator( segment* current, size_t index );
    
        segment*    current;
        size_t      index;

    };


public:

    typedef element_t value_type;
    typedef element_t& reference;
    typedef const element_t& const_reference;
    typedef basic_iterator< element_t > iterator;
    typedef basic_iterator< const element_t > const_iterator;
    typedef typename std::iterator_traits< iterator >::difference_type
                    difference_type;
    typedef size_t size_type;
    
    seglist();
    seglist( seglist&& s );
    seglist( const seglist& s );
    seglist& operator = ( seglist&& s );
    seglist& operator = ( const seglist& s );
    ~seglist();

    bool operator == ( const seglist& b ) const;
    bool operator != ( const seglist& b ) const;
    
    size_type       size() const;
    size_type       max_size() const;
    bool            empty() const;

    const_iterator  cbegin() const;
    const_iterator  begin() const;
    const_iterator  cend() const;
    const_iterator  end() const;
    const_reference back() const;

    iterator        begin();
    iterator        end();
    reference       back();

    void            push_back( element_t&& element );
    void            push_back( const element_t& element );
    template < typename ... arguments_t > void emplace_back( arguments_t ... arguments );
    void            pop_back();
    
    void            clear();

    void            swap( seglist& s );
    

private:

    segment*        new_segment();
    void            pushed_back();

    segment*        first;
    segment*        last;
    size_t          index;

};


template < typename element_t >
void swap( seglist< element_t >& a, seglist< element_t >& b );






template < typename element_t >
template < typename value_t >
seglist< element_t >::basic_iterator< value_t >::basic_iterator(
                segment* current, size_t index )
    :   current( current )
    ,   index( index )
{
}

template < typename element_t >
template < typename value_t >
seglist< element_t >::basic_iterator< value_t >::basic_iterator(
                const basic_iterator< const element_t >& iterator )
    :   current( iterator.current )
    ,   index( iterator.index )
{
}

template < typename element_t >
template < typename value_t >
bool seglist< element_t >::basic_iterator< value_t >::operator != (
                const basic_iterator& b ) const
{
    return current != b.current || index != b.index;
}

template < typename element_t >
template < typename value_t >
seglist< element_t >::basic_iterator< value_t >&
        seglist< element_t >::basic_iterator< value_t >::operator ++ ()
{
    index += 1;
    if ( index >= ELEMENT_COUNT )
    {
        current = current->next;
        index = 0;
    }
}

template < typename element_t >
template < typename value_t >
seglist< element_t >::basic_iterator< value_t >
        seglist< element_t >::basic_iterator< value_t >::operator ++ ( int )
{
    basic_iterator result( *this );
    operator ++ ();
    return result;
}

template < typename element_t >
template < typename value_t >
value_t& seglist< element_t >::basic_iterator< value_t >::operator * () const
{
    return current->elements[ index ];
}

template < typename element_t >
template < typename value_t >
value_t* seglist< element_t >::basic_iterator< value_t >::operator -> () const
{
    return current->elements + index;
}



template < typename element_t >
seglist< element_t >::seglist()<commit_msg>minor updates to seglist<commit_after>//
//  seglist.h
//
//  Created by <NAME> on 23/10/2014.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//


#ifndef SEGLIST_H
#define SEGLIST_H


/*
    A write-only container which is used to build a list of elements by
    appending them to the end.
*/


#include <assert.h>
#include <iterator>
#include <limits>
#include <new>


template < typename element_t >
class seglist
{
private:

    static const size_t ELEMENT_COUNT = 250;

    struct segment
    {
        segment*    next;
        segment*    prev;
        element_t   elements[];
    };

    template < typename result_t >
    class basic_iterator
        :   public std::iterator< std::forward_iterator_tag, result_t >
    {
    public:
    
        basic_iterator( const basic_iterator< const element_t >& iterator );
    
        bool operator != ( const basic_iterator& b ) const;

        basic_iterator& operator ++ ();
        basic_iterator operator ++ ( int );
        
        result_t& operator * () const;
        result_t* operator -> () const;
    
    private:
    
        friend class seglist;
        
        basic_iterator( segment* current, size_t index );
    
        segment*    current;
        size_t      index;

    };


public:

    typedef element_t value_type;
    typedef element_t& reference;
    typedef const element_t& const_reference;
    typedef basic_iterator< element_t > iterator;
    typedef basic_iterator< const element_t > const_iterator;
    typedef ptrdiff_t difference_type;
    typedef size_t size_type;
    
    seglist();
    seglist( seglist&& s );
    seglist( const seglist& s );
    seglist& operator = ( seglist&& s );
    seglist& operator = ( const seglist& s );
    ~seglist();

    bool operator == ( const seglist& b ) const;
    bool operator != ( const seglist& b ) const;
    
    size_type       size() const;
    size_type       max_size() const;
    bool            empty() const;

    const_iterator  cbegin() const;
    const_iterator  begin() const;
    const_iterator  cend() const;
    const_iterator  end() const;
    const_reference back() const;

    iterator        begin();
    iterator        end();
    reference       back();

    void            push_back( element_t&& element );
    void            push_back( const element_t& element );
    template < typename ... arguments_t > void emplace_back( arguments_t ... arguments );
    void            pop_back();
    void            clear();

    void            swap( seglist& s );
    

private:

    segment*        new_segment();
    void            pushed_back();

    segment*        first;
    segment*        last;
    size_t          index;

};


template < typename element_t >
void swap( seglist< element_t >& a, seglist< element_t >& b );






template < typename element_t >
template < typename result_t >
seglist< element_t >::basic_iterator< result_t >::basic_iterator(
                segment* current, size_t index )
    :   current( current )
    ,   index( index )
{
}

template < typename element_t >
template < typename result_t >
seglist< element_t >::basic_iterator< result_t >::basic_iterator(
                const basic_iterator< const element_t >& iterator )
    :   current( iterator.current )
    ,   index( iterator.index )
{
}

template < typename element_t >
template < typename result_t >
bool seglist< element_t >::basic_iterator< result_t >::operator != (
                const basic_iterator& b ) const
{
    return current != b.current || index != b.index;
}

template < typename element_t >
template < typename result_t >
seglist< element_t >::basic_iterator< result_t >&
        seglist< element_t >::basic_iterator< result_t >::operator ++ ()
{
    index += 1;
    if ( index >= ELEMENT_COUNT )
    {
        current = current->next;
        index = 0;
    }
}

template < typename element_t >
template < typename result_t >
seglist< element_t >::basic_iterator< result_t >
        seglist< element_t >::basic_iterator< result_t >::operator ++ ( int )
{
    basic_iterator result( *this );
    operator ++ ();
    return result;
}

template < typename element_t >
template < typename result_t >
result_t& seglist< element_t >::basic_iterator< result_t >::operator * () const
{
    return current->elements[ index ];
}

template < typename element_t >
template < typename result_t >
result_t* seglist< element_t >::basic_iterator< result_t >::operator -> () const
{
    return current->elements + index;
}



template < typename element_t >
seglist< element_t >::seglist()
{'fraction_non_alphanumeric': 0.1043649491302921, 'fraction_numerical': 0.003719505524559676, 'mean_word_length': 2.5080583269378356, 'pattern_counts': {'":': 0, '<': 106, '<?xml version=': 0, '>': 118, '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': '7286025', 'n_tokens_mistral': 2801, 'n_tokens_neox': 2703, 'n_words': 775}