瀏覽代碼

备份提交

master
AICells 4 年之前
父節點
當前提交
6832d8e746
共有 28 個檔案被更改,包括 554 行新增725 行删除
  1. +1
    -1
      c_src/binaryAddr/rebar.config
  2. +1
    -1
      c_src/cbase64-erlang-nif/rebar.config
  3. +6
    -6
      c_src/couchdb-khash/rebar.config
  4. +4
    -4
      c_src/couchdb_hqueue/rebar.config
  5. +1
    -1
      c_src/epqueue/rebar.config
  6. +1
    -1
      c_src/nifArray/rebar.config
  7. +1
    -1
      c_src/nifHashb/rebar.config
  8. +1
    -1
      c_src/nif_skiplist1/rebar.config
  9. +9
    -0
      src/comMisc/utMisc.erl
  10. +10
    -9
      src/comMisc/utRate.erl
  11. +65
    -65
      src/dataType/utGenTerm.erl
  12. +60
    -60
      src/dataType/utTermSize.erl
  13. +0
    -0
      src/docs/time相关的日志.md
  14. +1
    -1
      src/dynamicCompile/utDecompile.erl
  15. +13
    -13
      src/nifSrc/cbase64_erlang_nif/cbase64.erl
  16. +57
    -57
      src/nifSrc/couchdb-khash/khash.erl
  17. +53
    -53
      src/nifSrc/couchdb_hqeue/hqueue.erl
  18. +42
    -42
      src/nifSrc/epqueue/benchmarks/benchmark.erl
  19. +12
    -12
      src/nifSrc/epqueue/benchmarks/multi_spawn.erl
  20. +26
    -26
      src/nifSrc/epqueue/src/epqueue.app.src
  21. +21
    -21
      src/nifSrc/epqueue/src/epqueue.erl
  22. +23
    -23
      src/nifSrc/epqueue/src/epqueue_nif.erl
  23. +46
    -46
      src/nifSrc/epqueue/test/integrity_test_SUITE.erl
  24. +39
    -39
      src/nifSrc/nif_skiplist1/nif.erl
  25. +25
    -25
      src/nifSrc/nif_skiplist1/skiplist.erl
  26. +1
    -1
      src/testCase/DsTest/utTestDs.erl
  27. +35
    -35
      src/testCase/utTestPerformance.erl
  28. +0
    -181
      src/timeDate/time相关的日志.txt

+ 1
- 1
c_src/binaryAddr/rebar.config 查看文件

@ -1,5 +1,5 @@
{port_specs, [
{"../../priv/binaryAddr.so", ["*.c"]}
{"../../priv/binaryAddr.so", ["*.c"]}
]}.

+ 1
- 1
c_src/cbase64-erlang-nif/rebar.config 查看文件

@ -1,5 +1,5 @@
{port_specs, [
{"../../priv/cbase64.so", ["*.c"]}
{"../../priv/cbase64.so", ["*.c"]}
]}.

+ 6
- 6
c_src/couchdb-khash/rebar.config 查看文件

@ -1,12 +1,12 @@
{port_specs, [
{"../../priv/khash.so", ["*.c"]}
{"../../priv/khash.so", ["*.c"]}
]}.
{port_env, [
% Development compilation
% {".*", "CFLAGS", "$CFLAGS -g -Wall -Werror -fPIC"}
% Development compilation
% {".*", "CFLAGS", "$CFLAGS -g -Wall -Werror -fPIC"}
% Production compilation
{"(linux|solaris|darwin|freebsd)", "CFLAGS", "$CFLAGS -Wall -Werror -DNDEBUG -O3"},
{"win32", "CFLAGS", "$CFLAGS /O2 /DNDEBUG /Wall"}
% Production compilation
{"(linux|solaris|darwin|freebsd)", "CFLAGS", "$CFLAGS -Wall -Werror -DNDEBUG -O3"},
{"win32", "CFLAGS", "$CFLAGS /O2 /DNDEBUG /Wall"}
]}.

+ 4
- 4
c_src/couchdb_hqueue/rebar.config 查看文件

@ -1,12 +1,12 @@
{port_specs, [
{"../../priv/hqueue.so", ["hqueue*.c"]}
{"../../priv/hqueue.so", ["hqueue*.c"]}
]}.
{port_env, [
{"(linux|solaris|darwin|freebsd)", "CFLAGS", "$CFLAGS -g -Wall -Werror -DHQ_ENIF_ALLOC -O3"},
{"win32", "CFLAGS", "$CFLAGS /O2 /DNDEBUG /DHQ_ENIF_ALLOC /Dinline=__inline /Wall"}
%% {".*", "CFLAGS", "$CFLAGS -g -Wall -Werror -Wextra"}
{"(linux|solaris|darwin|freebsd)", "CFLAGS", "$CFLAGS -g -Wall -Werror -DHQ_ENIF_ALLOC -O3"},
{"win32", "CFLAGS", "$CFLAGS /O2 /DNDEBUG /DHQ_ENIF_ALLOC /Dinline=__inline /Wall"}
%% {".*", "CFLAGS", "$CFLAGS -g -Wall -Werror -Wextra"}
]}.

+ 1
- 1
c_src/epqueue/rebar.config 查看文件

@ -1,5 +1,5 @@
{port_specs, [
{"../../priv/epqueue_nif.so", ["*.cc"]}
{"../../priv/epqueue_nif.so", ["*.cc"]}
]}.

+ 1
- 1
c_src/nifArray/rebar.config 查看文件

@ -1,5 +1,5 @@
{port_specs, [
{"../../priv/nifArray.so", ["*.c"]}
{"../../priv/nifArray.so", ["*.c"]}
]}.

+ 1
- 1
c_src/nifHashb/rebar.config 查看文件

@ -1,5 +1,5 @@
{port_specs, [
{"../../priv/nifHashb.so", ["*.c"]}
{"../../priv/nifHashb.so", ["*.c"]}
]}.

+ 1
- 1
c_src/nif_skiplist1/rebar.config 查看文件

@ -1,5 +1,5 @@
{port_specs, [
{"../../priv/nif_skiplist.so", ["*.c"]}
{"../../priv/nif_skiplist.so", ["*.c"]}
]}.

+ 9
- 0
src/comMisc/utMisc.erl 查看文件

@ -70,5 +70,14 @@ compile_base_data(Table, ModName, IDPoses) ->
end,
ok.
%% CPU核数
coreCnt() ->
erlang:system_info(schedulers).
%% id
coreIndex() ->
erlang:system_info(scheduler_id).

+ 10
- 9
src/comMisc/utRate.erl 查看文件

@ -118,12 +118,13 @@ rand_list(List) ->
rand_list_n(List, Limit) ->
SortedList = lists:sort([{rand:uniform(), N} || N <- List]),
{Result, _} = misc_utils:each(fun({_Fator, Elem}, {Acc, Idx}) ->
if
Idx =:= Limit ->
{break, {Acc, Idx}};
Idx < Limit ->
{[Elem | Acc], Idx + 1}
end
end, {[], 0}, SortedList),
Result.
{Result, _} = misc_utils:each(
fun({_Fator, Elem}, {Acc, Idx}) ->
if
Idx =:= Limit ->
{break, {Acc, Idx}};
Idx < Limit ->
{[Elem | Acc], Idx + 1}
end
end, {[], 0}, SortedList),
Result.

+ 65
- 65
src/dataType/utGenTerm.erl 查看文件

