<commit_before>#ifndef MAP_THREAD_SAFE
#define MAP_THREAD_SAFE

#include <map>
#include <thread>
#include <mutex>
#include <shared_mutex>

namespace std
{
    namespace threadsafe
    {
        /*
        Concurrent Map prototype, it allows concurrent reads and safe writes.

        */
        template<class K,class V>
        class map
        {
            std::map<K,V> internal_map;

            std::shared_mutex mutex;

            public:
                map(){}
                map(const std::map<K,V> &m) : internal_map(m){}
                map(const std::threadsafe::map &m) = delete;

                V* get(const K& key)
                {
                    std::shared_lock<std::shared_mutex> lock(mutex);
                    auto it = internal_map.find(key);
                    if (it == internal_map.end())
                    {
                        return nullptr;
                    }
                    else{
                        return new V(it->second);
                    }
                }
            
                bool insert(const K & key,V & value){
                    std::unique_lock<std::shared_mutex> lock(mutex);
                    return internal_map.insert(std::make_pair(key,value)).second;
                }
            
                size_t erase(const K & key){
                    std::unique_lock<std::shared_mutex> lock(mutex);
                    return internal_map.erase(key);
                }

                size_t size(){
                    std::shared_lock<std::shared_mutex> lock(mutex);
                    return internal_map.size();
                }
                
                bool contains(const K& key){
                    std::shared_lock<std::shared_mutex> lock(mutex);
                    auto it = internal_map.find(key);<commit_msg>Map get returns a object copy instead of a pointer<commit_after>#ifndef MAP_THREAD_SAFE
#define MAP_THREAD_SAFE

#include <map>
#include <thread>
#include <mutex>
#include <shared_mutex>

namespace std
{
    namespace threadsafe
    {
        /*
        Concurrent Map prototype, it allows concurrent reads and safe writes.

        */
        template<class K,class V>
        class map
        {
            std::map<K,V> internal_map;

            std::shared_mutex mutex;

            public:
                map(){}
                map(const std::map<K,V> &m) : internal_map(m){}
                map(const std::threadsafe::map &m) = delete;

                V get(const K& key)
                {
                    std::shared_lock<std::shared_mutex> lock(mutex);
                    auto it = internal_map.find(key);
                    if (it == internal_map.end())
                    {
                        return nullptr;
                    }
                    else{
                        return V(it->second);
                    }
                }
            
                bool insert(const K & key,V & value){
                    std::unique_lock<std::shared_mutex> lock(mutex);
                    return internal_map.insert(std::make_pair(key,value)).second;
                }
            
                size_t erase(const K & key){
                    std::unique_lock<std::shared_mutex> lock(mutex);
                    return internal_map.erase(key);
                }

                size_t size(){
                    std::shared_lock<std::shared_mutex> lock(mutex);
                    return internal_map.size();
                }
                
                bool contains(const K& key){
                    std::shared_lock<std::shared_mutex> lock(mutex);
                    auto it = internal_map.find(key);
{'fraction_non_alphanumeric': 0.09820457018498367, 'fraction_numerical': 0.0, 'mean_word_length': 1.2190706095353048, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, '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': '486521', 'n_tokens_mistral': 986, 'n_tokens_neox': 909, 'n_words': 197}