Skip to content

Commit 0cbf8de

Browse files
committed
order: add wt_shortlex_compare from libsemigroups
1 parent cf7c55c commit 0cbf8de

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

docs/source/data-structures/order/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ Full API
3535
.. autofunction:: recursive_path_compare
3636

3737
.. autofunction:: shortlex_compare
38+
39+
.. autofunction:: wt_shortlex_compare

src/libsemigroups_pybind11/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
shortlex_compare,
100100
side,
101101
tril,
102+
wt_shortlex_compare,
102103
)
103104
except ModuleNotFoundError as e:
104105
raise ModuleNotFoundError(

src/order.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,59 @@ is based on the source code of :cite:`Holt2018aa`.
201201
R"pbdoc(
202202
:sig=(x: str | list[int], y: str | list[int]) -> bool:
203203
:only-document-once:
204+
)pbdoc");
205+
206+
// No prefix because not in subpackage
207+
m.def(
208+
"wt_shortlex_compare",
209+
[](std::string const& x, std::string const& y,
210+
std::vector<size_t> const& weights) {
211+
return wt_shortlex_compare(x, y, weights);
212+
},
213+
py::arg("x"),
214+
py::arg("y"),
215+
py::arg("weights"),
216+
R"pbdoc(
217+
:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool:
218+
:only-document-once:
219+
Compare two values of type :any:`str` or ``list[int]`` using weighted shortlex ordering.
220+
221+
This function compares two objects using the weighted short-lex ordering. The
222+
weight of a word is computed by adding up the weights of the letters in the
223+
word, where the ith index of the weights vector corresponds to the weight of
224+
the ith letter in the alphabet. Heavier words come later in the ordering than
225+
all lighter words. Amongst words of equal weight, short-lex ordering is used.
226+
227+
:param x: the first object for comparison.
228+
:type x: str | list[int]
229+
230+
:param y: the second object for comparison.
231+
:type y: str | list[int]
232+
233+
:param weights: the weights vector, where the ith index corresponds to the weight of the ith letter.
234+
:type weights: list[int]
235+
236+
:returns: The boolean value ``True`` if *x* is weighted short-lex less than *y*, and ``False`` otherwise.
237+
:rtype: bool
238+
239+
:raises LibsemigroupsError: if any letter in *x* or *y* is not a valid index into the weights vector.
240+
241+
:complexity: At most :math:`O(n + m)` where :math:`n` is the length of *x* and :math:`m` is the length of *y*.
242+
)pbdoc");
243+
244+
// No prefix because not in subpackage
245+
m.def(
246+
"wt_shortlex_compare",
247+
[](word_type const& x, word_type const& y,
248+
std::vector<size_t> const& weights) {
249+
return wt_shortlex_compare(x, y, weights);
250+
},
251+
py::arg("x"),
252+
py::arg("y"),
253+
py::arg("weights"),
254+
R"pbdoc(
255+
:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool:
256+
:only-document-once:
204257
)pbdoc");
205258
}
206259
} // namespace libsemigroups

0 commit comments

Comments
 (0)