Skip to content

Commit

Permalink
Documentation and initialisation conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed Nov 5, 2022
1 parent 1288538 commit 332e7a1
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 167 deletions.
19 changes: 9 additions & 10 deletions src/node.tcc
Expand Up @@ -8,28 +8,27 @@
using std::array;


/*!
* Leaf.
*/
/*! Leaf. */
struct Leaf {
size_t count = 0;
size_t count {0}; //!< Counter.
};

/*!
* Node.
/*! Node.
*
* \tparam alphabetSize Size of the alphabet.
* \tparam T Leaf type.
*/
template <uint8_t alphabetSize, class T>
class Node {
public:
bool isEmpty() const;

array<Node*, alphabetSize> child = {};
T* leaf = nullptr;
array<Node*, alphabetSize> child {}; //!< Children.
T* leaf {nullptr}; //!< Leaf.
};


/*!
* Check whether a node neither has any children, nor a leaf.
/*! Check whether a node neither has any children, nor a leaf.
*
* \return True is the node is empty, false otherwise.
*/
Expand Down
127 changes: 61 additions & 66 deletions src/trie.tcc
Expand Up @@ -4,147 +4,142 @@

#include "trieFunctions.tcc"

/*!
* Trie.
*/
/*! Trie. */
template <uint8_t alphabetSize, class T>
class Trie {
public:
/*! Constructor. */
Trie();

/*! Destructor. */
~Trie();


/*! Add a word.
*
* \param word Word.
*
* \return Leaf.
*/
T* add(vector<uint8_t> const&) const;

/*! Remove a word.
*
* \param word Word.
*/
void remove(vector<uint8_t> const&) const;

/*! Find a word.
*
* \param word Word.
*
* \return `node` if found, `nullptr` otherwise.
*/
Node<alphabetSize, T>* find(vector<uint8_t> const&) const;

/*! Traverse.
*
* \return Traversal results.
*/
generator<Result<T>> walk() const;

/*! Hamming.
*
* \param word Word.
* \param distance Maximum distance.
*
* \return Traversal results.
*/
generator<Result<T>> hamming(vector<uint8_t> const&, int const) const;

/*! Asymmetric Hamming.
*
* \param word Word.
* \param distance Maximum distance.
*
* \return Traversal results.
*/
generator<Result<T>> asymmetricHamming(
vector<uint8_t> const&, int const) const;

/*! Levenshtein.
*
* \param word Word.
* \param distance Maximum distance.
*
* \return Traversal results.
*/
generator<Result<T>> levenshtein(vector<uint8_t> const&, int const) const;

/*! Asymmetric Levenshtein.
*
* \param word Word.
* \param distance Maximum distance.
*
* \return Traversal results.
*/
generator<Result<T>> asymmetricLevenshtein(
vector<uint8_t> const&, int const) const;

private:
Node<alphabetSize, T>* root_ = nullptr;
Node<alphabetSize, T>* root_ {nullptr};
};


/*!
* Constructor.
*/
template <uint8_t alphabetSize, class T>
Trie<alphabetSize, T>::Trie() {
root_ = new Node<alphabetSize, T>;
}

/*!
* Destructor.
*/
template <uint8_t alphabetSize, class T>
Trie<alphabetSize, T>::~Trie() {
delete_(root_);
}


/*!
* Add a word.
*
* \param word Word.
*
* \return Leaf.
*/
template <uint8_t alphabetSize, class T>
T* Trie<alphabetSize, T>::add(vector<uint8_t> const& word) const {
return add_(root_, word);
}

/*!
* Remove a word.
*
* \param word Word.
*/
template <uint8_t alphabetSize, class T>
void Trie<alphabetSize, T>::remove(vector<uint8_t> const& word) const {
remove_(root_, word, 0);
}

/*!
* Find a word.
*
* \param word Word.
*
* \return `node` if found, `nullptr` otherwise.
*/
template <uint8_t alphabetSize, class T>
Node<alphabetSize, T>* Trie<alphabetSize, T>::find(
vector<uint8_t> const& word) const {
return find_(root_, word);
}

/*!
* Traverse.
*
* \return Traversal results.
*/
template <uint8_t alphabetSize, class T>
generator<Result<T>> Trie<alphabetSize, T>::walk() const {
vector<uint8_t> path;
co_yield walk_(root_, path);
}

/*!
* Hamming.
*
* \param word Word.
* \param distance Maximum distance.
*
* \return Traversal results.
*/
template <uint8_t alphabetSize, class T>
generator<Result<T>> Trie<alphabetSize, T>::hamming(
vector<uint8_t> const& word, int const distance) const {
vector<uint8_t> path;
co_yield hamming_<alphabetSize, T, true>(root_, word, 0, distance, path);
}

/*!
* Asymmetric Hamming.
*
* \param word Word.
* \param distance Maximum distance.
*
* \return Traversal results.
*/
template <uint8_t alphabetSize, class T>
generator<Result<T>> Trie<alphabetSize, T>::asymmetricHamming(
vector<uint8_t> const& word, int const distance) const {
vector<uint8_t> path;
co_yield hamming_<alphabetSize, T, false>(root_, word, 0, distance, path);
}

/*!
* Levenshtein.
*
* \param word Word.
* \param distance Maximum distance.
*
* \return Traversal results.
*/
template <uint8_t alphabetSize, class T>
generator<Result<T>> Trie<alphabetSize, T>::levenshtein(
vector<uint8_t> const& word, int const distance) const {
vector<uint8_t> path;
co_yield levenshtein_<alphabetSize, T, true>(root_, word, 0, distance, path);
}

/*!
* Asymmetric Levenshtein.
*
* \param word Word.
* \param distance Maximum distance.
*
* \return Traversal results.
*/
template <uint8_t alphabetSize, class T>
generator<Result<T>> Trie<alphabetSize, T>::asymmetricLevenshtein(
vector<uint8_t> const& word, int const distance) const {
Expand Down

0 comments on commit 332e7a1

Please sign in to comment.