Skip to content

Commit fdcc770

Browse files
committed
Edit 'is_chordal': use trait dispatch, add docstring examples
1 parent 98523a3 commit fdcc770

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

src/chordality.jl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,27 @@ parallel edges.
3131
May 29, 2025. Accessed June 2, 2025.
3232
https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.chordal.is_chordal.html.
3333
34-
# Examples
35-
TODO: Add examples
34+
### Examples
35+
```jldoctest
36+
julia> using Graphs
37+
38+
julia> is_chordal(cycle_graph(3))
39+
true
40+
41+
julia> is_chordal(cycle_graph(4))
42+
false
43+
44+
julia> g = SimpleGraph(4); add_edge!(g, 1, 2); add_edge!(g, 2, 3); add_edge!(g, 3, 4); add_edge!(g, 4, 1); add_edge!(g, 1, 3);
45+
46+
julia> is_chordal(g)
47+
true
48+
49+
```
3650
"""
37-
function is_chordal(g::AbstractGraph)
51+
function is_chordal end
52+
53+
@traitfn function is_chordal(g::AG::(!IsDirected)) where {AG<:AbstractGraph}
3854
# The `AbstractGraph` interface does not support parallel edges, so no need to check
39-
is_directed(g) && throw(ArgumentError("Graph must be undirected"))
4055
has_self_loops(g) && throw(ArgumentError("Graph must not have self-loops"))
4156

4257
# Every graph of order `< 4` has no cycles of length `≥ 4` and thus is trivially chordal

0 commit comments

Comments
 (0)