<commit_before>/*ckwg +5
 * Copyright 2011 by Kitware, Inc. All Rights Reserved. Please refer to
 * KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
 * Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
 */

#ifndef VISTK_PYTHON_HELPERS_SET_INDEXING_SUITE_H
#define VISTK_PYTHON_HELPERS_SET_INDEXING_SUITE_H

#include <boost/python/suite/indexing/indexing_suite.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/lexical_cast.hpp>

#include <algorithm>
#include <iterator>

namespace boost
{

namespace python
{

template <typename Container, bool NoProxy, typename DerivedPolicies>
class set_indexing_suite;

namespace detail
{

template <typename Container, bool NoProxy>
class final_set_derived_policies
  : public set_indexing_suite<Container, NoProxy, final_set_derived_policies<Container, NoProxy> >
{
};

}

template <
    typename Container
  , bool NoProxy = false
  , typename DerivedPolicies = detail::final_set_derived_policies<Container, NoProxy> >
class set_indexing_suite
  : public indexing_suite<Container, DerivedPolicies, NoProxy, true>
{
  public:
    typedef typename Container::value_type data_type;
    typedef typename Container::value_type key_type;
    typedef typename Container::size_type index_type;
    typedef typename Container::size_type size_type;
    typedef typename Container::difference_type difference_type;

    static bool
    contains(Container const& container, key_type const& key)
    {
      const_iterator_type const i = container.find(key);

      return (i != container.end());
    }

    static index_type
    convert_index(Container const& /*container*/, PyObject* /*i*/)
    {
      index_error();

      // Prevent a warning.
      return index_type();
    }

    static void
    delete_item(Container& /*container*/, index_type /*i*/)
    {
      index_error();
    }

    static data_type
    get_item(Container const& /*container*/, index_type /*i*/)
    {
      index_error();

      return data_type();
    }

    static void
    set_item(Container& /*container*/, index_type /*i*/, data_type const& /*v*/)
    {
      index_error();
    }

    static size_t
    size(Container const& container)
    {
      return container.size();
    }

    template <typename Class>
    static void
    extension_def(Class& cl)
    {
      cl
        .def("__and__", &intersection)
        .def("__iand__", &intersection)
        .def("__ior__", &union_)
        .def("__isub__", &difference)
        .def("__ixor__", &symmetric_difference)
        .def("__or__", &union_)
        .def("__rand__", &intersection)
        .def("__ror__", &union_)
        .def("__rsub__", &difference_reverse)
        .def("__rxor__", &symmetric_difference)
        .def("__sub__", &difference)<commit_msg>Fix the bindings for __i*__ operators on sets<commit_after>/*ckwg +5
 * Copyright 2011 by Kitware, Inc. All Rights Reserved. Please refer to
 * KITWARE_LICENSE.TXT for licensing information, or contact General Counsel,
 * Kitware, Inc., 28 Corporate Drive, Clifton Park, NY 12065.
 */

#ifndef VISTK_PYTHON_HELPERS_SET_INDEXING_SUITE_H
#define VISTK_PYTHON_HELPERS_SET_INDEXING_SUITE_H

#include <boost/python/suite/indexing/indexing_suite.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/lexical_cast.hpp>

#include <algorithm>
#include <iterator>

namespace boost
{

namespace python
{

template <typename Container, bool NoProxy, typename DerivedPolicies>
class set_indexing_suite;

namespace detail
{

template <typename Container, bool NoProxy>
class final_set_derived_policies
  : public set_indexing_suite<Container, NoProxy, final_set_derived_policies<Container, NoProxy> >
{
};

}

template <
    typename Container
  , bool NoProxy = false
  , typename DerivedPolicies = detail::final_set_derived_policies<Container, NoProxy> >
class set_indexing_suite
  : public indexing_suite<Container, DerivedPolicies, NoProxy, true>
{
  public:
    typedef typename Container::value_type data_type;
    typedef typename Container::value_type key_type;
    typedef typename Container::size_type index_type;
    typedef typename Container::size_type size_type;
    typedef typename Container::difference_type difference_type;

    static bool
    contains(Container const& container, key_type const& key)
    {
      const_iterator_type const i = container.find(key);

      return (i != container.end());
    }

    static index_type
    convert_index(Container const& /*container*/, PyObject* /*i*/)
    {
      index_error();

      // Prevent a warning.
      return index_type();
    }

    static void
    delete_item(Container& /*container*/, index_type /*i*/)
    {
      index_error();
    }

    static data_type
    get_item(Container const& /*container*/, index_type /*i*/)
    {
      index_error();

      return data_type();
    }

    static void
    set_item(Container& /*container*/, index_type /*i*/, data_type const& /*v*/)
    {
      index_error();
    }

    static size_t
    size(Container const& container)
    {
      return container.size();
    }

    template <typename Class>
    static void
    extension_def(Class& cl)
    {
      cl
        .def("__and__", &intersection)
        .def("__iand__", &intersection_update)
        .def("__ior__", &update)
        .def("__isub__", &difference_update)
        .def("__ixor__", &symmetric_difference_update)
        .def("__or__", &union_)
        .def("__rand__", &intersection)
        .def("__ror__", &union_)
        .def("__rsub__", &difference_reverse)
        .def("__rxor__", &symmetric_difference)
        .def("__sub__", &difference)
{'fraction_non_alphanumeric': 0.10816005591473003, 'fraction_numerical': 0.0041936047527520535, 'mean_word_length': 3.608695652173913, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '2964744', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1771, 'n_words': 412}