Skip to content

Commit

Permalink
Merge pull request #14 from d06alexandrov/nfa_to_dfa_sonarcloud_fix
Browse files Browse the repository at this point in the history
Fixed nfa_to_dfa issues found by sonarcloud
  • Loading branch information
d06alexandrov authored Jul 21, 2023
2 parents c20670e + de3aa60 commit abcdac2
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 167 deletions.
12 changes: 6 additions & 6 deletions lib/nfa.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ void nfa_free(struct nfa *nfa)
}
}

size_t nfa_state_count(struct nfa *nfa)
size_t nfa_state_count(const struct nfa *nfa)
{
return nfa->node_cnt;
}

size_t nfa_get_initial_state(struct nfa *nfa)
size_t nfa_get_initial_state(const struct nfa *nfa)
{
return nfa->first_index;
}
Expand Down Expand Up @@ -205,7 +205,7 @@ int nfa_rebuild(struct nfa *nfa)
return 0;
}

int nfa_join(struct nfa *dst, struct nfa *src)
int nfa_join(struct nfa *dst, const struct nfa *src)
{
size_t offset;

Expand Down Expand Up @@ -272,7 +272,7 @@ int nfa_add_node_n(struct nfa *nfa, size_t cnt, size_t *index)
return 0;
}

int nfa_state_is_final(struct nfa *nfa, size_t state)
int nfa_state_is_final(const struct nfa *nfa, size_t state)
{
if (nfa->nodes[state].isfinal)
return 1;
Expand Down Expand Up @@ -305,7 +305,7 @@ int nfa_add_lambda_trans(struct nfa *nfa, size_t from, size_t to)
return 0;
}

size_t nfa_get_lambda_trans(struct nfa *nfa, size_t from, size_t **trans)
size_t nfa_get_lambda_trans(const struct nfa *nfa, size_t from, size_t **trans)
{
if (from >= nfa_state_count(nfa)) {
return 0;
Expand All @@ -330,7 +330,7 @@ int nfa_add_trans(struct nfa *dst, size_t from, unsigned char mark, size_t to)
return 0;
}

size_t nfa_get_trans(struct nfa *nfa, size_t from, unsigned char mark,
size_t nfa_get_trans(const struct nfa *nfa, size_t from, unsigned char mark,
size_t **trans)
{
if (from >= nfa_state_count(nfa)) {
Expand Down
12 changes: 6 additions & 6 deletions lib/nfa.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void nfa_free(struct nfa *nfa);
* @param nfa pointer to the nfa structure
* @return total number of states
*/
size_t nfa_state_count(struct nfa *nfa);
size_t nfa_state_count(const struct nfa *nfa);

/**
* Get initial NFA's state.
Expand All @@ -133,7 +133,7 @@ size_t nfa_state_count(struct nfa *nfa);
* @param nfa pointer to the nfa structure
* @return index of the initial state
*/
size_t nfa_get_initial_state(struct nfa *nfa);
size_t nfa_get_initial_state(const struct nfa *nfa);

/**
* Set initial NFA's state.
Expand Down Expand Up @@ -165,7 +165,7 @@ int nfa_rebuild(struct nfa *nfa);
* @param src pointer to the nfa structure that will be joined to the dst
* @return 0 on success
*/
int nfa_join(struct nfa *dst, struct nfa *src);
int nfa_join(struct nfa *dst, const struct nfa *src);

/**
* Add new node (state) to the NFA.
Expand Down Expand Up @@ -200,7 +200,7 @@ int nfa_add_node_n(struct nfa *nfa, size_t cnt, size_t *index);
* @param state index of the NFA's state
* @return 1 if the state with provided index is final
*/
int nfa_state_is_final(struct nfa *nfa, size_t state);
int nfa_state_is_final(const struct nfa *nfa, size_t state);

/**
* Mark or unmark the NFA's state as a final state.
Expand Down Expand Up @@ -237,7 +237,7 @@ int nfa_add_lambda_trans(struct nfa *nfa, size_t from, size_t to);
* @param trans if not NULL then it will point to the list of states
* @return 0 on success
*/
size_t nfa_get_lambda_trans(struct nfa *nfa, size_t from, size_t **trans);
size_t nfa_get_lambda_trans(const struct nfa *nfa, size_t from, size_t **trans);

/**
* Add transition to NFA.
Expand Down Expand Up @@ -265,7 +265,7 @@ int nfa_add_trans(struct nfa *nfa, size_t from, unsigned char mark, size_t to);
* @param trans if not NULL then it will point to the list of states
* @return 0 on success
*/
size_t nfa_get_trans(struct nfa *nfa, size_t from, unsigned char mark,
size_t nfa_get_trans(const struct nfa *nfa, size_t from, unsigned char mark,
size_t **trans);

/**
Expand Down
Loading

0 comments on commit abcdac2

Please sign in to comment.