Graph Service#

Programming interface#

All types and functions in this section are declared in the oneapi::dal::preview namespace and are available via inclusion of the oneapi/dal/graph/service_functions.hpp header file.

The graph service is a set of functions that allow you to get access to the elements and characteristics of the graph, such as vertex degree or edge attribute.

Graph service functions are defined as function templates with Graph as a template parameter. Graph service functions introduce aliases to graph_traits as shown below.

Graph service functions#

Any service function has the following pattern:

template <typename Graph>
return_type<Graph> get_[graph_element](const Graph& g, ...);
template<typename Graph>
constexpr auto get_vertex_count(const Graph &g) noexcept -> vertex_size_type<Graph>#

Returns the number of vertices in the graph.

Template Parameters

Graph – Type of the graph.

Parameters

g – Input graph object.

template<typename Graph>
constexpr auto get_edge_count(const Graph &g) noexcept -> edge_size_type<Graph>#

Returns the number of edges in the graph.

Template Parameters

Graph – Type of the graph.

Parameters

g – Input graph object.

template<typename Graph>
constexpr auto get_vertex_degree(const Graph &g, vertex_type<Graph> u) -> vertex_edge_size_type<Graph>#

Returns the degree for the specified vertex.

Template Parameters

Graph – Type of the graph.

Parameters
  • g – Input graph object.

  • u – Vertex index.

template<typename Graph>
constexpr auto get_vertex_neighbors(const Graph &g, vertex_type<Graph> u) -> const_vertex_edge_range_type<Graph>#

Returns the range of the vertex neighbors for the specified vertex.

Template Parameters

Graph – Type of the graph.

Parameters
  • g – Input graph object.

  • u – Vertex index.

template<typename Graph>
constexpr auto get_vertex_outward_degree(const Graph &g, vertex_type<Graph> u) -> vertex_outward_edge_size_type<Graph>#

Returns the outward degree for the specified vertex.

Template Parameters

Graph – Type of the graph.

Parameters
  • g – Input graph object.

  • u – Vertex index.

template<typename Graph>
constexpr auto get_vertex_outward_neighbors(const Graph &g, vertex_type<Graph> u) -> const_vertex_outward_edge_range_type<Graph>#

Returns the range of the vertex outward neighbors for the specified vertex.

Template Parameters

Graph – Type of the graph.

Parameters
  • g – Input graph object.

  • u – Vertex index.

template<typename Graph>
constexpr auto get_edge_value(const Graph &g, vertex_type<Graph> u, vertex_type<Graph> v) -> const edge_user_value_type<Graph>&#

Returns the value of an edge (u, v).

Template Parameters

Graph – Type of the graph.

Parameters
  • u – Source vertex index.

  • v – Destination vertex index.

Usage Example#

using graph_type = ...;
const my_graph_type g = ...;
std::cout << "The number of vertices: " << oneapi::dal::preview::get_vertex_count(g) << std::endl;
std::cout << "The number of edges: " << oneapi::dal::preview::get_edge_count(g) << std::endl;

Service functions for supported graphs#

This section contains description of service functions supported for the specified graph types.

Service function

Valid graph concepts

get_vertex_count

undirected graph, directed graph

get_edge_count

undirected graph, directed graph

get_vertex_degree

undirected graph

get_vertex_outward_degree

directed graph

get_vertex_neighbors

undirected graph

get_vertex_outward_neighbors

directed graph

get_edge_value

undirected graph, directed graph