<commit_before>/*
 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 *
 * 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.
 */

package com.hazelcast.query.impl;

import com.hazelcast.nio.serialization.Data;

import java.util.NavigableSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListSet;

public class SortedIndexStore implements IndexStore {
    private final ConcurrentMap<Comparable, ConcurrentMap<Data, QueryableEntry>> mapRecords = new ConcurrentHashMap<Comparable, ConcurrentMap<Data, QueryableEntry>>(1000);
    private final NavigableSet<Comparable> sortedSet = new ConcurrentSkipListSet<Comparable>();

    public void getSubRecordsBetween(MultiResultSet results, Comparable from, Comparable to) {
        Set<Comparable> values = sortedSet.subSet(from, to);
        for (Comparable value : values) {
            ConcurrentMap<Data, QueryableEntry> records = mapRecords.get(value);
            if (records != null) {
                results.addResultSet(records);
            }
        }
        // to wasn't included so include now
        ConcurrentMap<Data, QueryableEntry> records = mapRecords.get(to);
        if (records != null) {
            results.addResultSet(records);
        }
    }

    public void getSubRecords(MultiResultSet results, ComparisonType comparisonType, Comparable searchedValue) {
        Set<Comparable> values = null;
        boolean notEqual = false;
        switch (comparisonType) {
            case LESSER:
                values = sortedSet.headSet(searchedValue, false);
                break;
            case LESSER_EQUAL:
                values = sortedSet.headSet(searchedValue, true);
                break;
            case GREATER:
                values = sortedSet.tailSet(searchedValue, false);
                break;
            case GREATER_EQUAL:
                values = sortedSet.tailSet(searchedValue, true);
                break;
            case NOT_EQUAL:
                values = sortedSet;
                notEqual = true;
                break;
        }
        if (values != null) {
            for (Comparable value : values) {
                if (notEqual && searchedValue.equals(value)) {
                    // skip this value if predicateType is NOT_EQUAL
                    continue;
                }
                ConcurrentMap<Data, QueryableEntry> records = mapRecords.get(value);
                if (records != null) {
                    results.addResultSet(records);
                }
            }
        }
    }

    public void newIndex(Comparable newValue, QueryableEntry record) {
        ConcurrentMap<Data, QueryableEntry> records = mapRecords.get(newValue);
        final boolean isNullObject = newValue.equals(IndexImpl.NULL);
        if (records == null && !isNullObject) {
            records = new ConcurrentHashMap<Data, QueryableEntry>(1, 0.75f, 1);
            mapRecords.put(newValue, records);
            sortedSet.add(newValue);
        }
        if (!isNullObject)
            records.put(record.getIndexKey(), record);
    }

    public ConcurrentMap<Data, QueryableEntry> getRecordMap(Comparable indexValue) {
        return mapRecords.get(indexValue);
    }

    public void clear() {
        mapRecords.clear();<commit_msg>index bug<commit_after>/*
 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 *
 * 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.
 */

package com.hazelcast.query.impl;

import com.hazelcast.nio.serialization.Data;

import java.util.NavigableSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListSet;

public class SortedIndexStore implements IndexStore {
    private final ConcurrentMap<Comparable, ConcurrentMap<Data, QueryableEntry>> mapRecords = new ConcurrentHashMap<Comparable, ConcurrentMap<Data, QueryableEntry>>(1000);
    private final NavigableSet<Comparable> sortedSet = new ConcurrentSkipListSet<Comparable>();

    public void getSubRecordsBetween(MultiResultSet results, Comparable from, Comparable to) {
        Set<Comparable> values = sortedSet.subSet(from, to);
        for (Comparable value : values) {
            ConcurrentMap<Data, QueryableEntry> records = mapRecords.get(value);
            if (records != null) {
                results.addResultSet(records);
            }
        }
        // to wasn't included so include now
        ConcurrentMap<Data, QueryableEntry> records = mapRecords.get(to);
        if (records != null) {
            results.addResultSet(records);
        }
    }

    public void getSubRecords(MultiResultSet results, ComparisonType comparisonType, Comparable searchedValue) {
        Set<Comparable> values = null;
        boolean notEqual = false;
        switch (comparisonType) {
            case LESSER:
                values = sortedSet.headSet(searchedValue, false);
                break;
            case LESSER_EQUAL:
                values = sortedSet.headSet(searchedValue, true);
                break;
            case GREATER:
                values = sortedSet.tailSet(searchedValue, false);
                break;
            case GREATER_EQUAL:
                values = sortedSet.tailSet(searchedValue, true);
                break;
            case NOT_EQUAL:
                values = sortedSet;
                notEqual = true;
                break;
        }
        if (values != null) {
            for (Comparable value : values) {
                if (notEqual && searchedValue.equals(value)) {
                    // skip this value if predicateType is NOT_EQUAL
                    continue;
                }
                ConcurrentMap<Data, QueryableEntry> records = mapRecords.get(value);
                if (records != null) {
                    results.addResultSet(records);
                }
            }
        }
    }

    public void newIndex(Comparable newValue, QueryableEntry record) {
        ConcurrentMap<Data, QueryableEntry> records = mapRecords.get(newValue);
        final boolean isNullObject = newValue instanceof IndexImpl.NullObject;
        if (records == null && !isNullObject) {
            records = new ConcurrentHashMap<Data, QueryableEntry>(1, 0.75f, 1);
            mapRecords.put(newValue, records);
            sortedSet.add(newValue);
        }
        if (!isNullObject)
            records.put(record.getIndexKey(), record);
    }

    public ConcurrentMap<Data, QueryableEntry> getRecordMap(Comparable indexValue) {
        return mapRecords.get(indexValue);
    }

    public void clear() {
        mapRecords.clear();
{'fraction_non_alphanumeric': 0.0854336306061781, 'fraction_numerical': 0.005428460643660334, 'mean_word_length': 2.371677559912854, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '376577', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1976, 'n_words': 552}