lgraph_vertex_iterator
-
namespace lgraph
-
namespace graph
-
namespace graph
-
namespace lgraph_api
-
class VertexIterator
- #include <lgraph_vertex_iterator.h>
VertexIterator can be used to iterate through vertices in the DB. Vertices are sorted according to vertex id in the DB.
A VertexIterator is valid iff it points to a valid vertex. Calling method functions on an invalid VertexIterator throws an InvalidIteratorError, except for the IsValid() and Goto() functions.
The following operations invalidates a VertexIterator:
Constructing an VertexIterator for non-existing vertex.
Calling Goto() with the id of a non-existing vertex.
Calling Next() on the last vertex.
Calling Delete() on the last vertex.
Public Functions
-
VertexIterator(VertexIterator &&rhs)
-
VertexIterator &operator=(VertexIterator &&rhs)
-
~VertexIterator()
-
void Close()
Closes this iterator.
-
bool Next()
Move to the next vertex.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
True if it succeeds, otherwise return false (no more vertex) and invalidate the iterator.
-
bool Goto(int64_t vid, bool nearest = false)
Goto the vertex with id src. If there is no vertex with exactly the same vid, and nearest==true, go to the next vertex with id>=vid, otherwise return false and invalidate the iterator.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
- Parameters
vid – Vertex id of the vertex to go.
nearest – (Optional) True to go to the closest vertex with id>=vid.
- Returns
True if it succeeds, otherwise false (no such vertex).
-
int64_t GetId() const
Gets the vertex id.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The id.
-
OutEdgeIterator GetOutEdgeIterator() const
Gets an OutEdgeIterator pointing to the first out-going edge.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The OutEdgeIterator.
-
OutEdgeIterator GetOutEdgeIterator(const EdgeUid &euid, bool nearest = false) const
Returns an OutEdgeIterator pointing to the edge specified by euid. If there is no such edge, and nearest==false an invalid iterator is returned. If the specified out-edge does not exist, and nearest==true, get the first out-edge that sorts after the specified one.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Parameters
euid – The Edge Unique Id.
nearest – (Optional) If set to true and the specified edge does not exist, get the edge that sorts right after it.
- Returns
The out edge iterator.
-
InEdgeIterator GetInEdgeIterator() const
Gets an InEdgeIterator pointing to the first in-coming edge.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The InEdgeIterator.
-
InEdgeIterator GetInEdgeIterator(const EdgeUid &euid, bool nearest = false) const
Returns an InEdgeIterator pointing to the edge specified by euid. If there is no such edge and nearest==false, an invalid iterator is returned. If the specified edge does not exist and nearest==true,.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Parameters
euid – The Edge Unique Id.
nearest – (Optional) If set to true and the specified edge does not exist, get the edge that sorts right after it.
- Returns
The InEdgeIterator.
-
bool IsValid() const
Query if this iterator is valid.
- Returns
True if valid, false if not.
-
const std::string &GetLabel() const
Gets the label of this vertex.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Returns
The label.
-
size_t GetLabelId() const
Gets label id of this vertex.
- 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 – Filename of the file.
- Returns
The indexed value.
-
inline FieldData operator[](size_t fid) const
Get field identified by field id.
- 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 – The field id.
- Returns
The indexed 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.
-
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 strings.
-
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.
-
std::vector<int64_t> ListSrcVids(size_t n_limit = std::numeric_limits<size_t>::max(), bool *more_to_go = nullptr)
List source vids. Each source vid is stored only once in the result.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Parameters
n_limit – (Optional) The limit on number of vids to return.
more_to_go – [out] (Optional) If non-null, returns whether the limit is exceeded.
- Returns
List of source vids.
-
std::vector<int64_t> ListDstVids(size_t n_limit = std::numeric_limits<size_t>::max(), bool *more_to_go = nullptr)
List destination vids. Each vid is stored only once in the result.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Parameters
n_limit – (Optional) The limit of number of vids to return.
more_to_go – [out] (Optional) If non-null, returns whether the limit is exceeded.
- Returns
List of desitnation vids.
-
size_t GetNumInEdges(size_t n_limit = std::numeric_limits<size_t>::max(), bool *more_to_go = nullptr)
Gets number of incoming edges, stopping on limit. This function can come in handy if we need to filter on large vertexes.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Parameters
n_limit – (Optional) The limit on number of in-coming edges to count. When the limit is reached, n_limit is returned.
more_to_go – [out] (Optional) If non-null, return whether the limit is exceeded.
- Returns
Number of incoming edges.
-
size_t GetNumOutEdges(size_t n_limit = std::numeric_limits<size_t>::max(), bool *more_to_go = nullptr)
Gets number of out-going edges, stopping on limit. This function can come in handy if we need to filter on large vertexes.
- Throws
InvalidTxnError – Thrown when called inside an invalid transaction.
InvalidIteratorError – Thrown when current iterator is invalid.
- Parameters
n_limit – (Optional) The limit on number of out-going edges to count. When the limit is reached, n_limit is returned and limit_exceeded is set to true.
more_to_go – [out] (Optional) If non-null, return whether the limit is exceeded.
- Returns
Number of out-going edges.
-
void Delete(size_t *n_in_edges = nullptr, size_t *n_out_edges = nullptr)
Deletes this vertex, also deletes all incoming and outgoing edges of this vertex. The iterator will point to the next vertex by vid if there is any.
- 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.
- Parameters
n_in_edges – [out] (Optional) If non-null, the number of in edges the vertex had.
n_out_edges – [out] (Optional) If non-null, the number of out edges the vertex had.
-
std::string ToString() const
Get the string representation of this vertex.
Private Functions
-
VertexIterator(const VertexIterator&) = delete
-
VertexIterator &operator=(const VertexIterator&) = delete
Private Members
Friends
- friend class Transaction
-
class VertexIterator