smollerGraph 0.20.2
A small graph database, from scratch
Loading...
Searching...
No Matches
smollergraph::Graph Class Reference

A graph kept in three files of records, one for nodes, one for relationships and one for their properties, with an index that finds a node by its name, and a store each for the tokens of labels and types. More...

#include <graph.h>

Public Member Functions

 Graph ()
 A graph in temporary files, which are deleted with it.
 
absl::Status Open (const std::string &path)
 Opens the graph in the folder at path, creating it when it isn't there.
 
void Flush ()
 Writes the graph's changed pages to its files, which closing it does too.
 
NodeId AddNode (std::string_view name)
 Returns the node with this name, adding it the first time.
 
RelationshipId AddRelationship (NodeId from, std::string_view type, NodeId to)
 
void SetLabel (NodeId node, std::string_view label)
 Gives a node its label, such as Species, in place of the one it had.
 
void SetProperty (NodeId node, std::string_view key, const Value &value)
 Sets a property of a node or a relationship, replacing the value it had.
 
void SetRelationshipProperty (RelationshipId relationship, std::string_view key, const Value &value)
 
void SetEmbedding (NodeId node, const Embedding &embedding)
 Keeps a node's embedding, in place of the one it had.
 
std::vector< Embedding > Embeddings () const
 Returns the embeddings of all the nodes, in the order of their ids, or none unless each node has one.
 
std::optional< Value > FindProperty (NodeId node, std::string_view key) const
 Returns a node's property, if it has one. Its name is a property too.
 
std::optional< Value > FindRelationshipProperty (RelationshipId relationship, std::string_view key) const
 Returns a relationship's property, if it has one, such as its weight.
 
std::vector< Property > Properties (NodeId node) const
 Returns the properties of a node or a relationship, in the order they were first set.
 
std::vector< Property > RelationshipProperties (RelationshipId relationship) const
 
std::optional< NodeId > Find (std::string_view name) const
 Returns the node with this name, if the graph has one.
 
std::vector< std::string > NamesStartingWith (std::string_view prefix, size_t limit) const
 Returns up to limit names that start with prefix, in order.
 
std::vector< Hop > Hops (NodeId node, const std::vector< std::string > &types, Direction direction) const
 Returns the hops from node along relationships of any of types: those that start at it, those that end at it with kIn, or with kBoth, the ones out and then the ones in.
 
std::vector< NodeId > Neighbours (NodeId node, std::string_view type, Direction direction=Direction::kOut) const
 Returns the nodes the hops along relationships of type lead to.
 
std::string name (NodeId node) const
 
std::string label (NodeId node) const
 
std::string type (RelationshipId relationship) const
 
NodeRecord node (NodeId id) const
 
RelationshipRecord relationship (RelationshipId id) const
 
PropertyRecord property (PropertyId id) const
 
size_t node_count () const
 
size_t relationship_count () const
 
uint64_t page_reads () const
 How many pages the graph's files have read and written.
 
uint64_t page_writes () const
 

Static Public Attributes

static constexpr size_t kMaxName = sizeof(NodeRecord::name) - 1
 The longest name, label and relationship type that fit in their records.
 
static constexpr size_t kMaxLabel = TokenStore::kMaxName
 
static constexpr size_t kMaxType = TokenStore::kMaxName
 
static constexpr size_t kMaxKey = sizeof(PropertyRecord::key) - 1
 The longest key and string that fit in a property's record.
 
static constexpr size_t kMaxString = sizeof(PropertyRecord::value) - 1
 

Detailed Description

A graph kept in three files of records, one for nodes, one for relationships and one for their properties, with an index that finds a node by its name, and a store each for the tokens of labels and types.

Definition at line 113 of file graph.h.

Constructor & Destructor Documentation

◆ Graph()

smollergraph::Graph::Graph ( )

A graph in temporary files, which are deleted with it.

Definition at line 50 of file graph.cc.

Member Function Documentation

◆ AddNode()

NodeId smollergraph::Graph::AddNode ( std::string_view  name)

Returns the node with this name, adding it the first time.

The name has to be at most kMaxName bytes long.

Definition at line 82 of file graph.cc.

◆ AddRelationship()

RelationshipId smollergraph::Graph::AddRelationship ( NodeId  from,
std::string_view  type,
NodeId  to 
)

Definition at line 95 of file graph.cc.

◆ Embeddings()

std::vector< Embedding > smollergraph::Graph::Embeddings ( ) const

Returns the embeddings of all the nodes, in the order of their ids, or none unless each node has one.

Definition at line 165 of file graph.cc.

◆ Find()

std::optional< NodeId > smollergraph::Graph::Find ( std::string_view  name) const

Returns the node with this name, if the graph has one.

Definition at line 220 of file graph.cc.

◆ FindProperty()

std::optional< Value > smollergraph::Graph::FindProperty ( NodeId  node,
std::string_view  key 
) const

Returns a node's property, if it has one. Its name is a property too.

Definition at line 175 of file graph.cc.

◆ FindRelationshipProperty()

std::optional< Value > smollergraph::Graph::FindRelationshipProperty ( RelationshipId  relationship,
std::string_view  key 
) const

Returns a relationship's property, if it has one, such as its weight.

