<div dir="ltr"><div><div><div><div><div>I have an ETS table called <b><span style="font-family:monospace,monospace">sune</span></b> which is a duplicate_bag containing many elements with the same key. The <b><span style="font-family:monospace,monospace">bert</span></b> elements have the structure <b><span style="font-family:monospace,monospace">{bert,SequenceNo,Data}</span></b> so I can see the ordering. If I do <b><span style="font-family:monospace,monospace">ets:match_object(sune, {bert,'_','_'})</span></b> I will get back a list of all the matching elements in the order they were inserted, which is what I want. However, there can be quite a few elements with the same key so I would prefer to get them in chunks instead of all at once. The solution for this is to start with <b><span style="font-family:monospace,monospace">ets:match_object(sune, {bert,'_','_'}, 5)</span></b> which returns a continuation and then follow with a sequence of <b><span style="font-family:monospace,monospace">ets:match_object(Continuation)</span></b> until I get all the elements in chunks of 5. That is when things start to get strange:<br><br></div>- Now the ordering is completely messed up. Each chunk of 5 contains a sequence but some in ascending order and some in descending order, for example 440,439,438,437,436.<br></div>- The chunks come in what looks like random order, for example chunks starting with 571,425,566,430 but starting with the outermost first working towards the middle.<br></div>- The really weird thing is that the continuation actually contains all the matching elements which haven't been returned yet.<br><br></div>The last is the really strange. According to the documentation for match_object/3:<br><br>"Works like <span class="">ets:match_object/2</span> but only returns a
limited (<span class="">Limit</span>) number of matching objects. The
<span class="">Continuation</span> term can then be used in subsequent calls
to <span class="">ets:match_object/1</span> to get the next chunk of matching
objects. This is a space efficient way to work on objects in a
table which is still faster than traversing the table object
by object using <span class="">ets:first/1</span> and <span class="">ets:next/1</span>."<br><br></div><div>But the continuation contains them all so where is the space efficiency? I mean why bother to use this at all as it gives me no benefits.<br><br></div><div>I tried the same thing using <b><span style="font-family:monospace,monospace">ets:select/3/1</span></b> and got the same result.<br><br></div><div>My original goal was to work how this would interact with inserting or deleting elements while I was scanning. My got my answer.<br><br></div><div>Robert<br><br></div></div>