简体   繁体   English

Erlang:在ets表中查找交集

[英]Erlang: Find intersections in a ets table

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]] 我有清单[[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. 我需要将ets表中的每个项目与列表中的一个项目进行比较,如果第一个是相同的原子,则将项目放在圆括号中。 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. 因此,如果我有[at, door, me] ,它与[at, {other_place}, me]匹配,我必须为所有ets表中的原子门更改{other_place}

I think this can be accomplished with ets:foldl by passing list to be compared to as an Acc argument. 我认为可以使用ets:foldl来实现,方法是传递要比较的列表作为Acc参数。

If necessary list can also be folded with lists:foldl if you need to go through it's sublists. 如果需要,还可以使用list:foldl折叠list,如果需要浏览它的子列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM