sgns::crdt::CrdtHeads¶
CrdtHeads manages the current Merkle-CRDT heads.
#include <crdt_heads.hpp>
Public Types¶
| Name | |
|---|---|
| using storage::rocksdb | DataStore |
| using base::Buffer | Buffer |
| using std::unordered_map< std::string, std::set< CID > > | CRDTHeadList |
| using std::pair< CRDTHeadList, uint64_t > | CRDTListResult |
Public Functions¶
| Name | |
|---|---|
| CrdtHeads(std::shared_ptr< DataStore > aDatastore, const HierarchicalKey & aNamespace) | |
| CrdtHeads(const CrdtHeads & aHeads) | |
| virtual | ~CrdtHeads() =default Destroy the Crdt Heads object. |
| bool | operator==(const CrdtHeads & aHeads) const |
| bool | operator!=(const CrdtHeads & aHeads) const |
| CrdtHeads & | operator=(const CrdtHeads & aHeads) |
| HierarchicalKey | GetNamespaceKey() const |
| outcome::result< HierarchicalKey > | GetKey(const std::string & topic, const CID & aCid) const |
| bool | IsHead(const CID & aCid, const std::string & topic) const |
| outcome::result< uint64_t > | GetHeadHeight(const CID & aCid, const std::string & topic) const |
| outcome::result< size_t > | GetLength(const std::string & topic ="") const |
| outcome::result< void > | Add(const CID & aCid, uint64_t aHeight, const std::string & topic) |
| outcome::result< void > | Remove(const CID & aCid, const std::string & topic) |
| outcome::result< void > | Replace(const CID & aCidHead, const CID & aNewHeadCid, uint64_t aHeight, const std::string & topic) |
| outcome::result< CRDTListResult > | GetList(const std::unordered_set< std::string > & topics ={}) const |
| outcome::result< void > | PrimeCache() |
Protected Functions¶
| Name | |
|---|---|
| outcome::result< void > | Write(storage::BufferBatch & aDataStore, const CID & aCid, uint64_t aHeight, const std::string & topic) const |
| outcome::result< void > | Delete(const std::unique_ptr< storage::BufferBatch > & aDataStore, const CID & aCid, const std::string & topic) const |
Public Types Documentation¶
using DataStore¶
using Buffer¶
using CRDTHeadList¶
using CRDTListResult¶
Public Functions Documentation¶
function CrdtHeads¶
Parameters:
- aDatastore Pointer to datastore
- aNamespace Namespace key (e.g "/namespace")
Constructor
function CrdtHeads¶
Copy constructor
function ~CrdtHeads¶
Destroy the Crdt Heads object.
function operator==¶
Return: true if equal otherwise, it returns false.
Equality operator
function operator!=¶
Return: true if NOT equal otherwise, it returns false.
Equality operator
function operator=¶
Assignment operator
function GetNamespaceKey¶
Get namespace hierarchical key
function GetKey¶
Parameters:
- topic Topic namespace.
- aCid Content identifier.
Return: full path to CID key as HierarchicalKey or outcome::failure on error
Get full path to CID key. Path format: /namespace/topic/cid
function IsHead¶
Parameters:
- aCid Content identifier
- topic Topic namespace
Return: true is CID is head, false otherwise
Check if CID is among the current heads.
function GetHeadHeight¶
Parameters:
- aCid Content identifier
- topic Topic namespace
Return: Height of head or outcome::failure on error
Check if CID is head and return it height if it is
function GetLength¶
Return: length, current number of heads or outcome::failure on error
Get current number of heads
function Add¶
Parameters:
- aCid Content identifier
- aHeight height of head
- topic Topic namespace
Return: outcome::failure on error
Add head CID to datastore with full namespace
function Remove¶
function Replace¶
outcome::result< void > Replace(
const CID & aCidHead,
const CID & aNewHeadCid,
uint64_t aHeight,
const std::string & topic
)
Parameters:
- aCidHead Content identifier of head to replace
- aNewHeadCid Content identifier of new head
- aHeight height of head
- topic Topic namespace
Return: outcome::failure on error
Replace a head with a new cid.
function GetList¶
outcome::result< CRDTListResult > GetList(
const std::unordered_set< std::string > & topics ={}
) const
Parameters:
- topics Topic to get list from
Return: outcome::failure on error
Returns the list of current heads plus the max height.
function PrimeCache¶
Return: outcome::failure on error
primeCache builds the heads cache based on what's in storage; since it is called from the constructor only we don't bother locking.
Protected Functions Documentation¶
function Write¶
outcome::result< void > Write(
storage::BufferBatch & aDataStore,
const CID & aCid,
uint64_t aHeight,
const std::string & topic
) const
Parameters:
- aDataStore Pointer to datastore batch
- aCid Content identifier to add
- aHeight height of CID head
- topic Topic namespace
Return: outcome::failure on error
Write data to datastore in batch mode
function Delete¶
outcome::result< void > Delete(
const std::unique_ptr< storage::BufferBatch > & aDataStore,
const CID & aCid,
const std::string & topic
) const
Parameters:
- aDataStore Pointer to datastore batch
- aCid Content identifier to remove
- topic Topic namespace
Delete data from datastore in batch mode
Updated on 2026-03-04 at 13:10:43 -0800