c - 如何创建和迭代 graphids 列表(Apache AGE)?

标签 c postgresql apache-age

我正在为 Apache AGE 创建一个函数,我需要迭代 graphidsList,我应该如何正确执行?

我本质上想做的是:

graphid new_graphid = 0;
graphid vertex_to_connect = 0;
List* graphids_array = NIL;

(...)

for (int64 i=(int64)1;i<graph.graph_size;i++)
{  
        new_graphid = create_vertex(&graph);

        graphids_array = lappend_int(graphids_array, new_graphid);
        
        for(int64 j = 0; j<graphids_array->length-1; j++)
        {
            vertex_to_connect = list_nth_int(graphids_array, j);
            connect_vertexes_by_graphid(&graph,
                                        new_graphid,
                                        vertex_to_connect);
        }
}

(...)

发生的问题是 vertex_to_connect 变量没有接收到正确的 graphid (应该是一个像 844424930131970 这样的大数字),相反,它得到的值似乎很小来自 j 变量。

任何有关我可能犯错的地方的帮助都会受到赞赏。

最佳答案

为了迭代 List您可以使用foreach循环 ListCell迭代器。以下是如何执行此操作的示例:

List *graphid_list = NIL;
ListCell *lc;

// Go through all cells in the list.
foreach (lc, graphid_list)
{
    // Code goes here.
}

或者,您可以使用 ListGraphId结构来创建您的列表。因为它只是graphid s,我相信它会成功。然后,您需要创建一个迭代器来查看列表中的每个元素,如GraphIdNode。 。我相信有必要创建一个 forwhile循环执行此操作,但然后在循环结束时更新迭代器为 GraphIdNode 的下一个值。所以,像这样的东西会遍历整个列表:

    ListGraphId *container;
    GraphIdNode *current = get_list_head(container);
    GraphIdNode *previous = NULL;

    while (current != NULL)
    {
        previous = current;
        current = next_GraphIdNode(current);
    }

您可以在src/backend/utils/adt/age_graphid_ds.c找到更多相关信息。和src/include/utils/age_grapid_ds.h .

https://github.com/apache/age/blob/master/src/backend/utils/adt/age_graphid_ds.c

关于c - 如何创建和迭代 graphids 列表(Apache AGE)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76307612/

相关文章:

c - 如何计算输出?

mysql - 必须出现在 GROUP BY 子句中或用于聚合函数 (PostgreSQL)

postgresql - 为什么 PostgreSQL 需要 WAL 缓冲区和 WAL 段文件?

c - 处理输入时意外卡住

c - 使用硬件性能计数器是个好主意

c - C语言有没有必须安装的框架?

sql - 构建正确的逻辑数据库

postgresql - WAL 存档备份和恢复

cypher - Apache AGE-如何实现两个图之间的关系

postgresql - 如何通过 DirectFunctionCall 发送 NULL 参数?