Skip to content

Commit 0920b03

Browse files
Better names than "validate" (libsemigroups#688)
1 parent a19883f commit 0920b03

52 files changed

Lines changed: 576 additions & 480 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmarks/bench-sims1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ namespace libsemigroups {
834834
REQUIRE(S.size() == 81);
835835

836836
auto p = to<Presentation<word_type>>(S);
837-
p.validate();
837+
p.throw_if_bad_alphabet_or_rules();
838838
REQUIRE(p.alphabet().size() == 10);
839839
REQUIRE(presentation::length(p) == 719);
840840

include/libsemigroups/action.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,8 @@ namespace libsemigroups {
832832
Forest const& f,
833833
index_type pos);
834834

835-
void validate_index(index_type i) const;
836-
void validate_gens() const;
835+
void throw_if_index_out_of_range(index_type i) const;
836+
void throw_if_no_generators() const;
837837
};
838838

839839
//! \ingroup action_group

include/libsemigroups/action.tpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ namespace libsemigroups {
333333
MultiplierCache& mults,
334334
Forest const& f,
335335
index_type pos) {
336-
validate_gens();
337-
validate_index(pos);
336+
throw_if_no_generators();
337+
throw_if_index_out_of_range(pos);
338338

339339
if (cache_scc_multipliers()) {
340340
if (mults.defined(pos)) {
@@ -389,8 +389,8 @@ namespace libsemigroups {
389389
typename Func,
390390
typename Traits,
391391
side LeftOrRight>
392-
void Action<Element, Point, Func, Traits, LeftOrRight>::validate_index(
393-
index_type i) const {
392+
void Action<Element, Point, Func, Traits, LeftOrRight>::
393+
throw_if_index_out_of_range(index_type i) const {
394394
if (i > _orb.size()) {
395395
LIBSEMIGROUPS_EXCEPTION(
396396
"index out of range, expected value in [0, {}) but found {}",
@@ -405,7 +405,8 @@ namespace libsemigroups {
405405
typename Traits,
406406
side LeftOrRight>
407407
void
408-
Action<Element, Point, Func, Traits, LeftOrRight>::validate_gens() const {
408+
Action<Element, Point, Func, Traits, LeftOrRight>::throw_if_no_generators()
409+
const {
409410
if (_gens.empty()) {
410411
LIBSEMIGROUPS_EXCEPTION("no generators defined, this function cannot "
411412
"be used until at least one generator is added")

include/libsemigroups/aho-corasick.hpp

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,12 @@ namespace libsemigroups {
430430
//! After validating \p current, this function performs the same as
431431
//! `traverse_no_checks(current, a)`.
432432
//!
433-
//! \throws LibsemigroupsException if `validate_active_node_index(current)`
434-
//! throws.
433+
//! \throws LibsemigroupsException if
434+
//! `throw_if_node_index_not_active(current)` throws.
435435
//!
436-
//! \sa \ref traverse_no_checks, \ref validate_active_node_index.
436+
//! \sa \ref traverse_no_checks, \ref throw_if_node_index_not_active.
437437
[[nodiscard]] index_type traverse(index_type current, letter_type a) const {
438-
validate_active_node_index(current);
438+
throw_if_node_index_not_active(current);
439439
return traverse_no_checks(current, a);
440440
}
441441

@@ -491,12 +491,12 @@ namespace libsemigroups {
491491
//! After validating \p i, this function performs the same as
492492
//! `signature_no_checks(w, i)`.
493493
//!
494-
//! \throws LibsemigroupsException if `validate_active_node_index(i)`
494+
//! \throws LibsemigroupsException if `throw_if_node_index_not_active(i)`
495495
//! throws.
496496
//!
497-
//! \sa \ref signature_no_checks, \ref validate_active_node_index.
497+
//! \sa \ref signature_no_checks, \ref throw_if_node_index_not_active.
498498
void signature(word_type& w, index_type i) const {
499-
validate_active_node_index(i);
499+
throw_if_node_index_not_active(i);
500500
signature_no_checks(w, i);
501501
}
502502

@@ -505,12 +505,12 @@ namespace libsemigroups {
505505
//! After validating \p i, this function performs the same as
506506
//! `signature_no_checks(i)`.
507507
//!
508-
//! \throws LibsemigroupsException if `validate_active_node_index(i)`
508+
//! \throws LibsemigroupsException if `throw_if_node_index_not_active(i)`
509509
//! throws.
510510
//!
511-
//! \sa \ref signature_no_checks, \ref validate_active_node_index.
511+
//! \sa \ref signature_no_checks, \ref throw_if_node_index_not_active.
512512
word_type signature(index_type i) const {
513-
validate_active_node_index(i);
513+
throw_if_node_index_not_active(i);
514514
return signature_no_checks(i);
515515
}
516516

@@ -539,12 +539,12 @@ namespace libsemigroups {
539539
//! After validating \p i, this function performs the same as
540540
//! `height_no_checks(i)`.
541541
//!
542-
//! \throws LibsemigroupsException if `validate_active_node_index(i)`
542+
//! \throws LibsemigroupsException if `throw_if_node_index_not_active(i)`
543543
//! throws.
544544
//!
545-
//! \sa \ref height_no_checks, \ref validate_active_node_index.
545+
//! \sa \ref height_no_checks, \ref throw_if_node_index_not_active.
546546
[[nodiscard]] size_t height(index_type i) const {
547-
validate_active_node_index(i);
547+
throw_if_node_index_not_active(i);
548548
return height_no_checks(i);
549549
}
550550

@@ -575,12 +575,12 @@ namespace libsemigroups {
575575
//! After validating \p current, this function performs the same as
576576
//! `suffix_link_no_checks(current)`.
577577
//!
578-
//! \throws LibsemigroupsException if `validate_active_node_index(current)`
579-
//! throws.
578+
//! \throws LibsemigroupsException if
579+
//! `throw_if_node_index_not_active(current)` throws.
580580
//!
581-
//! \sa \ref suffix_link_no_checks, \ref validate_active_node_index.
581+
//! \sa \ref suffix_link_no_checks, \ref throw_if_node_index_not_active.
582582
[[nodiscard]] index_type suffix_link(index_type current) const {
583-
validate_active_node_index(current);
583+
throw_if_node_index_not_active(current);
584584
return suffix_link_no_checks(current);
585585
}
586586

@@ -600,7 +600,7 @@ namespace libsemigroups {
600600
//! Constant.
601601
//!
602602
//! \note The node returned by this function may not represent a node
603-
//! presently stored in the trie. See \ref validate_active_node_index.
603+
//! presently stored in the trie. See \ref throw_if_node_index_not_active.
604604
//!
605605
//! \warning This function does no checks on its arguments whatsoever. In
606606
//! particular, if the index \p i is greater than the number of nodes that
@@ -615,11 +615,12 @@ namespace libsemigroups {
615615
//! After validating \p i, this function performs the same as
616616
//! `node_no_checks(i)`.
617617
//!
618-
//! \throws LibsemigroupsException if `validate_node_index(i)` throws.
618+
//! \throws LibsemigroupsException if `throw_if_node_index_out_of_range(i)`
619+
//! throws.
619620
//!
620-
//! \sa \ref node_no_checks, \ref validate_node_index.
621+
//! \sa \ref node_no_checks, \ref throw_if_node_index_out_of_range.
621622
[[nodiscard]] Node const& node(index_type i) const {
622-
validate_node_index(i);
623+
throw_if_node_index_out_of_range(i);
623624
return node_no_checks(i);
624625
}
625626

@@ -655,13 +656,13 @@ namespace libsemigroups {
655656
//! After validating \p parent, this function performs the same as
656657
//! `child_no_checks(parent, letter)`.
657658
//!
658-
//! \throws LibsemigroupsException if `validate_active_node_index(parent)`
659-
//! throws.
659+
//! \throws LibsemigroupsException if
660+
//! `throw_if_node_index_not_active(parent)` throws.
660661
//!
661-
//! \sa \ref child_no_checks, \ref validate_active_node_index.
662+
//! \sa \ref child_no_checks, \ref throw_if_node_index_not_active.
662663
[[nodiscard]] index_type child(index_type parent,
663664
letter_type letter) const {
664-
validate_active_node_index(parent);
665+
throw_if_node_index_not_active(parent);
665666
return _all_nodes[parent].child(letter);
666667
}
667668

@@ -670,45 +671,46 @@ namespace libsemigroups {
670671
//! This function checks if the given index \p i corresponds to the index of
671672
//! a node; either active or inactive.
672673
//!
673-
//! \param i the index to validate.
674+
//! \param i the index to check.
674675
//!
675676
//! \throws LibsemigroupsException if \p i does not correspond to the index
676677
//! of a node; that is, if \p i is larger than the size of the container
677678
//! storing the indices of nodes.
678679
//!
679680
//! \complexity
680681
//! Constant.
681-
void validate_node_index(index_type i) const;
682+
void throw_if_node_index_out_of_range(index_type i) const;
682683

683684
//! \brief Check if an index corresponds to a node currently in the trie.
684685
//!
685-
//! This function validates whether the given index \p i corresponds to an
686+
//! This function checks whether the given index \p i corresponds to an
686687
//! active node.
687688
//!
688-
//! \param i the index to validate.
689+
//! \param i the index to check.
689690
//!
690-
//! \throws LibsemigroupsException if `validate_node_index(i)` throws, or if
691+
//! \throws LibsemigroupsException if `throw_if_node_index_out_of_range(i)`
692+
//! throws, or if
691693
//! \p i is not an active node.
692694
//!
693695
//! \complexity
694696
//! Constant.
695697
//!
696-
//! \sa \ref validate_node_index.
697-
void validate_active_node_index(index_type i) const;
698+
//! \sa \ref throw_if_node_index_out_of_range.
699+
void throw_if_node_index_not_active(index_type i) const;
698700

699701
private:
700702
[[nodiscard]] index_type new_active_node_no_checks(index_type parent,
701703
letter_type a);
702704

703705
[[nodiscard]] index_type new_active_node(index_type parent, letter_type a) {
704-
validate_active_node_index(parent);
706+
throw_if_node_index_not_active(parent);
705707
return new_active_node_no_checks(parent, a);
706708
}
707709

708710
void deactivate_node_no_checks(index_type i);
709711

710712
void deactivate_node(index_type i) {
711-
validate_active_node_index(i);
713+
throw_if_node_index_not_active(i);
712714
deactivate_node_no_checks(i);
713715
}
714716

@@ -887,18 +889,18 @@ namespace libsemigroups {
887889
//! After validating \p start with respect to \p ac, this function performs
888890
//! the same as `traverse_word_no_checks(ac, start, first, last)`.
889891
//!
890-
//! \throws LibsemigroupsException if `ac.validate_active_node_index(start)`
891-
//! throws.
892+
//! \throws LibsemigroupsException if
893+
//! `ac.throw_if_node_index_not_active(start)` throws.
892894
//!
893895
//! \sa \ref traverse_word_no_checks(AhoCorasick const& ac, index_type
894896
//! start, Iterator first, Iterator last),
895-
//! \ref AhoCorasick::validate_active_node_index.
897+
//! \ref AhoCorasick::throw_if_node_index_not_active.
896898
template <typename Iterator>
897899
[[nodiscard]] index_type traverse_word(AhoCorasick const& ac,
898900
index_type start,
899901
Iterator first,
900902
Iterator last) {
901-
ac.validate_active_node_index(start);
903+
ac.throw_if_node_index_not_active(start);
902904
return traverse_word_no_checks(ac, start, first, last);
903905
}
904906

0 commit comments

Comments
 (0)