Erlang:在 ets 表中查找交集
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这可以通过 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.