<commit_before>package com.graphhopper.routing.util.probabilistic;

import com.graphhopper.util.shapes.BBox;
import com.sun.beans.util.Cache;

import java.util.LinkedHashSet;
import java.util.Set;

public class GridData
{
    private Set<GridEntry> entries;

    private GridEntry lastResult;

    public GridData()
    {
        this.entries = new LinkedHashSet<>(1500); // about the amount of grids
    }

    public GridEntry getEntryForBoundingBox( BBox boundingBox )
    {
        synchronized (entries)
        {
            if (lastResult != null && boundingBox.equals(lastResult.getBoundingBox()))
            {
                return lastResult;
            }
            for (GridEntry entry : entries)
            {
                if (boundingBox.equals(entry.getBoundingBox()))
                {
                    lastResult = entry;
                    return entry;
                }
            }
            return null;
        }

    }

    public GridEntry getGridEntryForEdgeId( int id )
    {
        if (lastResult != null && lastResult.containsEdgeId(id))
        {
            return lastResult;
        }
        synchronized (entries)
        {
            for (GridEntry entry : entries)
            {
                if (entry.containsEdgeId(id))
                {
                    lastResult = entry;
                    return entry;
                }
            }
            return null;
        }

    }

    public void updateWithGridEntry( GridEntry gridEntry )
    {
        synchronized (entries)
        {
            if (!entries.add(gridEntry))
            {
                for (GridEntry entry : entries)
                {
                    if (entry.equals(gridEntry))
                    {
                        entry.updateValues(gridEntry.getValues());
                    }
                }
            }
        }

    }
}<commit_msg>Edge cache to map them directly to a grid entry<commit_after>package com.graphhopper.routing.util.probabilistic;

import com.graphhopper.util.shapes.BBox;

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class GridData
{
    private Set<GridEntry> entries;

    private GridEntry lastResult;

    private ConcurrentMap<Integer, GridEntry> edgeCache;

    public GridData()
    {
        this.entries = new LinkedHashSet<>();
        this.edgeCache = new ConcurrentHashMap<>();
    }

    public GridEntry getEntryForBoundingBox( BBox boundingBox )
    {
        synchronized (entries)
        {
            if (lastResult != null && boundingBox.equals(lastResult.getBoundingBox()))
            {
                return lastResult;
            }
            for (GridEntry entry : entries)
            {
                if (boundingBox.equals(entry.getBoundingBox()))
                {
                    lastResult = entry;
                    return entry;
                }
            }
            return null;
        }

    }

    public GridEntry getGridEntryForEdgeId( int id )
    {
        return edgeCache.get(id);
    }

    public void updateWithGridEntry( GridEntry gridEntry )
    {
        for (int edge : gridEntry.getEdges())
        {
            edgeCache.put(edge, gridEntry);
        }
        synchronized (entries)
        {
            if (!entries.add(gridEntry))
            {
                for (GridEntry entry : entries)
                {
                    if (entry.equals(gridEntry))
                    {
                        entry.updateValues(gridEntry.getValues());
                    }
                }
            }
        }

    }
}
{'fraction_non_alphanumeric': 0.0839902147322642, 'fraction_numerical': 0.0010872519706441968, 'mean_word_length': 1.37879767291532, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4629428', 'n_tokens_mistral': 973, 'n_tokens_neox': 931, 'n_words': 191}