Skip to content
Draft
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
2 changes: 2 additions & 0 deletions docs/source/data-structures/order/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ Full API
.. autofunction:: recursive_path_compare

.. autofunction:: shortlex_compare

.. autofunction:: wt_shortlex_compare
1 change: 1 addition & 0 deletions src/libsemigroups_pybind11/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
shortlex_compare,
side,
tril,
wt_shortlex_compare,
)
except ModuleNotFoundError as e:
raise ModuleNotFoundError(
Expand Down
53 changes: 53 additions & 0 deletions src/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,59 @@ is based on the source code of :cite:`Holt2018aa`.
R"pbdoc(
:sig=(x: str | list[int], y: str | list[int]) -> bool:
:only-document-once:
)pbdoc");

// No prefix because not in subpackage
m.def(
"wt_shortlex_compare",
[](std::string const& x, std::string const& y,
std::vector<size_t> const& weights) {
return wt_shortlex_compare(x, y, weights);
},
py::arg("x"),
py::arg("y"),
py::arg("weights"),
R"pbdoc(
:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool:
:only-document-once:
Compare two values of type :any:`str` or ``list[int]`` using weighted shortlex ordering.

This function compares two objects using the weighted short-lex ordering. The
weight of a word is computed by adding up the weights of the letters in the
word, where the ith index of the weights vector corresponds to the weight of
the ith letter in the alphabet. Heavier words come later in the ordering than
all lighter words. Amongst words of equal weight, short-lex ordering is used.

:param x: the first object for comparison.
:type x: str | list[int]

:param y: the second object for comparison.
:type y: str | list[int]

:param weights: the weights vector, where the ith index corresponds to the weight of the ith letter.
:type weights: list[int]

:returns: The boolean value ``True`` if *x* is weighted short-lex less than *y*, and ``False`` otherwise.
:rtype: bool

:raises LibsemigroupsError: if any letter in *x* or *y* is not a valid index into the weights vector.

:complexity: At most :math:`O(n + m)` where :math:`n` is the length of *x* and :math:`m` is the length of *y*.
)pbdoc");

// No prefix because not in subpackage
m.def(
"wt_shortlex_compare",
[](word_type const& x, word_type const& y,
std::vector<size_t> const& weights) {
return wt_shortlex_compare(x, y, weights);
},
py::arg("x"),
py::arg("y"),
py::arg("weights"),
R"pbdoc(
:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool:
:only-document-once:
)pbdoc");
}
} // namespace libsemigroups