summaryrefslogtreecommitdiffstats
path: root/list.h
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2014-12-09 10:31:37 +0900
committerFreeArtMan <dos21h@gmail.com>2014-12-09 10:31:37 +0900
commita57c6bed8f6ab7d0f4355190c0cff7cd913da6a0 (patch)
treec8b85b9de364cb63678d05625bdff6a2cf12ecda /list.h
parentdc4bbe5366d6c733f9f77b7c9fee0cbba3e0d92b (diff)
downloadmicrobbs-a57c6bed8f6ab7d0f4355190c0cff7cd913da6a0.tar.gz
microbbs-a57c6bed8f6ab7d0f4355190c0cff7cd913da6a0.zip
New planned functionality. Menuconfig support. Simple captcha.
Diffstat (limited to 'list.h')
-rw-r--r--list.h83
1 files changed, 75 insertions, 8 deletions
diff --git a/list.h b/list.h
index c443430..94794f0 100644
--- a/list.h
+++ b/list.h
@@ -10,42 +10,102 @@
//use stack memallocation features. need to make some changes in api
+//!TODO give for_each macros that can be used
+//!TODO add insert element in list for sorting stuff
+//!TODO save/load could be just void* list->val that to save, sequently
+
+
+//when need to compare 2 nodes values with are pointers on anything
+// return:
+// -1 (<) void 1 is less then void 2
+// 0 (=) void 1 is equal to void 2
+// 1 (>) void 1 is bigger then void 2
+typedef int (*clb_llist_cmp)(void *, void *);
+
+//when need to free whole list and also values of list with are just pointer
+//to anything
+// param void* - list->val
+typedef int (*clb_llist_free)(void *);
+
+//load and save data to file if possible
+//return
+// 0 - everything is ok
+// non-zero - something went wrong
+// can put different errors that you whant
+//param
+//void* - string where to save, or how to save
+//void* - linked list that need to save
+typedef int (*clb_llist_save)(void *, void *);
+//return
+// non-zero - some error happened
+// 0 - everything is ok
+//param
+//void* - string from where to load
+//void* - list where to save
+typedef int (*clb_llist_load)(void *, void **);
typedef struct ListNode
{
struct ListNode *next;
- void *val;
+ void *val;
} ListNode;
typedef struct List
{
- int count;
+ int count;
ListNode *first;
ListNode *last;
} List;
+typedef struct ListManager
+{
+ List *list;
+ int sorted; //auto sort if needed
+ int mode; // read only
+ char *name; // list name
+ clb_llist_cmp *cmp;
+ clb_llist_free *free;
+ clb_llist_save *save;
+ clb_llist_load *load;
+} ListManager;
+
+
+
+
struct List* llist_new();
struct ListNode* llist_newn( void* );
+struct ListManager* llist_newm();
//#define __LLIST_NEW()
//#define __LLIST_NEWN()
int llist_length( struct List* );
int llist_index( struct List*, void* );
//llist_find( struct List );
-//find by pointer
-//find by value
-void llist_reverse( struct List** );
+//!find by pointer
+//!find by value
+
+void llist_reverse( struct List* );
+
+//void llist_append( struct List*, void* );
-void llist_append( struct List*, void* );
void llist_appendn( struct List**, void*, struct ListNode* );
//#define __LIST_APPEND()
+// get one element from list and erease it from list
void* llist_pop( struct List* );
+//add at the end one element
void llist_push( struct List*, void* );
+//remove node from list and return value of element
+//void* llist_remove( struct List*, struct ListNode* );
+void* llist_removen( struct List*, struct ListNode* );
+//delete one element from the list
+//void llist_delete( struct List*, void*);
+
void llist_free( struct List* );
void llist_freen( struct ListNode* );
+
//void llist_merge( struct List**, struct List* );
//void llist_compare( struct List
//void llist_split( struct List*,
@@ -53,8 +113,12 @@ void llist_freen( struct ListNode* );
//void llist_splitp( struct List*, void*
//void llist_splitc( struct List*, void (*)(void*)
//void llist_sort(
-//sort by pointer
-//sort by value
+//!sort by pointer
+//!sort by val value, need compare callback
+void llist_sortn( struct List*, clb_llist_cmp );
+
+int llist_save( struct List*, clb_llist_save );
+struct List* llist_load( clb_llist_load, const char* );
#define llist_first(A) ((A)->first)
#define llist_last(A) ((A)->last)
@@ -66,4 +130,7 @@ void llist_freen( struct ListNode* );
//#define llist_isfirstn(A) ()
//#define llist_getfirstn(A) ((A))
//#define llist_getlastn(A) ()
+
+
+
#endif