@ -1,110 +1,110 @@
-module(utGenTerm).
-export([
any/0,
any/1,
genAtom/1,
genInteger/1,
genFloat/1,
genReference/1,
genPort/1,
genPid/1,
genTuple/1,
genList/1,
genShortString/1,
genString/1,
genBinary/1,
genBitstring/1,
genBigNum/1,
genFunction/1
any/0,
any/1,
genAtom/1,
genInteger/1,
genFloat/1,
genReference/1,
genPort/1,
genPid/1,
genTuple/1,
genList/1,
genShortString/1,
genString/1,
genBinary/1,
genBitstring/1,
genBigNum/1,
genFunction/1
]).
any() ->
any(16).
any(16).
any(MaxSize) when MaxSize =< 0 ->
Fun = choice(valueTypes()),
?MODULE:Fun(MaxSize);
Fun = choice(valueTypes()),
?MODULE:Fun(MaxSize);
any(MaxSize) ->
Fun = choice(allTypes()),
?MODULE:Fun(MaxSize).
Fun = choice(allTypes()),
?MODULE:Fun(MaxSize).
genAtom(MaxSize) ->
list_to_atom(genShortString(MaxSize)).
list_to_atom(genShortString(MaxSize)).
genInteger(_) ->
Value = case rand:uniform() < 0.5 of
true -> rand:uniform(127);
false -> rand:uniform(16#FFFFFFFF)
end,
case rand:uniform() < 0.5 of
true -> -1 * Value;
false -> Value
end.
Value = case rand:uniform() < 0.5 of
true -> rand:uniform(127);
false -> rand:uniform(16#FFFFFFFF)
end,
case rand:uniform() < 0.5 of
true -> -1 * Value;
false -> Value
end.
genFloat(_) ->
rand:uniform() * float(16#FFFFFFFF).
rand:uniform() * float(16#FFFFFFFF).
genReference(_) ->
erlang:make_ref().
erlang:make_ref().
genPort(_) ->
Ports = erlang:ports(),
lists:nth(rand:uniform(length(Ports)), Ports).
Ports = erlang:ports(),
lists:nth(rand:uniform(length(Ports)), Ports).
genPid(_) ->
Pids = erlang:processes(),
lists:nth(rand:uniform(length(Pids)), Pids).
Pids = erlang:processes(),
lists:nth(rand:uniform(length(Pids)), Pids).
genTuple(MaxSize) ->
list_to_tuple(genList(MaxSize)).
list_to_tuple(genList(MaxSize)).
genList(MaxSize) ->
Width = rand:uniform(MaxSize),
[any(MaxSize-Width) || _ <- lists:seq(1, Width)].
Width = rand:uniform(MaxSize),
[any(MaxSize - Width) || _ <- lists:seq(1, Width)].
genShortString(_) ->
Size = rand:uniform(255),
[rand:uniform(127) || _ <- lists:seq(1, Size)].
Size = rand:uniform(255),
[rand:uniform(127) || _ <- lists:seq(1, Size)].
genString() ->
Size = rand:uniform(4096),
[rand:uniform(127) || _ <- lists:seq(1, Size)].
Size = rand:uniform(4096),
[rand:uniform(127) || _ <- lists:seq(1, Size)].
genString(MaxSize) ->
[rand:uniform(255) || _ <- lists:seq(1, MaxSize)].
[rand:uniform(255) || _ <- lists:seq(1, MaxSize)].
genBinary(MaxSize) ->
list_to_binary(genString(MaxSize)).
list_to_binary(genString(MaxSize)).
genBitstring(MaxSize) ->
B = genBinary(MaxSize),
<<2:4/integer, B/binary>>.
B = genBinary(MaxSize),
<<2:4/integer, B/binary>>.
genBigNum(_) ->
16#FFFFFFFFFFFFFFFF + rand:uniform(16#FFFFFFFF).
16#FFFFFFFFFFFFFFFF + rand:uniform(16#FFFFFFFF).
genFunction(_) ->
choice(allTypes()).
choice(allTypes()).
choice(Options) ->
lists:nth(rand:uniform(length(Options)), Options).
lists:nth(rand:uniform(length(Options)), Options).
valueTypes() ->
[
genAtom,
genInteger,
genFloat,
genReference,
genPort,
genPid,
genShortString,
genString,
genBinary,
genBitstring,
genBigNum,
genFunction
].
[
genAtom,
genInteger,
genFloat,
genReference,
genPort,
genPid,
genShortString,
genString,
genBinary,
genBitstring,
genBigNum,
genFunction
].
allTypes() ->
valueTypes() ++ [genTuple, genList].
valueTypes() ++ [genTuple, genList].

+ 60
- 60
src/dataType/utTermSize.erl 查看文件

@ -1,99 +1,99 @@
-module(utTermSize).
-export([
byteSize/1
, byteSize/2
byteSize/1
, byteSize/2
]).
-define(HEAP_BINARY_LIMIT, 64).
byteSize(Term) ->
byteSize(Term, erlang:system_info(wordsize)).
byteSize(Term, erlang:system_info(wordsize)).
byteSize(Term, WordSize) ->
byteSizeTermLocal(Term, WordSize) + byteSizeTerms(Term).
byteSizeTermLocal(Term, WordSize) + byteSizeTerms(Term).
byteSizeTerms(Term) when is_list(Term) ->
byteSizeTermsInList(Term, 0);
byteSizeTermsInList(Term, 0);
byteSizeTerms(Term) when is_tuple(Term) ->
if
Term == {} ->
0;
true ->
byteSizeTermsInTuple(1, erlang:tuple_size(Term), Term, 0)
end;
if
Term == {} ->
0;
true ->
byteSizeTermsInTuple(1, erlang:tuple_size(Term), Term, 0)
end;
byteSizeTerms(Term) when is_map(Term) ->
maps:fold(
fun(K, V, Bytes) ->
byteSizeTerms(K) + byteSizeTerms(V) + Bytes
end, 0, Term);
maps:fold(
fun(K, V, Bytes) ->
byteSizeTerms(K) + byteSizeTerms(V) + Bytes
end, 0, Term);
byteSizeTerms(Term) ->
byteSizeTerm(Term).
byteSizeTerm(Term).
byteSizeTermsInList([], SumSize) ->
SumSize;
SumSize;
byteSizeTermsInList([Term | L], SumSize) ->
TermSize = byteSizeTerms(Term),
byteSizeTermsInList(L, TermSize + SumSize);
TermSize = byteSizeTerms(Term),
byteSizeTermsInList(L, TermSize + SumSize);
byteSizeTermsInList(Term, SumSize) ->
% element of improper list
byteSizeTerms(Term) + SumSize.
% element of improper list
byteSizeTerms(Term) + SumSize.
byteSizeTermsInTuple(Size, Size, Term, SumSize) ->
byteSizeTerms(erlang:element(Size, Term)) + SumSize;
byteSizeTerms(erlang:element(Size, Term)) + SumSize;
byteSizeTermsInTuple(I, Size, Term, SumSize) ->
TermSize = byteSizeTerms(erlang:element(I, Term)),
byteSizeTermsInTuple(I + 1, Size, Term, TermSize + SumSize).
TermSize = byteSizeTerms(erlang:element(I, Term)),
byteSizeTermsInTuple(I + 1, Size, Term, TermSize + SumSize).
byteSizeTerm(Term) ->
byteSizeTermGlobal(Term).
byteSizeTermGlobal(Term).
byteSizeTermLocal(Term, WordSize) ->
% stack/register size + heap size
(1 + erts_debug:flat_size(Term)) * WordSize.
% stack/register size + heap size
(1 + erts_debug:flat_size(Term)) * WordSize.
byteSizeTermGlobal(Term) when is_binary(Term) ->
% global data storage within allocators
BinarySize = erlang:byte_size(Term),
if
BinarySize > ?HEAP_BINARY_LIMIT ->
% refc binary
BinarySize;
true ->
% heap binary
0
end;
% global data storage within allocators
BinarySize = erlang:byte_size(Term),
if
BinarySize > ?HEAP_BINARY_LIMIT ->
% refc binary
BinarySize;
true ->
% heap binary
0
end;
byteSizeTermGlobal(_) ->
0.
0.
-define(TEST, 64).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
internal_test() ->
RefcBinary = <<1:((?HEAP_BINARY_LIMIT + 1) * 8)>>,
HeapBinary = <<1:(?HEAP_BINARY_LIMIT * 8)>>,
true = (7 == (1 + erts_debug:flat_size(RefcBinary))),
% doesn't work in console shell
% (process heap size of binary is excluded
% when executed in the console shell)
true = (11 == (1 + erts_debug:flat_size(HeapBinary))),
true = (4 == (1 + erts_debug:flat_size(<<1:8>>))),
RefcBinary = <<1:((?HEAP_BINARY_LIMIT + 1) * 8)>>,
HeapBinary = <<1:(?HEAP_BINARY_LIMIT * 8)>>,
true = (7 == (1 + erts_debug:flat_size(RefcBinary))),
% doesn't work in console shell
% (process heap size of binary is excluded
% when executed in the console shell)
true = (11 == (1 + erts_debug:flat_size(HeapBinary))),
true = (4 == (1 + erts_debug:flat_size(<<1:8>>))),
24 = byteSize(<<>>, 8),
32 = byteSize(<<"abc">>, 8),
32 = byteSize(<<$a, $b, $c>>, 8),
8 = byteSize([], 8),
24 = byteSize([0|[]], 8),
24 = byteSize([1|2], 8), % itime_tmproper list
16 = byteSize({}, 8),
24 = byteSize({0}, 8),
8 = byteSize(0, 8),
8 = byteSize(erlang:self(), 8),
8 = byteSize(atom, 8),
88 = byteSize(#{1=>1, 2=>2, 3=>3}, 8),
136 = byteSize(#{1=>RefcBinary, 2=>2, 3=>3}, 8) - erlang:byte_size(RefcBinary),
ok.
24 = byteSize(<<>>, 8),
32 = byteSize(<<"abc">>, 8),
32 = byteSize(<<$a, $b, $c>>, 8),
8 = byteSize([], 8),
24 = byteSize([0 | []], 8),
24 = byteSize([1 | 2], 8), % itime_tmproper list
16 = byteSize({}, 8),
24 = byteSize({0}, 8),
8 = byteSize(0, 8),
8 = byteSize(erlang:self(), 8),
8 = byteSize(atom, 8),
88 = byteSize(#{1=>1, 2=>2, 3=>3}, 8),
136 = byteSize(#{1=>RefcBinary, 2=>2, 3=>3}, 8) - erlang:byte_size(RefcBinary),
ok.
-endif.

src/docs/time相关的日志.txt → src/docs/time相关的日志.md 查看文件


+ 1
- 1
src/dynamicCompile/utDecompile.erl 查看文件

@ -26,4 +26,4 @@ decCom(BeamDir, SrcDir) ->
ProAcc
end
end,
filelib:fold_files(BeamDir, "\\.beam$", true, FunRead, []).
filelib:fold_files(BeamDir, "\\.beam$", true, FunRead, []).

+ 13
- 13
src/nifSrc/cbase64_erlang_nif/cbase64.erl 查看文件

@ -27,22 +27,22 @@
-on_load(on_load/0).
on_load() ->
BaseDir =
case code:priv_dir(?MODULE) of
{error, bad_name} ->
EbinDir = filename:dirname(code:which(?MODULE)),
AppPath = filename:dirname(EbinDir),
filename:join(AppPath, "priv");
Dir ->
Dir
end,
SoName = filename:join(BaseDir, atom_to_list(?MODULE)),
erlang:load_nif(SoName, 0).
BaseDir =
case code:priv_dir(?MODULE) of
{error, bad_name} ->
EbinDir = filename:dirname(code:which(?MODULE)),
AppPath = filename:dirname(EbinDir),
filename:join(AppPath, "priv");
Dir ->
Dir
end,
SoName = filename:join(BaseDir, atom_to_list(?MODULE)),
erlang:load_nif(SoName, 0).
-spec encode(binary() | iolist()) -> binary().
encode(_Data) ->
erlang:nif_error(not_loaded, [{module, ?MODULE}, {line, ?LINE}]).
erlang:nif_error(not_loaded, [{module, ?MODULE}, {line, ?LINE}]).
-spec decode(binary() | iolist()) -> binary().
decode(_Data) ->
erlang:nif_error(not_loaded, [{module, ?MODULE}, {line, ?LINE}]).
erlang:nif_error(not_loaded, [{module, ?MODULE}, {line, ?LINE}]).

+ 57
- 57
src/nifSrc/couchdb-khash/khash.erl 查看文件

@ -7,21 +7,21 @@
-export([
new/0,
new/1,
from_list/1,
from_list/2,
to_list/1,
clear/1,
lookup/2,
get/2,
get/3,
put/3,
del/2,
size/1,
iter/1,
iter_next/1,
fold/3
new/0,
new/1,
from_list/1,
from_list/2,
to_list/1,
clear/1,
lookup/2,
get/2,
get/3,
put/3,
del/2,
size/1,
iter/1,
iter_next/1,
fold/3
]).
@ -36,122 +36,122 @@
-spec new() -> {ok, khash()}.
new() ->
new([]).
new([]).
-spec new([option()]) -> {ok, khash()}.
new(_Options) ->
?NOT_LOADED.
?NOT_LOADED.
-spec from_list([kv()]) -> {ok, khash()}.
from_list(KVList) ->
from_list(KVList, []).
from_list(KVList, []).
-spec from_list([kv()], [option()]) -> {ok, khash()}.
from_list(KVList, Options) ->
{ok, Hash} = ?MODULE:new(Options),
lists:foreach(fun({Key, Val}) ->
?MODULE:put(Hash, Key, Val)
end, KVList),
{ok, Hash}.
{ok, Hash} = ?MODULE:new(Options),
lists:foreach(fun({Key, Val}) ->
?MODULE:put(Hash, Key, Val)
end, KVList),
{ok, Hash}.
-spec to_list(khash()) -> [kv()].
to_list(_Hash) ->
?NOT_LOADED.
?NOT_LOADED.
-spec clear(khash()) -> ok.
clear(_Hash) ->
?NOT_LOADED.
?NOT_LOADED.
-spec lookup(khash(), any()) -> {value, any()} | not_found.
lookup(Hash, Key) ->
lookup_int(Hash, erlang:phash2(Key), Key).
lookup_int(Hash, erlang:phash2(Key), Key).
-spec get(khash(), any()) -> any().
get(Hash, Key) ->
get(Hash, Key, undefined).
get(Hash, Key, undefined).
-spec get(khash(), any(), any()) -> any().
get(Hash, Key, Default) ->
get_int(Hash, erlang:phash2(Key), Key, Default).
get_int(Hash, erlang:phash2(Key), Key, Default).
-spec put(khash(), any(), any()) -> ok.
put(Hash, Key, Value) ->
put_int(Hash, erlang:phash2(Key), Key, Value).
put_int(Hash, erlang:phash2(Key), Key, Value).
-spec del(khash(), any()) -> ok.
del(Hash, Key) ->
del_int(Hash, erlang:phash2(Key), Key).
del_int(Hash, erlang:phash2(Key), Key).
-spec size(khash()) -> non_neg_integer().
size(_Hash) ->
?NOT_LOADED.
?NOT_LOADED.
-spec iter(khash()) -> {ok, khash_iter()}.
iter(_Hash) ->
?NOT_LOADED.
?NOT_LOADED.
-spec iter_next(khash_iter()) ->
kv() | end_of_table | {error, expired_iterator}.
kv() | end_of_table | {error, expired_iterator}.
iter_next(_Iter) ->
?NOT_LOADED.
?NOT_LOADED.
-spec fold(khash(), fun(), any()) -> any().
fold(Hash, FoldFun, Acc) ->
{ok, Iter} = ?MODULE:iter(Hash),
fold_int(Iter, FoldFun, Acc).
{ok, Iter} = ?MODULE:iter(Hash),
fold_int(Iter, FoldFun, Acc).
fold_int(Iter, FoldFun, Acc) ->
case ?MODULE:iter_next(Iter) of
{Key, Value} ->
NewAcc = FoldFun(Key, Value, Acc),
fold_int(Iter, FoldFun, NewAcc);
end_of_table ->
Acc
end.
case ?MODULE:iter_next(Iter) of
{Key, Value} ->
NewAcc = FoldFun(Key, Value, Acc),
fold_int(Iter, FoldFun, NewAcc);
end_of_table ->
Acc
end.
init() ->
PrivDir = case code:priv_dir(?MODULE) of
{error, _} ->
EbinDir = filename:dirname(code:which(?MODULE)),
AppPath = filename:dirname(EbinDir),
filename:join(AppPath, "priv");
Path ->
Path
end,
erlang:load_nif(filename:join(PrivDir, "khash"), 0).
PrivDir = case code:priv_dir(?MODULE) of
{error, _} ->
EbinDir = filename:dirname(code:which(?MODULE)),
AppPath = filename:dirname(EbinDir),
filename:join(AppPath, "priv");
Path ->
Path
end,
erlang:load_nif(filename:join(PrivDir, "khash"), 0).
lookup_int(_Hash, _HashValue, _Key) ->
?NOT_LOADED.
?NOT_LOADED.
get_int(_Hash, _HashValue, _Key, _Default) ->
?NOT_LOADED.
?NOT_LOADED.
put_int(_Hash, _HashValue, _Key, _Value) ->
?NOT_LOADED.
?NOT_LOADED.
del_int(_Hash, _HashValue, _Key) ->
?NOT_LOADED.
?NOT_LOADED.
not_loaded(Line) ->
erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, Line}]}).
erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, Line}]}).

