Created
January 6, 2013 16:02
-
-
Save dergraf/4468143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(continuation_test). | |
-export([test/0]). | |
-define(SIZE, 100). | |
test() -> | |
ets:new(test, [named_table]), | |
[ets:insert(test, {I, I}) || I<- lists:seq(1,?SIZE)], | |
{Res, Cont} = ets:match_object(test, {'_', '_'}, 10), | |
L = [p(R) || R <- Res], | |
c(Cont, L). | |
c('$end_of_table', L1) -> | |
L2 = lists:flatten(L1), | |
F = fun | |
(Fun, [ok|T], DelSum, OkSum) -> | |
Fun(Fun, T, DelSum, OkSum+1); | |
(Fun, [del|T], DelSum, OkSum) -> | |
Fun(Fun, T, DelSum+1, OkSum); | |
(_Fun, [], DelSum, OkSum) -> | |
io:format("del ~p, ok ~p~n", [DelSum, OkSum]) | |
end, | |
F(F, L2, 0, 0); | |
c(C, L1) -> | |
{Res, Cont} = ets:match_object(C), | |
L2 = [p(R) || R <- Res], | |
c(Cont, L1 ++ L2). | |
p({I, I}) when I rem 4 == 0 -> | |
ets:delete(test, I), | |
io:format("deleted ~p ~n", [I]), | |
del; | |
p({I, I}) when I rem 2 == 0 -> | |
io:format("normal add ~p ~n", [I]), | |
ets:insert(test, {?SIZE + I, ?SIZE + I}), | |
ok; | |
p({I, I}) -> | |
io:format("normal ~p ~n", [I]), | |
ok. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.2 (abort with ^G)
1> continuation_test:test().
normal 85
normal add 74
deleted 100
normal 69
normal 39
normal 23
normal 79
normal add 58
deleted 40
normal 67
normal 41
normal add 14
normal 89
normal 5
normal 83
normal add 70
normal 29
normal add 22
deleted 12
normal 61
normal add 98
normal 35
normal 3
normal add 26
deleted 44
normal 33
normal add 170
normal add 30
normal add 66
normal 91
normal 95
deleted 24
normal 55
normal add 82
deleted 76
normal add 2
deleted 88
normal 81
deleted 64
normal add 90
normal add 50
normal 13
normal add 34
normal 49
normal add 270
deleted 92
normal 75
normal 17
normal add 182
deleted 52
deleted 72
normal 59
normal 77
deleted 28
normal 97
normal add 54
normal add 114
deleted 56
normal 45
normal add 158
deleted 60
normal 47
normal add 94
normal 51
normal add 130
deleted 80
normal add 174
normal add 190
normal add 42
deleted 8
normal add 154
deleted 96
normal 99
deleted 68
normal 9
normal 57
normal add 62
normal 63
normal add 10
deleted 48
normal 15
deleted 4
normal 93
normal add 38
deleted 84
normal 1
normal 11
normal 31
normal add 78
normal 19
normal add 230
normal add 162
deleted 36
normal add 290
normal add 178
normal 53
normal 87
normal add 6
normal 65
normal 37
normal add 330
deleted 16
normal 7
normal add 198
normal add 46
normal 73
normal add 18
normal add 370
normal 71
normal add 274
deleted 20
normal add 470
normal 21
normal add 86
normal 43
normal 27
deleted 32
normal add 122
normal 25
del 25, ok 94
ok