erlang各种有用的函数包括一些有用nif封装,还有一些性能测试case。
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

2.1 KiB

-type matchExpression() :: [ matchFunction(), ... ].

-type matchFunction() :: { matchHead(), matchConditions(), matchBody()}.

-type matchHead() :: matchVariable() | '_' | { matchHeadPart(), ...}.

-type matchHeadPart() :: term() | matchVariable() | '_'.

-type matchVariable() :: '$'.

-type matchConditions() :: [ matchCondition(), ...] | [].

-type matchCondition() :: { guardFunction() } | { guardFunction(), conditionExpression(), ... }. -type boolFunction() :: is_atom | is_float | is_integer | is_list | is_number | is_pid | is_port | is_reference | is_tuple | is_map | map_is_key | is_binary | is_function | is_record | 'and' | 'or' | 'not' | 'xor' | 'andalso' | 'orelse'. -type conditionExpression() :: exprMatchVariable() | { guardFunction() } | { guardFunction(), conditionExpression(), ... } | termConstruct(). -type exprMatchVariable() :: matchVariable() (bound in the MatchHead) | '$_' | '$$' -type termConstruct():: {{}} | {{ conditionExpression(), ... }} | [] | [conditionExpression(), ...] | #{} | #{term() => conditionExpression(), ...} | nonCompositeTerm() | constant(). -type nonCompositeTerm() :: term(). %% (not list or tuple or map) -type constant() :: {const, term()}. -type guardFunction() :: boolFunction() | abs | element | hd | length | map_get | map_size | node | round | size | bit_size | tl | trunc | '+' | '-' | '*' | 'div' | 'rem' | 'band' | 'bor' | 'bxor' | 'bnot' | 'bsl' | 'bsr' | '>' | '>=' | '<' | '=<' | '=:=' | '==' | '=/=' | '/=' | self. -type matchBody() :: [ conditionExpression(), ... ].

ets表并发写优化 1.核心思想还是避免数据写操作是并发操作 这种可以将ets 设置为bag 相当于有主key 是并发的 然后次key的拥有者只能自己写自己的数据 2. 使用ets:select_replace 实现无锁替换操作 update_with_fun(Table, Key, Fun) -> [Old] = ets:lookup(Table, Key), New = Fun(Old), Success = (1 =:= ets:select_replace(Table, [{Old, [], [{const, New}]}])), case Success of true -> New; false -> update_with_fun(Table, Key, Fun) end.