+ 53
- 53
src/nifSrc/couchdb_hqeue/hqueue.erl 查看文件

@ -17,25 +17,25 @@
-export([
new/0,
new/1,
new/0,
new/1,
extract_max/1,
insert/3,
extract_max/1,
insert/3,
from_list/1,
from_list/2,
to_list/1,
from_list/1,
from_list/2,
to_list/1,
heap_size/1,
info/1,
is_empty/1,
max_elems/1,
size/1,
heap_size/1,
info/1,
is_empty/1,
max_elems/1,
size/1,
resize_heap/2,
scale_by/2,
set_max_elems/2
resize_heap/2,
scale_by/2,
set_max_elems/2
]).
@ -47,114 +47,114 @@
-type hqueue_val() :: term().
-type hqueue_elem() :: {hqueue_priority(), hqueue_val()}.
-type hqueue_option() :: {max_elems, pos_integer()}
| {heap_size, pos_integer()}.
| {heap_size, pos_integer()}.
-type hqueue_stat() :: {max_elems, pos_integer()}
| {heap_size, pos_integer()}
| {size, non_neg_integer()}.
| {heap_size, pos_integer()}
| {size, non_neg_integer()}.
-export_type([hqueue/0]).
-spec new() -> {ok, hqueue()}.
new() ->
new([]).
new([]).
-spec new([hqueue_option()]) -> {ok, hqueue()}.
new(_Options) ->
?NOT_LOADED.
?NOT_LOADED.
%% Extraction order is undefined for entries with duplicate priorities
-spec extract_max(hqueue()) -> hqueue_elem() | {error, empty}.
extract_max(_HQ) ->
?NOT_LOADED.
?NOT_LOADED.
-spec insert(hqueue(), hqueue_priority(), hqueue_val()) -> ok | {error, full}.
insert(_HQ, _Priority, _Val) ->
?NOT_LOADED.
?NOT_LOADED.
-spec size(hqueue()) -> integer().
size(_HQ) ->
?NOT_LOADED.
?NOT_LOADED.
-spec max_elems(hqueue()) -> integer().
max_elems(_HQ) ->
?NOT_LOADED.
?NOT_LOADED.
%% Returns old max elems or error if NewMaxElems < size(HQ)
-spec set_max_elems(hqueue(), pos_integer()) -> pos_integer()
| {error, too_small}.
| {error, too_small}.
set_max_elems(_HQ, _NewMaxElems) ->
?NOT_LOADED.
?NOT_LOADED.
-spec is_empty(hqueue()) -> boolean().
is_empty(HQ) ->
hqueue:size(HQ) =:= 0.
hqueue:size(HQ) =:= 0.
-spec to_list(hqueue()) -> [hqueue_elem()].
to_list(_HQ) ->
?NOT_LOADED.
?NOT_LOADED.
-spec from_list([hqueue_elem()]) -> {ok, hqueue()}.
from_list(Elems) ->
from_list(Elems, []).
from_list(Elems, []).
-spec from_list([hqueue_elem()], [hqueue_option()]) -> {ok, hqueue()}.
from_list(Elems, Options) ->
{ok, HQ} = ?MODULE:new(Options),
lists:foreach(fun({Priority, Val}) ->
?MODULE:insert(HQ, Priority, Val)
end, Elems),
{ok, HQ}.
{ok, HQ} = ?MODULE:new(Options),
lists:foreach(fun({Priority, Val}) ->
?MODULE:insert(HQ, Priority, Val)
end, Elems),
{ok, HQ}.
-spec scale_by(hqueue(), float()) -> ok.
scale_by(_HQ, _Factor) ->
?NOT_LOADED.
?NOT_LOADED.
%% Returns old heap size or error if NewHeapSize < size(HQ)
-spec resize_heap(hqueue(), pos_integer()) -> pos_integer()
| {error, too_small}.
| {error, too_small}.
resize_heap(_HQ, _NewHeapSize) ->
?NOT_LOADED.
?NOT_LOADED.
-spec heap_size(hqueue()) -> pos_integer().
heap_size(_HQ) ->
?NOT_LOADED.
?NOT_LOADED.
-spec info(hqueue()) -> [hqueue_stat()].
info(HQ) ->
[
{heap_size, hqueue:heap_size(HQ)},
{max_elems, hqueue:max_elems(HQ)},
{size, hqueue:size(HQ)}
].
[
{heap_size, hqueue:heap_size(HQ)},
{max_elems, hqueue:max_elems(HQ)},
{size, hqueue:size(HQ)}
].
init() ->
PrivDir = case code:priv_dir(?MODULE) of
{error, _} ->
EbinDir = filename:dirname(code:which(?MODULE)),
AppPath = filename:dirname(EbinDir),
filename:join(AppPath, "priv");
Path ->
Path
end,
erlang:load_nif(filename:join(PrivDir, "hqueue"), 0).
PrivDir = case code:priv_dir(?MODULE) of
{error, _} ->
EbinDir = filename:dirname(code:which(?MODULE)),
AppPath = filename:dirname(EbinDir),
filename:join(AppPath, "priv");
Path ->
Path
end,
erlang:load_nif(filename:join(PrivDir, "hqueue"), 0).
not_loaded(Line) ->
erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, Line}]}).
erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, Line}]}).

