mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 02:49:02 -04:00
Add a new list count operation to TommyDS
This commit is contained in:
parent
c0970c02b3
commit
41a496fe99
2 changed files with 18 additions and 5 deletions
|
|
@ -517,11 +517,7 @@ void state_device(struct snapraid_state* state, int operation)
|
|||
#endif
|
||||
|
||||
if (operation == DEVICE_SMART) {
|
||||
/* count the logical disks forming the array */
|
||||
unsigned count = state->level;
|
||||
for (i = state->disklist; i != 0; i = i->next)
|
||||
++count;
|
||||
state_smart(count, &low);
|
||||
state_smart(state->level + tommy_list_count(&state->disklist), &low);
|
||||
}
|
||||
|
||||
tommy_list_foreach(&high, free);
|
||||
|
|
|
|||
|
|
@ -298,6 +298,23 @@ tommy_inline tommy_bool_t tommy_list_empty(tommy_list* list)
|
|||
return tommy_list_head(list) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of elements.
|
||||
* \note This operation is O(n).
|
||||
*/
|
||||
tommy_inline tommy_count_t tommy_list_count(tommy_list* list)
|
||||
{
|
||||
tommy_count_t count = 0;
|
||||
tommy_node* i = tommy_list_head(list);
|
||||
|
||||
while (i) {
|
||||
++count;
|
||||
i = i->next;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the specified function for each element in the list.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue