Skip to content

Commit

Permalink
[tests][memory] Update sc-dictionary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaZotov committed Apr 15, 2023
1 parent cf510a1 commit fcdf146
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void * sc_dictionary_get_by_key(
return null_ptr;
}

void sc_dictionary_get_by_key_prefix(
sc_bool sc_dictionary_get_by_key_prefix(
const sc_dictionary * dictionary,
const sc_char * sc_string,
const sc_uint32 sc_string_size,
Expand All @@ -292,8 +292,7 @@ void sc_dictionary_get_by_key_prefix(
sc_dictionary_node * node = dictionary->root;

sc_uint32 i = 0;
sc_uint32 string_size = sc_string_size;
while (i < string_size)
while (i < sc_string_size)
{
sc_dictionary_node * next = _sc_dictionary_get_next_node(dictionary, node, sc_string[i]);
if (SC_DICTIONARY_NODE_IS_VALID(next) &&
Expand All @@ -306,8 +305,23 @@ void sc_dictionary_get_by_key_prefix(
break;
}

callable(node, dest);
sc_dictionary_visit_down_node_from_node(dictionary, node, callable, dest);
if (i == sc_string_size)
callable(node, dest);

sc_uint8 j;
for (j = 0; j < dictionary->size; ++j)
{
sc_dictionary_node * next = node->next[j];
if (SC_DICTIONARY_NODE_IS_VALID(next) && (i == sc_string_size || sc_str_has_prefix(next->offset, sc_string + i)))
{
if (!callable(next, dest))
return SC_FALSE;

if (!sc_dictionary_visit_down_node_from_node(dictionary, next, callable, dest))
return SC_FALSE;
}
}
return SC_TRUE;
}

sc_bool sc_dictionary_visit_down_node_from_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ sc_bool sc_dictionary_has(const sc_dictionary * dictionary, const sc_char * sc_s
*/
void * sc_dictionary_get_by_key(const sc_dictionary * dictionary, const sc_char * sc_string, sc_uint32 sc_string_size);

void sc_dictionary_get_by_key_prefix(
sc_bool sc_dictionary_get_by_key_prefix(
const sc_dictionary * dictionary,
const sc_char * sc_string,
sc_uint32 sc_string_size,
Expand Down
Loading

0 comments on commit fcdf146

Please sign in to comment.