<commit_before>// =================================================================== //
// LightContainer : std::vector like container
// Time-stamp: <15 Sep 08 14:11:27 <EMAIL>> 
// =================================================================== //
#ifndef __Light_Container__ 
#define __Light_Container__

#include <iostream>
#include <cstdlib>
#include "linbox/util/contracts.h"
#include "linbox/vector/vector-traits.h"


namespace LinBox 
{

template<typename Elem> struct LightContainer {
private:
    typedef LightContainer<Elem> Self_t;
    size_t allocated;
    Elem * _container;
    Elem * _finish;
public:
    typedef Elem value_type;
    typedef Elem* iterator;
    typedef const Elem* const_iterator;

    LightContainer() : allocated(2), _container(new Elem[allocated]), _finish(_container) { 
        ENSURE( (allocated == 2) && (size() == 0) );

    }
    LightContainer(size_t s) : allocated(s), _container(new Elem[s]), _finish(_container+s) {
        
        ENSURE( (allocated == s) && (size() == s) );
        ENSURE( allocated >= size() );
     
    }

    Self_t& operator=(const Self_t& v) {
        this->resize(v.size());
        const_iterator vit = v.begin();
        for(iterator tit = begin(); tit != end(); ++tit, ++vit)
            *tit = *vit;
        return *this;
    }

    LightContainer(const Self_t& v) : allocated(v.allocated) {
        _container = new Elem[allocated];
        _finish = _container +v.size();
        const_iterator vit = v.begin();
        for(iterator tit = begin(); tit != end(); ++tit, ++vit)
            *tit = *vit;
    }

    void reserve(size_t s) { 
        STATE( size_t oldsize = size() );
        reallocate(s, size() );
        ENSURE( (allocated >= s) && (size() == oldsize) && ( allocated >= size() ) );
    }

    size_t size() const { return size_t(_finish - _container); }

    Elem& operator[](size_t i) { 
        REQUIRE( (i >= 0) && (i < allocated) && (i < size()) );
        return _container[i]; }

    const Elem& operator[](size_t i) const { 
        REQUIRE( (i >= 0) && (i < allocated) && (i < size()) );
        return _container[i]; }

    void clear() { _finish = _container; 
            ENSURE( (size() == 0) );

    }
    void resize(size_t s) {
        if (s>allocated) reallocate( s+(s>>1), s );
        else _finish = _container + s;
        ENSURE( allocated >= size() );
    }
    iterator begin() { return _container; }
    iterator end() { return _finish; }
    const_iterator begin() const { return const_iterator(_container); }
    const_iterator end() const { return const_iterator(_finish); }
    Elem& front() { return *_container; }
    const Elem& front() const { return *_container; }
    Elem& back() { return *(_finish-1); }
    const Elem& back() const { return *(_finish-1); }

    void push_back(const Elem& c) {
        STATE( size_t  oldsize = size() );
        if (size() == allocated) reserve(allocated+(allocated>>1));
        *(_finish) = c; ++_finish; 

        ENSURE( size() == (oldsize+1) );
        ENSURE( allocated >= size() );
    }
    void pop_back() {
        STATE( size_t  oldsize = size() );
        REQUIRE( oldsize >= 1 );
        --_finish;
        ENSURE( size() == (oldsize-1) );
        ENSURE( allocated >= size() );
    }

    ~LightContainer() { delete[] _container; }


    iterator insert(iterator pos, const Elem& c) {
        REQUIRE( (pos-begin()) <= (end()-begin()) );
        REQUIRE( (pos-begin()) >= 0 );
        STATE( size_t oldsize = size() );
        if (pos == _finish) {
            push_back(c);
        } else {
            insert(pos+1, *(pos));
            *(pos) = c;
        }
        ENSURE( size() == oldsize+1 );
        ENSURE( allocated >= size() );
        return pos;
    }
    
    
/*
    friend std::ostream& operator<< (std::ostream& o, const Self_t& C) {
        o << '[';
        const_iterator refs =  C.begin();
        for( ; refs != (C.end()-1) ; ++refs )
            o << (*refs) << ',';
        return o << (*refs) << ']';
    }
    friend std::ostream& operator<< (std::ostream& o, const Self_t& C) {
        o << '[';
        for(size_t i=0; i<(C.size()-1); ++i) 
            o << C[i] << ',';
        return o << C[C.size()-1] << ']';
    }
*/
<commit_msg>added insert from 2 iterators<commit_after>// =================================================================== //
// LightContainer : std::vector like container
// Time-stamp: <22 Apr 10 12:27:19 <EMAIL>> 
// =================================================================== //
#ifndef __Light_Container__ 
#define __Light_Container__

#include <iostream>
#include <cstdlib>
#include "linbox/util/contracts.h"
#include "linbox/vector/vector-traits.h"


namespace LinBox 
{

template<typename Elem> struct LightContainer {
private:
    typedef LightContainer<Elem> Self_t;
    size_t allocated;
    Elem * _container;
    Elem * _finish;
public:
    typedef Elem value_type;
    typedef Elem* iterator;
    typedef const Elem* const_iterator;

    LightContainer() : allocated(2), _container(new Elem[allocated]), _finish(_container) { 
        ENSURE( (allocated == 2) && (size() == 0) );

    }
    LightContainer(size_t s) : allocated(s), _container(new Elem[s]), _finish(_container+s) {
        
        ENSURE( (allocated == s) && (size() == s) );
        ENSURE( allocated >= size() );
     
    }

    Self_t& operator=(const Self_t& v) {
        this->resize(v.size());
        const_iterator vit = v.begin();
        for(iterator tit = begin(); tit != end(); ++tit, ++vit)
            *tit = *vit;
        return *this;
    }

    LightContainer(const Self_t& v) : allocated(v.allocated) {
        _container = new Elem[allocated];
        _finish = _container +v.size();
        const_iterator vit = v.begin();
        for(iterator tit = begin(); tit != end(); ++tit, ++vit)
            *tit = *vit;
    }

    void reserve(size_t s) { 
        STATE( size_t oldsize = size() );
        reallocate(s, size() );
        ENSURE( (allocated >= s) && (size() == oldsize) && ( allocated >= size() ) );
    }

    size_t size() const { return size_t(_finish - _container); }

    Elem& operator[](size_t i) { 
        REQUIRE( (i >= 0) && (i < allocated) && (i < size()) );
        return _container[i]; }

    const Elem& operator[](size_t i) const { 
        REQUIRE( (i >= 0) && (i < allocated) && (i < size()) );
        return _container[i]; }

    void clear() { _finish = _container; 
            ENSURE( (size() == 0) );

    }
    void resize(size_t s) {
        if (s>allocated) reallocate( s+(s>>1), s );
        else _finish = _container + s;
        ENSURE( allocated >= size() );
    }
    iterator begin() { return _container; }
    iterator end() { return _finish; }
    const_iterator begin() const { return const_iterator(_container); }
    const_iterator end() const { return const_iterator(_finish); }
    Elem& front() { return *_container; }
    const Elem& front() const { return *_container; }
    Elem& back() { return *(_finish-1); }
    const Elem& back() const { return *(_finish-1); }

    void push_back(const Elem& c) {
        STATE( size_t  oldsize = size() );
        if (size() == allocated) reserve(allocated+(allocated>>1));
        *(_finish) = c; ++_finish; 

        ENSURE( size() == (oldsize+1) );
        ENSURE( allocated >= size() );
    }
    void pop_back() {
        STATE( size_t  oldsize = size() );
        REQUIRE( oldsize >= 1 );
        --_finish;
        ENSURE( size() == (oldsize-1) );
        ENSURE( allocated >= size() );
    }

    ~LightContainer() { delete[] _container; }


    iterator insert(iterator pos, const Elem& c) {
        REQUIRE( (pos-begin()) <= (end()-begin()) );
        REQUIRE( (pos-begin()) >= 0 );
        STATE( size_t oldsize = size() );
        if (pos == _finish) {
            push_back(c);
        } else {
            insert(pos+1, *(pos));
            *(pos) = c;
        }
        ENSURE( size() == oldsize+1 );
        ENSURE( allocated >= size() );
        return pos;
    }
    
    iterator insert(iterator pos, const_iterator beg, const_iterator end) {
        REQUIRE( (pos-begin()) <= (end()-begin()) );
        REQUIRE( (pos-begin()) >= 0 );
        if (pos == _finish) {
            for(const_iterator iter=beg; iter != end; ++iter)
                push_back(*iter);
        } else {
            for(const_iterator iter=beg; iter != end; ++iter)
                insert(pos, *iter);
        }
        ENSURE( allocated >= size() );
        return pos;
    }

    
/*
    friend std::ostream& operator<< (std::ostream& o, const Self_t& C) {
        o << '[';
        const_iterator refs =  C.begin();
        for( ; refs != (C.end()-1) ; ++refs )
            o << (*refs) << ',';
        return o << (*refs) << ']';
    }
    friend std::ostream& operator<< (std::ostream& o, const Self_t& C) {
        o << '[';
        for(size_t i=0; i<(C.size()-1); ++i) 
            o << C[i] << ',';
        return o << C[C.size()-1] << ']';
    }
*/

{'fraction_non_alphanumeric': 0.19815411987101078, 'fraction_numerical': 0.006894251084176582, 'mean_word_length': 2.357222844344905, 'pattern_counts': {'":': 0, '<': 76, '<?xml version=': 0, '>': 51, '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': '1544374', 'n_tokens_mistral': 3003, 'n_tokens_neox': 2851, 'n_words': 709}