简体   繁体   中英

Using ETS Select To Form An Intersection

i have the following ets structure:

SomeTable = ets:new(sometable, [bag]).
ets:insert(SomeTable, [
                        {set1,item1},
                        {set1,item2},
                        {set1,item3},
                        {set2,item1},
                        {set2,item2},
                        {set2,item4}]).

i want to get intersection of set1 and set2 using ets:select and fun2ms, result will be [item1, item2].

i spent hours and hours trying to accomplist it with ets:select and fun2ms with no success. can you help me out using ets:select and fun2ms?

thanks for all answers!

ps: i know about sets module, but i have to use ets and this exact data structure.

qlc:e(qlc:q([ I || {set1, I} <- ets:table(sometable), ets:match_object(sometable, {set2, I}) =/= []])).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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