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.

55 lines
1.2 KiB

  1. //
  2. // Created by fox on 2017/10/10.
  3. //
  4. #ifndef NIF_SKIPLIST_SKIPLIST_H
  5. #define NIF_SKIPLIST_SKIPLIST_H
  6. #ifdef USENIF
  7. #define imalloc enif_alloc
  8. #define icalloc enif_alloc
  9. #define irealloc enif_realloc
  10. #define ifree enif_free
  11. #else
  12. #define imalloc malloc
  13. #define icalloc(x) calloc(x, 1)
  14. #define irealloc realloc
  15. #define ifree free
  16. #endif
  17. typedef int vtype;
  18. typedef struct snode {
  19. int score;
  20. int value;
  21. struct skiplistLevel {
  22. struct snode *forward;
  23. unsigned int span;
  24. } level[];
  25. } snode;
  26. typedef struct skiplist {
  27. int level;
  28. int size;
  29. struct snode *header;
  30. } skiplist;
  31. typedef struct skiplist_search_ret {
  32. int index; // start from 1
  33. snode *node;
  34. } skiplist_search_ret;
  35. void test_skiplist(void);
  36. // functions
  37. skiplist *skiplist_init(void);
  38. void skiplist_free(skiplist *list);
  39. int skiplist_insert(skiplist *list, int score, vtype value);
  40. int skiplist_update(skiplist *list, int score, vtype value, int old_score);
  41. int skiplist_delete(skiplist *list, int score, vtype value);
  42. void skiplist_search(skiplist *list, int score, skiplist_search_ret *ret);
  43. int skiplist_index_of_score(skiplist *list, int score);
  44. snode *skiplist_at(skiplist *list, int index);
  45. #endif //NIF_SKIPLIST_SKIPLIST_H