Added function for loop checking in dictionary

pull/23/head
parent 93817dee16
commit f954a62efa

@ -332,6 +332,71 @@ dictionary *yon_dictionary_get_nth(dictionary *dict, int place)
} else return NULL;
}
dictionary *yon_dictionary_sort(dictionary *dict){
dictionary *first = dict->first;
dictionary *prev = first;
dictionary *current = first->next;
while (current){
if (current!=prev&&strcmp(current->key,prev->key)<0){
if (current->next)
current->next->prev=prev;
prev->next=current->next;
current->next=prev;
current->prev=prev->prev;
if (prev->prev)
prev->prev->next=current;
prev->prev=current;
if (prev==prev->first){
yon_dictionary_make_first(current);
}
dictionary *temp = prev;
prev = current;
current=temp;
}
prev=prev->next;
current = current->next;
}
return first;
}
int _yon_dictionary_check_loops(dictionary *_REG_DICT,dictionary *link){
if (_REG_DICT){
dictionary *dict;
for_dictionaries(dict,_REG_DICT){
if (dict->data==link){
return 1;
}
}
}
return 0;
}
dictionary *yon_dictionary_check_loops(dictionary *target){
dictionary *found = NULL;
dictionary *dict;
for_dictionaries(dict,target){
if (_yon_dictionary_check_loops(found,dict)){
return dict;
} else {
yon_dictionary_add_or_create_if_exists_with_data(found,NULL,dict);
}
}
yon_dictionary_free_all(found,NULL);
found = NULL;
dict=yon_dictionary_get_last(target);
for(;dict;dict=dict->prev){
if (_yon_dictionary_check_loops(found,dict)){
return dict;
} else {
yon_dictionary_add_or_create_if_exists_with_data(found,NULL,dict);
}
}
yon_dictionary_free_all(found,NULL);
return NULL;
}
// char functions
int yon_char_find_last(char *source, char find){
@ -858,7 +923,7 @@ config_str yon_dir_get_contents(char *dir_path, int *size){
config_str yon_dir_get_by_mask(char *path, char *mask, int *size){
(*size)=0;
if (yon_char_find_count(mask,"*")<=1){
if (yon_char_count(mask,"*")<=1){
char *lpart;
char *rpart=yon_char_new(mask);
lpart = yon_char_divide_search(rpart,"*",-1);

@ -290,6 +290,11 @@ void *yon_dictionary_free(dictionary *dictionary_to_free);
*/
void *yon_dictionary_free_all(dictionary *dictionary,void (data_manipulation)(void*));
[[ deprecated ]]
dictionary *yon_dictionary_sort(dictionary *dict);
dictionary *yon_dictionary_check_loops(dictionary *target);
// char functions
#define yon_char_divide_search_self(str,find,delete_divider) {char *temp = str; str = yon_char_divide_search(str,find,delete_divider); free(temp);}
@ -441,6 +446,7 @@ int yon_char_parsed_check_repeats(char **parameters, int size, int *first_overla
* [RU]
* Считает количество символов [find] в строке [source]
*/
[[ deprecated("Use yon_char_count instead") ]]
int yon_char_find_count(char *source, char *find);
int yon_char_count(char *source, char *find);

Loading…
Cancel
Save