C++ Templates · Graphs

Graphs

b6b12730

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/ustore/templates/graphs.md' | claude -p "How would this fit my code?"

§ Ordering Half-Edges

A graph collection files every vertex and both ends of every edge as one half_edge_t, so a vertex’s entries form one contiguous run of an ordered set, and adding an edge writes two entries rather than rewriting either vertex:

#include <algorithm> // `std::ranges::sort`
#include <array>     // `std::array`

#include <ustore/graph/half_edges.hpp> // `half_edge_t`, `half_edge_order_t`

namespace ug = unum::ustore::graph;
namespace uu = unum::ustore::utilities;

int main() {
    ustore_key_t const a = uu::key_from_integer(1), b = uu::key_from_integer(2), edge = uu::key_from_integer(12);
    // One edge from `a` to `b` files twice, outgoing under `a` and incoming under `b`, beside each vertex's own entry.
    std::array entries {
        ug::half_edge_t {b, ug::half_edge_direction_t::incoming_k, a, edge},
        ug::half_edge_t::vertex_entry(b),
        ug::half_edge_t {a, ug::half_edge_direction_t::outgoing_k, b, edge},
        ug::half_edge_t::vertex_entry(a),
    };
    std::ranges::sort(entries, ug::half_edge_order_t {});
    // Bytewise order groups each run: `a`, its edge to `b`, then `b`, its edge from `a`.
    return entries.front() == ug::half_edge_t::vertex_entry(a) ? 0 : 1;
}