LIST.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // this header will define a list data type (based on python's)
  2. // will be used for complex stuff so it will use a lot of memory
  3. #ifndef LIST_HEADER
  4. #define LIST_HEADER
  5. // this header needs
  6. #include "../../BASIC_TYPES.h"
  7. #include "../ENDIAN.h"
  8. #include "../MEM_ALLOC.h"
  9. // real includes
  10. #include "../ARRAY/CHAR/CHAR_ARR/STRING/STRING.h"
  11. #include "../ARRAY/NUMBER/NUMBER.h"
  12. // enum to be used to generally identify
  13. // the data contained in the node
  14. typedef enum
  15. {
  16. LNODE_DT_NO_TYPE,
  17. // integers
  18. LNODE_DT_UINT8,
  19. LNODE_DT_UINT16BE,
  20. LNODE_DT_UINT16LE,
  21. LNODE_DT_UINT32BE,
  22. LNODE_DT_UINT32LE,
  23. LNODE_DT_SINT8,
  24. LNODE_DT_SINT16BE,
  25. LNODE_DT_SINT16LE,
  26. LNODE_DT_SINT32BE,
  27. LNODE_DT_SINT32LE,
  28. // floats
  29. LNODE_DT_FLT16BE,
  30. LNODE_DT_FLT16LE,
  31. LNODE_DT_FLT32BE,
  32. LNODE_DT_FLT32LE,
  33. LNODE_DT_FLT64BE,
  34. LNODE_DT_FLT64LE,
  35. // strings
  36. LNODE_DT_STR_ASCII,
  37. LNODE_DT_STR_CP1252,
  38. LNODE_DT_STR_CP932,
  39. LNODE_DT_STR_SHIFT_JIS,
  40. LNODE_DT_STR_UTF8,
  41. LNODE_DT_STR_UTF16BE,
  42. LNODE_DT_STR_UTF16LE,
  43. } lnode_data_type;
  44. // list node struct, the foundation block of the list array
  45. struct lnode
  46. {
  47. // element desc/info
  48. byte * SRC; // pointer to the element referenced by in the node
  49. umax SIZE; // number of bytes able to be read from SRC
  50. lnode_data_type TYPE; // integer with the type of data to be read from SRC
  51. // relations
  52. struct lnode * BEHIND; // pointer to the element behind the current node (same level)
  53. struct lnode * FRONT; // pointer to the element in front the current node (same level)
  54. struct lnode * PARENT; // pointer to the parent of the current node (upper level)
  55. struct lnode * CHILD; // pointer to the immediate child of this element (lower level)
  56. // elemental functions
  57. umax (* print) (void * src, umax size); // I need to be able to see the element easily somehow
  58. };
  59. // the holy typedef
  60. typedef struct lnode lnode;
  61. // functions to handle a lnodes
  62. lnode * get_lnode(void * src, umax src_size, lnode_data_type type);
  63. // building complex lists functions
  64. lnode * find_lnode_behind(lnode * node, umax index);
  65. lnode * find_lnode_front(lnode * node, umax index);
  66. lnode * find_lnode_parent(lnode * node, umax index);
  67. lnode * find_lnode_child(lnode * node, umax index);
  68. lnode * add_lnode_front(lnode * node, void * src, umax src_size, lnode_data_type type);
  69. lnode * add_lnode_child(lnode * node, void * src, umax src_size, lnode_data_type type);
  70. // deleting a node
  71. lnode * rm_lnode(lnode * node);
  72. // delete direct fronts/childs functions
  73. umax rm_lnode_fronts(lnode * node);
  74. umax rm_lnode_childs(lnode * node);
  75. umax rm_lnode_list(lnode * node);
  76. // other operations on lists
  77. umax count_lnode_fronts(lnode * node);
  78. umax count_lnode_childs(lnode * node);
  79. umax count_lnodes(lnode * node);
  80. umax count_lnodes_parent_lvls(lnode * node);
  81. umax print_lnode_list(lnode * node);
  82. // enum for the search function below
  83. typedef enum
  84. {
  85. LNODE_DIR_NO_DIR,
  86. LNODE_DIR_FRONT,
  87. LNODE_DIR_BEHIND,
  88. LNODE_DIR_PARENT,
  89. LNODE_DIR_CHILD,
  90. } lnode_dir;
  91. // specific search function
  92. lnode * find_lnode(lnode * node, lnode_dir dir, umax index);
  93. #include "LIST.c"
  94. #endif // LIST_HEADER