Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deps/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ add_library(libsemigroups_julia SHARED
report.cpp
runner.cpp
transf.cpp
word-graph.cpp
word-range.cpp
)

Expand Down
1 change: 1 addition & 0 deletions deps/src/libsemigroups_julia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace libsemigroups_julia {

define_order(mod);
define_word_range(mod);
define_word_graph(mod);
}

} // namespace libsemigroups_julia
1 change: 1 addition & 0 deletions deps/src/libsemigroups_julia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace libsemigroups_julia {
void define_bmat8(jl::Module& mod);
void define_order(jl::Module& mod);
void define_word_range(jl::Module& mod);
void define_word_graph(jl::Module& mod);

} // namespace libsemigroups_julia

Expand Down
79 changes: 79 additions & 0 deletions deps/src/word-graph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// Semigroups.jl
// Copyright (C) 2026, James W. Swent
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#include "libsemigroups_julia.hpp"

#include <libsemigroups/word-graph.hpp>

#include <cstddef>
#include <cstdint>

namespace jlcxx {
template <>
struct IsMirroredType<libsemigroups::WordGraph<uint32_t>> : std::false_type {
};
} // namespace jlcxx

namespace libsemigroups_julia {

void define_word_graph(jl::Module& m) {
using WordGraph_ = libsemigroups::WordGraph<uint32_t>;

auto type = m.add_type<WordGraph_>("WordGraph");

// Constructor: (num_nodes, out_degree)
type.constructor<std::size_t, std::size_t>();

// --- Read queries ---

type.method("number_of_nodes", [](WordGraph_ const& g) -> std::size_t {
return g.number_of_nodes();
});

type.method("out_degree", [](WordGraph_ const& g) -> std::size_t {
return g.out_degree();
});

type.method("target",
[](WordGraph_ const& g, uint32_t s, uint32_t a) -> uint32_t {
return g.target(s, a);
});

// --- Mutators ---
// Getter `target(s, a)` and setter `target(s, a, t)` are same-name
// different-arity in C++; CxxWrap cannot reliably dispatch these, so the
// setter is bound under a distinct `target!` name. Returns void -- Julia
// does not need the *this chaining idiom.

type.method("target!",
[](WordGraph_& g, uint32_t s, uint32_t a, uint32_t t) {
g.target(s, a, t);
});

// libsemigroups' target(s, a, t) rejects t = UNDEFINED (typemax) as
// out-of-range; clearing an edge requires the distinct `remove_target`
// entry point. Julia's `target!(g, s, a, UNDEFINED)` dispatches here.
type.method("remove_target!", [](WordGraph_& g, uint32_t s, uint32_t a) {
g.remove_target(s, a);
});

type.method("add_nodes!",
[](WordGraph_& g, std::size_t n) { g.add_nodes(n); });
}

} // namespace libsemigroups_julia
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ makedocs(;
"Constants" => "data-structures/constants/index.md",
"Orders" => "data-structures/order.md",
"Words" => "data-structures/word-range.md",
"Word Graphs" => "data-structures/word-graph.md",
"Elements" => [
"Overview" => "data-structures/elements/index.md",
"Transformations" => [
Expand Down
31 changes: 31 additions & 0 deletions docs/src/data-structures/word-graph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# The WordGraph type

This page contains the documentation of the type [`WordGraph`](@ref
Semigroups.WordGraph), a representation of a word graph over an alphabet
of fixed out-degree.

```@docs
Semigroups.WordGraph
```

## Contents

| Function | Description |
| ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [`WordGraph`](@ref Semigroups.WordGraph(::Integer, ::Integer)) | Construct from number of nodes and out degree. |
| [`number_of_nodes`](@ref Semigroups.number_of_nodes(::WordGraph)) | Returns the number of nodes. |
| [`out_degree`](@ref Semigroups.out_degree(::WordGraph)) | Returns the out-degree. |
| [`target`](@ref Semigroups.target(::WordGraph, ::Integer, ::Integer)) | Get the target of the edge with given source node and label. |
| [`target!`](@ref Semigroups.target!(::WordGraph, ::Integer, ::Integer, ::Integer)) | Set the target of the edge with given source node and label. |
| [`add_nodes!`](@ref Semigroups.add_nodes!(::WordGraph, ::Integer)) | Add a number of new nodes. |

## Full API

```@docs
Semigroups.WordGraph(::Integer, ::Integer)
Semigroups.number_of_nodes(::WordGraph)
Semigroups.out_degree(::WordGraph)
Semigroups.target(::WordGraph, ::Integer, ::Integer)
Semigroups.target!(::WordGraph, ::Integer, ::Integer, ::Integer)
Semigroups.add_nodes!(::WordGraph, ::Integer)
```
4 changes: 4 additions & 0 deletions src/Semigroups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ include("report.jl")
include("runner.jl")
include("order.jl")
include("word-range.jl")
include("word-graph.jl")

# High-level element types
include("bmat8.jl")
Expand Down Expand Up @@ -107,6 +108,9 @@ export order, set_order!, set_upper_bound!, set_min!, set_max!
export number_of_words, random_word
export next!, at_end, valid, init!, size_hint, upper_bound

# WordGraph
export WordGraph, number_of_nodes, out_degree, target, target!, add_nodes!

# Transformation types and functions
export Transf, PPerm, Perm
export degree, rank, image, domain, inverse
Expand Down
Loading
Loading