Skip to content

src/crdt/crdt_data_filter.hpp

Header file of the CRDT Filter class. More...

Namespaces

Name
sgns
sgns::crdt

Classes

Name
class sgns::crdt::CRDTDataFilter

Detailed Description

Header file of the CRDT Filter class.

Date: 2025-04-07 Henrique A. Klein ([email protected])

Source code

#ifndef _CRDT_DATA_FILTER_HPP_
#define _CRDT_DATA_FILTER_HPP_

#include <unordered_map>
#include <functional>
#include <string>
#include <memory>
#include <regex>
#include <shared_mutex>

#include "crdt/proto/delta.pb.h"

namespace sgns::crdt
{
    class CRDTDataFilter
    {
    public:
        using ElementFilterCallback  = std::function<std::optional<std::vector<pb::Element>>( const pb::Element & )>;
        using FilterCallbackRegistry = std::unordered_map<std::string, ElementFilterCallback>;

        explicit CRDTDataFilter( bool accept_by_default = true );

        ~CRDTDataFilter() = default;

        bool RegisterElementFilter( const std::string &pattern, ElementFilterCallback filter );

        bool RegisterTombstoneFilter( const std::string &pattern, ElementFilterCallback filter );

        void UnregisterElementFilter( const std::string &pattern );

        void UnregisterTombstoneFilter( const std::string &pattern );

        void FilterElementsOnDelta( pb::Delta &delta ) const;

        void FilterTombstonesOnDelta( pb::Delta &delta );

    private:
        const bool             accept_by_default_;        
        mutable std::shared_mutex      element_registry_mutex_;   
        std::shared_mutex      tombstone_registry_mutex_; 
        FilterCallbackRegistry element_registry_;         
        FilterCallbackRegistry tombstone_registry_;       
    };

}

#endif

Updated on 2026-03-04 at 13:10:44 -0800