erlang各种有用的函数包括一些有用nif封装,还有一些性能测试case。
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

  1. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  2. // use this file except in compliance with the License. You may obtain a copy of
  3. // the License at
  4. //
  5. // http://www.apache.org/licenses/LICENSE-2.0
  6. //
  7. // Unless required by applicable law or agreed to in writing, software
  8. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. // License for the specific language governing permissions and limitations under
  11. // the License.
  12. #pragma once
  13. #include <stdint.h>
  14. #define HQ_VERSION 0
  15. #define HQ_SCALE_FACTOR 2 // heap expansion scale factor
  16. // Override the default memory allocator to use the Erlang versions.
  17. // This bubbles up memory usage for the NIF into Erlang stats.
  18. #ifdef HQ_ENIF_ALLOC
  19. #include "erl_nif.h"
  20. #define HQUEUE_ALLOC enif_alloc
  21. #define HQUEUE_FREE enif_free
  22. #else
  23. #define HQUEUE_ALLOC malloc
  24. #define HQUEUE_FREE free
  25. #endif
  26. typedef struct hqnode hqnode_t;
  27. typedef struct hqueue hqueue_t;
  28. hqueue_t* hqueue_new(uint32_t max_elems, uint32_t heap_size);
  29. void hqueue_free(hqueue_t* hqueue);
  30. void hqueue_free2(hqueue_t* hqueue, void (*free_node)(void* node));
  31. int hqueue_insert(hqueue_t* hqueue, double priority, void* val);
  32. int hqueue_extract_max(hqueue_t* hqueue, double* priority, void** value);
  33. void hqueue_get_elem(hqueue_t* hqueue, uint32_t idx, double *priority,
  34. void** value);
  35. uint32_t hqueue_size(hqueue_t* hqueue);
  36. uint32_t hqueue_heap_size(hqueue_t* hqueue);
  37. uint32_t hqueue_max_elems(hqueue_t* hqueue);
  38. int hqueue_set_max_elems(hqueue_t* hqueue, uint32_t new_max_elems);
  39. void hqueue_scale_by(hqueue_t* hqueue, double factor);
  40. uint32_t hqueue_resize_heap(hqueue_t* hqueue, uint32_t new_heap_size);