Erlang:在 ets 表中查找交集

发布于 2024-08-31 10:35:47 字数 455 浏览 3 评论 0原文

我有一个 ets 和下一个项目:

[at, {other_place}, me],
[other_place, {place}, {other_place}]],
[at, {place}, me], 
[on, {surface}, {object}],
[small, {object}]

我有列表 [[at,door,me],[on,floor,chair],[small,bannanas]]

我需要比较每个项目将 ets 表中的项目替换为列表中的项目,如果第一个是相同的原子,则替换圆括号中的项目。因此,如果我有 [at,door,me],它与 [at, {other_place}, me] 匹配,我必须更改 {other_place}< /code> 为所有 ets 表中的原子门。

I have an ets with the next items:

[at, {other_place}, me],
[other_place, {place}, {other_place}]],
[at, {place}, me], 
[on, {surface}, {object}],
[small, {object}]

And I have the list [[at, door, me],[on, floor, chair],[small, bannanas]]

I need to compare every item in the ets table to an item in the list and if the first one is the same atom, replace the items in round brackets. So if I have [at, door, me], it matches with [at, {other_place}, me], I have to change {other_place} for the atom door in all the ets table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情痴 2024-09-07 10:35:47

我认为这可以通过 ets:foldl 通过传递列表来完成与 Acc 参数进行比较。

如果需要,列表也可以用 lists:foldl 折叠,如果你需要遍历它的子列表。

I think this can be accomplished with ets:foldl by passing list to be compared to as an Acc argument.

If necessary list can also be folded with lists:foldl if you need to go through it's sublists.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文