gpt4 book ai didi

c - C 语言中的字典/LUT 实现

转载 作者:行者123 更新时间:2023-11-30 16:46:43 27 4
gpt4 key购买 nike

我有 500 个帧,我将每个帧的长度存储在数组中,因为帧按升序排列。

const char header_length = {23,34, 45, 12, 23,56,......,2,4};

这里帧 1 的长度为 23 字节,帧 2 的长度为 34 字节。现在,当我请求带有 header 4 的帧时,我必须用带有 header 7 的帧进行回复,带有 header 8 的帧将需要带有 header 60 的回复帧。相互关系是一个常量, header 4 帧将始终回复 header 7 帧。所以我在这里需要一个查找表的实现。我计划使用多维数组来实现这一点。虽然有更好的方法来实现这个吗?

最佳答案

我是根据上面OP的评论来回答的,否则OP的问题就没有意义。

假设最大帧大小受到相当小的 N 的限制,那么最好保留另一个数组,如下所示,

const char header_length[] = {23,34, 45, 12, 23,56,......,2,4};
const int to_be_replied[N+1] = {...,0,...,2,...,0,...,4,...}; /* fill remaining */
/* here are their positions @12 @23 @34 @45 */

并在回复期间使用以下内容。

int frame_num, reply_frame_num;
frame_num = get_frame_number(); /* some function */
reply_frame_num = to_be_replied[header_length[frame_num]];

关于c - C 语言中的字典/LUT 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43619717/

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