Skip to content

Commit

Permalink
API clean up
Browse files Browse the repository at this point in the history
 - change API name into unified naming convention ( pkg_moduleFUNC /w cammel case )
 - revising heavily recursive into less or no recursive for practical use
 - generic base class(like) is integrated to lists / trees implementation
  • Loading branch information
fritzprix committed Mar 27, 2016
1 parent 2cb7644 commit 4038060
Show file tree
Hide file tree
Showing 28 changed files with 1,169 additions and 254 deletions.
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## makefile for cdsl
# makefile for cdsl


CC=clang-3.6
Expand All @@ -8,7 +8,7 @@ PYTHON=python
PIP=pip
MKDIR=mkdir

DBG_CFLAG = -O0 -g3 -fmessage-length=0
DBG_CFLAG = -O0 -g3 -fmessage-length=0 -D__DBG
REL_CFLAG = -O2 -g0 -fmessage-length=0
DYNAMIC_FLAG = -fPIC

Expand All @@ -21,6 +21,7 @@ TOOL_DIR=$(PROJECT_ROOT_DIR)/tools
CONFIG_PY=$(TOOL_DIR)/jconfigpy/jconfigpy.py

TEST_TARGET=cdsl
DEV_TEST_TARGET=cdsl_dev

DBG_STATIC_TARGET=libcdsld.a
DBG_DYNAMIC_TARGET=libcdsld.so
Expand All @@ -45,7 +46,7 @@ REL_CACHE_DIR=Release
SILENT+= $(REL_STATIC_TARGET) $(REL_DYNAMIC_TARGET) $(DBG_OBJS)
SILENT+= $(DBG_STATIC_TARGET) $(DBG_DYNAMIC_TARGET) $(REL_OBJS)
SILENT+= $(DBG_SH_OBJS) $(REL_SH_OBJS)
SILENT+= $(TEST_TARGET) $(REL_CACHE_DIR)/main.o
SILENT+= $(TEST_TARGET) $(REL_CACHE_DIR)/main.o $(DEV_TEST_TARGET) $(DBG_CACHE_DIR)/main.do


.SILENT : $(SILENT) clean
Expand All @@ -58,7 +59,7 @@ debug : $(DBG_CACHE_DIR) $(DBG_STATIC_TARGET) $(DBG_DYNAMIC_TARGET)

release : $(REL_CACHE_DIR) $(REL_STATIC_TARGET) $(REL_DYNAMIC_TARGET)

test : $(REL_CACHE_DIR) $(TEST_TARGET)
test : $(REL_CACHE_DIR) $(DBG_CACHE_DIR) $(TEST_TARGET) $(DEV_TEST_TARGET)

config : $(CONFIG_PY)
$(PYTHON) $(CONFIG_PY) -c -i config.json
Expand Down Expand Up @@ -89,6 +90,11 @@ $(TEST_TARGET) : $(REL_CACHE_DIR)/main.o $(REL_OBJS)
@echo 'Building unit-test executable... $@'
$(CC) -o $@ $(REL_CFLAG) $< $(REL_OBJS)


$(DEV_TEST_TARGET) : $(DBG_CACHE_DIR)/main.do $(DBG_OBJS)
@echo 'Building unit-test executable... $@'
$(CC) -o $@ $(DBG_CFLAG) $< $(DBG_OBJS)

$(DBG_CACHE_DIR)/%.do : %.c
@echo 'compile...$@'
$(CC) -c -o $@ $(DBG_CFLAG) $< $(INCS)
Expand All @@ -110,7 +116,7 @@ PHONY += clean
clean :
rm -rf $(DBG_CACHE_DIR) $(DBG_STATIC_TARGET) $(DBG_DYNAMIC_TARGET)\
$(REL_CACHE_DIR) $(REL_STATIC_TARGET) $(REL_DYNAMIC_TARGET)\
$(TEST_TARGET) $(REL_SH_OBJS) $(DBG_SH_OBJS)
$(TEST_TARGET) $(REL_SH_OBJS) $(DBG_SH_OBJS) $(DEV_TEST_TARGET)