Definition at line 182 of file graph.cc.

◆ Flush()

void smollergraph::Graph::Flush ( )
inline

Writes the graph's changed pages to its files, which closing it does too.

Definition at line 129 of file graph.h.

◆ Hops()

std::vector< Hop > smollergraph::Graph::Hops ( NodeId  node,
const std::vector< std::string > &  types,
Direction  direction 
) const

Returns the hops from node along relationships of any of types: those that start at it, those that end at it with kIn, or with kBoth, the ones out and then the ones in.

Definition at line 224 of file graph.cc.

◆ label()

std::string smollergraph::Graph::label ( NodeId  node) const
inline

Definition at line 191 of file graph.h.

◆ name()

std::string smollergraph::Graph::name ( NodeId  node) const
inline

Definition at line 190 of file graph.h.

◆ NamesStartingWith()

std::vector< std::string > smollergraph::Graph::NamesStartingWith ( std::string_view  prefix,
size_t  limit 
) const
inline

Returns up to limit names that start with prefix, in order.

Definition at line 176 of file graph.h.

◆ Neighbours()

std::vector< NodeId > smollergraph::Graph::Neighbours ( NodeId  node,
std::string_view  type,
Direction  direction = Direction::kOut 
) const

Returns the nodes the hops along relationships of type lead to.

Definition at line 262 of file graph.cc.

◆ node()

NodeRecord smollergraph::Graph::node ( NodeId  id) const
inline

Definition at line 197 of file graph.h.

◆ node_count()

size_t smollergraph::Graph::node_count ( ) const
inline

Definition at line 202 of file graph.h.

◆ Open()

absl::Status smollergraph::Graph::Open ( const std::string &  path)

Opens the graph in the folder at path, creating it when it isn't there.

Definition at line 65 of file graph.cc.

◆ page_reads()

uint64_t smollergraph::Graph::page_reads ( ) const
inline

How many pages the graph's files have read and written.

Definition at line 205 of file graph.h.

◆ page_writes()

uint64_t smollergraph::Graph::page_writes ( ) const
inline

Definition at line 210 of file graph.h.

◆ Properties()

std::vector< Property > smollergraph::Graph::Properties ( NodeId  node) const

Returns the properties of a node or a relationship, in the order they were first set.

Definition at line 198 of file graph.cc.

◆ property()

PropertyRecord smollergraph::Graph::property ( PropertyId  id) const
inline

Definition at line 201 of file graph.h.

◆ relationship()

RelationshipRecord smollergraph::Graph::relationship ( RelationshipId  id) const
inline

Definition at line 198 of file graph.h.

◆ relationship_count()

size_t smollergraph::Graph::relationship_count ( ) const
inline

Definition at line 203 of file graph.h.

◆ RelationshipProperties()

std::vector< Property > smollergraph::Graph::RelationshipProperties ( RelationshipId  relationship) const

Definition at line 202 of file graph.cc.

◆ SetEmbedding()

void smollergraph::Graph::SetEmbedding ( NodeId  node,
const Embedding &  embedding 
)

Keeps a node's embedding, in place of the one it had.

The nodes are given theirs in the order of their ids.

Definition at line 157 of file graph.cc.

◆ SetLabel()

void smollergraph::Graph::SetLabel ( NodeId  node,
std::string_view  label 
)

Gives a node its label, such as Species, in place of the one it had.

The label has to be at most kMaxLabel bytes long.

Definition at line 119 of file graph.cc.

◆ SetProperty()

void smollergraph::Graph::SetProperty ( NodeId  node,
std::string_view  key,
const Value &  value 
)

Sets a property of a node or a relationship, replacing the value it had.

The key has to be at most kMaxKey bytes long, and a string kMaxString. A node's name is in its record already, so it's not a key to set.

Definition at line 125 of file graph.cc.

◆ SetRelationshipProperty()

void smollergraph::Graph::SetRelationshipProperty ( RelationshipId  relationship,
std::string_view  key,
const Value &  value 
)

Definition at line 131 of file graph.cc.

◆ type()

std::string smollergraph::Graph::type ( RelationshipId  relationship) const
inline

Definition at line 194 of file graph.h.

Member Data Documentation

◆ kMaxKey

constexpr size_t smollergraph::Graph::kMaxKey = sizeof(PropertyRecord::key) - 1
staticconstexpr

The longest key and string that fit in a property's record.

Definition at line 120 of file graph.h.

◆ kMaxLabel

constexpr size_t smollergraph::Graph::kMaxLabel = TokenStore::kMaxName
staticconstexpr

Definition at line 117 of file graph.h.

◆ kMaxName

constexpr size_t smollergraph::Graph::kMaxName = sizeof(NodeRecord::name) - 1
staticconstexpr

The longest name, label and relationship type that fit in their records.

Definition at line 116 of file graph.h.

◆ kMaxString

constexpr size_t smollergraph::Graph::kMaxString = sizeof(PropertyRecord::value) - 1
staticconstexpr

Definition at line 121 of file graph.h.

◆ kMaxType

constexpr size_t smollergraph::Graph::kMaxType = TokenStore::kMaxName
staticconstexpr

Definition at line 118 of file graph.h.


The documentation for this class was generated from the following files: