erlang各种有用的函数包括一些有用nif封装,还有一些性能测试case。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
2.1 KiB

преди 3 години
  1. -type matchExpression() :: [ matchFunction(), ... ].
  2. -type matchFunction() :: { matchHead(), matchConditions(), matchBody()}.
  3. -type matchHead() :: matchVariable() | '_' | { matchHeadPart(), ...}.
  4. -type matchHeadPart() :: term() | matchVariable() | '_'.
  5. -type matchVariable() :: '$<number>'.
  6. -type matchConditions() :: [ matchCondition(), ...] | [].
  7. -type matchCondition() :: { guardFunction() } | { guardFunction(), conditionExpression(), ... }.
  8. -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'.
  9. -type conditionExpression() :: exprMatchVariable() | { guardFunction() } | { guardFunction(), conditionExpression(), ... } | termConstruct().
  10. -type exprMatchVariable() :: matchVariable() (bound in the MatchHead) | '$_' | '$$'
  11. -type termConstruct():: {{}} | {{ conditionExpression(), ... }} | [] | [conditionExpression(), ...] | #{} | #{term() => conditionExpression(), ...} | nonCompositeTerm() | constant().
  12. -type nonCompositeTerm() :: term(). %% (not list or tuple or map)
  13. -type constant() :: {const, term()}.
  14. -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.
  15. -type matchBody() :: [ conditionExpression(), ... ].
  16. ets表并发写优化
  17. 1.核心思想还是避免数据写操作是并发操作 这种可以将ets 设置为bag 相当于有主key 是并发的 然后次key的拥有者只能自己写自己的数据
  18. 2. 使用ets:select_replace 实现无锁替换操作
  19. update_with_fun(Table, Key, Fun) ->
  20. [Old] = ets:lookup(Table, Key),
  21. New = Fun(Old),
  22. Success = (1 =:= ets:select_replace(Table, [{Old, [], [{const, New}]}])),
  23. case Success of
  24. true -> New;
  25. false -> update_with_fun(Table, Key, Fun)
  26. end.