views:

55

answers:

1

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.

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