<commit_before>/* -*- mode: C++; style: linux; -*- */

/* linbox/vector/subvector.h
 * Copyright (C) 2002 <NAME>
 *
 * ------------------------------------
 *
 * See COPYING for license information.
 *
 * Written by <NAME> <<EMAIL>>
 * Mods by -bds 
 * Maintainer: -bds 
 * (where there is missing or buggy function, please contact me rather than workaround)
 */

#ifndef __SUBVECTOR_H
#define __SUBVECTOR_H

#include <linbox/vector/subiterator.h>
#include <iterator>
#include <linbox/vector/vector-traits.h>
#include <stdexcept>

namespace LinBox 	{
//wrapper Iterator to get a const Iterator

/** Dense subvector class
 * This class provides a statically sized subvector of a 
 * random access container (such as std::vector, deque).
 * It does not work on sparse linbox vectors.
 * It implements all of the types and methods of a std::vector
 * except for those that invalidate iterators, i.e.,
 * those (potentially) involving vector resizing, such as
 * push_back(), insert(), resize().
 */
template <typename Iterator, typename ConstIterator = Iterator> 
class Subvector //: public Vector // for types
{
    public:
	// Types
	typedef typename std::iterator_traits<Iterator>::value_type value_type;
	// should allocator_type even be offered?
	//include <memory>
	//typedef allocator<value_type>	allocator_type;
    
	typedef size_t                                              size_type;
	typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
	typedef typename std::iterator_traits<Iterator>::pointer	    pointer;
	typedef typename std::iterator_traits<Iterator>::reference	    reference;
	typedef const reference	                                    const_reference;
	typedef Iterator                                            iterator;
	//typedef typename ConstIteratorType<Iterator>::const_iterator         const_iterator;

	typedef ConstIterator                                            const_iterator;

	typedef std::reverse_iterator<iterator>	                    reverse_iterator;
	typedef std::reverse_iterator<const_iterator>               const_reverse_iterator;
   	
	Subvector() : _begin(Iterator ()), _end(Iterator ()) {}
   	
	template<class Vector>
	Subvector (Vector& v, size_type start, size_type stride, size_type length)
	: _begin (iterator (v.begin() + start, stride)),
	  _end   (iterator (v.begin() + start + (stride * length), stride)) {}
	
	Subvector(iterator begin, iterator end) : _begin(begin), _end(end) {}
	
	Subvector(iterator begin, size_type length) : _begin(begin), _end(begin + length) {}
	
	//copy constructor
	Subvector(const Subvector& x) : _begin(x._begin), _end(x._end) {}
	
	~Subvector() {}
	
	// Iterators
	
	iterator               begin  (void)       { return _begin; }
	const_iterator         begin  (void) const { return _begin; }
	iterator               end    (void)       { return _end; }
	const_iterator         end    (void) const { return _end; }
	
	reverse_iterator       rbegin (void)       { return reverse_iterator (_end); }
	const_reverse_iterator rbegin (void) const { return reverse_iterator (_end); }
	reverse_iterator       rend   (void)       { return reverse_iterator (_begin); }
	const_reverse_iterator rend   (void) const { return reverse_iterator (_begin); }
	
	// Element access
	
	reference       operator[] (size_type n)       { return _begin[n]; }
	const_reference operator[] (size_type n) const { return _begin[n]; }
	
	// the method "at" does appear to be implemented 
	// in the gnu implementation of the STL
	reference at(size_type n)  // validity is relative to valid _begin, _end
	{   
		iterator p = _begin + n;
		if ( _begin <= p && p < _end ) 
			return *p;
		else 
			throw std::out_of_range(); //out of range error message.
	}
	
	const_reference at(size_type n) const 
	{
		const_iterator p = _begin + n;
		if ( _begin <= p && p < _end)
			return *p;
		else 
			throw std::out_of_range(); //out of range error message
	}
	
	reference       front (void)       { return *_begin; }
	const_reference front (void) const { return *_begin; }
	reference       back  (void)       { return *( _end - 1 ); }
	const_reference back  (void) const { return *( _end - 1 ); }
	
	template<class Container>
	/** assign the elements of Container one by one to *this.
	 *  Container must be at least as long as this.
	 */
	Subvector& operator= (const Container& x)
	{
		typename Container::const_iterator q = x.begin ();
		
		for (iterator p = _begin (); p != _end (); ++p, ++q)
			*p = *q;
		
		return *this;
	}
	
	template<class Iterator2>
	Subvector& operator = (const Subvector<Iterator2>& sub)
	{
		_begin=sub.begin();
		_end=sub.end();
		return *this;
	}
	
	//		template <class In> void assign(In first, In last);
	//		void assign(size_type n, const T& val);
	
	// Stack operations:  
	// 	not implemented because they invalidate iterators
	
	// List operations:
	// 	not implemented because they invalidate iterators
	
	// Capacity
	// 	resize, reserve: not implemented because they 
	// 		invalidate iterators
	
	//copy assignment
	Subvector& operator=(const Subvector& sub)
	{ _begin = sub._begin; _end = sub._end; return *this; }
	