+ 42
- 42
src/nifSrc/epqueue/benchmarks/benchmark.erl 查看文件

@ -1,68 +1,68 @@
-module(benchmark).
-export([
benchmark_serial/3,
benchmark_concurrent/3
benchmark_serial/3,
benchmark_concurrent/3
]).
benchmark_serial(Elements, MaxPriority, Lock) ->
rand:uniform(), %just to init the seed
{ok, Q} = epqueue:new([{global_lock, Lock}]),
rand:uniform(), %just to init the seed
{ok, Q} = epqueue:new([{global_lock, Lock}]),
{T0, ok} = timer:tc(fun() -> insert_none(Elements, MaxPriority) end),
{T1, ok} = timer:tc(fun() -> insert_item(Elements, Q, MaxPriority) end),
{T2, ok} = timer:tc(fun() -> remove_item(Q) end),
{T0, ok} = timer:tc(fun() -> insert_none(Elements, MaxPriority) end),
{T1, ok} = timer:tc(fun() -> insert_item(Elements, Q, MaxPriority) end),
{T2, ok} = timer:tc(fun() -> remove_item(Q) end),
T0Ms = T0/1000,
T1Ms = T1/1000,
T2Ms = T2/1000,
T0Ms = T0 / 1000,
T1Ms = T1 / 1000,
T2Ms = T2 / 1000,
io:format(<<"insert overhead: ~p ms insert time: ~p ms pop time: ~p ms ~n">>, [T0Ms, T1Ms, T2Ms]).
io:format(<<"insert overhead: ~p ms insert time: ~p ms pop time: ~p ms ~n">>, [T0Ms, T1Ms, T2Ms]).
benchmark_concurrent(Procs, Elements, MaxPriority) ->
{ok, Q} = epqueue:new([{global_lock, true}]),
{ok, Q} = epqueue:new([{global_lock, true}]),
ElsPerProcess = round(Elements/Procs),
ElsPerProcess = round(Elements / Procs),
InsertNoneWorkFun = fun() ->
insert_none(ElsPerProcess, MaxPriority)
end,
InsertNoneWorkFun = fun() ->
insert_none(ElsPerProcess, MaxPriority)
end,
InsertWorkFun = fun() ->
insert_item(ElsPerProcess, Q, MaxPriority)
end,
InsertWorkFun = fun() ->
insert_item(ElsPerProcess, Q, MaxPriority)
end,
RemoveWorkFun = fun() ->
remove_item(Q)
end,
RemoveWorkFun = fun() ->
remove_item(Q)
end,
{T0, _} = timer:tc(fun()-> multi_spawn:do_work(InsertNoneWorkFun, Procs) end),
{T1, _} = timer:tc(fun()-> multi_spawn:do_work(InsertWorkFun, Procs) end),
{T2, _} = timer:tc(fun()-> multi_spawn:do_work(RemoveWorkFun, Procs) end),
{T0, _} = timer:tc(fun() -> multi_spawn:do_work(InsertNoneWorkFun, Procs) end),
{T1, _} = timer:tc(fun() -> multi_spawn:do_work(InsertWorkFun, Procs) end),
{T2, _} = timer:tc(fun() -> multi_spawn:do_work(RemoveWorkFun, Procs) end),
T0Ms = T0/1000,
T1Ms = T1/1000,
T2Ms = T2/1000,
T0Ms = T0 / 1000,
T1Ms = T1 / 1000,
T2Ms = T2 / 1000,
io:format(<<"insert overhead: ~p ms insert time: ~p ms pop time: ~p ms ~n">>, [T0Ms, T1Ms, T2Ms]).
io:format(<<"insert overhead: ~p ms insert time: ~p ms pop time: ~p ms ~n">>, [T0Ms, T1Ms, T2Ms]).
insert_item(0, _Q, _Max) ->
ok;
ok;
insert_item(N, Q, Max) ->
El = rand:uniform(Max),
{ok, _} = epqueue:insert(Q, El, El),
insert_item(N-1, Q, Max).
El = rand:uniform(Max),
{ok, _} = epqueue:insert(Q, El, El),
insert_item(N - 1, Q, Max).
remove_item(Q) ->
case epqueue:pop(Q) of
undefined->
ok;
{ok, _, _} ->
remove_item(Q)
end.
case epqueue:pop(Q) of
undefined ->
ok;
{ok, _, _} ->
remove_item(Q)
end.
insert_none(0, _Max) ->
ok;
ok;
insert_none(N, Max) ->
rand:uniform(Max),
insert_none(N-1, Max).
rand:uniform(Max),
insert_none(N - 1, Max).

