GraphAddNodeL
Description
Add a new node to the graph, taking ownership of lval. L-value form: when the graph has no copy_init handler, the node payload is moved out of lval (source zeroed) on success. With a deep-copy handler the source is left untouched.
Parameters
| Name | Direction | Description |
|---|---|---|
g |
in,out | Graph handle. |
lval |
in | Addressable node payload to insert. |
Usage example (from documentation)
GraphNodeId id = GraphAddNodeL(&g, payload);
if (!id) { /* recover */ }Success
Returns the new node’s stable GraphNodeId (non-zero). A new slot has been allocated (or a freed slot reused with a bumped generation); live_count grows by one. The node’s outgoing and incoming adjacency lists are empty. When the graph has no copy_init handler, lval has been zeroed (payload ownership transferred into the slot); otherwise lval is unchanged.
Failure
Returns 0 on allocation failure (payload buffer or slot growth). The graph and lval are unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Graph.Init.c:85:
Str *stored_name;
node_id = GraphAddNodeL(&graph, name);
node = GraphGetNode(&graph, node_id);
stored_name = GraphNodeDataPtr(&graph, node); int shared = 7;
GraphNodeId id0 = GraphAddNodeL(&graph, owned);
GraphNodeId id1 = GraphAddNodeR(&graph, shared);- In
Insert.h:84:
/// TAGS: Graph, Add, Node, Insert
///
#define GraphAddNode(g, lval) GraphAddNodeL((g), (lval))
///
- In
Insert.h:123:
#define GraphMustAddNodeL(g, lval) \
do { \
if (!GraphAddNodeL((g), (lval))) { \
LOG_FATAL("GraphMustAddNodeL failed"); \
} \
Last updated on