<commit_before>/*
 * Copyright 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <q/block.hpp>
#include <q/exception.hpp>

namespace q {

byte_block::byte_block( )
: offset_( 0 )
, size_( 0 )
{ }

byte_block::byte_block( const std::string& s )
: offset_( 0 )
, size_( s.size( ) )
{
	data_.resize( size_ );
	memcpy( &data_[ 0 ], s.data( ), size_ );
}

byte_block::byte_block( std::size_t size )
: offset_( 0 )
, size_( size )
{
	data_.resize( size, 0 );
}

void byte_block::resize( std::size_t new_size )
{
	if ( new_size > size_ )
		Q_THROW( std::out_of_range(
			"byte_block::resize can only shrink, not grow" ) );

	size_ = new_size;
}

void byte_block::advance( std::size_t amount )
{
	if ( amount > size_ )
		Q_THROW( std::out_of_range(
			"byte_block::advance cannot advance out of buffer" ) );

	offset_ += amount;
	size_ -= amount;
}

std::size_t byte_block::size( ) const
{<commit_msg>Missing header include (POSIX)<commit_after>/*
 * Copyright 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <q/block.hpp>
#include <q/exception.hpp>

#include <cstring>

namespace q {

byte_block::byte_block( )
: offset_( 0 )
, size_( 0 )
{ }

byte_block::byte_block( const std::string& s )
: offset_( 0 )
, size_( s.size( ) )
{
	data_.resize( size_ );
	std::memcpy( &data_[ 0 ], s.data( ), size_ );
}

byte_block::byte_block( std::size_t size )
: offset_( 0 )
, size_( size )
{
	data_.resize( size, 0 );
}

void byte_block::resize( std::size_t new_size )
{
	if ( new_size > size_ )
		Q_THROW( std::out_of_range(
			"byte_block::resize can only shrink, not grow" ) );

	size_ = new_size;
}

void byte_block::advance( std::size_t amount )
{
	if ( amount > size_ )
		Q_THROW( std::out_of_range(
			"byte_block::advance cannot advance out of buffer" ) );

	offset_ += amount;
	size_ -= amount;
}

std::size_t byte_block::size( ) const
{
{'fraction_non_alphanumeric': 0.12777008310249308, 'fraction_numerical': 0.009695290858725761, 'mean_word_length': 4.024347826086957, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7180087', 'n_tokens_mistral': 1004, 'n_tokens_neox': 961, 'n_words': 321}