<commit_before>#ifndef TURBO_MEMORY_MARKED_PTR_HPP
#define TURBO_MEMORY_MARKED_PTR_HPP

#include <cstdint>
#include <limits>
#include <stdexcept>
#include <string>
#include <turbo/toolset/extension.hpp>

namespace turbo {
namespace memory {

class unaligned_ptr_error : public std::invalid_argument
{
public:
    explicit unaligned_ptr_error(const std::string& what) : invalid_argument(what) { }
    explicit unaligned_ptr_error(const char* what) : invalid_argument(what) { }
};

template <class value_t, class mark_t>
class marked_ptr
{
public:
    inline explicit marked_ptr(value_t* ptr)
	:
	    ptr_(ptr)
    {
	if ((reinterpret_cast<std::uintptr_t>(ptr) & mark_mask()) != 0U)
	{
	    throw unaligned_ptr_error("Given pointer is not a multiple of 4");
	}
    }
    inline marked_ptr(const marked_ptr<value_t, mark_t>& other)
	:
	    ptr_(other.ptr_)
    { }
    inline marked_ptr<value_t, mark_t>& operator=(const marked_ptr<value_t, mark_t>& other)
    {
	if (TURBO_LIKELY(this != &other))
	{
	    ptr_ = other.ptr_;
	}
	return *this;
    }
    ~marked_ptr() = default;
    inline value_t* get_ptr() const
    {
	return reinterpret_cast<value_t*>(reinterpret_cast<std::uintptr_t>(ptr_) & ptr_mask());
    }
    inline mark_t get_mark() const
    {
	return static_cast<mark_t>(reinterpret_cast<std::uintptr_t>(ptr_) & mark_mask());
    }
    inline bool operator==(const marked_ptr<value_t, mark_t>& other) const
    {
	return ptr_ == other.ptr_;
    }
    inline bool operator!=(const marked_ptr<value_t, mark_t>& other) const
    {
	return !(*this == other);
    }
    inline marked_ptr<value_t, mark_t> operator|(const mark_t mark) const
    {
	return marked_ptr<value_t, mark_t>(reinterpret_cast<value_t*>(reinterpret_cast<std::uintptr_t>(get_ptr()) | (static_cast<std::uintptr_t>(mark) & mark_mask())));
    }
    inline void reset(value_t* ptr)
    {
	ptr_ = ptr;
    }
    inline void set_mark(mark_t mark)
    {
	ptr_ = reinterpret_cast<value_t*>(reinterpret_cast<std::uintptr_t>(get_ptr()) | (static_cast<std::uintptr_t>(mark) & mark_mask()));
    }
    inline value_t& operator*()
    {
	return *get_ptr();
    }
    inline value_t* operator->()
    {
	return get_ptr();
    }
private:
    constexpr std::uintptr_t ptr_mask()
    {
	return std::numeric_limits<std::uintptr_t>::max() - 3U;
    }
    constexpr std::uintptr_t mark_mask()
    {
	return static_cast<std::uintptr_t>(3U);
    }
    value_t* ptr_;
};

} // namespace memory
} // namespace turbo

#endif<commit_msg>marked_ptr is now std::atomic lock free compatible<commit_after>#ifndef TURBO_MEMORY_MARKED_PTR_HPP
#define TURBO_MEMORY_MARKED_PTR_HPP

#include <cstdint>
#include <limits>
#include <stdexcept>
#include <string>
#include <turbo/toolset/extension.hpp>

namespace turbo {
namespace memory {

class unaligned_ptr_error : public std::invalid_argument
{
public:
    explicit unaligned_ptr_error(const std::string& what) : invalid_argument(what) { }
    explicit unaligned_ptr_error(const char* what) : invalid_argument(what) { }
};

template <class value_t, class mark_t>
class marked_ptr
{
public:
    inline marked_ptr() noexcept
	:
	    ptr_(nullptr)
    { }
    inline explicit marked_ptr(value_t* ptr)
	:
	    ptr_(ptr)
    {
	if ((reinterpret_cast<std::uintptr_t>(ptr) & mark_mask()) != 0U)
	{
	    throw unaligned_ptr_error("Given pointer is not a multiple of 4");
	}
    }
    marked_ptr(const marked_ptr<value_t, mark_t>& other) = default;
    marked_ptr(marked_ptr<value_t, mark_t>&& other) = default;
    marked_ptr<value_t, mark_t>& operator=(const marked_ptr<value_t, mark_t>& other) = default;
    marked_ptr<value_t, mark_t>& operator=(marked_ptr<value_t, mark_t>&& other) = default;
    ~marked_ptr() = default;
    inline value_t* get_ptr() const
    {
	return reinterpret_cast<value_t*>(reinterpret_cast<std::uintptr_t>(ptr_) & ptr_mask());
    }
    inline mark_t get_mark() const
    {
	return static_cast<mark_t>(reinterpret_cast<std::uintptr_t>(ptr_) & mark_mask());
    }
    inline bool is_empty() const
    {
	return get_ptr() == nullptr;
    }
    inline void set_mark(mark_t mark)
    {
	ptr_ = reinterpret_cast<value_t*>(reinterpret_cast<std::uintptr_t>(get_ptr()) | (static_cast<std::uintptr_t>(mark) & mark_mask()));
    }
    inline bool operator==(const marked_ptr<value_t, mark_t>& other) const
    {
	return ptr_ == other.ptr_;
    }
    inline bool operator!=(const marked_ptr<value_t, mark_t>& other) const
    {
	return !(*this == other);
    }
    inline marked_ptr<value_t, mark_t> operator|(const mark_t mark) const
    {
	marked_ptr<value_t, mark_t> tmp;
	tmp.set_mark(mark);
	return tmp;
    }
    inline void reset(value_t* ptr)
    {
	ptr_ = ptr;
    }
    inline value_t& operator*()
    {
	return *get_ptr();
    }
    inline value_t* operator->()
    {
	return get_ptr();
    }
private:
    constexpr std::uintptr_t ptr_mask()
    {
	return std::numeric_limits<std::uintptr_t>::max() - 3U;
    }
    constexpr std::uintptr_t mark_mask()
    {
	return static_cast<std::uintptr_t>(3U);
    }
    value_t* ptr_;
};

} // namespace memory
} // namespace turbo

#endif
{'fraction_non_alphanumeric': 0.13290145268943857, 'fraction_numerical': 0.0015704750687082843, 'mean_word_length': 4.214943705220062, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 57, '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': '7455267', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1845, 'n_words': 359}