<commit_before>/*
 * CPIndexSet.j
 * Foundation
 *
 * Created by <NAME>.
 * Copyright 2008, 280 North, Inc.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

@import "CPRange.j"
@import "CPObject.j"

#define _CPMaxRange(aRange) ((aRange).location + (aRange).length)
#define _CPMakeRange(aLocation, aLength) { location:(aLocation), length:aLength }
#define _CPMakeRangeCopy(aRange) { location:(aRange).location, length:(aRange).length }

/*! 
    @class CPIndexSet
    @ingroup foundation
    @brief A collection of unique integers.

    Instances of this class are collections of numbers. Each integer can appear
    in a collection only once.
*/
@implementation CPIndexSet : CPObject
{
    unsigned    _count;
    CPArray     _ranges;
}

// Creating an Index Set
/*!
    Returns a new empty index set.
*/
+ (id)indexSet
{
    return [[self alloc] init];
}

/*!
    Returns a new index set with just one index.
*/
+ (id)indexSetWithIndex:(int)anIndex
{
    return [[self alloc] initWithIndex:anIndex];
}

/*!
    Returns a new index set with all the numbers in the specified range.
    @param aRange the range of numbers to add to the index set.
*/
+ (id)indexSetWithIndexesInRange:(CPRange)aRange
{
    return [[self alloc] initWithIndexesInRange:aRange];
}

// Initializing and Index Set

- (id)init
{
    return [self initWithIndexesInRange:_CPMakeRange(0, 0)];
}

/*!
    Initializes the index set with a single index.
    @return the initialized index set
*/
- (id)initWithIndex:(CPInteger)anIndex
{
    return [self initWithIndexesInRange:_CPMakeRange(anIndex, 1)];
}

/*!
    Initializes the index set with numbers from the specified range.
    @param aRange the range of numbers to add to the index set
    @return the initialized index set
*/
- (id)initWithIndexesInRange:(CPRange)aRange
{
    self = [super init];

    if (self)
    {
        _count = MAX(0, aRange.length);

        if (_count > 0)
            _ranges = [aRange];
        else
            _ranges = [];
    }

    return self;
}

/*!
    Initializes the index set with another index set.
    @param anIndexSet the index set from which to read the initial index set
    @return the initialized index set
*/
- (id)initWithIndexSet:(CPIndexSet)anIndexSet
{
    self = [super init];

    if (self)
    {
        _count = [anIndexSet count];
        _ranges = [];

        var otherRanges = anIndexSet._ranges,
            otherRangesCount = otherRanges.length;

        while (otherRangesCount--)
            _ranges[otherRangesCount] = _CPMakeRangeCopy(otherRanges[otherRangesCount]);
    }

    return self;
}

// Querying an Index Set
/*!
    Compares the receiver with the provided index set.
    @param anIndexSet the index set to compare to
    @return <code>YES</code> if the receiver and the index set are functionally equivalent
*/
- (BOOL)isEqualToIndexSet:(CPIndexSet)anIndexSet
{
    if (!anIndexSet)
        return NO;

    // Comparisons to ourself are always return YES.
    if (self === anIndexSet)
       return YES;

    var rangesCount = _ranges.length,
        otherRanges = anIndexSet._ranges;

    // If we have a discrepency in the number of ranges or the number of indexes,
    // simply return NO.
    if (rangesCount !== otherRanges.length || _count !== anIndexSet._count)
        return NO;

    while (count--)
        if (!CPEqualRanges(_ranges[count], otherRanges[count]))
            return NO;<commit_msg>Fixed incorrect variable in CPIndexSet.<commit_after>/*
 * CPIndexSet.j
 * Foundation
 *
 * Created by <NAME>.
 * Copyright 2008, 280 North, Inc.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

@import "CPRange.j"
@import "CPObject.j"

#define _CPMaxRange(aRange) ((aRange).location + (aRange).length)
#define _CPMakeRange(aLocation, aLength) { location:(aLocation), length:aLength }
#define _CPMakeRangeCopy(aRange) { location:(aRange).location, length:(aRange).length }

/*! 
    @class CPIndexSet
    @ingroup foundation
    @brief A collection of unique integers.

    Instances of this class are collections of numbers. Each integer can appear
    in a collection only once.
*/
@implementation CPIndexSet : CPObject
{
    unsigned    _count;
    CPArray     _ranges;
}

// Creating an Index Set
/*!
    Returns a new empty index set.
*/
+ (id)indexSet
{
    return [[self alloc] init];
}

/*!
    Returns a new index set with just one index.
*/
+ (id)indexSetWithIndex:(int)anIndex
{
    return [[self alloc] initWithIndex:anIndex];
}

/*!
    Returns a new index set with all the numbers in the specified range.
    @param aRange the range of numbers to add to the index set.
*/
+ (id)indexSetWithIndexesInRange:(CPRange)aRange
{
    return [[self alloc] initWithIndexesInRange:aRange];
}

// Initializing and Index Set

- (id)init
{
    return [self initWithIndexesInRange:_CPMakeRange(0, 0)];
}

/*!
    Initializes the index set with a single index.
    @return the initialized index set
*/
- (id)initWithIndex:(CPInteger)anIndex
{
    return [self initWithIndexesInRange:_CPMakeRange(anIndex, 1)];
}

/*!
    Initializes the index set with numbers from the specified range.
    @param aRange the range of numbers to add to the index set
    @return the initialized index set
*/
- (id)initWithIndexesInRange:(CPRange)aRange
{
    self = [super init];

    if (self)
    {
        _count = MAX(0, aRange.length);

        if (_count > 0)
            _ranges = [aRange];
        else
            _ranges = [];
    }

    return self;
}

/*!
    Initializes the index set with another index set.
    @param anIndexSet the index set from which to read the initial index set
    @return the initialized index set
*/
- (id)initWithIndexSet:(CPIndexSet)anIndexSet
{
    self = [super init];

    if (self)
    {
        _count = [anIndexSet count];
        _ranges = [];

        var otherRanges = anIndexSet._ranges,
            otherRangesCount = otherRanges.length;

        while (otherRangesCount--)
            _ranges[otherRangesCount] = _CPMakeRangeCopy(otherRanges[otherRangesCount]);
    }

    return self;
}

// Querying an Index Set
/*!
    Compares the receiver with the provided index set.
    @param anIndexSet the index set to compare to
    @return <code>YES</code> if the receiver and the index set are functionally equivalent
*/
- (BOOL)isEqualToIndexSet:(CPIndexSet)anIndexSet
{
    if (!anIndexSet)
        return NO;

    // Comparisons to ourself are always return YES.
    if (self === anIndexSet)
       return YES;

    var rangesCount = _ranges.length,
        otherRanges = anIndexSet._ranges;

    // If we have a discrepency in the number of ranges or the number of indexes,
    // simply return NO.
    if (rangesCount !== otherRanges.length || _count !== anIndexSet._count)
        return NO;

    while (rangesCount--)
        if (!CPEqualRanges(_ranges[rangesCount], otherRanges[rangesCount]))
            return NO;
{'fraction_non_alphanumeric': 0.09215306369581013, 'fraction_numerical': 0.006054734802615646, 'mean_word_length': 3.117148554336989, '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': '4974904', 'n_tokens_mistral': 2487, 'n_tokens_neox': 2383, 'n_words': 887}