<commit_before>
//
// Copyright (c) 2013 Limit Point Systems, Inc.
//
// 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.
//

/// @file
/// Implementation for class list_index_space_state

#include "list_index_space_state.h"
#include "assert_contract.h"
#include "arg_list.h"
#include "list_index_space_iterator.h"
#include "deep_size.h"
#include "hub_index_space_handle.h"

// ===========================================================
// LIST_INDEX_SPACE_STATE FACET
// ===========================================================

// PUBLIC MEMBER FUNCTIONS

// PROTECTED MEMBER FUNCTIONS

sheaf::list_index_space_state::
list_index_space_state()
  : mutable_index_space_state()
{
  // Preconditions:
    
  // Body:
  
  _capacity = 0;

  // Postconditions:

  ensure(invariant());
  ensure(is_empty());
  ensure(capacity() == 0);

  // Exit:

  return; 
}

sheaf::list_index_space_state::
list_index_space_state(const arg_list& xargs)
  : mutable_index_space_state(xargs)
{
  // Preconditions:
    
  require(precondition_of(mutable_index_space_state::mutable_index_space_state(xargs)));

  // Body:
  
  _capacity = 0;

  // Postconditions:

  ensure(invariant());
  ensure(postcondition_of(mutable_index_space_state::mutable_index_space_state(xargs)));
  ensure(capacity() == 0);

  // Exit:

  return; 
}

sheaf::list_index_space_state::
~list_index_space_state()
{  
  // Preconditions:
    
  // Body:
  
  // nothing to do.

  // Postconditions:

  // Exit:

  return; 
}

// PRIVATE MEMBER FUNCTIONS


// ===========================================================
// MUTABLE INDEX SPACE FACET
// ===========================================================

// PUBLIC MEMBER FUNCTIONS

void
sheaf::list_index_space_state::
update_extrema()
{
  // Preconditions:

  // Body:

  _begin = invalid_pod_index();
  _end = invalid_pod_index();

  pod_type ldomain_id;

  // Find begin.
  
  to_range_type::const_iterator itr;

  for(itr = _to_range.begin(), ldomain_id = 0;
      itr != _to_range.end();
      ++itr, ++ldomain_id)
  {
    if(is_valid(*itr))
    {
      _begin = ldomain_id;
      break;
    }
  }

  if(is_valid(_begin))
  {
    // An entry was found, the end is always the last entry in the map.

    _end = _to_range.size();
  }
  else
  {
    // The map is empty, end is invalid.

    _end = invalid_pod_index();
  }

  // Postconditions:

  // Exit

  return;
}

void
sheaf::list_index_space_state::
reserve(size_type xcapacity)
{
  // Preconditions:

  // Body:

  _capacity = xcapacity;

  // Postconditions:

  ensure(invariant());
  ensure(capacity() >= xcapacity);

  // Exit:

  return;
}

sheaf::size_type
sheaf::list_index_space_state::
capacity() const
{
  // Preconditions:

  // Body:

  size_type result = _capacity;

  // Postconditions:

  ensure(is_basic_query);

  // Exit:

  return result;
}

// PROTECTED MEMBER FUNCTIONS

// PRIVATE MEMBER FUNCTIONS


// ===========================================================
// MAP REPRESENTATION FACET
// ===========================================================

// PUBLIC MEMBER FUNCTIONS

// PROTECTED MEMBER FUNCTIONS

