lgraph_vertex_iterator

namespace lgraph
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:

  1. Constructing an VertexIterator for non-existing vertex.

  2. Calling Goto() with the id of a non-existing vertex.

  3. Calling Next() on the last vertex.

  4. 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.

抛出
返回

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.

抛出

InvalidTxnError – Thrown when called inside an invalid transaction.

参数
  • vid – Vertex id of the vertex to go.

  • nearest – (Optional) True to go to the closest vertex with id>=vid.

返回

True if it succeeds, otherwise false (no such vertex).

int64_t GetId() const

Gets the vertex id.

抛出
返回

The id.

OutEdgeIterator GetOutEdgeIterator() const

Gets an OutEdgeIterator pointing to the first out-going edge.

抛出
返回

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.

抛出
参数
  • 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.

返回

The out edge iterator.

InEdgeIterator GetInEdgeIterator() const

Gets an InEdgeIterator pointing to the first in-coming edge.

抛出
返回

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,

抛出
参数
  • 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.

返回

The InEdgeIterator.

bool IsValid() const

Query if this iterator is valid.

返回

True if valid, false if not.

const std::string &GetLabel() const

Gets the label of this vertex.

抛出
返回

The label.

size_t GetLabelId() const

Gets label id of this vertex.

抛出
返回

The label identifier.

std::vector<FieldData> GetFields(const std::vector<std::string> &field_names) const

Gets the fields specified.

抛出
参数

field_names – List of names of the fields.

返回

The fields.

FieldData GetField(const std::string &field_name) const

Gets the field specified.

抛出
参数

field_name – Field name.

返回

Field value.

std::vector<FieldData> GetFields(const std::vector<size_t> &field_ids) const

Gets the fields specified.

抛出
参数

field_ids – List of ids for the fields.

返回

The fields.

FieldData GetField(size_t field_id) const

Gets the field specified.

抛出
参数

field_id – Field ID.

返回

Field value.

inline FieldData operator[](const std::string &field_name) const

Get field identified by field_name

抛出
参数

field_name – Filename of the file.

返回

The indexed value.

inline FieldData operator[](size_t fid) const

Get field identified by field id

抛出
参数

fid – The field id.

返回

The indexed value.

std::map<std::string, FieldData> GetAllFields() const

Gets all fields of current vertex.

抛出
返回

all fields.

void SetField(const std::string &field_name, const FieldData &field_value)

Sets the specified field.

抛出
参数
  • field_name – Field name.

  • field_value – Field value.

void SetField(size_t field_id, const FieldData &field_value)

Sets the specified field.

抛出
参数
  • 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.

抛出
参数
  • 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.

抛出
参数
  • 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.

抛出
参数
  • 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.

抛出
参数
  • 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.

返回

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.

抛出
参数
  • 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.

返回

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.

抛出
参数
  • 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.

返回

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.

抛出
参数
  • 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.

返回

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.

抛出
参数
  • 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(lgraph::graph::VertexIterator&&, const std::shared_ptr<lgraph::Transaction>&)
VertexIterator(const VertexIterator&) = delete
VertexIterator &operator=(const VertexIterator&) = delete

Private Members

std::unique_ptr<lgraph::graph::VertexIterator> it_
std::shared_ptr<lgraph::Transaction> txn_

Friends

friend class Transaction