+ 12
- 12
src/nifSrc/epqueue/benchmarks/multi_spawn.erl 查看文件

@ -1,24 +1,24 @@
-module(multi_spawn).
-export([
do_work/2
do_work/2
]).
do_work(Fun, Count) ->
process_flag(trap_exit, true),
spawn_childrens(Fun, Count),
wait_responses(Count).
process_flag(trap_exit, true),
spawn_childrens(Fun, Count),
wait_responses(Count).
spawn_childrens(_Fun, 0) ->
ok;
ok;
spawn_childrens(Fun, Count) ->
spawn_link(Fun),
spawn_childrens(Fun, Count -1).
spawn_link(Fun),
spawn_childrens(Fun, Count - 1).
wait_responses(0) ->
ok;
ok;
wait_responses(Count) ->
receive
{'EXIT',_FromPid, _Reason} ->
wait_responses(Count -1)
end.
receive
{'EXIT', _FromPid, _Reason} ->
wait_responses(Count - 1)
end.

+ 26
- 26
src/nifSrc/epqueue/src/epqueue.app.src 查看文件

@ -1,29 +1,29 @@
{application, epqueue, [
{description, "Erlang Priority Queue"},
{licenses, ["MIT"]},
{links,[{"Github","https://github.com/silviucpp/epqueue"}]},
{vsn, "1.2.1"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{env, []},
{files, [
"LICENSE*",
"*.MD",
"Makefile",
"rebar.config",
"rebar.lock",
"src/*.erl",
"src/*.src",
"c_src/*.h",
"c_src/*.cc",
"c_src/Makefile",
"c_src/nif.mk",
"test/*.erl",
"test/cover.spec",
"benchmarks/*.erl"
]}
{description, "Erlang Priority Queue"},
{licenses, ["MIT"]},
{links, [{"Github", "https://github.com/silviucpp/epqueue"}]},
{vsn, "1.2.1"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{env, []},
{files, [
"LICENSE*",
"*.MD",
"Makefile",
"rebar.config",
"rebar.lock",
"src/*.erl",
"src/*.src",
"c_src/*.h",
"c_src/*.cc",
"c_src/Makefile",
"c_src/nif.mk",
"test/*.erl",
"test/cover.spec",
"benchmarks/*.erl"
]}
]}.

+ 21
- 21
src/nifSrc/epqueue/src/epqueue.erl 查看文件

@ -1,13 +1,13 @@
-module(epqueue).
-export([
new/0,
new/1,
size/1,
insert/3,
remove/2,
pop/1,
peek/1
new/0,
new/1,
size/1,
insert/3,
remove/2,
pop/1,
peek/1
]).
-type error() :: badarg | {error, binary()}.
@ -18,43 +18,43 @@
-type data_ref() :: reference().
-spec new() ->
{ok, queue_ref()} | error().
{ok, queue_ref()} | error().
new() ->
epqueue_nif:new([]).
epqueue_nif:new([]).
-spec new([queue_option()]) ->
{ok, queue_ref()} | error().
{ok, queue_ref()} | error().
new(Options) ->
epqueue_nif:new(Options).
epqueue_nif:new(Options).
-spec size(queue_ref()) ->
non_neg_integer() | badarg.
non_neg_integer() | badarg.
size(QueueRef) ->
epqueue_nif:size(QueueRef).
epqueue_nif:size(QueueRef).
-spec insert(queue_ref(), data(), priority()) ->
{ok, data_ref()} | error().
{ok, data_ref()} | error().
insert(QueueRef, Data, Priority) ->
epqueue_nif:insert(QueueRef, Data, Priority).
epqueue_nif:insert(QueueRef, Data, Priority).
-spec remove(queue_ref(), data_ref()) ->
boolean() | error().
boolean() | error().
remove(QueueRef, Ref) ->
epqueue_nif:remove(QueueRef, Ref).
epqueue_nif:remove(QueueRef, Ref).
-spec pop(queue_ref()) ->
{ok, data(), priority()} | error().
{ok, data(), priority()} | error().
pop(QueueRef) ->
epqueue_nif:pop(QueueRef).
epqueue_nif:pop(QueueRef).
-spec peek(queue_ref()) ->
{ok, data(), priority()} | error().
{ok, data(), priority()} | error().
peek(QueueRef) ->
epqueue_nif:peek(QueueRef).
epqueue_nif:peek(QueueRef).

+ 23
- 23
src/nifSrc/epqueue/src/epqueue_nif.erl 查看文件

@ -5,47 +5,47 @@
-on_load(load_nif/0).
-export([
new/1,
size/1,
insert/3,
remove/2,
pop/1,
peek/1
new/1,
size/1,
insert/3,
remove/2,
pop/1,
peek/1
]).
load_nif() ->
SoName = get_priv_path(?MODULE),
io:format(<<"Loading library: ~p ~n">>, [SoName]),
ok = erlang:load_nif(SoName, 0).
SoName = get_priv_path(?MODULE),
io:format(<<"Loading library: ~p ~n">>, [SoName]),
ok = erlang:load_nif(SoName, 0).
new(_Options) ->
?NOT_LOADED.
?NOT_LOADED.
size(_QueueRef) ->
?NOT_LOADED.
?NOT_LOADED.
insert(_QueueRef, _Data, _Priority) ->
?NOT_LOADED.
?NOT_LOADED.
remove(_QueueRef, _Ref) ->
?NOT_LOADED.
?NOT_LOADED.
pop(_QueueRef) ->
?NOT_LOADED.
?NOT_LOADED.
peek(_QueueRef) ->
?NOT_LOADED.
?NOT_LOADED.
% internals
get_priv_path(File) ->
case code:priv_dir(epqueue) of
{error, bad_name} ->
Ebin = filename:dirname(code:which(?MODULE)),
filename:join([filename:dirname(Ebin), "priv", File]);
Dir ->
filename:join(Dir, File)
end.
case code:priv_dir(epqueue) of
{error, bad_name} ->
Ebin = filename:dirname(code:which(?MODULE)),
filename:join([filename:dirname(Ebin), "priv", File]);
Dir ->
filename:join(Dir, File)
end.
not_loaded(Line) ->
erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, Line}]}).
erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, Line}]}).

+ 46
- 46
src/nifSrc/epqueue/test/integrity_test_SUITE.erl 查看文件

