Skip to content

Commit

Permalink
feat: add aghead and agtail
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelom97 committed Oct 26, 2024
1 parent f96992e commit 2f632bf
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cgraph/cgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,22 @@ func (e *Edge) SetNode(v *Node) {
e.wasm.SetNode(v.getWasm())
}

func (e *Edge) Head() (*Node, error) {
n, err := e.wasm.Head(context.Background())
if err != nil {
return nil, err
}
return toNode(n), nil
}

func (e *Edge) Tail() (*Node, error) {
n, err := e.wasm.Tail(context.Background())
if err != nil {
return nil, err
}
return toNode(n), nil
}

func (c *CommonFields) Disc() *Disc {
return toDisc(c.wasm.GetDisc())
}
Expand Down
62 changes: 62 additions & 0 deletions graphviz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,65 @@ func TestNodeDegree(t *testing.T) {
}
}
}

func TestEdgeSourceAndTarget(t *testing.T) {
ctx := context.Background()
graph, err := graphviz.New(ctx)
if err != nil {
t.Fatalf("Error: %+v", err)
}

g, err := graph.Graph()
if err != nil {
t.Fatalf("Error: %+v", err)
}

nodeA, err := g.CreateNodeByName("a")
if err != nil {
t.Fatalf("Error: %+v", err)
}

nodeB, err := g.CreateNodeByName("b")
if err != nil {
t.Fatalf("Error: %+v", err)
}

edge, err := g.CreateEdgeByName("edge", nodeA, nodeB)
if err != nil {
t.Fatalf("Error: %+v", err)
}

head, err := edge.Head()
if err != nil {
t.Fatalf("Error: %+v", err)
}
if head == nil {
t.Fatalf("Source is nil")
}

headName, err := head.Name()
if err != nil {
t.Fatalf("Error: %+v", err)
}

if headName != "b" {
t.Fatalf("Expected source name to be 'b', got '%s'", headName)
}

target, err := edge.Tail()
if err != nil {
t.Fatalf("Error: %+v", err)
}
if target == nil {
t.Fatalf("Target is nil")
}

tailName, err := target.Name()
if err != nil {
t.Fatalf("Error: %+v", err)
}

if tailName != "a" {
t.Fatalf("Expected target name to be 'a', got '%s'", tailName)
}
}
20 changes: 20 additions & 0 deletions internal/wasm/bind.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions internal/wasm/bind.proto
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,26 @@ option (nori.file).export = {
pointer: 1
}
}
method {
recv: "Edge"
name: "head"
alias: "aghead"
return {
kind: STRUCT
ref: "Node"
pointer: 1
}
}
method {
recv: "Edge"
name: "tail"
alias: "agtail"
return {
kind: STRUCT
ref: "Node"
pointer: 1
}
}
method {
recv: "Graph"
name: "idEdge"
Expand Down
20 changes: 20 additions & 0 deletions internal/wasm/build/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -5690,6 +5690,26 @@ void wasm_bridge_Graph_edge(void * _arg0, void * _arg1, void * _arg2, void * _ar
*_arg5 = v;
}

void wasm_bridge_Edge_head(void * _arg0, void ** _arg1) {
Agedge_t * arg0;
arg0 = (Agedge_t *)_arg0;
Agnode_t * ret = aghead(
arg0
);
Agnode_t * v = (Agnode_t *)ret;
*_arg1 = v;
}

void wasm_bridge_Edge_tail(void * _arg0, void ** _arg1) {
Agedge_t * arg0;
arg0 = (Agedge_t *)_arg0;
Agnode_t * ret = agtail(
arg0
);
Agnode_t * v = (Agnode_t *)ret;
*_arg1 = v;
}

void wasm_bridge_Graph_idEdge(void * _arg0, void * _arg1, void * _arg2, unsigned long long int _arg3, int _arg4, void ** _arg5) {
Agraph_t * arg0;
arg0 = (Agraph_t *)_arg0;
Expand Down
Binary file modified internal/wasm/graphviz.wasm
Binary file not shown.

0 comments on commit 2f632bf

Please sign in to comment.