<commit_before>//
// $Id: ArrayIntSet.java,v 1.10 2002/12/19 22:41:13 mdb Exp $
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001 <NAME>
// 
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package com.samskivert.util;

import java.io.Serializable;

import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * Provides an {@link IntSet} implementation using a sorted array of
 * integers to maintain the contents of the set.
 */
public class ArrayIntSet extends AbstractSet
    implements IntSet, Cloneable, Serializable
{
    // documentation inherited from interface
    public int size ()
    {
        return _size;
    }

    /**
     * Returns the element at the specified index. Note that the elements
     * in the set are unordered and could change order after insertion or
     * removal. This method is useful only for accessing elements of a
     * static set (and has the desirable property of allowing access to
     * the values in this set without having to create integer objects).
     */
    public int get (int index)
    {
        return _values[index];
    }

    // documentation inherited from interface
    public boolean isEmpty ()
    {
        return _size == 0;
    }

    // documentation inherited from interface
    public boolean contains (Object o)
    {
        return contains(((Integer)o).intValue());
    }

    // documentation inherited from interface
    public boolean contains (int value)
    {
        return (binarySearch(value) >= 0);
    }

    // documentation inherited from interface
    public Iterator iterator ()
    {
        return new Iterator() {
            public boolean hasNext () {
                return (_pos < _size);
            }

            public Object next () {
                if (_pos == _size) {
                    throw new NoSuchElementException();
                } else {
                    return new Integer(_values[_pos++]);
                }
            }

            public void remove () {
                throw new UnsupportedOperationException();
            }

            protected int _pos;
        };
    }

    // documentation inherited from interface
    public Object[] toArray ()
    {
        return toArray(new Integer[_size]);
    }

    // documentation inherited from interface
    public Object[] toArray (Object[] a)
    {
        for (int i = 0; i < _size; i++) {
            a[i] = new Integer(_values[i]);
        }
        return a;
    }

    // documentation inherited from interface
    public int[] toIntArray ()
    {
        int[] values = new int[_size];
        System.arraycopy(_values, 0, values, 0, _size);
        return values;
    }

    // documentation inherited from interface
    public boolean add (Object o)
    {
        return add(((Integer)o).intValue());
    }

    // documentation inherited from interface
    public boolean add (int value)
    {
        int index = binarySearch(value);
        if (index >= 0) {
            return false;
        }

        // convert the return value into the insertion point
        index += 1;
        index *= -1;

        // expand the values array if necessary, leaving room for the
        // newly added element
        int valen = _values.length;
        int[] source = _values;
        if (valen == _size) {
            _values = new int[valen*2];
            System.arraycopy(source, 0, _values, 0, index);
        }

        // shift and insert
        if (_size > index) {
            System.arraycopy(source, index, _values, index+1, _size-index);
        }<commit_msg>Added ability to copy ourselves into another array at an offset.<commit_after>//
// $Id: ArrayIntSet.java,v 1.11 2003/01/31 02:27:48 mdb Exp $
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001 <NAME>
// 
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package com.samskivert.util;

import java.io.Serializable;

import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * Provides an {@link IntSet} implementation using a sorted array of
 * integers to maintain the contents of the set.
 */
public class ArrayIntSet extends AbstractSet
    implements IntSet, Cloneable, Serializable
{
    // documentation inherited from interface
    public int size ()
    {
        return _size;
    }

    /**
     * Returns the element at the specified index. Note that the elements
     * in the set are unordered and could change order after insertion or
     * removal. This method is useful only for accessing elements of a
     * static set (and has the desirable property of allowing access to
     * the values in this set without having to create integer objects).
     */
    public int get (int index)
    {
        return _values[index];
    }

    // documentation inherited from interface
    public boolean isEmpty ()
    {
        return _size == 0;
    }

    // documentation inherited from interface
    public boolean contains (Object o)
    {
        return contains(((Integer)o).intValue());
    }

    // documentation inherited from interface
    public boolean contains (int value)
    {
        return (binarySearch(value) >= 0);
    }

    // documentation inherited from interface
    public Iterator iterator ()
    {
        return new Iterator() {
            public boolean hasNext () {
                return (_pos < _size);
            }

            public Object next () {
                if (_pos == _size) {
                    throw new NoSuchElementException();
                } else {
                    return new Integer(_values[_pos++]);
                }
            }

            public void remove () {
                throw new UnsupportedOperationException();
            }

            protected int _pos;
        };
    }

    // documentation inherited from interface
    public Object[] toArray ()
    {
        return toArray(new Integer[_size]);
    }

    // documentation inherited from interface
    public Object[] toArray (Object[] a)
    {
        for (int i = 0; i < _size; i++) {
            a[i] = new Integer(_values[i]);
        }
        return a;
    }

    // documentation inherited from interface
    public int[] toIntArray ()
    {
        int[] values = new int[_size];
        System.arraycopy(_values, 0, values, 0, _size);
        return values;
    }

    /**
     * Serializes this int set into an array at the specified offset. The
     * array must be large enough to hold all the integers in our set at
     * the offset specified.
     *
     * @return the array passed in.
     */
    public int[] toIntArray (int[] target, int offset)
    {
        System.arraycopy(_values, 0, target, offset, _size);
        return target;
    }

    // documentation inherited from interface
    public boolean add (Object o)
    {
        return add(((Integer)o).intValue());
    }

    // documentation inherited from interface
    public boolean add (int value)
    {
        int index = binarySearch(value);
        if (index >= 0) {
            return false;
        }

        // convert the return value into the insertion point
        index += 1;
        index *= -1;

        // expand the values array if necessary, leaving room for the
        // newly added element
        int valen = _values.length;
        int[] source = _values;
        if (valen == _size) {
            _values = new int[valen*2];
            System.arraycopy(source, 0, _values, 0, index);
        }

        // shift and insert
        if (_size > index) {
            System.arraycopy(source, index, _values, index+1, _size-index);
        }
{'fraction_non_alphanumeric': 0.08678135888501742, 'fraction_numerical': 0.010779616724738676, 'mean_word_length': 2.1199048913043477, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1115509', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2296, 'n_words': 956}