Skip to content

Commit be27505

Browse files
committed
order: add wt_lex_compare from libsemigroups
1 parent 0cbf8de commit be27505

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

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_lex_compare,
102103
wt_shortlex_compare,
103104
)
104105
except ModuleNotFoundError as e:

src/order.cpp

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ is based on the source code of :cite:`Holt2018aa`.
206206
// No prefix because not in subpackage
207207
m.def(
208208
"wt_shortlex_compare",
209-
[](std::string const& x, std::string const& y,
209+
[](std::string const& x,
210+
std::string const& y,
210211
std::vector<size_t> const& weights) {
211212
return wt_shortlex_compare(x, y, weights);
212213
},
@@ -244,7 +245,8 @@ all lighter words. Amongst words of equal weight, short-lex ordering is used.
244245
// No prefix because not in subpackage
245246
m.def(
246247
"wt_shortlex_compare",
247-
[](word_type const& x, word_type const& y,
248+
[](word_type const& x,
249+
word_type const& y,
248250
std::vector<size_t> const& weights) {
249251
return wt_shortlex_compare(x, y, weights);
250252
},
@@ -254,6 +256,61 @@ all lighter words. Amongst words of equal weight, short-lex ordering is used.
254256
R"pbdoc(
255257
:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool:
256258
:only-document-once:
259+
)pbdoc");
260+
261+
// No prefix because not in subpackage
262+
m.def(
263+
"wt_lex_compare",
264+
[](std::string const& x,
265+
std::string const& y,
266+
std::vector<size_t> const& weights) {
267+
return wt_lex_compare(x, y, weights);
268+
},
269+
py::arg("x"),
270+
py::arg("y"),
271+
py::arg("weights"),
272+
R"pbdoc(
273+
:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool:
274+
:only-document-once:
275+
Compare two values of type :any:`str` or ``list[int]`` using weighted lex ordering.
276+
277+
This function compares two objects using the weighted lex ordering. The
278+
weight of a word is computed by adding up the weights of the letters in the
279+
word, where the ith index of the weights vector corresponds to the weight of
280+
the ith letter in the alphabet. Heavier words come later in the ordering than
281+
all lighter words. Amongst words of equal weight, lexicographic ordering is used.
282+
283+
:param x: the first object for comparison.
284+
:type x: str | list[int]
285+
286+
:param y: the second object for comparison.
287+
:type y: str | list[int]
288+
289+
:param weights: the weights vector, where the ith index corresponds to the weight of the ith letter.
290+
:type weights: list[int]
291+
292+
:returns: The boolean value ``True`` if *x* is weighted lex less than *y*, and ``False`` otherwise.
293+
:rtype: bool
294+
295+
:raises LibsemigroupsError: if any letter in *x* or *y* is not a valid index into the weights vector.
296+
297+
:complexity: At most :math:`O(n + m)` where :math:`n` is the length of *x* and :math:`m` is the length of *y*.
298+
)pbdoc");
299+
300+
// No prefix because not in subpackage
301+
m.def(
302+
"wt_lex_compare",
303+
[](word_type const& x,
304+
word_type const& y,
305+
std::vector<size_t> const& weights) {
306+
return wt_lex_compare(x, y, weights);
307+
},
308+
py::arg("x"),
309+
py::arg("y"),
310+
py::arg("weights"),
311+
R"pbdoc(
312+
:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool:
313+
:only-document-once:
257314
)pbdoc");
258315
}
259316
} // namespace libsemigroups

0 commit comments

Comments
 (0)