@ -3,67 +3,67 @@
-compile(export_all).
all() -> [
{group, epqueue_group}
{group, epqueue_group}
].
groups() -> [
{epqueue_group, [sequence], [
basic_ops,
empty_queue,
non_empty_queue,
test_remove,
test_pop
]}
{epqueue_group, [sequence], [
basic_ops,
empty_queue,
non_empty_queue,
test_remove,
test_pop
]}
].
init_per_suite(Config) ->
Config.
Config.
end_per_suite(_Config) ->
ok.
ok.
basic_ops(_Config) ->
{ok, Q} = epqueue:new([]),
{ok, _Ref} = epqueue:insert(Q, 1, 1),
{ok, 1, 1} = epqueue:peek(Q),
1 = epqueue:size(Q),
{ok, 1, 1} = epqueue:pop(Q),
0 = epqueue:size(Q),
ok.
{ok, Q} = epqueue:new([]),
{ok, _Ref} = epqueue:insert(Q, 1, 1),
{ok, 1, 1} = epqueue:peek(Q),
1 = epqueue:size(Q),
{ok, 1, 1} = epqueue:pop(Q),
0 = epqueue:size(Q),
ok.
empty_queue(_Config) ->
{ok, _} = epqueue:new([]),
ok.
{ok, _} = epqueue:new([]),
ok.
non_empty_queue(_Config) ->
{ok, Q1} = epqueue:new([]),
{ok, _} = epqueue:insert(Q1, 1, 1),
{ok, _} = epqueue:insert(Q1, 2, 2),
{ok, _} = epqueue:insert(Q1, 3, 3),
{ok, _} = epqueue:insert(Q1, 4, 4),
{ok, _} = epqueue:insert(Q1, 5, 5),
ok.
{ok, Q1} = epqueue:new([]),
{ok, _} = epqueue:insert(Q1, 1, 1),
{ok, _} = epqueue:insert(Q1, 2, 2),
{ok, _} = epqueue:insert(Q1, 3, 3),
{ok, _} = epqueue:insert(Q1, 4, 4),
{ok, _} = epqueue:insert(Q1, 5, 5),
ok.
test_remove(_Config) ->
{ok, Q1} = epqueue:new([]),
{ok, Q2} = epqueue:new([]),
{ok, Ref7} = epqueue:insert(Q2, 7, 7),
{ok, Ref3} = epqueue:insert(Q1, 3, 3),
{ok, Ref5} = epqueue:insert(Q1, 5, 5),
{ok, Ref1} = epqueue:insert(Q1, 1, 1),
false = epqueue:remove(Q1, Ref7),
true = epqueue:remove(Q1, Ref5),
true = epqueue:remove(Q1, Ref3),
true = epqueue:remove(Q1, Ref1),
true = epqueue:remove(Q2, Ref7),
ok.
{ok, Q1} = epqueue:new([]),
{ok, Q2} = epqueue:new([]),
{ok, Ref7} = epqueue:insert(Q2, 7, 7),
{ok, Ref3} = epqueue:insert(Q1, 3, 3),
{ok, Ref5} = epqueue:insert(Q1, 5, 5),
{ok, Ref1} = epqueue:insert(Q1, 1, 1),
false = epqueue:remove(Q1, Ref7),
true = epqueue:remove(Q1, Ref5),
true = epqueue:remove(Q1, Ref3),
true = epqueue:remove(Q1, Ref1),
true = epqueue:remove(Q2, Ref7),
ok.
test_pop(_Config) ->
{ok, Q1} = epqueue:new([]),
epqueue:insert(Q1, 3, 3),
epqueue:insert(Q1, 5, 5),
epqueue:insert(Q1, 1, 1),
{ok, 1, 1} = epqueue:pop(Q1),
{ok, 3, 3} = epqueue:pop(Q1),
{ok, 5, 5} = epqueue:pop(Q1),
ok.
{ok, Q1} = epqueue:new([]),
epqueue:insert(Q1, 3, 3),
epqueue:insert(Q1, 5, 5),
epqueue:insert(Q1, 1, 1),
{ok, 1, 1} = epqueue:pop(Q1),
{ok, 3, 3} = epqueue:pop(Q1),
{ok, 5, 5} = epqueue:pop(Q1),
ok.

+ 39
- 39
src/nifSrc/nif_skiplist1/nif.erl 查看文件

@ -13,58 +13,58 @@
-export([init/0, test/0]).
init() ->
skiplist:init("./nif_skiplist"),
ok.
skiplist:init("./nif_skiplist"),
ok.
test() ->
init(),
A = skiplist:new(),
skiplist:insert(A, 10, 10),
skiplist:insert(A, 5, 5),
skiplist:insert(A, 8, 8),
skiplist:insert(A, 1, 1),
skiplist:insert(A, 4, 4),
skiplist:insert(A, 7, 7),
io:format("~p~n", [skiplist:to_list(A)]),
init(),
A = skiplist:new(),
skiplist:insert(A, 10, 10),
skiplist:insert(A, 5, 5),
skiplist:insert(A, 8, 8),
skiplist:insert(A, 1, 1),
skiplist:insert(A, 4, 4),
skiplist:insert(A, 7, 7),
io:format("~p~n", [skiplist:to_list(A)]),
skiplist:delete(A, 7, 7),
io:format("~p~n", [skiplist:to_list(A)]),
skiplist:delete(A, 7, 7),
io:format("~p~n", [skiplist:to_list(A)]),
io:format("get=~p~n", [skiplist:index_of_score(A, 5)]),
io:format("get=~p~n", [skiplist:index_of_score(A, 6)]),
io:format("get=~p~n", [skiplist:index_of_score(A, 15)]),
io:format("get=~p~n", [skiplist:index_of_score(A, 5)]),
io:format("get=~p~n", [skiplist:index_of_score(A, 6)]),
io:format("get=~p~n", [skiplist:index_of_score(A, 15)]),
io:format("at=~p~n", [skiplist:at(A, 1)]),
io:format("at=~p~n", [skiplist:at(A, 5)]),
io:format("at=~p~n", [skiplist:at(A, 6)]),
io:format("at=~p~n", [skiplist:at(A, 1)]),
io:format("at=~p~n", [skiplist:at(A, 5)]),
io:format("at=~p~n", [skiplist:at(A, 6)]),
io:format("range=~p~n", [skiplist:range(A, 1, 10)]),
io:format("range=~p~n", [skiplist:range(A, 2, 3)]),
io:format("range=~p~n", [skiplist:range(A, 8, 10)]),
io:format("range=~p~n", [skiplist:range(A, 1, 10)]),
io:format("range=~p~n", [skiplist:range(A, 2, 3)]),
io:format("range=~p~n", [skiplist:range(A, 8, 10)]),
io:format("range_with_score=~p~n", [skiplist:range_with_score(A, 1, 10)]),
io:format("range_with_score=~p~n", [skiplist:range_with_score(A, 2, 3)]),
io:format("range_with_score=~p~n", [skiplist:range_with_score(A, 8, 10)]),
io:format("range_with_score=~p~n", [skiplist:range_with_score(A, 1, 10)]),
io:format("range_with_score=~p~n", [skiplist:range_with_score(A, 2, 3)]),
io:format("range_with_score=~p~n", [skiplist:range_with_score(A, 8, 10)]),
erlang:statistics(wall_clock),
loop_test(30*1000, A),
{_, Time} = erlang:statistics(wall_clock),
io:format("time=~p~n", [Time]),
erlang:statistics(wall_clock),
loop_test(30 * 1000, A),
{_, Time} = erlang:statistics(wall_clock),
io:format("time=~p~n", [Time]),
%% io:format("range_by_score=~p~n", [skiplist:range_by_score(A, -10, 10)]),
%% io:format("range_by_score=~p~n", [skiplist:range_by_score(A, 2, 3)]),
io:format("range_by_score=~p~n", [skiplist:range_by_score(A, 101, 10)]),
io:format("range_by_score=~p~n", [skiplist:range_by_score(A, 101, 10)]),
skiplist:free(A).
skiplist:free(A).
loop_test(0, _) ->
ok;
ok;
loop_test(N, L) ->
case rand:uniform(500) < 300 of
true ->
skiplist:insert(L, rand:uniform(100), rand:uniform(20));
_ ->
skiplist:delete(L, rand:uniform(100), rand:uniform(20))
end,
loop_test(N - 1, L).
case rand:uniform(500) < 300 of
true ->
skiplist:insert(L, rand:uniform(100), rand:uniform(20));
_ ->
skiplist:delete(L, rand:uniform(100), rand:uniform(20))
end,
loop_test(N - 1, L).

