mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-06-06 05:08:45 +08:00
Update
This commit is contained in:
12
dict.h
12
dict.h
@@ -54,6 +54,18 @@ void dict_iter(struct Dict<K, V>* d, void(*callback)(K key, V value, Args... arg
|
||||
callback(t->d.key, t->d.value, args...);
|
||||
}
|
||||
}
|
||||
template <typename K, typename V, typename ... Args>
|
||||
void dict_iter(struct Dict<K, V>* d, void(*callback)(size_t index, K key, V value, Args... args), Args... args) {
|
||||
if (!d || !callback) return;
|
||||
struct Dict<K, V>* t = d;
|
||||
size_t i = 0;
|
||||
callback(i, t->d.key, t->d.value, args...);
|
||||
while (t->next) {
|
||||
t = t->next;
|
||||
i++;
|
||||
callback(i, t->d.key, t->d.value, args...);
|
||||
}
|
||||
}
|
||||
template <typename K, typename V>
|
||||
bool dict_set(struct Dict<K, V>*& d, K key, V value, void(*free_func)(V) = nullptr) {
|
||||
if (!d) {
|
||||
|
||||
@@ -259,6 +259,31 @@ void linked_list_iter(struct LinkedList<T>* list, void(*callback)(size_t index,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename ... Args>
|
||||
void linked_list_iter(struct LinkedList<T>* list, void(*callback)(T data, Args... args), Args... args) {
|
||||
if (!list || !callback) return;
|
||||
struct LinkedList<T>* t = list;
|
||||
callback(t->d, args...);
|
||||
while (t->next) {
|
||||
t = t->next;
|
||||
callback(t->d, args...);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename D, typename ... Args>
|
||||
D linked_list_iter(struct LinkedList<T>* list, D(*callback)(T data, Args... args), D failed, Args... args) {
|
||||
if (!list || !callback) return failed;
|
||||
struct LinkedList<T>* t = list;
|
||||
D re = callback(t->d, args...);
|
||||
if (re == failed) return re;
|
||||
while (t->next) {
|
||||
t = t->next;
|
||||
re = callback(t->d, args...);
|
||||
if (re == failed) return re;
|
||||
}
|
||||
return re;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void linked_list_remove(struct LinkedList<T>*& node, void(*free_func)(T) = nullptr) {
|
||||
if (!node) return;
|
||||
|
||||
Reference in New Issue
Block a user