	size_type size      (void) const { return _end - _begin; }
	bool      empty     (void) const { return _end == _begin; }
	size_type max_size  (void) const { return _end - _begin; }
	//size_type capacity(void) const { return _end - _begin; }<commit_msg>Enable assignment bewteen different Subvector if they are compatible<commit_after>/* -*- mode: C++; style: linux; -*- */

/* linbox/vector/subvector.h
 * Copyright (C) 2002 <NAME>
 *
 * ------------------------------------
 *
 * See COPYING for license information.
 *
 * Written by <NAME> <<EMAIL>>
 * Mods by -bds 
 * Maintainer: -bds 
 * (where there is missing or buggy function, please contact me rather than workaround)
 */

#ifndef __SUBVECTOR_H
#define __SUBVECTOR_H

#include <linbox/vector/subiterator.h>
#include <iterator>
#include <linbox/vector/vector-traits.h>
#include <stdexcept>

namespace LinBox 	{
//wrapper Iterator to get a const Iterator

/** Dense subvector class
 * This class provides a statically sized subvector of a 
 * random access container (such as std::vector, deque).
 * It does not work on sparse linbox vectors.
 * It implements all of the types and methods of a std::vector
 * except for those that invalidate iterators, i.e.,
 * those (potentially) involving vector resizing, such as
 * push_back(), insert(), resize().
 */
template <typename Iterator, typename ConstIterator = Iterator> 
class Subvector //: public Vector // for types
{
    public:
	// Types
	typedef typename std::iterator_traits<Iterator>::value_type value_type;
	// should allocator_type even be offered?
	//include <memory>
	//typedef allocator<value_type>	allocator_type;
    
	typedef size_t                                              size_type;
	typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
	typedef typename std::iterator_traits<Iterator>::pointer	    pointer;
	typedef typename std::iterator_traits<Iterator>::reference	    reference;
	typedef const reference	                                    const_reference;
	typedef Iterator                                            iterator;
	//typedef typename ConstIteratorType<Iterator>::const_iterator         const_iterator;

	typedef ConstIterator                                            const_iterator;

	typedef std::reverse_iterator<iterator>	                    reverse_iterator;
	typedef std::reverse_iterator<const_iterator>               const_reverse_iterator;
   	
	Subvector() : _begin(Iterator ()), _end(Iterator ()) {}
   	
	template<class Vector>
	Subvector (Vector& v, size_type start, size_type stride, size_type length)
	: _begin (iterator (v.begin() + start, stride)),
	  _end   (iterator (v.begin() + start + (stride * length), stride)) {}
	
	Subvector(iterator begin, iterator end) : _begin(begin), _end(end) {}
	
	Subvector(iterator begin, size_type length) : _begin(begin), _end(begin + length) {}
	
	//copy constructor
	Subvector(const Subvector& x) : _begin(x._begin), _end(x._end) {}
	
	~Subvector() {}
	
	// Iterators
	
	iterator               begin  (void)       { return _begin; }
	const_iterator         begin  (void) const { return _begin; }
	iterator               end    (void)       { return _end; }
	const_iterator         end    (void) const { return _end; }
	
	reverse_iterator       rbegin (void)       { return reverse_iterator (_end); }
	const_reverse_iterator rbegin (void) const { return reverse_iterator (_end); }
	reverse_iterator       rend   (void)       { return reverse_iterator (_begin); }
	const_reverse_iterator rend   (void) const { return reverse_iterator (_begin); }
	
	// Element access
	
	reference       operator[] (size_type n)       { return _begin[n]; }
	const_reference operator[] (size_type n) const { return _begin[n]; }
	
	// the method "at" does appear to be implemented 
	// in the gnu implementation of the STL
	reference at(size_type n)  // validity is relative to valid _begin, _end
	{   
		iterator p = _begin + n;
		if ( _begin <= p && p < _end ) 
			return *p;
		else 
			throw std::out_of_range(); //out of range error message.
	}
	
	const_reference at(size_type n) const 
	{
		const_iterator p = _begin + n;
		if ( _begin <= p && p < _end)
			return *p;
		else 
			throw std::out_of_range(); //out of range error message
	}
	
	reference       front (void)       { return *_begin; }
	const_reference front (void) const { return *_begin; }
	reference       back  (void)       { return *( _end - 1 ); }
	const_reference back  (void) const { return *( _end - 1 ); }
	
	template<class Container>
	/** assign the elements of Container one by one to *this.
	 *  Container must be at least as long as this.
	 */
	Subvector& operator= (const Container& x)
	{
		typename Container::const_iterator q = x.begin ();
		
		for (iterator p = _begin (); p != _end (); ++p, ++q)
			*p = *q;
		
		return *this;
	}
	
	template<class Iterator2, class ConstIterator2>
	Subvector& operator = (const Subvector<Iterator2, ConstIterator2>& sub)
	{
		_begin=sub.begin();
		_end=sub.end();
		return *this;
	}
	
	//		template <class In> void assign(In first, In last);
	//		void assign(size_type n, const T& val);
	
	// Stack operations:  
	// 	not implemented because they invalidate iterators
	
	// List operations:
	// 	not implemented because they invalidate iterators
	
	// Capacity
	// 	resize, reserve: not implemented because they 
	// 		invalidate iterators
	
	//copy assignment
	Subvector& operator=(const Subvector& sub)
	{ _begin = sub._begin; _end = sub._end; return *this; }
	
	size_type size      (void) const { return _end - _begin; }
	bool      empty     (void) const { return _end == _begin; }
	size_type max_size  (void) const { return _end - _begin; }
	//size_type capacity(void) const { return _end - _begin; }
{'fraction_non_alphanumeric': 0.11392288580104905, 'fraction_numerical': 0.001656390908254348, 'mean_word_length': 2.8925501432664755, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6322764', 'n_tokens_mistral': 3408, 'n_tokens_neox': 3145, 'n_words': 1029}