+ 25
- 25
src/nifSrc/nif_skiplist1/skiplist.erl 查看文件

@ -11,71 +11,71 @@
%% API
-export([
init/1,
new/0, free/1,
insert/3, delete/3, update/4,
to_list/1,
range/3, range_with_score/3, range_by_score/3,
index_of_score/2, at/2,
size/1]).
init/1,
new/0, free/1,
insert/3, delete/3, update/4,
to_list/1,
range/3, range_with_score/3, range_by_score/3,
index_of_score/2, at/2,
size/1]).
-type skiplist() :: non_neg_integer().
-type score() :: integer().
-type value() :: integer().
-spec init(Path) -> ok | Error when
Path :: string(),
Error :: any().
Path :: string(),
Error :: any().
init(Path) ->
erlang:load_nif(Path, 0).
erlang:load_nif(Path, 0).
-spec new() -> skiplist().
new() ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec free(skiplist()) -> ok.
free(_List) ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec insert(skiplist(), score(), value()) -> 0.
insert(_List, _Score, _Value) ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec delete(skiplist(), score(), value()) ->
0 | 1. %% 0 success, 1 fail
0 | 1. %% 0 success, 1 fail
delete(_List, _Score, _Value) ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec update(skiplist(), score(), value(), score()) -> 0.
update(_List, _Score, _Value, _OldScore) ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec to_list(skiplist()) -> [{score(), value()}].
to_list(_List) ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec size(skiplist()) -> non_neg_integer().
size(_List) ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec index_of_score(skiplist(), score()) -> non_neg_integer().
index_of_score(_List, _Score) ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec at(skiplist(), non_neg_integer()) -> error | {score(), value()}.
at(_List, _Index) ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec range(skiplist(), non_neg_integer(), non_neg_integer()) -> [value()].
range(_List, _Start, _Len) ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec range_with_score(skiplist(), non_neg_integer(), non_neg_integer()) ->
[{score(), value()}].
[{score(), value()}].
range_with_score(_List, _Start, _Len) ->
erlang:nif_error(undef).
erlang:nif_error(undef).
-spec range_by_score(skiplist(), score(), score()) ->
{StartIndex :: non_neg_integer(), [{score(), value()}]}.
{StartIndex :: non_neg_integer(), [{score(), value()}]}.
range_by_score(_List, _Score1, _Score2) ->
erlang:nif_error(undef).
erlang:nif_error(undef).

+ 1
- 1
src/testCase/DsTest/utTestDs.erl 查看文件

@ -108,7 +108,7 @@ calcAvg(CntList, Num) ->
%%
AvgCnt = ?Cnt - 2,
SortList = lists:sort(CntList),
AvgList = lists:sublist(SortList, 2,AvgCnt),
AvgList = lists:sublist(SortList, 2, AvgCnt),
float_to_list(lists:sum(AvgList) / AvgCnt / Num, [{decimals, 2}]) ++ "ns".
storeStatistics(Ds, Num, Insert, Read, Update, For, Delete) ->

+ 35
- 35
src/testCase/utTestPerformance.erl 查看文件

@ -222,7 +222,7 @@ getMonth3(Month) ->
<<"">>
end.
-define(List, [1, 2, 3234235, <<"fdsfasf">>, <<"fdsfasf111111111111111111111111">>, [3434,43,434], tryrer, {rqwrer, 342144}, #{23424 => "fdsfsdafsaf"}, {432143, "fdsaf", 76767}]).
-define(List, [1, 2, 3234235, <<"fdsfasf">>, <<"fdsfasf111111111111111111111111">>, [3434, 43, 434], tryrer, {rqwrer, 342144}, #{23424 => "fdsfsdafsaf"}, {432143, "fdsaf", 76767}]).
ht(0, _Fun) ->
ok;
@ -388,41 +388,41 @@ doPAL([OneAction | LeftActions], CallbackForm, CycleData, Debug, IsPostpone, IsH
{{u_gTimeout, _Name}, _TimeoutMsg} ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
%case OneAction of
c_eTimeout ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
c_sTimeout ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
{c_gTimeout, _Name} ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
{isHibernate, NewIsHibernate} ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, NewIsHibernate, DoAfter, Timeouts, NextEvents);
{isPostpone, NewIsPostpone} ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, NewIsPostpone, IsHibernate, DoAfter, Timeouts, NextEvents);
{doAfter, Args} ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, {true, Args}, Timeouts, NextEvents);
{nextEvent, Type, Content} ->
%% next_event动作
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, Timeouts, [{Type, Content} | NextEvents])
c_eTimeout ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
c_sTimeout ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
{c_gTimeout, _Name} ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
{isHibernate, NewIsHibernate} ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, NewIsHibernate, DoAfter, Timeouts, NextEvents);
{isPostpone, NewIsPostpone} ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, NewIsPostpone, IsHibernate, DoAfter, Timeouts, NextEvents);
{doAfter, Args} ->
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, {true, Args}, Timeouts, NextEvents);
{nextEvent, Type, Content} ->
%% next_event动作
doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, Timeouts, [{Type, Content} | NextEvents])
%_ ->
%case OneAction of
% c_eTimeout when CallbackForm == 1 ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
% c_sTimeout when CallbackForm == 1 ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
% {c_gTimeout, _Name} when CallbackForm == 1 ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
% {isHibernate, NewIsHibernate} ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, NewIsHibernate, DoAfter, Timeouts, NextEvents);
% {isPostpone, NewIsPostpone} when (not NewIsPostpone orelse CallbackForm == 1) ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, NewIsPostpone, IsHibernate, DoAfter, Timeouts, NextEvents);
% {doAfter, Args} when CallbackForm == 1 ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, {true, Args}, Timeouts, NextEvents);
% {nextEvent, Type, Content} when CallbackForm == 1 orelse CallbackForm == 2 ->
% %% next_event动作
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, Timeouts, [{Type, Content} | NextEvents]);
% _ActRet ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, Timeouts, NextEvents)
%end
%case OneAction of
% c_eTimeout when CallbackForm == 1 ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
% c_sTimeout when CallbackForm == 1 ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
% {c_gTimeout, _Name} when CallbackForm == 1 ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, [OneAction | Timeouts], NextEvents);
% {isHibernate, NewIsHibernate} ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, NewIsHibernate, DoAfter, Timeouts, NextEvents);
% {isPostpone, NewIsPostpone} when (not NewIsPostpone orelse CallbackForm == 1) ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, NewIsPostpone, IsHibernate, DoAfter, Timeouts, NextEvents);
% {doAfter, Args} when CallbackForm == 1 ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, {true, Args}, Timeouts, NextEvents);
% {nextEvent, Type, Content} when CallbackForm == 1 orelse CallbackForm == 2 ->
% %% next_event动作
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, Timeouts, [{Type, Content} | NextEvents]);
% _ActRet ->
% doPAL(LeftActions, CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, Timeouts, NextEvents)
%end
end.
doPAL2([], _CallbackForm, CycleData, Debug, IsPostpone, IsHibernate, DoAfter, Timeouts, NextEvents) ->

+ 0
- 181
src/timeDate/time相关的日志.txt 查看文件