.PHONY = $(PHONY)

Expand Down
8 changes: 3 additions & 5 deletions cdsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ extern "C" {
#define TEST_SIZE 5000
#endif

#define VERBOSE_LOG

#ifdef VERBOSE_LOG
#define log(...) printf(__VA_ARGS__)
#ifdef __DBG
#define __dev_log(...) printf(__VA_ARGS__)
#else
#define log(...)
#define __dev_log(...)
#endif

#define container_of(ptr, type, elem) ((type*) ((size_t) ptr - offsetof(type, elem)))
Expand Down
27 changes: 14 additions & 13 deletions include/cdsl_bstree.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ extern "C"{
#endif


typedef struct bs_treenode bs_treeNode_t;
typedef struct bs_treeroot bs_treeRoot_t;
typedef struct bs_treenode bstreeNode_t;
typedef struct bs_treeroot bstreeRoot_t;

#define cdsl_bstreeMaxDepth(root) tree_max_depth((base_treeRoot_t*) root)
#define cdsl_bstreeTraverse(root, cb, order) tree_traverse((base_treeRoot_t*) root, (base_tree_callback_t) cb, order)
#define cdsl_bstreeSize(root) tree_size((base_treeRoot_t*) root)
#define cdsl_bstreePrint(root, print) tree_print((base_treeRoot_t*) root, print)

#define ORDER_INC (int) 0
#define ORDER_DEC (int) 1
Expand All @@ -29,7 +34,7 @@ typedef int (*bs_tree_callback_t) (int order,void*);
struct bs_treenode {
union {
struct {
bs_treeNode_t *left, *right;
bstreeNode_t *left, *right;
};
base_treeNode_t node;
};
Expand All @@ -38,21 +43,17 @@ struct bs_treenode {

struct bs_treeroot {
union {
bs_treeNode_t* entry;
bstreeNode_t* entry;
base_treeRoot_t root;
};
};


extern void bstree_root_init(bs_treeRoot_t* rootp);
extern void bstree_node_init(bs_treeNode_t* node,int key);
extern bs_treeNode_t* bstree_insert(bs_treeRoot_t* rootp,bs_treeNode_t* item);
extern bs_treeNode_t* bstree_lookup(bs_treeRoot_t* rootp,int key);
extern bs_treeNode_t* bstree_delete(bs_treeRoot_t* rootp,int key);
extern void bstree_traverse(bs_treeRoot_t* rootp,base_tree_callback_t cb,int order);
extern int bstree_size(bs_treeRoot_t* rootp);
extern void bstree_print(bs_treeRoot_t* rootp,cdsl_generic_printer_t prt);
extern int bstree_max_depth(bs_treeRoot_t* rootp);
extern void cdsl_bstreeRootInit(bstreeRoot_t* rootp);
extern void cdsl_bstreeNodeInit(bstreeNode_t* node,int key);
extern bstreeNode_t* cdsl_bstreeInsert(bstreeRoot_t* rootp,bstreeNode_t* item);
extern bstreeNode_t* cdsl_bstreeLookup(bstreeRoot_t* rootp,int key);
extern bstreeNode_t* cdsl_bstreeDelete(bstreeRoot_t* rootp,int key);


#if defined(__cplusplus)
Expand Down
21 changes: 10 additions & 11 deletions include/cdsl_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
extern "C" {
#endif



#define cdsl_heapMaxDepth(root) tree_max_depth((base_treeRoot_t*) root)
#define cdsl_heapTraverse(root, cb, order) tree_traverse((base_treeRoot_t*) root, (base_tree_callback_t) cb, order)
#define cdsl_heapSize(root) tree_size((base_treeRoot_t*) root)
#define cdsl_heapPrint(root, print) tree_print((base_treeRoot_t*) root, print)

typedef struct heap_node heapNode_t;
typedef struct heap_root heapRoot_t;
Expand All @@ -28,27 +30,24 @@ struct heap_node {
struct {
heapNode_t* left, *right;
};
base_treeNode_t _node;
base_treeNode_t node;
};
uint32_t key;
};

struct heap_root {
union {
heapNode_t* entry;
base_treeRoot_t _root;
base_treeRoot_t root;
};
int dir;
heapType_t type;
};

extern void heap_root_init(heapRoot_t* rootp,heapType_t type);
extern void heap_node_init(heapNode_t* node,int key);
extern int heap_enqueue(heapRoot_t* rootp,heapNode_t* item);
extern heapNode_t* heap_deqeue(heapRoot_t* rootp);
extern void heap_print(heapRoot_t* rootp,cdsl_generic_printer_t print);
extern int heap_size(heapRoot_t* rootp);
extern int heap_max_depth(heapRoot_t* rootp);
extern void cdsl_heapRootInit(heapRoot_t* rootp,heapType_t type);
extern void cdsl_heapNodeInit(heapNode_t* node,int key);
extern int cdsl_heapEnqueue(heapRoot_t* rootp,heapNode_t* item);
extern heapNode_t* cdsl_heapDeqeue(heapRoot_t* rootp);

#if defined(__cplusplus)
}
Expand Down
67 changes: 67 additions & 0 deletions include/cdsl_nrbtree.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* cdsl_nrbtree.h
*
* Created on: Mar 24, 2016
* Author: innocentevil
*/

#ifndef INCLUDE_CDSL_NRBTREE_H_
#define INCLUDE_CDSL_NRBTREE_H_

#include "base_tree.h"
#include "cdsl.h"

#ifdef __cplusplus
extern "C" {
#endif


#ifndef rb_key_t
#define rb_key_t uint32_t
#endif

#define cdsl_nrbtreeMaxDepth(root) tree_max_depth((base_treeRoot_t*) root)
#define cdsl_nrbtreeTraverse(root, cb, order) tree_traverse((base_treeRoot_t*) root, (base_tree_callback_t) cb, order)
#define cdsl_nrbtreeSize(root) tree_size((base_treeRoot_t*) root)
#define cdsl_nrbtreePrint(root, print) tree_print((base_treeRoot_t*) root, print)

typedef struct cdsl_nrbtree nrbtreeNode_t;
typedef struct cdsl_nrbroot {
union {
struct base_tree_root base_root;
nrbtreeNode_t* entry;
};
}nrbtreeRoot_t;

struct cdsl_nrbtree {
union {
struct base_tree_node base_node;
struct {
nrbtreeNode_t* left;
nrbtreeNode_t* right;
};

};
rb_key_t key;
};



extern void cdsl_nrbtreeRootInit(nrbtreeRoot_t* rootp);
extern void cdsl_nrbtreeNodeInit(nrbtreeNode_t* node, rb_key_t key);
extern nrbtreeNode_t* cdsl_nrbtreeInsert(nrbtreeRoot_t* rootp,nrbtreeNode_t* item);
extern nrbtreeNode_t* cdsl_nrbtreeLookup(nrbtreeRoot_t* rootp,rb_key_t key);
extern nrbtreeNode_t* cdsl_nrbtreeDelete(nrbtreeRoot_t* rootp,rb_key_t key);

#ifdef __DBG
extern void cdsl_nrbtreePrint_dev(nrbtreeRoot_t* root);
#else
#define cdsl_nrbtreePrint_dev(root)
#endif


#ifdef __cplusplus
}
#endif

#endif /* INCLUDE_CDSL_NRBTREE_H_ */
38 changes: 29 additions & 9 deletions include/cdsl_spltree.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,46 @@
#ifndef CDSL_SPLTREE_H_
#define CDSL_SPLTREE_H_

#include "base_tree.h"

#if defined(__cplusplus)
extern "C" {
#endif


#define cdsl_spltreeMaxDepth(root) tree_max_depth((base_treeRoot_t*) root)
#define cdsl_traverse(root, cb, order) tree_traverse((base_treeRoot_t*) root, (base_tree_callback_t) cb, order)
#define cdsl_spltreeSize(root) tree_size((base_treeRoot_t*) root)
#define cdsl_spltreePrint(root, print) tree_print((base_treeRoot_t*) root, print)

typedef struct spltree_node spltreeNode_t;
typedef struct spltree_root spltreeRoot_t;

struct spltree_root {
union {
base_treeRoot_t root_base;
spltreeNode_t* entry;
};
};

struct spltree_node {
spltreeNode_t* left,*right;
union {
base_treeNode_t node_base;
struct {
spltreeNode_t* left,*right;
};
};
int key;
};


extern void cdsl_spltreeRootInit(spltreeRoot_t* root);
extern void cdsl_spltreeNodeInit(spltreeNode_t* node,int key);
extern void cdsl_spltreeInsert(spltreeNode_t** root,spltreeNode_t* item);
extern spltreeNode_t* cdsl_spltreeLookup(spltreeNode_t** root,int key,BOOL splay);
extern spltreeNode_t* cdsl_spltreeLookupLargest(spltreeNode_t** root,BOOL splay);
extern spltreeNode_t* cdsl_spltreeLookupSmallest(spltreeNode_t** root,BOOL splay);
extern spltreeNode_t* cdsl_spltreeDelete(spltreeNode_t** root,int key);
extern int cdsl_spltreeSize(spltreeNode_t** root);
extern int cdsl_spltreeMaxDepth(spltreeNode_t** root);
extern void cdsl_spltreePrint(spltreeNode_t** root);
extern void cdsl_spltreeInsert(spltreeRoot_t* root,spltreeNode_t* item);
extern spltreeNode_t* cdsl_spltreeLookup(spltreeRoot_t* root,int key,BOOL splay);
extern spltreeNode_t* cdsl_spltreeLookupLargest(spltreeRoot_t* root,BOOL splay);
extern spltreeNode_t* cdsl_spltreeLookupSmallest(spltreeRoot_t* root,BOOL splay);
extern spltreeNode_t* cdsl_spltreeDelete(spltreeRoot_t* root,int key);



Expand Down
7 changes: 7 additions & 0 deletions include/test/cdsl_bstree_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@

#include "cdsl.h"

#ifdef __cplusplus
extern "C" {
#endif

extern BOOL cdsl_bstreeDoTest(void);

#ifdef __cplusplus
}
#endif

#endif /* CDSL_BSTREE_TEST_H_ */
7 changes: 6 additions & 1 deletion include/test/cdsl_hash_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@

#include "cdsl.h"

#ifdef __cplusplus
extern "C" {
#endif

extern BOOL cdsl_hashDoTest(void);



#ifdef __cplusplus
}
#endif

#endif /* CDSL_HASH_TEST_H_ */
9 changes: 9 additions & 0 deletions include/test/cdsl_list_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
#ifndef CDSL_LIST_TEST_H_
#define CDSL_LIST_TEST_H_

#include "cdsl.h"

#ifdef __cplusplus
extern "C" {
#endif

extern BOOL cdsl_listDoTest(void);

#ifdef __cplusplus
}
#endif

#endif /* CDSL_LIST_TEST_H_ */
22 changes: 22 additions & 0 deletions include/test/cdsl_nrbtree_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* cdsl_nrbtree_test.h
*
* Created on: Mar 26, 2016
* Author: innocentevil
*/

#ifndef INCLUDE_TEST_CDSL_NRBTREE_TEST_H_
#define INCLUDE_TEST_CDSL_NRBTREE_TEST_H_
#include "cdsl.h"

#ifdef __cplusplus
extern "C" {
#endif

extern BOOL cdsl_nrbtreeDoTest(void);

#ifdef __cplusplus
}
#endif

#endif /* INCLUDE_TEST_CDSL_NRBTREE_TEST_H_ */
9 changes: 9 additions & 0 deletions include/test/cdsl_rbtree_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
#ifndef CDSL_RBTREE_TEST_H_
#define CDSL_RBTREE_TEST_H_

#include "cdsl.h"

#ifdef __cplusplus
extern "C" {
#endif

extern BOOL cdsl_rbtreeDoTest(void);

#ifdef __cplusplus
}
#endif

#endif /* CDSL_RBTREE_TEST_H_ */
Loading

0 comments on commit 4038060

Please sign in to comment.