gpt4 book ai didi

linux - 你认为tasklet_head的数据结构是有线的吗?

转载 作者:太空宇宙 更新时间:2023-11-04 05:54:18 25 4
gpt4 key购买 nike

我正在阅读tasklet的源代码并尝试理解它。

我认为tasklet_head的数据结构是有线的,你也这么认为吗?为什么第二个元素的数据类型是struct tasklet_struct **,它只会使源代码变得更加复杂并且让人困惑,扭伤?我的意思是,为什么作者不使用struct tasklet_struct *tail?也许作者太聪明了,我无法理解这种简单。如果是真的,如果你明白的话,请指点一下。

398 /*
399 * Tasklets
400 */
401 struct tasklet_head
402 {
403 struct tasklet_struct *head;
404 struct tasklet_struct **tail;
405 };

完整的源代码可以找到here.

最佳答案

我将回答手头的编程问题。

当然*tail和**tail是完全不同的东西,这就是为什么它是**tail而不是*tail。

您将保留某种尾部引用,以避免迭代整个链表以在末尾添加某些内容(对于 O(1) 追加而不是 O(n))。 Tail 可以设置为特定实例,但这种特定实现策略是有原因的。相反,指向下一个字段,就像这样简单:

new_item->next = NULL;
*tail = new_item;
tail = &(new_item->next);

希望这有帮助。

关于linux - 你认为tasklet_head的数据结构是有线的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13642829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com