linux lib/list_sort.c排序算法

这篇博客探讨了Linux内核中的list_sort函数,该函数用于排序list_head结构体。文章提到了__attribute__((nonnull))属性在编译时检查指针非空的重要性。此外,还介绍了Fisher-Yates洗牌算法,这是一种在各种数据打乱场景下常用的方法。通过阅读,可以增进对底层系统排序和随机化算法的理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

linux lib/list_sort.c排序算法

没看懂,留念一下。
patch地址是https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1957556.html
 
 
知识点:
__attribute__((nonnull)) 让 compiler 对指定位置的 pointer 是 NULL 时发出警告。
比如:

__attribute__((nonnull(2,3)))
void list_sort(void *priv, struct list_head *head,
		int (*cmp)(void *priv, struct list_head *a,
			struct list_head *b))

 
 
真的是深奥啊。
 
 

随机打乱算法——洗牌算法

有排序就有打乱的需求,详细见 Fisher–Yates shuffle 洗牌算法
 
 

INFO | open_webui.retrieval.models.external:predict:37 - ExternalReranker:predict:query 深圳河水质监测技术改进 - {} 2025-07-24 16:45:44 2025-07-24 16:45:44.142 | ERROR | open_webui.retrieval.models.external:predict:59 - Error in external reranking: 405 Client Error: Method Not Allowed for url: http://host.docker.internal:11434/ - {} 2025-07-24 16:45:44 Traceback (most recent call last): 2025-07-24 16:45:44 2025-07-24 16:45:44 File "/usr/local/lib/python3.11/threading.py", line 1002, in _bootstrap 2025-07-24 16:45:44 self._bootstrap_inner() 2025-07-24 16:45:44 │ └ <function Thread._bootstrap_inner at 0x786151af09a0> 2025-07-24 16:45:44 └ <Thread(ThreadPoolExecutor-10_1, started 132355104691904)> 2025-07-24 16:45:44 File "/usr/local/lib/python3.11/threading.py", line 1045, in _bootstrap_inner 2025-07-24 16:45:44 self.run() 2025-07-24 16:45:44 │ └ <function Thread.run at 0x786151af0680> 2025-07-24 16:45:44 └ <Thread(ThreadPoolExecutor-10_1, started 132355104691904)> 2025-07-24 16:45:44 File "/usr/local/lib/python3.11/threading.py", line 982, in run 2025-07-24 16:45:44 self._target(*self._args, **self._kwargs) 2025-07-24 16:45:44 │ │ │ │ │ └ {} 2025-07-24 16:45:44 │ │ │ │ └ <Thread(ThreadPoolExecutor-10_1, started 132355104691904)> 2025-07-24 16:45:44 │ │ │ └ (<weakref at 0x786082c8acf0; to 'ThreadPoolExecutor' at 0x786083728310>, <_queue.SimpleQueue object at 0x786082e0bf10>, None,... 2025-07-24 16:45:44 │ │ └ <Thread(ThreadPoolExecutor-10_1, started 132355104691904)> 2025-07-24 16:45:44 │ └ <function _worker at 0x786150bb2b60> 2025-07-24 16:45:44 └ <Thread(ThreadPoolExecutor-10_1, started 132355104691904)> 2025-07-24 16:45:44 File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 83, in _worker 2025-07-24 16:45:44 work_item.run() 2025-07-24 16:45:44 │ └ <function _WorkItem.run at 0x786150bb2ca0> 2025-07-24 16:45:44 └ <concurrent.futures.thread._WorkItem object at 0x786087361990> 2025-07-24 16:45:44 File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run 2025-07-24 16:45:44 result = self.fn(*self.args, **self.kwargs) 2025-07-24 16:45:44 │ │ │ │ │ └ {} 2025-07-24 16:45:44 │ │ │ │ └ <concurrent.futures.thread._WorkItem object at 0x786087361990> 2025-07-24 16:45:44 │ │ │ └ ('b5dcbf6d-5774-402d-9fff-5ec4906807ea', '深圳河水质监测技术改进') 2025-07-24 16:45:44 │ │ └ <concurrent.futures.thread._WorkItem object at 0x786087361990> 2025-07-24 16:45:44 │ └ <function query_collection_with_hybrid_search.<locals>.process_query at 0x78608378b100> 2025-07-24 16:45:44 └ <concurrent.futures.thread._WorkItem object at 0x786087361990> 2025-07-24 16:45:44 2025-07-24 16:45:44 File "/app/backend/open_webui/retrieval/utils.py", line 354, in process_query 2025-07-24 16:45:44 result = query_doc_with_hybrid_search( 2025-07-24 16:45:44 └ <function query_doc_with_hybrid_search at 0x78608d3b8220> 2025-07-24 16:45:44 2025-07-24 16:45:44 File "/app/backend/open_webui/retrieval/utils.py", line 161, in query_doc_with_hybrid_search 2025-07-24 16:45:44 result = compression_retriever.invoke(query) 2025-07-24 16:45:44 │ │ └ '深圳河水质监测技术改进' 2025-07-24 16:45:44 │ └ <function BaseRetriever.invoke at 0x78608d4d8a40> 2025-07-24 16:45:44 └ ContextualCompressionRetriever(base_compressor=RerankCompressor(embedding_function=<function chat_completion_files_handler.<l... 2025-07-24 16:45:44 2025-07-24 16:45:44 File "/usr/local/lib/python3.11/site-packages/langchain_core/retrievers.py", line 259, in invoke 2025-07-24 16:45:44 result = self._get_relevant_documents( 2025-07-24 16:45:44 │ └ <function ContextualCompressionRetriever._get_relevant_documents at 0x78608d4d87c0> 2025-07-24 16:45:44 └ ContextualCompressionRetriever(base_compressor=RerankCompressor(embedding_function=<function chat_completion_files_handler.<l... 2025-07-24 16:45:44 File "/usr/local/lib/python3.11/site-packages/langchain/retrievers/contextual_compression.py", line 48, in _get_relevant_documents 2025-07-24 16:45:44 compressed_docs = self.base_compressor.compress_documents( 2025-07-24 16:45:44 │ │ └ <function RerankCompressor.compress_documents at 0x78608d3ba520> 2025-07-24 16:45:44 │ └ RerankCompressor(embedding_function=<function chat_completion_files_handler.<locals>.<lambda>.<locals>.<lambda> at 0x78608378... 2025-07-24 16:45:44 └ ContextualCompressionRetriever(base_compressor=RerankCompressor(embedding_function=<function chat_completion_files_handler.<l... 2025-07-24 16:45:44 2025-07-24 16:45:44 File "/app/backend/open_webui/retrieval/utils.py", line 877, in compress_documents 2025-07-24 16:45:44 scores = self.reranking_function.predict( 2025-07-24 16:45:44 │ │ └ <function ExternalReranker.predict at 0x7860893142c0> 2025-07-24 16:45:44 │ └ <open_webui.retrieval.models.external.ExternalReranker object at 0x786082e78fd0> 2025-07-24 16:45:44 └ RerankCompressor(embedding_function=<function chat_completion_files_handler.<locals>.<lambda>.<locals>.<lambda> at 0x78608378... 2025-07-24 16:45:44 2025-07-24 16:45:44 > File "/app/backend/open_webui/retrieval/models/external.py", line 48, in predict 2025-07-24 16:45:44 r.raise_for_status() 2025-07-24 16:45:44 │ └ <function Response.raise_for_status at 0x78614e2a6ca0> 2025-07-24 16:45:44 └ <Response [405]> 2025-07-24 16:45:44 2025-07-24 16:45:44 File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1026, in raise_for_status 2025-07-24 16:45:44 raise HTTPError(http_error_msg, response=self) 2025-07-24 16:45:44 │ │ └ <Response [405]> 2025-07-24 16:45:44 │ └ '405 Client Error: Method Not Allowed for url: http://host.docker.internal:11434/' 2025-07-24 16:45:44 └ <class 'requests.exceptions.HTTPError'> 2025-07-24 16:45:44 2025-07-24 16:45:44 requests.exceptions.HTTPError: 405 Client Error: Method Not Allowed for url: http://host.docker.internal:11434/ 2025-07-24 16:45:44 2025-07-24 16:45:44.145 | ERROR | open_webui.retrieval.utils:query_doc_with_hybrid_search:187 - Error querying doc b5dcbf6d-5774-402d-9fff-5ec4906807ea with hybrid search: 'NoneType' object has no attribute 'tolist' - {}
最新发布
07-25
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值