lgraph_edge_iterator
-
namespace lgraph
-
namespace graph
-
namespace graph
-
namespace lgraph_api
Functions
-
bool operator==(const OutEdgeIterator &lhs, const OutEdgeIterator &rhs)
Check whether lhs and rhs points to the same edge.
-
bool operator==(const OutEdgeIterator &lhs, const InEdgeIterator &rhs)
Check whether lhs and rhs points to the same edge.
-
bool operator==(const InEdgeIterator &lhs, const OutEdgeIterator &rhs)
Check whether lhs and rhs points to the same edge.
-
bool operator==(const InEdgeIterator &lhs, const InEdgeIterator &rhs)
Check whether lhs and rhs points to the same edge.
-
bool operator!=(const OutEdgeIterator &lhs, const OutEdgeIterator &rhs)
Check whether lhs and rhs points to the same edge.
-
bool operator!=(const OutEdgeIterator &lhs, const InEdgeIterator &rhs)
Check whether lhs and rhs points to the same edge.
-
bool operator!=(const InEdgeIterator &lhs, const OutEdgeIterator &rhs)
Check whether lhs and rhs points to the same edge.
-
bool operator!=(const InEdgeIterator &lhs, const InEdgeIterator &rhs)
Check whether lhs and rhs points to the same edge.
-
class InEdgeIterator
- #include <lgraph_edge_iterator.h>
An InEdgeIterator can be used to iterate through the in-coming edges of a vertex. Edges are sorted in (lid, tid, src, eid) order, and each (dst, lid, tid, src, eid) tuple is guaranteed to uniquely identify an edge.
An InEdgeIterator is valid iff it points to a valid in-coming edge, otherwise it is invalid. Calling member function on an invalid InEdgeIterator throws an exception, except for the IsValid() and Goto() functions.
The following operations invalidates an InEdgeIterator:
Constructing an InEdgeIterator for non-existing edge.
Calling Goto() with the id of a non-existing edge.
Calling Next() on the last in-coming edge.
Calling Delete() on the last in-coming edge.
Calling Close() on the iterator.
In TuGraph, every iterator belongs to a transaction, and can only be used when the transaction is valid. Calling member functions on an iterator inside an invalid transaction yields InvalidTxnError, except for Invalid().
Public Functions
-
InEdgeIterator(InEdgeIterator &&rhs)
-
InEdgeIterator &operator=(InEdgeIterator&&)
-
~InEdgeIterator()
-
void Close() noexcept
Closes this iterator. The iterator turns invalid after being closed.
-
bool Next()
Move to the next incoming edge to current destination vertex. If there is no more edge, the iterator becomes invalid and false is returned.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
- Returns
True if it succeeds, false if it fails.
-
bool Goto(EdgeUid euid, bool nearest = false)
Go to the edge specified by euid. If the specified edge cannot be found and nearest==true, then try to get the next in-coming edge to the vertex euid.dst, sorted by (label, tid, src, eid). If there is no such edge, iterator is invalidated and false is returned.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
- Parameters
euid – Edge Unique Id.
nearest – (Optional) True to get the nearest edge if the specified one cannot be found.
- Returns
True if it succeeds, false if it fails.
-
EdgeUid GetUid() const
Gets the Edge Unique Id.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
- Returns
The UID.
-
int64_t GetSrc() const
Gets the source vertex id.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
- Returns
The source vertex id.
-
int64_t GetDst() const
Gets destination vertex id.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
- Returns
The destination vertex id.
-
int64_t GetEdgeId() const
Gets edge id.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
- Returns
The edge id.
-
int64_t GetTemporalId() const
Gets temporal id.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
- Returns
The temporal id.
-
bool IsValid() const
Query if this iterator is valid.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
- Returns
True if valid, false if not.
-
const std::string &GetLabel() const
Gets the label of this edge.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
- Returns
The label.
-
int16_t GetLabelId() const
Gets label id of this edge.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
- Returns
The label identifier.
-
std::vector<FieldData> GetFields(const std::vector<std::string> &field_names) const
Gets the fields specified.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
InputError – Thrown if any field does not exist.
- Parameters
field_names – List of names of the fields.
- Returns
The fields.
-
FieldData GetField(const std::string &field_name) const
Gets the field specified.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
InputError – Thrown if field does not exist.
- Parameters
field_name – Field name.
- Returns
Field value.
-
std::vector<FieldData> GetFields(const std::vector<size_t> &field_ids) const
Gets the fields specified.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
InputError – Thrown if any field does not exist.
- Parameters
field_ids – List of ids for the fields.
- Returns
The fields.
-
FieldData GetField(size_t field_id) const
Gets the field specified.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
InputError – Thrown if field does not exist.
- Parameters
field_id – Field ID.
- Returns
Field value.
-
inline FieldData operator[](const std::string &field_name) const
Get field identified by field_name.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
InputError – Thrown if field does not exist.
- Parameters
field_name – Filename of the file.
- Returns
The indexed value.
-
inline FieldData operator[](size_t fid) const
Get field identified by field id.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
InputError – Thrown if field does not exist.
- Parameters
fid – The field id.
- Returns
The indexed value.
-
std::map<std::string, FieldData> GetAllFields() const
Gets all fields of current vertex.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
InputError – Thrown if any field does not exist.
- Returns
All field names and values stored as a {(field_name, field_value),…} map.
-
void SetField(const std::string &field_name, const FieldData &field_value)
Sets the specified field.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
WriteNotAllowedError – Thrown if called inside a read-only transaction.
InputError – Thrown if any field does not exist.
- Parameters
field_name – Field name.
field_value – Field value.
-
void SetField(size_t field_id, const FieldData &field_value)
Sets the specified field.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
WriteNotAllowedError – Thrown if called inside a read-only transaction.
InputError – Thrown if field does not exist.
- Parameters
field_id – Field id.
field_value – Field value.
-
void SetFields(const std::vector<std::string> &field_names, const std::vector<std::string> &field_value_strings)
Sets the fields specified.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
WriteNotAllowedError – Thrown if called inside a read-only transaction.
InputError – Thrown if any field does not exist or field value type is incorrect.
- Parameters
field_names – List of names of the fields.
field_value_strings – The field value strings.
-
void SetFields(const std::vector<std::string> &field_names, const std::vector<FieldData> &field_values)
Sets the fields specified.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
WriteNotAllowedError – Thrown if called inside a read-only transaction.
InputError – Thrown if any field does not exist or field value type is incorrect.
- Parameters
field_names – List of names of the fields.
field_values – The field values.
-
void SetFields(const std::vector<size_t> &field_ids, const std::vector<FieldData> &field_values)
Sets the fields specified.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
WriteNotAllowedError – Thrown if called inside a read-only transaction.
InputError – Thrown if any field does not exist or field value type is incorrect.
- Parameters
field_ids – List of identifiers for the fields.
field_values – The field values.
-
void Delete()
Deletes this edge. The iterator will point to the next incoming edge sorted by (lid, tid, src, eid) if there is any. If no in-coming edge is left for this vertex, the iterator becomes invalid.
- Throws
InvalidTxnError – Thrown if the transaction is invalid.
InvalidIteratorError – Thrown if the iterator is invalid.
WriteNotAllowedError – Thrown if called inside a read-only transaction.
-
std::string ToString() const
Get string representation of the edge.
Private Functions
Constructors are private, use Transaction::GetInEdgeIterator() or VertexIterator::GetInEdgeIterator() instead.
-
InEdgeIterator(const InEdgeIterator&) = delete
-
InEdgeIterator &operator=(const InEdgeIterator&) = delete
Private Members
Friends
- friend class Transaction
- friend class VertexIterator
-
class OutEdgeIterator
- #include <lgraph_edge_iterator.h>
An OutEdgeIterator can be used to iterate through the out-going edges of a vertex. Edges are sorted in (lid, dst, eid) order, and each (src, lid, tid, dst, eid) tuple is guaranteed to uniquely identify an edge.
An OutEdgeIterator is valid iff it points to a valid out-going edge, otherwise it is invalid. Calling member function on an invalid OutEdgeIterator throws an InvalidIteratorError, except for the IsValid() and Goto() functions.
The following operations invalidates an OutEdgeIterator:
Constructing an OutEdgeIterator for non-existing edge.
Calling Goto() with the id of a non-existing edge.
Calling Next() on the last out-going edge.
Calling Delete() on the last out-going edge.
Calling Close() on the iterator.
In TuGraph, every iterator belongs to a transaction, and can only be used when the transaction is valid. Calling member functions on an iterator inside an invalid transaction yields InvalidTxnError, except for Invalid().
Public Functions
-
OutEdgeIterator(OutEdgeIterator &&rhs)
-
OutEdgeIterator &operator=(OutEdgeIterator &&rhs)
-
~OutEdgeIterator()
-
void Close() noexcept
Closes this iterator. The iterator turns invalid after being closed.
-
bool Goto(EdgeUid euid, bool nearest = false)
Go to the edge specified by euid. That is, an edge from Vertex euid.src to euid.dst, with LabelId==euid.label, Tid==euid.tid, and EdgeId==euid.eid. If neareast==true and the exact edge was not found, the iterator tries to get the next edge that sorts after the specified edge. The edges are sorted in (label, tid, dst, eid) order. The iterator becomes invalid if there is no outgoing edge from euid.src that sorts after euid.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
- Parameters
euid – Edge Unique ID.
nearest – (Optional) True to get the nearest edge if the specified one cannot be found.
- Returns
True if it succeeds, false if there is no such edge.
-
bool IsValid() const noexcept
Query if this iterator is valid.
- Returns
True if valid, false if not.
-
bool Next()
Move to the next edge. Invalidates iterator if there is no more out edges from current source vertex.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
True if it succeeds, false if it fails (no more out edge from current source).
-
EdgeUid GetUid() const
Gets the Edge Unique Id.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The UID.
-
int64_t GetDst() const
Gets destination of the edge.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The destination vertex id.
-
int64_t GetEdgeId() const
Gets edge id.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The edge identifier.
-
int64_t GetTemporalId() const
Gets primary id.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The primary id of the edge.
-
int64_t GetSrc() const
Gets the source vertex id.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The source vertex id.
-
const std::string &GetLabel() const
Gets the label of this edge.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The label.
-
int16_t GetLabelId() const
Gets label id of this edge.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The label identifier.
-
std::vector<FieldData> GetFields(const std::vector<std::string> &field_names) const
Gets the fields specified.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
field_names – List of names of the fields.
- Returns
The fields.
-
FieldData GetField(const std::string &field_name) const
Gets the field specified.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
field_name – Field name.
- Returns
Field value.
-
std::vector<FieldData> GetFields(const std::vector<size_t> &field_ids) const
Gets the fields specified.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
field_ids – List of ids for the fields.
- Returns
The fields.
-
FieldData GetField(size_t field_id) const
Gets the field specified.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
field_id – Field ID.
- Returns
Field value.
-
inline FieldData operator[](const std::string &field_name) const
Get field identified by field_name.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
field_name – The name of the field to get.
- Returns
Field value.
-
inline FieldData operator[](size_t fid) const
Get field identified by field id. FieldId can be obtained with txn.GetEdgeFieldId()
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
fid – fid The field id.
- Returns
Field value.
-
std::map<std::string, FieldData> GetAllFields() const
Gets all fields of current vertex.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
All fields in a dictionary of {(field_name, field_value),…}.
-
void SetField(const std::string &field_name, const FieldData &field_value)
Sets the specified field.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
WriteNotAllowedError – Thrown when called in a read-only transaction.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
field_name – Field name.
field_value – Field value.
-
void SetField(size_t field_id, const FieldData &field_value)
Sets the specified field.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
WriteNotAllowedError – Thrown when called in a read-only transaction.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
field_id – Field id.
field_value – Field value.
-
void SetFields(const std::vector<std::string> &field_names, const std::vector<std::string> &field_value_strings)
Sets the fields specified.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
WriteNotAllowedError – Thrown when called in a read-only transaction.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
field_names – List of names of the fields.
field_value_strings – The field value in string representation.
-
void SetFields(const std::vector<std::string> &field_names, const std::vector<FieldData> &field_values)
Sets the fields specified.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
WriteNotAllowedError – Thrown when called in a read-only transaction.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
field_names – List of names of the fields.
field_values – The field values.
-
void SetFields(const std::vector<size_t> &field_ids, const std::vector<FieldData> &field_values)
Sets the fields specified.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
WriteNotAllowedError – Thrown when called in a read-only transaction.
InputError – Thrown on other input errors (field not exist, etc.).
- Parameters
field_ids – List of identifiers for the fields.
field_values – The field values.
-
void Delete()
Deletes this edge. The iterator will point to the next out-going edge sorted by (label, tid, dst, eid) if there is any. If there is no more out-going edges for this source vertex, the iterator becomes invalid.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
WriteNotAllowedError – Thrown when called in a read-only transaction.
-
std::string ToString() const
Get string representation of the edge.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
A std::string that represents this object.
Private Functions
Constructors are private, use Transaction::GetInEdgeIterator() or VertexIterator::GetInEdgeIterator() instead.
-
OutEdgeIterator(const OutEdgeIterator&) = delete
-
OutEdgeIterator &operator=(const OutEdgeIterator&) = delete
Private Members
Friends
- friend class Transaction
- friend class VertexIterator
-
bool operator==(const OutEdgeIterator &lhs, const OutEdgeIterator &rhs)