Add clear functions to table and trie.
This commit is contained in:
		
							parent
							
								
									34b97e42ac
								
							
						
					
					
						commit
						19416d0e15
					
				@ -134,6 +134,11 @@ libab_result libab_table_put(libab_table* table, const char* string,
 | 
				
			|||||||
 * @param parent a valid reference to a parent table.
 | 
					 * @param parent a valid reference to a parent table.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void libab_table_set_parent(libab_table* table, libab_ref* parent);
 | 
					void libab_table_set_parent(libab_table* table, libab_ref* parent);
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Clears the table.
 | 
				
			||||||
 | 
					 * @param table the table to clear.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void libab_table_clear(libab_table* table);
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Frees the resources allocated by the
 | 
					 * Frees the resources allocated by the
 | 
				
			||||||
 * given table.
 | 
					 * given table.
 | 
				
			||||||
 | 
				
			|||||||
@ -60,6 +60,7 @@ libab_result libab_trie_put(libab_trie* trie, const char* key, void* value);
 | 
				
			|||||||
const ll* libab_trie_get(const libab_trie* trie, const char* key);
 | 
					const ll* libab_trie_get(const libab_trie* trie, const char* key);
 | 
				
			||||||
int libab_trie_foreach(const libab_trie* trie, void* data, compare_func compare,
 | 
					int libab_trie_foreach(const libab_trie* trie, void* data, compare_func compare,
 | 
				
			||||||
                       foreach_func foreach);
 | 
					                       foreach_func foreach);
 | 
				
			||||||
 | 
					void libab_trie_clear(libab_trie* trie);
 | 
				
			||||||
void libab_trie_free(libab_trie* trie);
 | 
					void libab_trie_free(libab_trie* trie);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
@ -110,6 +110,9 @@ void libab_table_set_parent(libab_table* table, libab_ref* parent) {
 | 
				
			|||||||
    libab_ref_free(&table->parent);
 | 
					    libab_ref_free(&table->parent);
 | 
				
			||||||
    libab_ref_copy(parent, &table->parent);
 | 
					    libab_ref_copy(parent, &table->parent);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					void libab_table_clear(libab_table* table) {
 | 
				
			||||||
 | 
					    libab_trie_clear(&table->trie);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
void libab_table_free(libab_table* table) {
 | 
					void libab_table_free(libab_table* table) {
 | 
				
			||||||
    libab_trie_foreach(&table->trie, NULL, compare_always,
 | 
					    libab_trie_foreach(&table->trie, NULL, compare_always,
 | 
				
			||||||
                       _table_foreach_entry_free);
 | 
					                       _table_foreach_entry_free);
 | 
				
			||||||
 | 
				
			|||||||
@ -110,6 +110,11 @@ int libab_trie_foreach(const libab_trie* trie, void* data, compare_func compare,
 | 
				
			|||||||
    return _libab_trie_foreach(trie->head, data, compare, foreach);
 | 
					    return _libab_trie_foreach(trie->head, data, compare, foreach);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void libab_trie_clear(libab_trie* trie) {
 | 
				
			||||||
 | 
					    libab_trie_free(trie);
 | 
				
			||||||
 | 
					    libab_trie_init(trie);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void libab_trie_free(libab_trie* trie) {
 | 
					void libab_trie_free(libab_trie* trie) {
 | 
				
			||||||
    _libab_trie_free(trie->head);
 | 
					    _libab_trie_free(trie->head);
 | 
				
			||||||
    trie->head = NULL;
 | 
					    trie->head = NULL;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user