Munging ets continuations

Colm Dougan colm.dougan@REDACTED
Fri Sep 4 16:21:48 CEST 2009


Hi,

I know that I can do :

{_, C} = ets:match_object(T, '_', 5).

And the continuation will looks something like this :

{16397,5,[],5,<<>>,[],0,0}

... where it looks like the first element is the ets table reference
and that the two 5s are the next offset and limit.

I realize that the continuation contains an opaque reference and so I
need to use repair_continuation to "bless" an arbitrary tuple (like
the above) to make it a usable continuation.

My question is: is there a programmatic way to create continuations
for a given offset/length?  Or is there a way I can munge it myself?

I have tried this :

            ets:select(
            ets:repair_continuation(
                {Tab, Offset, [], Limit, <<>>, [], 0, 0},
                [{Query,[],['$_']}]
            ))

Initially results were encouraging but it didn't appear to work in
some cases and I know it may be encapsulation breaching and evil.

My use-case is that I have an ordered_set table with (say) 1000
entries and I want to look at a given offset within them, e.g. entries
700 to 720 without having to pull back the whole list or
walk along it in chunks until I reach 700.  What i want to do is use
something like continuations to give me the appropriate slice in one
shot.   Maybe continuations are not the answer - if not then I'd like
to hear about any alternative solutions to this.

Any help appreciated.

Thanks,
Colm


More information about the erlang-questions mailing list