void
sheaf::list_index_space_state::
map_rep_insert_entry(pod_type xdomain_id, pod_type xrange_id)
{
  // Preconditions:

  require(!contains_hub(xrange_id));
  require(!contains(xdomain_id));

  // Body:

  // Assign mapping.

  if(is_valid(_end) && xdomain_id < _end)
  {
    // The domain id already is in the map.  Find it and set the range id.

    to_range_type::iterator itr;
    pod_type ldomain_id;

    for(itr = _to_range.begin(), ldomain_id = 0;
	itr != _to_range.end();
	++itr, ++ldomain_id)
    {
      if(ldomain_id == xdomain_id)
      {
	*itr = xrange_id;
	break;
      }
    }
  }
  else
  {
    // The domain id is not in the map.  Construct entries needed to insert
    // the id into the map.

    if(xdomain_id > _end)
    {
      // Add invalid entries into the map so that the next entry inserted
      // will be the xdomain_id.

      _to_range.resize(xdomain_id, invalid_pod_index());
    }
<commit_msg>Dealt with the case that an id is inserted that is not zero when the end of the id space has not been initialized.<commit_after>
//
// Copyright (c) 2013 Limit Point Systems, Inc.
//
// 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.
//

/// @file
/// Implementation for class list_index_space_state

#include "list_index_space_state.h"
#include "assert_contract.h"
#include "arg_list.h"
#include "list_index_space_iterator.h"
#include "deep_size.h"
#include "hub_index_space_handle.h"

// ===========================================================
// LIST_INDEX_SPACE_STATE FACET
// ===========================================================

// PUBLIC MEMBER FUNCTIONS

// PROTECTED MEMBER FUNCTIONS

sheaf::list_index_space_state::
list_index_space_state()
  : mutable_index_space_state()
{
  // Preconditions:
    
  // Body:
  
  _capacity = 0;

  // Postconditions:

  ensure(invariant());
  ensure(is_empty());
  ensure(capacity() == 0);

  // Exit:

  return; 
}

sheaf::list_index_space_state::
list_index_space_state(const arg_list& xargs)
  : mutable_index_space_state(xargs)
{
  // Preconditions:
    
  require(precondition_of(mutable_index_space_state::mutable_index_space_state(xargs)));

  // Body:
  
  _capacity = 0;

  // Postconditions:

  ensure(invariant());
  ensure(postcondition_of(mutable_index_space_state::mutable_index_space_state(xargs)));
  ensure(capacity() == 0);

  // Exit:

  return; 
}

sheaf::list_index_space_state::
~list_index_space_state()
{  
  // Preconditions:
    
  // Body:
  
  // nothing to do.

  // Postconditions:

  // Exit:

  return; 
}

// PRIVATE MEMBER FUNCTIONS


// ===========================================================
// MUTABLE INDEX SPACE FACET
// ===========================================================

// PUBLIC MEMBER FUNCTIONS

void
sheaf::list_index_space_state::
update_extrema()
{
  // Preconditions:

  // Body:

  _begin = invalid_pod_index();
  _end = invalid_pod_index();

  pod_type ldomain_id;

  // Find begin.
  
  to_range_type::const_iterator itr;

  for(itr = _to_range.begin(), ldomain_id = 0;
      itr != _to_range.end();
      ++itr, ++ldomain_id)
  {
    if(is_valid(*itr))
    {
      _begin = ldomain_id;
      break;
    }
  }

  if(is_valid(_begin))
  {
    // An entry was found, the end is always the last entry in the map.

    _end = _to_range.size();
  }
  else
  {
    // The map is empty, end is invalid.

    _end = invalid_pod_index();
  }

  // Postconditions:

  // Exit

  return;
}

void
sheaf::list_index_space_state::
reserve(size_type xcapacity)
{
  // Preconditions:

  // Body:

  _capacity = xcapacity;

  // Postconditions:

  ensure(invariant());
  ensure(capacity() >= xcapacity);

  // Exit:

  return;
}

sheaf::size_type
sheaf::list_index_space_state::
capacity() const
{
  // Preconditions:

  // Body:

  size_type result = _capacity;

  // Postconditions:

  ensure(is_basic_query);

  // Exit:

  return result;
}

// PROTECTED MEMBER FUNCTIONS

// PRIVATE MEMBER FUNCTIONS


// ===========================================================
// MAP REPRESENTATION FACET
// ===========================================================

// PUBLIC MEMBER FUNCTIONS

// PROTECTED MEMBER FUNCTIONS

void
sheaf::list_index_space_state::
map_rep_insert_entry(pod_type xdomain_id, pod_type xrange_id)
{
  // Preconditions:

  require(!contains_hub(xrange_id));
  require(!contains(xdomain_id));

  // Body:

  // Assign mapping.

  if(is_valid(_end) && xdomain_id < _end)
  {
    // The domain id already is in the map.  Find it and set the range id.

    to_range_type::iterator itr;
    pod_type ldomain_id;

    for(itr = _to_range.begin(), ldomain_id = 0;
	itr != _to_range.end();
	++itr, ++ldomain_id)
    {
      if(ldomain_id == xdomain_id)
      {
	*itr = xrange_id;
	break;
      }
    }
  }
  else
  {
    // The domain id is not in the map.  Construct entries needed to insert
    // the id into the map.

    if((!is_valid(_end) && xdomain_id > 0) || (xdomain_id > _end))
    {
      // Add invalid entries into the map so that the next entry inserted
      // will be the xdomain_id.

      _to_range.resize(xdomain_id, invalid_pod_index());
    }

{'fraction_non_alphanumeric': 0.18823146944083224, 'fraction_numerical': 0.003142609449501517, 'mean_word_length': 3.392670157068063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '4430386', 'n_tokens_mistral': 3177, 'n_tokens_neox': 2993, 'n_words': 722}