@ -1,181 +0,0 @@
erlang 模块的时间函数---------》》》》
localtime_to_universaltime/1
如果基础操作系统支持,则将本地日期和时间转换为世界标准时间(UTC). 否则,不进行任何转换,并 返回Localtime
localtime_to_universaltime/2
将本地日期和时间转换为erlang:localtime_to_universaltime / 1,以协调世界时(UTC),但调用者确定夏令时是否处于活动状态。
如果IsDst == true,则本地 时间位于夏令时,如果IsDst == false ,则不是。如果IsDst == undefined,则底层操作系统可以猜测,
这与调用 erlang:localtime_to_universaltime(Localtime)相同。
universaltime_to_localtime/1
如果基础操作系统支持,则以{{Year,Month,Day},{Hour,Minute,Second}}的形式将世界标准时间(UTC)日期和时间转换为本地日期和时间 。
否则,不进行任何转换,并 返回Universaltime。例:
time/0
以{Hour,Minute,Second}的形式返回当前时间。时区和夏令时校正取决于基础操作系统。
date/0
返回当前日期为{Year,Month,Day}。时区和夏令时校正取决于基础操作系统。
localtime/0
返回当前的本地日期和时间 {{Year,Month,Day},{Hour,Minute,Second}} 时区和夏令时校正取决于基础操作系统。
universaltime/0
如果基础操作系统支持,则根据世界标准时间(UTC)以{{Year,Month,Day},{Hour,Minute,Second}}的形式返回当前日期和时间 。
否则,erlang:universaltime()等效于 erlang:localtime()。例:
posixtime_to_universaltime/1
posixtime 转为 universaltime
universaltime_to_posixtime/1
universaltime换为posixtime时间戳
system_time/0,
以本地时间单位返回当前的 Erlang系统时间。
system_time/1
返回当前的 Erlang系统时间, 该时间已转换为作为参数传递的Unit。
convert_time_unit/3
转换时间的时间单位的值 FromUnit到相应 ConvertedTime时间单元的值 ToUnit。使用下限功能对结果进行四舍五入。
警告:在时间单位之间进行转换时,可能会失去准确性和精度。为了最大程度地减少此类损失,请以本地时间单位收集所有数据,然后对最终结果进行转换。
time_offset/0
以 本地时间单位返回Erlang单调时间和 Erlang系统时间之间的当前时间偏移 。添加到Erlang单调时间的当前时间偏移会给出相应的Erlang系统时间。
时间偏移可能会或可能不会在操作期间更改,具体取决于所使用的时间扭曲模式。
注意:
通过不同的过程,可以在稍有不同的时间点观察到时间偏移量的变化。
如果运行时系统处于 多时间扭曲模式,则当运行时系统检测到OS系统时间已更改时,时间偏移也会 更改。但是,运行时系统不会立即检测到它。
检查时间偏移的任务计划至少每分钟执行一次;因此,在正常操作下,一分钟内即可检测到,但是在重负载下可能需要更长的时间。
time_offset/1
返回Erlang单调时间和 Erlang系统时间之间的当前时间偏移, 该时间已转换为作为参数传递的Unit。
timestamp/0
以{MegaSecs,Secs,MicroSecs}格式返回当前的 Erlang系统时间。此格式与os:timestamp / 0 和不赞成使用的erlang:now / 0相同 。
存在erlang:timestamp()的原因纯粹是为了简化对采用这种时间戳格式的现有代码的使用。可以使用erlang:system_time / 1以您选择的时间单位
更有效地检索当前Erlang系统时间 。
The erlang:timestamp() BIF is equivalent to:
timestamp() ->
ErlangSystemTime = erlang:system_time(microsecond),
MegaSecs = ErlangSystemTime div 1000000000000,
Secs = ErlangSystemTime div 1000000 - MegaSecs*1000000,
MicroSecs = ErlangSystemTime rem 1000000,
{MegaSecs, Secs, MicroSecs}.
calendar 时间模块 -------》》》》》
模块总结
本地和世界时间,星期几,日期和时间转换。
描述
此模块提供本地和通用时间,星期几以及许多时间转换功能的计算。
根据当前时区和夏令时进行调整时,时间是本地时间。当它反映的是经度为零的时间时,它是通用的,无需为夏时制进行任何调整。
世界标准时间(UTC)时间也称为格林威治标准时间(GMT)。
此模块中的时间函数local_time / 0和 Universal_time / 0都返回日期和时间。这是因为日期和时间的单独功能可能导致日期/时间组合错开24小时。
如果其中一个功能在午夜之前调用,而另一个功能在午夜之后调用,则会发生这种情况。此问题也适用于Erlang BIF date / 0和time / 0,
如果需要可靠的日期/时间戳,强烈建议不要使用它们。
所有日期均符合公历。此历法由教皇格雷戈里十三世在1582年引入,从今年开始在所有天主教国家中使用。德国和荷兰的新教部分在1698年采用了它,
英格兰随后在1752年采用了,俄国在1918年(根据格里高利历法,1917年10月的革命发生在11月)。
此模块中的公历将回溯到0年。对于给定的日期,公历天数是指指定日期之前(包括该日期)的天数。同样,指定日期和时间的公历秒数是直至并包括指定日期和时间的秒数。
要计算时间间隔之间的差异,请使用计算公历天或秒的功能。如果将纪元指定为本地时间,则必须将其转换为通用时间,以获取各纪元之间经过时间的正确值
。不建议使用功能time_difference / 2。
一年中的一周存在不同的定义。该模块包含符合ISO 8601标准的一年中的一周实施。由于指定日期的星期数可以落在上一个,当前或下一年,
因此指定年号和星期数很重要。函数iso_week_number / 0和iso_week_number / 1 返回年份和星期数的元组。
calendar:
date_to_gregorian_days/1
date_to_gregorian_days/3
计算从0年开始到指定日期结束的公历天数。
datetime_to_gregorian_seconds/1
计算从年份0开始到指定的日期和时间的公历秒数。
gregorian_days_to_date/1
根据指定的公历天数计算日期。
gregorian_seconds_to_datetime/1
根据指定的公历秒数计算日期和时间。
day_of_the_week/1
day_of_the_week/3
从指定的Year,Month和 Day计算星期几 。将星期几返回为 1:星期一,2:星期二,依此类推。
is_leap_year/1
检查指定的年份是否为闰年。
iso_week_number/0
返回表示实际日期的ISO周编号的元组{Year,WeekNum}。要确定实际日期,请使用函数 local_time / 0。
iso_week_number/1
返回表示指定日期的ISO周编号的元组{Year,WeekNum}。
last_day_of_the_month/2
计算一个月中的天数。
local_time/0
等效于 erlang:localtime()
local_time_to_universal_time/1 %% 不推荐使用了 额豁
从本地时间转换为世界标准时间(UTC)。 DateTime1必须引用1970年1月1日之后的本地日期。
警告:不推荐使用此功能。请改用 local_time_to_universal_time_dst / 1 ,因为它可以提供更正确和完整的结果。
尤其是对于不存在的时间段,由于在切换到夏时制时会被跳过,因此此功能仍会返回结果。
local_time_to_universal_time/2
local_time_to_universal_time_dst/1
从本地时间转换为世界标准时间(UTC)。 参数DateTime1必须引用1970年1月1日之后的本地日期。
返回值是0、1或2个可能的UTC时间的列表:
[]
对于当地时间{Date1,Time1},在切换到夏令时时会跳过该时间段,因此没有相应的UTC,因为当地时间是非法的(从未发生过)。
[DstDateTimeUTC,DateTimeUTC]
对于从夏令时开始重复的时段中的本地{Date1,Time1},存在两个对应的UTC;一个用于夏令时仍处于活动状态的时段的第一个实例,另一个用于第二个实例。
[DateTimeUTC]
对于所有其他本地时间,仅存在一个对应的UTC。
now_to_datetime/1 % = now_to_universal_time/1
返回从erlang:timestamp / 0的返回值转换的通用协调时间(UTC) 。
now_to_local_time/1
返回从erlang:timestamp / 0的返回值转换的本地日期和时间 。
now_to_universal_time/1
返回从erlang:timestamp / 0的返回值转换的通用协调时间(UTC) 。
rfc3339_to_system_time/1
rfc3339_to_system_time/2
将RFC 3339时间戳转换为系统时间。RFC 3339描述了RFC 3339时间戳的数据格式 。
seconds_to_daystime/1
将指定的秒数转换为天,小时,分钟和秒。时间始终是非负的,但是如果参数Seconds是,则 Days是负的 。
seconds_to_time/1
根据指定的秒数计算时间。 秒数必须小于每天的秒数(86400)。
system_time_to_local_time/2
将指定的系统时间转换为本地日期和时间。 TODO 优化此函数
system_time_to_universal_time/2 TODO 优化此函数
将指定的系统时间转换为通用日期和时间。
system_time_to_rfc3339/1
system_time_to_rfc3339/2
将系统时间转换为RFC 3339时间戳。RFC 3339描述了RFC 3339时间戳的数据格式 。偏移量的数据格式也由RFC 3339描述。
time_difference/2 %% 改函数过时 不用
time_to_seconds/1
返回自午夜到指定时间的秒数。
universal_time/0
等效于erlang:universaltime().
universal_time_to_local_time/1
erlang:universaltime_to_localtime(DateTime).
valid_date/1
valid_date/3
此功能检查日期是否有效。

Loading…
取消
儲存