llist.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (C) 2021 Alibaba Group Holding Limited
  3. * Author: zhuxinran <fuqian.zxr@alibaba-inc.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef __LLIST_H__
  10. #define __LLIST_H__
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define LLIST_FORWARD 1
  15. #define LLIST_BACKWARD 2
  16. typedef void llist_op(const void *);
  17. typedef int llist_cmp(const void *, const void *);
  18. struct llist_node_st {
  19. struct llist_node_st *prev;
  20. struct llist_node_st *next;
  21. char data[1];
  22. };
  23. typedef struct llist_head_st {
  24. int size;
  25. struct llist_node_st head;
  26. int (*insert)(struct llist_head_st *, const void *data, int mode);
  27. void *(*find)(struct llist_head_st *, const void *data, llist_cmp *cmp);
  28. int (*delete)(struct llist_head_st *, const void *data, llist_cmp *cmp);
  29. int (*fetch)(struct llist_head_st *, const void *data, llist_cmp *cmp,
  30. void *rdata);
  31. void (*travel)(struct llist_head_st *, llist_op *op);
  32. } LLIST;
  33. LLIST *llist_create(int size);
  34. void llist_destroy(LLIST *);
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #endif