junkcode: upload via website.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 19 Apr 2011 00:54:27 +0000 (10:24 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 19 Apr 2011 00:54:27 +0000 (10:24 +0930)
70 files changed:
junkcode/dongre.avinash@gmail.com-clibutils/inc/c_array.h [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/inc/c_deque.h [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/inc/c_errors.h [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/inc/c_heap.h [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/inc/c_lib.h [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/inc/c_map.h [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/inc/c_rb.h [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/inc/c_set.h [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/inc/c_slist.h [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/inc/c_stack.h [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/src/Makefile [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/src/c_array.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/src/c_deque.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/src/c_heap.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/src/c_map.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/src/c_rb.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/src/c_set.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/src/c_slist.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/src/c_stack.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/src/c_util.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/test/Makefile [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_array.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_deque.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_heap.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_map.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_rb.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_set.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_slist.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_stack.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/test/t_clibutils.c [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.ncb [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.sln [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.suo [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.vcproj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.vcproj.ADPROD.avdongre.user [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/BuildLog.htm [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_array.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_deque.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_heap.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_map.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_rb.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_set.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_slist.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_stack.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_util.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.idb [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.lib [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.pdb [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils.vcproj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils.vcproj.ADPROD.avdongre.user [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/BuildLog.htm [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/mt.dep [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_array.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_deque.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_heap.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_map.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_rb.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_set.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_slist.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_stack.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_clibutils.obj [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe.embed.manifest [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe.embed.manifest.res [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe.intermediate.manifest [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.idb [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.ilk [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.pdb [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils_pure.ini [new file with mode: 0644]
junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils_pure.log [new file with mode: 0644]

diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_array.h b/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_array.h
new file mode 100644 (file)
index 0000000..ad233fd
--- /dev/null
@@ -0,0 +1,49 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#ifndef _C_ARRAY_H_\r
+#define _C_ARRAY_H_\r
+\r
+struct clib_array {\r
+    int no_max_elements; /* Number of maximum elements array can hold without reallocation */\r
+    int no_of_elements;  /* Number of current elements in the array */\r
+    struct clib_object** pElements; /* actual storage area */\r
+    clib_compare compare_fn; /* Compare function pointer*/\r
+    clib_destroy destruct_fn; /* Destructor function pointer*/\r
+};\r
+\r
+extern struct clib_array* new_clib_array ( int init_size, clib_compare fn_c, clib_destroy fn_d);\r
+extern clib_error push_back_clib_array ( struct clib_array *pArray, void *elem, size_t elem_size);\r
+extern clib_error element_at_clib_array( struct clib_array *pArray, int pos, void **e);\r
+extern clib_error insert_at_clib_array ( struct clib_array *pArray, int index, void *elem, size_t elem_size);\r
+extern int size_clib_array( struct clib_array *pArray);\r
+extern int capacity_clib_array( struct clib_array *pArray );\r
+extern clib_bool  empty_clib_array( struct clib_array *pArray);\r
+extern clib_error reserve_clib_array( struct clib_array *pArray, int pos);\r
+extern clib_error front_clib_array( struct clib_array *pArray,void *elem);\r
+extern clib_error back_clib_array( struct clib_array *pArray,void *elem);\r
+extern clib_error remove_clib_array ( struct clib_array *pArray, int pos);\r
+extern clib_error delete_clib_array( struct clib_array *pArray);\r
+extern void swap_element_clib_array ( struct clib_array *pArray, int left, int right);\r
+extern void for_each_clib_array ( struct clib_array *pArray, void (*fn)(void*));\r
+#endif\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_deque.h b/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_deque.h
new file mode 100644 (file)
index 0000000..4695e4e
--- /dev/null
@@ -0,0 +1,51 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#ifndef _C_DEQUE_H_\r
+#define _C_DEQUE_H_\r
+\r
+struct clib_deque {\r
+    struct clib_object**pElements;\r
+    int no_max_elements;\r
+    int head;\r
+    int tail;\r
+    int no_of_elements;\r
+    clib_compare compare_fn;\r
+    clib_destroy destruct_fn;\r
+}c_deque;\r
+\r
+extern struct clib_deque* new_clib_deque( int deq_size , clib_compare fn_c, clib_destroy fn_d);\r
+extern clib_error     push_back_clib_deque (struct clib_deque *pDeq, void *elem, size_t elem_size);\r
+extern clib_error     push_front_clib_deque(struct clib_deque *pDeq, void *elem,size_t elem_size);\r
+\r
+extern clib_error     front_clib_deque     (struct clib_deque *pDeq,void*);\r
+extern clib_error     back_clib_deque      (struct clib_deque *pDeq,void*);\r
+extern clib_error     pop_back_clib_deque  (struct clib_deque *pDeq);\r
+extern clib_error     pop_front_clib_deque (struct clib_deque *pDeq);\r
+extern clib_bool      empty_clib_deque     (struct clib_deque *pDeq);\r
+extern int            size_clib_deque ( struct clib_deque *pDeq);\r
+extern clib_error     delete_clib_deque ( struct clib_deque *pDeq);\r
+extern clib_error     element_at_clib_deque (struct clib_deque *pDeq, int index, void**elem);\r
+extern void for_each_clib_deque ( struct clib_deque *pDeq, void (*fn)(void*));\r
+\r
+#endif\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_errors.h b/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_errors.h
new file mode 100644 (file)
index 0000000..52aee8e
--- /dev/null
@@ -0,0 +1,58 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#ifndef _C_ERRORS_H_\r
+#define _C_ERRORS_H_\r
+\r
+/* ------------------------------------------------------------------------*/\r
+/*                 C O M M O N    E R R O R    C O D E                     */\r
+/* ------------------------------------------------------------------------*/\r
+#define CLIB_ERROR_SUCCESS  0\r
+#define CLIB_ERROR_ERROR    1\r
+#define CLIB_ERROR_MEMORY   2\r
+#define CLIB_ELEMENT_RETURN_ERROR 3\r
+/* ------------------------------------------------------------------------*/\r
+/*         D Y N A M I C    A R R A Y   E R R O R    C O D E S             */\r
+/* ------------------------------------------------------------------------*/\r
+#define CLIB_ARRAY_NOT_INITIALIZED    101\r
+#define CLIB_ARRAY_INDEX_OUT_OF_BOUND 102\r
+#define CLIB_ARRAY_INSERT_FAILED      103\r
+\r
+#define CLIB_DEQUE_NOT_INITIALIZED    201\r
+#define CLIB_DEQUE_INDEX_OUT_OF_BOUND 202\r
+\r
+#define CLIB_RBTREE_NOT_INITIALIZED   401\r
+#define CLIB_RBTREE_KEY_DUPLICATE     401\r
+#define CLIB_RBTREE_KEY_NOT_FOUND     402\r
+\r
+#define CLIB_SET_NOT_INITIALIZED      501\r
+#define CLIB_SET_INVALID_INPUT        502\r
+\r
+#define CLIB_MAP_NOT_INITIALIZED      501\r
+#define CLIB_MAP_INVALID_INPUT        502\r
+\r
+#define CLIB_SLIST_INSERT_FAILED      601\r
+\r
+\r
+\r
+#endif
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_heap.h b/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_heap.h
new file mode 100644 (file)
index 0000000..5ec3edd
--- /dev/null
@@ -0,0 +1,43 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+#ifndef _C_HEAP_H\r
+#define _C_HEAP_H\r
+\r
+struct clib_heap {\r
+       struct clib_array *pHeapPtr;\r
+       int heap_parent;\r
+       int heap_left;\r
+       int heap_right;\r
+};\r
+\r
+extern struct clib_heap *new_clib_heap( int default_size, clib_compare fn_c, clib_destroy fn_d );\r
+extern void delete_clib_heap( struct clib_heap *pHeap);\r
+extern void insert_clib_heap ( struct clib_heap *pHeap, void *elem, size_t elem_size);\r
+extern void build_max_clib_heap ( struct clib_heap *pHeap );\\r
+extern void build_min_clib_heap ( struct clib_heap *pHeap );\r
+extern void *extract_max_clib_heap( struct clib_heap *pHeap);\r
+extern void *extract_min_clib_heap( struct clib_heap *pHeap);\r
+extern clib_bool empty_clib_heap( struct clib_heap *pHeap);\r
+extern void for_each_clib_heap ( struct clib_heap *pHeap, void (*fn)(void*));\r
+\r
+#endif
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_lib.h b/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_lib.h
new file mode 100644 (file)
index 0000000..890d9d4
--- /dev/null
@@ -0,0 +1,78 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#ifndef _C_LIB_H_\r
+#define _C_LIB_H_\r
+\r
+#include "c_errors.h"\r
+#include <stdlib.h>\r
+\r
+/* ------------------------------------------------------------------------*/\r
+/*       C O M M O N       D E F I N I T O N S                             */\r
+/* ------------------------------------------------------------------------*/\r
+\r
+typedef void (*clib_destroy)(void*);\r
+typedef int  (*clib_compare)(void*,void*);\r
+typedef void (*clib_traversal)( void*);\r
+\r
+typedef int  clib_error;\r
+typedef int  clib_bool;\r
+\r
+#define clib_black           0\r
+#define clib_red             1\r
+#define clib_true            1\r
+#define clib_false           0\r
+\r
+/* ------------------------------------------------------------------------*/\r
+/*                            P  A  I   R                                  */\r
+/* ------------------------------------------------------------------------*/\r
+\r
+struct clib_object {\r
+    void* raw_data;\r
+    size_t size;\r
+};\r
+\r
+#include "c_array.h"\r
+#include "c_deque.h"\r
+#include "c_rb.h"\r
+#include "c_set.h"\r
+#include "c_map.h"\r
+#include "c_slist.h"\r
+#include "c_map.h"\r
+#include "c_stack.h"\r
+#include "c_heap.h"\r
+\r
+/* ------------------------------------------------------------------------*/\r
+/*            H E L P E R       F U N C T I O N S                          */\r
+/* ------------------------------------------------------------------------*/\r
+\r
+extern void  clib_copy ( void *destination, void *source, size_t size );\r
+extern void  clib_get  ( void *destination, void *source, size_t size);\r
+extern char* clib_strdup ( char *ptr );\r
+\r
+extern struct clib_object* new_clib_object (void *inObject, size_t obj_size);\r
+extern clib_error get_raw_clib_object (struct clib_object *inObject, void**elem);\r
+extern void  delete_clib_object  (struct clib_object* inObject );\r
+extern void replace_raw_clib_object(struct clib_object* current_object,void *elem, size_t elem_size);\r
+\r
+#endif\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_map.h b/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_map.h
new file mode 100644 (file)
index 0000000..4d5ace9
--- /dev/null
@@ -0,0 +1,39 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#ifndef _C_MAP_H_\r
+#define _C_MAP_H_\r
+\r
+struct clib_map {\r
+    struct clib_rb* root;\r
+};\r
+\r
+\r
+extern struct clib_map* new_clib_map    ( clib_compare fn_clib_k, clib_destroy fn_k_d, clib_destroy fn_v_d);\r
+extern clib_error   insert_clib_map ( struct clib_map *pMap, void *key, size_t key_size, void *value,  size_t value_size);\r
+extern clib_bool    exists_clib_map ( struct clib_map *pMap, void *key);\r
+extern clib_error   remove_clib_map ( struct clib_map *pMap, void *key);\r
+extern clib_bool    find_clib_map   ( struct clib_map *pMap, void *key, void **value);\r
+extern clib_error   delete_clib_map ( struct clib_map *pMap);\r
+\r
+#endif
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_rb.h b/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_rb.h
new file mode 100644 (file)
index 0000000..4631c27
--- /dev/null
@@ -0,0 +1,54 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#ifndef _C_RB_H_\r
+#define _C_RB_H_\r
+\r
+struct clib_rb_node {\r
+    struct clib_rb_node *left;\r
+    struct clib_rb_node *right;\r
+    struct clib_rb_node *parent;\r
+    int color; \r
+    struct clib_object* key;\r
+    struct clib_object* value; \r
+};\r
+\r
+struct clib_rb {\r
+    struct clib_rb_node* root;\r
+    struct clib_rb_node sentinel;\r
+    clib_destroy destruct_k_fn;\r
+       clib_destroy destruct_v_fn;\r
+    clib_compare compare_fn;\r
+};\r
+\r
+extern struct clib_rb* new_clib_rb(clib_compare fn_c,clib_destroy fn_ed, clib_destroy fn_vd );\r
+extern clib_error  insert_clib_rb(struct clib_rb *pTree, void *key, size_t key_size, void *value, size_t value_size);\r
+extern struct clib_rb_node*   find_clib_rb (struct clib_rb *pTree, void *key);\r
+extern struct clib_rb_node* remove_clib_rb (struct clib_rb *pTree, void *key);\r
+extern clib_error  delete_clib_rb (struct clib_rb *pTree);\r
+extern clib_bool   empty_clib_rb  (struct clib_rb *pTree);\r
+\r
+extern struct clib_rb_node *minimum_clib_rb( struct clib_rb *pTree, struct clib_rb_node *x );\r
+extern struct clib_rb_node *maximum_clib_rb( struct clib_rb *pTree, struct clib_rb_node *x );\r
+\r
+#endif
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_set.h b/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_set.h
new file mode 100644 (file)
index 0000000..683ad0b
--- /dev/null
@@ -0,0 +1,38 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#ifndef _C_SET_H_\r
+#define _C_SET_H_\r
+\r
+struct clib_set {\r
+    struct clib_rb* root;\r
+};\r
+\r
+extern struct clib_set* new_clib_set( clib_compare fn_c, clib_destroy fn_d);\r
+extern clib_error   insert_clib_set ( struct clib_set *pSet, void *key, size_t key_size);\r
+extern clib_bool    exists_clib_set ( struct clib_set *pSet, void *key);\r
+extern clib_error   remove_clib_set ( struct clib_set *pSet, void *key);\r
+extern clib_bool    find_clib_set   ( struct clib_set *pSet, void *key, void* outKey);\r
+extern clib_error   delete_clib_set ( struct clib_set *pSet);\r
+\r
+#endif
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_slist.h b/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_slist.h
new file mode 100644 (file)
index 0000000..cbb6ab4
--- /dev/null
@@ -0,0 +1,49 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#ifndef _C_SLIST_H_\r
+#define _C_SLIST_H_\r
+\r
+struct clib_slist_node {\r
+    struct clib_object* elem;\r
+    struct clib_slist_node *next;\r
+};\r
+\r
+struct clib_slist {\r
+    struct clib_slist_node* head;\r
+    clib_destroy destruct_fn;\r
+    clib_compare compare_fn;\r
+    int size;\r
+};\r
+\r
+\r
+extern struct clib_slist* new_clib_slist(clib_destroy fn_d, clib_compare fn_c);\r
+extern void           delete_clib_slist   (struct clib_slist *pSlist);\r
+extern clib_error     insert_clib_slist   (struct clib_slist *pSlist, int pos, void *elem, size_t elem_size);\r
+extern clib_error     push_back_clib_slist(struct clib_slist *pSlist, void *elem, size_t elem_size);\r
+extern void           remove_clib_slist   (struct clib_slist *pSlist, int pos);\r
+extern void           for_each_clib_slist (struct clib_slist *pSlist, void (*fn)(void* ));\r
+extern clib_bool      find_clib_slist     (struct clib_slist *pSlist, void* find_value, void**out_value);\r
+\r
+\r
+#endif
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_stack.h b/junkcode/dongre.avinash@gmail.com-clibutils/inc/c_stack.h
new file mode 100644 (file)
index 0000000..e96c8ca
--- /dev/null
@@ -0,0 +1,37 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+#ifndef _C_STACK_H\r
+#define _C_STACK_H\r
+\r
+struct clib_stack {\r
+       struct clib_array *pStackArr;\r
+};\r
+\r
+extern struct clib_stack *new_clib_stack( int default_size, clib_destroy fn_d);\r
+extern void delete_clib_stack(struct clib_stack *pStack);\r
+extern void push_clib_stack(struct clib_stack *pStack, void *elem, size_t elem_size);\r
+extern void pop_clib_stack(struct clib_stack *pStack, void **elem);\r
+extern clib_bool empty_clib_stack ( struct clib_stack *pStack);\r
+\r
+\r
+#endif
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/src/Makefile b/junkcode/dongre.avinash@gmail.com-clibutils/src/Makefile
new file mode 100644 (file)
index 0000000..c37e3f4
--- /dev/null
@@ -0,0 +1,21 @@
+P_NAME          :=  libclibutils.a
+P_C_SRCS        :=  $(wildcard *.c)
+P_C_OBJS        :=  ${P_C_SRCS:.c=.o}
+P_OBJS          :=  $(P_C_OBJS) 
+P_INCLUDE_DIRS  :=  ../inc
+CPPFLAGS        +=  $(foreach includedir,$(P_INCLUDE_DIRS),-I$(includedir))
+LDFLAGS         +=  $(foreach librarydir,$(P_LIBRARY_DIRS),-L$(librarydir))
+LDFLAGS         +=  $(foreach library,$(P_LIBRARIES),-l$(library))
+CXX             :=  gcc
+CC              :=  gcc -g -Wall -Wextra -Wparentheses -pedantic
+
+.PHONY:         all clean
+all:            $(P_NAME)
+$(P_NAME):      $(P_OBJS)
+               ar rcs $(P_NAME) $(P_OBJS)
+clean:
+               @- $(RM) $(P_NAME)
+               @- $(RM) $(P_OBJS)
+               @- $(RM) core*
+               @- $(RM) tags
+
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/src/c_array.c b/junkcode/dongre.avinash@gmail.com-clibutils/src/c_array.c
new file mode 100644 (file)
index 0000000..f30de02
--- /dev/null
@@ -0,0 +1,232 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+#include <string.h>\r
+#include <stdio.h>\r
+\r
+\r
+static struct clib_array* \r
+array_check_and_grow ( struct clib_array* pArray) {\r
+    if ( pArray->no_of_elements >= pArray->no_max_elements ) {\r
+        pArray->no_max_elements  = 2 * pArray->no_max_elements;\r
+        pArray->pElements        = (struct clib_object**) realloc ( pArray->pElements, \r
+                                      pArray->no_max_elements * sizeof ( struct clib_object*));\r
+    }\r
+    return pArray;\r
+}\r
+\r
+struct clib_array* \r
+new_clib_array(int array_size, clib_compare fn_c, clib_destroy fn_d) {\r
+\r
+    struct clib_array* pArray = (struct clib_array*)malloc(sizeof(struct clib_array));\r
+    if ( ! pArray )\r
+        return (struct clib_array*)0;\r
+\r
+    pArray->no_max_elements = array_size < 8 ? 8 : array_size;\r
+    pArray->pElements = (struct clib_object**) malloc(pArray->no_max_elements * sizeof(struct clib_object*));\r
+    if ( ! pArray->pElements ){\r
+        free ( pArray );\r
+        return (struct clib_array*)0;\r
+    }\r
+    pArray->compare_fn      = fn_c;\r
+    pArray->destruct_fn     = fn_d;\r
+    pArray->no_of_elements  = 0;\r
+\r
+    return pArray;\r
+}\r
+\r
+static clib_error \r
+insert_clib_array ( struct clib_array* pArray, int index, void *elem, size_t elem_size) {\r
+\r
+    clib_error rc           = CLIB_ERROR_SUCCESS;\r
+    struct clib_object* pObject = new_clib_object ( elem, elem_size );\r
+    if ( ! pObject )\r
+        return CLIB_ARRAY_INSERT_FAILED;\r
+\r
+    pArray->pElements[index] = pObject;\r
+    pArray->no_of_elements++;\r
+    return rc;\r
+}\r
+\r
+clib_error \r
+push_back_clib_array (struct clib_array* pArray, void *elem, size_t elem_size) {\r
+    clib_error rc = CLIB_ERROR_SUCCESS;        \r
+\r
+    if ( ! pArray)\r
+        return CLIB_ARRAY_NOT_INITIALIZED;\r
+\r
+    array_check_and_grow ( pArray);\r
+\r
+    rc = insert_clib_array( pArray, pArray->no_of_elements, elem, elem_size);\r
+\r
+    return rc;\r
+}\r
+\r
+clib_error \r
+element_at_clib_array (struct clib_array* pArray, int index, void** elem) {\r
+    clib_error rc = CLIB_ERROR_SUCCESS;\r
+\r
+    if ( ! pArray )\r
+        return CLIB_ARRAY_NOT_INITIALIZED;\r
+\r
+       if ( index < 0 || index >= pArray->no_of_elements )\r
+        return CLIB_ARRAY_INDEX_OUT_OF_BOUND;\r
+\r
+    get_raw_clib_object ( pArray->pElements[index], elem );\r
+    return rc;\r
+}\r
+\r
+int\r
+size_clib_array ( struct clib_array* pArray ) {\r
+       if ( pArray == (struct clib_array*)0 )\r
+               return 0;\r
+       return pArray->no_of_elements;\r
+}\r
+\r
+int\r
+capacity_clib_array ( struct clib_array* pArray ) {\r
+       if ( pArray == (struct clib_array*)0 )\r
+               return 0;\r
+       return pArray->no_max_elements;\r
+}\r
+\r
+clib_bool  \r
+empty_clib_array ( struct clib_array* pArray) {\r
+       if ( pArray == (struct clib_array*)0 )\r
+               return 0;\r
+       if ( pArray->no_of_elements == 0 )\r
+               return clib_true;\r
+       else\r
+               return clib_false;\r
+}\r
+\r
+clib_error \r
+reserve_clib_array ( struct clib_array* pArray, int new_size) {\r
+       if ( pArray == (struct clib_array*)0 )\r
+               return CLIB_ARRAY_NOT_INITIALIZED;\r
+\r
+       if ( new_size <= pArray->no_max_elements )\r
+               return CLIB_ERROR_SUCCESS;\r
+\r
+       array_check_and_grow ( pArray);\r
+       return CLIB_ERROR_SUCCESS;\r
+\r
+}\r
+\r
+clib_error \r
+front_clib_array ( struct clib_array* pArray,void *elem) {\r
+    return element_at_clib_array ( pArray, 0, elem );\r
+}\r
+\r
+clib_error \r
+back_clib_array ( struct clib_array* pArray,void *elem) {\r
+    return element_at_clib_array ( pArray, pArray->no_of_elements - 1, elem );\r
+}\r
+\r
+clib_error \r
+insert_at_clib_array ( struct clib_array* pArray, int index, void *elem, size_t elem_size) {\r
+    clib_error rc = CLIB_ERROR_SUCCESS;\r
+    if ( ! pArray )\r
+        return CLIB_ARRAY_NOT_INITIALIZED;\r
+\r
+    if ( index < 0 || index > pArray->no_max_elements )\r
+        return CLIB_ARRAY_INDEX_OUT_OF_BOUND;\r
+\r
+    array_check_and_grow ( pArray);\r
+\r
+    memmove ( &(pArray->pElements[index + 1]),\r
+              &pArray->pElements[index],\r
+              (pArray->no_of_elements - index ) * sizeof(struct clib_object*));\r
+\r
+    rc = insert_clib_array ( pArray, index, elem , elem_size);\r
+\r
+    return rc;\r
+}\r
+\r
+clib_error     \r
+remove_clib_array ( struct clib_array* pArray, int index) {\r
+    clib_error   rc = CLIB_ERROR_SUCCESS;\r
+\r
+    if ( ! pArray )\r
+        return rc;\r
+       if ( index < 0 || index >= pArray->no_of_elements )\r
+        return CLIB_ARRAY_INDEX_OUT_OF_BOUND;\r
+\r
+    if ( pArray->destruct_fn ) {\r
+        void *elem;\r
+        if ( CLIB_ERROR_SUCCESS == element_at_clib_array ( pArray, index , &elem ) ) {\r
+            pArray->destruct_fn(elem);\r
+        }\r
+    }\r
+    delete_clib_object ( pArray->pElements[index]);\r
+\r
+       if ( index != pArray->no_of_elements - 1 ) {\r
+           memmove ( &(pArray->pElements[index]),\r
+                         &pArray->pElements[index + 1],\r
+                             (pArray->no_of_elements - index ) * sizeof(struct clib_object*));\r
+       }\r
+    pArray->no_of_elements--;\r
+    return rc;\r
+}\r
+\r
+clib_error \r
+delete_clib_array( struct clib_array* pArray) {\r
+    clib_error rc = CLIB_ERROR_SUCCESS;\r
+    int i = 0;\r
+\r
+    if ( pArray == (struct clib_array*)0 )\r
+        return rc;\r
+\r
+    if ( pArray->destruct_fn ) {\r
+        for ( i = 0; i < pArray->no_of_elements; i++) {\r
+            void *elem;\r
+            if ( CLIB_ERROR_SUCCESS == element_at_clib_array ( pArray, i , &elem ) )\r
+                pArray->destruct_fn(elem);\r
+        }\r
+    }\r
+    for ( i = 0; i < pArray->no_of_elements; i++) \r
+        delete_clib_object ( pArray->pElements[i]);    \r
+\r
+    free ( pArray->pElements);\r
+    free ( pArray );\r
+    return rc;\r
+}\r
+\r
+void \r
+swap_element_clib_array ( struct clib_array *pArray, int left, int right) {\r
+       struct clib_object *temp = pArray->pElements[left];\r
+       pArray->pElements[left] = pArray->pElements[right];\r
+       pArray->pElements[right] = temp;\r
+}\r
+\r
+void for_each_clib_array ( struct clib_array *pArray, void (*fn)(void*)) {\r
+       int size = pArray->no_of_elements;\r
+       int i = 0;\r
+       for ( i = 0; i < size; i++ ) {\r
+               void *elem;\r
+               element_at_clib_array ( pArray, i , &elem);\r
+               (fn)(elem);\r
+               free ( elem );\r
+       }\r
+}
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/src/c_deque.c b/junkcode/dongre.avinash@gmail.com-clibutils/src/c_deque.c
new file mode 100644 (file)
index 0000000..fc5e54f
--- /dev/null
@@ -0,0 +1,218 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+\r
+#include <string.h>\r
+\r
+#define CLIB_DEQUE_INDEX(x)  ((char *)(pDeq)->pElements + (sizeof(struct clib_object) * (x)))\r
+\r
+static clib_error \r
+insert_clib_deque ( struct clib_deque *pDeq, int index, void *elem,size_t elem_size) {\r
+    clib_error rc           = CLIB_ERROR_SUCCESS;\r
+    struct clib_object* pObject = new_clib_object ( elem, elem_size );\r
+    if ( ! pObject )\r
+        return CLIB_ARRAY_INSERT_FAILED;\r
+\r
+    pDeq->pElements[index] = pObject;\r
+    pDeq->no_of_elements++;\r
+    return rc;\r
+}\r
+\r
+static struct clib_deque*\r
+grow_deque ( struct clib_deque *pDeq ) {\r
+\r
+       pDeq->no_max_elements = pDeq->no_max_elements * 2;\r
+    pDeq->pElements        = (struct clib_object**) realloc ( pDeq->pElements, \r
+                                 pDeq->no_max_elements * sizeof ( struct clib_object*));\r
+    return pDeq;\r
+\r
+}\r
+struct clib_deque*  \r
+new_clib_deque( int deq_size , clib_compare fn_c, clib_destroy fn_d) {\r
+\r
+    struct clib_deque *pDeq = (struct clib_deque*)malloc(sizeof(struct clib_deque));\r
+       if ( pDeq == (struct clib_deque*)0 )\r
+               return (struct clib_deque*)0;\r
+\r
+    pDeq->no_max_elements  = deq_size < 8 ? 8 : deq_size;\r
+    pDeq->pElements = (struct clib_object**) malloc(pDeq->no_max_elements * sizeof(struct clib_object*));\r
+\r
+       if ( pDeq == (struct clib_deque*)0 )\r
+               return (struct clib_deque*)0;\r
+\r
+    pDeq->compare_fn      = fn_c;\r
+    pDeq->destruct_fn     = fn_d;\r
+    pDeq->head            = (int)pDeq->no_max_elements / 2;\r
+    pDeq->tail            = pDeq->head + 1;\r
+    pDeq->no_of_elements  = 0;    \r
+\r
+    return pDeq;\r
+}\r
+clib_error \r
+push_back_clib_deque(struct clib_deque *pDeq, void *elem, size_t elem_size) {\r
+       if ( pDeq == (struct clib_deque*)0 )\r
+               return CLIB_DEQUE_NOT_INITIALIZED;\r
+\r
+    if ( pDeq->tail == pDeq->no_max_elements )\r
+        pDeq = grow_deque(pDeq);\r
+\r
+    insert_clib_deque(pDeq, pDeq->tail, elem, elem_size);\r
+    pDeq->tail++;\r
+\r
+    return CLIB_ERROR_SUCCESS;\r
+}\r
+clib_error \r
+push_front_clib_deque(struct clib_deque *pDeq, void *elem,size_t elem_size) {\r
+    clib_error rc = CLIB_ERROR_SUCCESS;        \r
+    int to        = 0;\r
+    int from      = 0;\r
+    int count     = 0;\r
+\r
+    if ( pDeq->head == 0 ) {\r
+        pDeq = grow_deque(pDeq);\r
+        to    = (pDeq->no_max_elements - pDeq->no_of_elements)/2;\r
+        from  = pDeq->head + 1;\r
+        count = pDeq->tail - from + 1;\r
+        memmove (&(pDeq->pElements[to]), &(pDeq->pElements[from]), count * sizeof (struct clib_object*));\r
+        pDeq->head = to - 1;\r
+        pDeq->tail  = pDeq->head + count;\r
+    }\r
+    insert_clib_deque(pDeq, pDeq->head, elem, elem_size);\r
+    pDeq->head--;\r
+    return rc;\r
+}\r
+\r
+clib_error     \r
+front_clib_deque (struct clib_deque *pDeq, void *elem) {\r
+       if ( pDeq == (struct clib_deque*)0 )\r
+               return CLIB_DEQUE_NOT_INITIALIZED;\r
+    element_at_clib_deque ( pDeq, pDeq->head + 1, elem );\r
+    return CLIB_ERROR_SUCCESS;\r
+}\r
+\r
+clib_error \r
+back_clib_deque (struct clib_deque *pDeq, void *elem) {\r
+       if ( pDeq == (struct clib_deque*)0 )\r
+               return CLIB_DEQUE_NOT_INITIALIZED;\r
+    element_at_clib_deque ( pDeq, pDeq->tail - 1, elem );\r
+    return CLIB_ERROR_SUCCESS;\r
+}\r
+\r
+clib_error     \r
+pop_back_clib_deque (struct clib_deque *pDeq) {\r
+       if ( pDeq == (struct clib_deque*)0 )\r
+               return CLIB_DEQUE_NOT_INITIALIZED;\r
+\r
+    if ( pDeq->destruct_fn ) {\r
+        void *elem;\r
+        if ( element_at_clib_deque( pDeq, pDeq->tail - 1, &elem ) == CLIB_ERROR_SUCCESS ) \r
+            pDeq->destruct_fn(elem);\r
+    }\r
+    delete_clib_object(pDeq->pElements[pDeq->tail - 1]);\r
+    pDeq->tail--;\r
+    pDeq->no_of_elements--;\r
+\r
+    return CLIB_ERROR_SUCCESS;\r
+\r
+}\r
+\r
+clib_error     \r
+pop_front_clib_deque(struct clib_deque *pDeq) {\r
+    \r
+       if ( pDeq == (struct clib_deque*)0 )\r
+               return CLIB_DEQUE_NOT_INITIALIZED;\r
+\r
+    if ( pDeq->destruct_fn ) {\r
+        void *elem;\r
+        if ( element_at_clib_deque( pDeq, pDeq->head + 1, &elem ) == CLIB_ERROR_SUCCESS ) \r
+            pDeq->destruct_fn(elem);\r
+    }\r
+    delete_clib_object(pDeq->pElements[pDeq->head + 1]);\r
+\r
+    pDeq->head++;\r
+    pDeq->no_of_elements--;\r
+\r
+    return CLIB_ERROR_SUCCESS;\r
+}\r
+clib_bool      \r
+empty_clib_deque (struct clib_deque *pDeq) {\r
+       if ( pDeq == (struct clib_deque*)0 )\r
+               return clib_true;\r
+\r
+    return pDeq->no_of_elements == 0 ? clib_true : clib_false;\r
+}\r
+int \r
+size_clib_deque( struct clib_deque *pDeq ) {\r
+       if ( pDeq == (struct clib_deque*)0 )\r
+               return clib_true;\r
+\r
+    return pDeq->no_of_elements - 1;\r
+}\r
+\r
+clib_error \r
+element_at_clib_deque (struct clib_deque *pDeq, int index, void**elem) {\r
+\r
+    clib_error rc = CLIB_ERROR_SUCCESS;\r
+\r
+    if ( ! pDeq )\r
+        return CLIB_DEQUE_NOT_INITIALIZED;\r
+\r
+    get_raw_clib_object ( pDeq->pElements[index], elem );\r
+    return rc;\r
+}\r
+\r
+clib_error\r
+delete_clib_deque ( struct clib_deque *pDeq ) {\r
+    int i = 0;\r
+\r
+       if ( pDeq == (struct clib_deque*)0 )\r
+               return CLIB_ERROR_SUCCESS;\r
+\r
+    if ( pDeq->destruct_fn ) {\r
+        for ( i = pDeq->head + 1; i < pDeq->tail; i++ ){\r
+            void *elem;\r
+            if ( element_at_clib_deque( pDeq, i, &elem ) == CLIB_ERROR_SUCCESS ) {\r
+                pDeq->destruct_fn(elem);\r
+            }\r
+        }\r
+    }\r
+    for ( i = pDeq->head + 1; i < pDeq->tail; i++ ){\r
+        delete_clib_object(pDeq->pElements[i]);\r
+    }\r
+    free ( pDeq->pElements);\r
+    free ( pDeq );\r
+\r
+    return CLIB_ERROR_SUCCESS;\r
+}\r
+void \r
+for_each_clib_deque ( struct clib_deque *pDeq, void (*fn)(void*)) {\r
+       int index = 0;\r
+       for ( index = pDeq->head + 1; index < pDeq->tail; index++ ){\r
+               void *elem;\r
+               if ( element_at_clib_deque( pDeq, index, &elem ) == CLIB_ERROR_SUCCESS ) {\r
+                       (fn)(elem);\r
+                       free ( elem );\r
+               }\r
+       }\r
+}\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/src/c_heap.c b/junkcode/dongre.avinash@gmail.com-clibutils/src/c_heap.c
new file mode 100644 (file)
index 0000000..f29e5cf
--- /dev/null
@@ -0,0 +1,175 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+#include "c_lib.h"\r
+\r
+static int\r
+pvt_clib_heap_isLeaf( int pos , struct clib_heap *pHeap) { \r
+       return ( pos >= (pHeap->pHeapPtr->no_of_elements/2)) && ( pos < pHeap->pHeapPtr->no_of_elements );\r
+}\r
+\r
+static int \r
+pvt_clib_heap_leftchild( int pos ) {\r
+      return 2 * pos + 1;            \r
+}\r
+\r
+static int\r
+pvt_clib_heap_compare(struct clib_array *pArray, int lIndex , int rIndex) {\r
+       void *left         =  (void*)0;\r
+       void *right        = (void*)0;\r
+       int compare_result = 0;\r
+       clib_error rc      = 0;\r
+       rc = element_at_clib_array ( pArray, lIndex , &left);\r
+       rc = element_at_clib_array ( pArray, rIndex , &right);\r
+       compare_result =  pArray->compare_fn ( left, right );\r
+       if ( left ) free ( left );\r
+       if ( right ) free ( right );\r
+       return compare_result;\r
+}\r
+\r
+static void\r
+pvt_clib_heap_siftdown_max( struct clib_heap *pHeap, int pos ) {\r
+\r
+       struct clib_array *pArray = pHeap->pHeapPtr;\r
+       int n = pArray->no_of_elements;\r
+\r
+       while ( !pvt_clib_heap_isLeaf(pos, pHeap) ) {\r
+               int j = pvt_clib_heap_leftchild( pos );\r
+               if ( ( j < ( n - 1) )  &&  \r
+                       (pvt_clib_heap_compare( pArray, j, j+1) == -1)) {\r
+                       j++;\r
+               }\r
+               if ( pvt_clib_heap_compare( pArray, pos, j ) == 1 || \r
+                        pvt_clib_heap_compare( pArray, pos, j ) == 0) return;\r
+\r
+               swap_element_clib_array(pArray, pos, j);\r
+               pos = j;\r
+       }\r
+}\r
+\r
+static void\r
+pvt_clib_heap_siftdown_min( struct clib_heap *pHeap, int pos ) {\r
+\r
+       struct clib_array *pArray = pHeap->pHeapPtr;\r
+       int n = pArray->no_of_elements;\r
+\r
+       while ( !pvt_clib_heap_isLeaf(pos, pHeap) ) {\r
+               int j = pvt_clib_heap_leftchild( pos );\r
+               if ( ( j < ( n - 1) )  &&  \r
+                       (pvt_clib_heap_compare( pArray, j, j+1) == 1)) {\r
+                       j++;\r
+               }\r
+               if ( pvt_clib_heap_compare( pArray, pos, j ) == -1 || \r
+                        pvt_clib_heap_compare( pArray, pos, j ) == 0) return;\r
+\r
+               swap_element_clib_array(pArray, pos, j);\r
+               pos = j;\r
+       }\r
+}\r
+\r
+struct clib_heap *\r
+new_clib_heap( int default_size, clib_compare fn_c, clib_destroy fn_d ) {\r
+       struct clib_heap *pHeap = ( struct clib_heap *) malloc ( sizeof ( struct clib_heap ));\r
+       pHeap->pHeapPtr =  new_clib_array ( default_size, fn_c, fn_d);\r
+       pHeap->heap_left = 0;\r
+       pHeap->heap_parent = 0;\r
+       pHeap->heap_right = 0;\r
+       return pHeap;\r
+}\r
+\r
+void \r
+delete_clib_heap( struct clib_heap *pHeap) {\r
+       delete_clib_array ( pHeap->pHeapPtr );\r
+       free ( pHeap );\r
+}\r
+\r
+void \r
+insert_clib_heap ( struct clib_heap *pHeap, void *elem, size_t elem_size) {\r
+       push_back_clib_array ( pHeap->pHeapPtr, elem, elem_size);\r
+}\r
+\r
+void\r
+build_max_clib_heap ( struct clib_heap *pHeap ) {\r
+       int i = 0;\r
+       for (  i = (pHeap->pHeapPtr->no_of_elements / 2 ) - 1; i >= 0; i--) {\r
+               pvt_clib_heap_siftdown_max(pHeap, i);\r
+       }\r
+}\r
+void *\r
+extract_max_clib_heap( struct clib_heap *pHeap) {\r
+       void *elem;\r
+       swap_element_clib_array(pHeap->pHeapPtr, \r
+                                   0,\r
+                                                       pHeap->pHeapPtr->no_of_elements - 1);\r
+\r
+       back_clib_array( pHeap->pHeapPtr, &elem);\r
+       remove_clib_array ( pHeap->pHeapPtr, pHeap->pHeapPtr->no_of_elements - 1 );\r
+\r
+       if (pHeap->pHeapPtr->no_of_elements != 0) {\r
+               pvt_clib_heap_siftdown_max(pHeap, 0);\r
+       }\r
+\r
+       return elem;\r
+}\r
+\r
+void\r
+build_min_clib_heap ( struct clib_heap *pHeap ) {\r
+       int i = 0;\r
+       for (  i = (pHeap->pHeapPtr->no_of_elements / 2 ) - 1; i >= 0; i--) {\r
+               pvt_clib_heap_siftdown_min(pHeap, i);\r
+       }\r
+}\r
+\r
+void *\r
+extract_min_clib_heap( struct clib_heap *pHeap) {\r
+       void *elem;\r
+       swap_element_clib_array(pHeap->pHeapPtr, \r
+                                   0,\r
+                                                       pHeap->pHeapPtr->no_of_elements - 1);\r
+\r
+       back_clib_array( pHeap->pHeapPtr, &elem);\r
+       remove_clib_array ( pHeap->pHeapPtr, pHeap->pHeapPtr->no_of_elements - 1 );\r
+\r
+       if (pHeap->pHeapPtr->no_of_elements != 0) {\r
+               pvt_clib_heap_siftdown_min(pHeap, 0);\r
+       }\r
+       return elem;\r
+}\r
+clib_bool      \r
+empty_clib_heap ( struct clib_heap *pHeap) {\r
+       if ( pHeap == ( struct clib_heap*)0 )\r
+               return clib_true;\r
+\r
+       return pHeap->pHeapPtr->no_of_elements == 0 ? clib_true : clib_false;\r
+}\r
+\r
+\r
+void for_each_clib_heap ( struct clib_heap *pHeap, void (*fn)(void*)) {\r
+       int size = size_clib_array ( pHeap->pHeapPtr );\r
+       int i = 0;\r
+       for ( i = 0; i < size; i++ ) {\r
+               void *elem;\r
+               element_at_clib_array ( pHeap->pHeapPtr, i , &elem);\r
+               (fn)(elem);\r
+               free ( elem );\r
+       }\r
+}\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/src/c_map.c b/junkcode/dongre.avinash@gmail.com-clibutils/src/c_map.c
new file mode 100644 (file)
index 0000000..443149d
--- /dev/null
@@ -0,0 +1,117 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+\r
+#include <stdio.h>\r
+\r
+\r
+struct clib_map* \r
+new_clib_map ( clib_compare fn_clib_k, clib_destroy fn_k_d,  \r
+            clib_destroy fn_v_d) {\r
+\r
+    struct clib_map *pMap  =  (struct clib_map*)malloc(sizeof(struct clib_map));\r
+    if (pMap == (struct clib_map*)0)\r
+        return (struct clib_map*)0;\r
+\r
+    pMap->root  = new_clib_rb (fn_clib_k, fn_k_d, fn_v_d);\r
+    if (pMap->root == (struct clib_rb*)0)\r
+        return (struct clib_map*)0;\r
+\r
+    return pMap;\r
+}\r
+clib_error   \r
+insert_clib_map ( struct clib_map *pMap, void *key, size_t key_size, void *value,  size_t value_size) {\r
+    if (pMap == (struct clib_map*)0)\r
+        return CLIB_MAP_NOT_INITIALIZED;\r
+\r
+    return insert_clib_rb ( pMap->root, key, key_size, value, value_size);\r
+}\r
+clib_bool    \r
+exists_clib_map ( struct clib_map *pMap, void *key) {\r
+    clib_bool found = clib_false;\r
+    struct clib_rb_node* node;\r
+\r
+    if (pMap == (struct clib_map*)0)\r
+        return clib_false;\r
+    \r
+    node = find_clib_rb ( pMap->root, key);\r
+    if ( node != (struct clib_rb_node*)0  ) {\r
+        return clib_true;\r
+    }\r
+    return found;    \r
+}\r
+clib_error   \r
+remove_clib_map ( struct clib_map *pMap, void *key) {\r
+    clib_error rc = CLIB_ERROR_SUCCESS;\r
+    struct clib_rb_node* node;\r
+    if (pMap == (struct clib_map*)0)\r
+        return CLIB_MAP_NOT_INITIALIZED;\r
+\r
+    node = remove_clib_rb ( pMap->root, key );\r
+    if ( node != (struct clib_rb_node*)0  ) {\r
+        void* removed_node;\r
+        get_raw_clib_object ( node->key, &removed_node );\r
+        free ( removed_node);\r
+        delete_clib_object ( node->key );\r
+\r
+        get_raw_clib_object ( node->value, &removed_node );\r
+        free ( removed_node);\r
+        delete_clib_object ( node->value);\r
+\r
+        free ( node );\r
+    }\r
+    return rc;\r
+}\r
+clib_bool    \r
+find_clib_map ( struct clib_map *pMap, void *key, void **value) {\r
+    struct clib_rb_node* node;\r
+\r
+    if (pMap == (struct clib_map*)0)\r
+        return clib_false;\r
+\r
+    node = find_clib_rb ( pMap->root, key);\r
+    if ( node == (struct clib_rb_node*)0  ) \r
+        return clib_false;\r
+\r
+    get_raw_clib_object ( node->value, value );\r
+\r
+    return clib_true;\r
+\r
+}\r
+\r
+clib_error    \r
+delete_clib_map ( struct clib_map* x) {\r
+    clib_error rc = CLIB_ERROR_SUCCESS;\r
+    if ( x != (struct clib_map*)0 ){\r
+        rc = delete_clib_rb ( x->root );\r
+        free ( x );\r
+    }\r
+    return rc;\r
+}\r
+\r
+static struct clib_rb_node *\r
+minimum_clib_map( struct clib_map *x ) {\r
+       return minimum_clib_rb( x->root, x->root->root);\r
+}\r
+\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/src/c_rb.c b/junkcode/dongre.avinash@gmail.com-clibutils/src/c_rb.c
new file mode 100644 (file)
index 0000000..14b2843
--- /dev/null
@@ -0,0 +1,500 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <assert.h>\r
+\r
+#define rb_sentinel &pTree->sentinel\r
+\r
+static void debug_verify_properties(struct clib_rb*);\r
+static void debug_verify_property_1(struct clib_rb*,struct clib_rb_node*);\r
+static void debug_verify_property_2(struct clib_rb*,struct clib_rb_node*);\r
+static int debug_node_color(struct clib_rb*,struct clib_rb_node* n);\r
+static void debug_verify_property_4(struct clib_rb*,struct clib_rb_node*);\r
+static void debug_verify_property_5(struct clib_rb*,struct clib_rb_node*);\r
+static void debug_verify_property_5_helper(struct clib_rb*,struct clib_rb_node*,int,int*);\r
+\r
+\r
+static void\r
+pvt_left_rotate(struct clib_rb *pTree, struct clib_rb_node *x){\r
+    struct clib_rb_node *y;\r
+    y = x->right;\r
+    x->right = y->left;\r
+    if (y->left != rb_sentinel)\r
+        y->left->parent = x;\r
+    if (y != rb_sentinel)\r
+        y->parent = x->parent;\r
+    if (x->parent){\r
+        if (x == x->parent->left)\r
+            x->parent->left = y;\r
+        else\r
+            x->parent->right = y;\r
+    }\r
+    else\r
+        pTree->root = y;\r
+    y->left = x;\r
+    if (x != rb_sentinel)\r
+        x->parent = y;\r
+}\r
+static void\r
+pvt_right_rotate(struct clib_rb *pTree, struct clib_rb_node *x) {\r
+    struct clib_rb_node *y = x->left;\r
+    x->left = y->right;\r
+    if (y->right != rb_sentinel)\r
+        y->right->parent = x;\r
+    if (y != rb_sentinel)\r
+        y->parent = x->parent;\r
+    if (x->parent) {\r
+        if (x == x->parent->right)\r
+            x->parent->right = y;\r
+        else\r
+            x->parent->left = y;\r
+    }\r
+    else\r
+        pTree->root = y;\r
+    y->right = x;\r
+    if (x != rb_sentinel)\r
+        x->parent = y;\r
+}\r
+\r
+struct clib_rb*\r
+new_clib_rb(clib_compare fn_c,clib_destroy fn_ed, clib_destroy fn_vd ){\r
+\r
+    struct clib_rb *pTree = (struct clib_rb*)malloc(sizeof(struct clib_rb));\r
+    if ( pTree == (struct clib_rb*)0 )\r
+        return (struct clib_rb*)0;\r
+\r
+    pTree->compare_fn           = fn_c;\r
+    pTree->destruct_k_fn        = fn_ed;\r
+    pTree->destruct_v_fn        = fn_vd;\r
+    pTree->root                 = rb_sentinel;\r
+    pTree->sentinel.left        = rb_sentinel;\r
+    pTree->sentinel.right       = rb_sentinel;\r
+    pTree->sentinel.parent      = (struct clib_rb_node*)0 ;\r
+    pTree->sentinel.color       = clib_black;\r
+\r
+    return pTree;\r
+}\r
+static void\r
+pvt_rb_insert_fixup( struct clib_rb *pTree, struct clib_rb_node *x ) {\r
+    while (x != pTree->root && x->parent->color == clib_red) {\r
+        if (x->parent == x->parent->parent->left) {\r
+            struct clib_rb_node *y = x->parent->parent->right;\r
+            if (y->color == clib_red) {\r
+                x->parent->color         = clib_black;\r
+                y->color                 = clib_black;\r
+                x->parent->parent->color = clib_red;\r
+                x = x->parent->parent;\r
+            } else {\r
+                if (x == x->parent->right){\r
+                    x = x->parent;\r
+                    pvt_left_rotate (pTree, x);\r
+                }\r
+                x->parent->color         = clib_black;\r
+                x->parent->parent->color = clib_red;\r
+                pvt_right_rotate (pTree, x->parent->parent);\r
+            }\r
+        } else {\r
+            struct clib_rb_node *y = x->parent->parent->left;\r
+            if (y->color == clib_red) {\r
+                x->parent->color         = clib_black;\r
+                y->color                 = clib_black;\r
+                x->parent->parent->color = clib_red;\r
+                x = x->parent->parent;\r
+            } else {\r
+                if (x == x->parent->left) {\r
+                    x = x->parent;\r
+                    pvt_right_rotate (pTree, x);\r
+                }\r
+                x->parent->color         = clib_black;\r
+                x->parent->parent->color = clib_red;\r
+                pvt_left_rotate (pTree, x->parent->parent);\r
+            }\r
+        }\r
+    }\r
+    pTree->root->color = clib_black;\r
+}\r
+struct clib_rb_node*   \r
+find_clib_rb (struct clib_rb *pTree, void *key) {\r
+    struct clib_rb_node *x = pTree->root;\r
+\r
+    while (x != rb_sentinel) {\r
+        int c = 0;\r
+        void *cur_key ;\r
+        get_raw_clib_object ( x->key, &cur_key );\r
+        c = pTree->compare_fn (key, cur_key);\r
+        free ( cur_key );\r
+        if (c == 0) {\r
+            break;\r
+        } else {\r
+            x = c < 0 ? x->left : x->right;\r
+        }\r
+    }\r
+    if ( x == rb_sentinel )\r
+        return (struct clib_rb_node*)0 ;\r
+\r
+    return x;\r
+}\r
+\r
+clib_error  \r
+insert_clib_rb(struct clib_rb *pTree, void *k, size_t key_size, void *v, size_t value_size) {\r
+\r
+    clib_error rc = CLIB_ERROR_SUCCESS;\r
+    struct clib_rb_node *x;\r
+       struct clib_rb_node *y;\r
+       struct clib_rb_node *z;\r
+\r
+    x = (struct clib_rb_node*)malloc (sizeof(struct clib_rb_node));\r
+    if ( x == (struct clib_rb_node*)0  ) \r
+        return CLIB_ERROR_MEMORY;\r
+\r
+    x->left    = rb_sentinel;\r
+    x->right   = rb_sentinel;\r
+    x->color   = clib_red;\r
+\r
+    x->key     = new_clib_object ( k, key_size );\r
+    if ( v ) {\r
+        x->value   = new_clib_object ( v, value_size );\r
+    } else {\r
+        x->value =  (struct clib_object*)0;\r
+    }\r
+\r
+    y = pTree->root;\r
+    z = (struct clib_rb_node*)0 ;\r
+\r
+    while (y != rb_sentinel) {\r
+        int c = 0;\r
+        void *cur_key;\r
+               void* new_key;\r
+\r
+        get_raw_clib_object ( y->key, &cur_key );\r
+        get_raw_clib_object ( x->key, &new_key );\r
+\r
+        c = (pTree->compare_fn) ( new_key , cur_key);\r
+        free ( cur_key );\r
+        free ( new_key );\r
+        if (c == 0) {\r
+            /* TODO : Delete node here */\r
+            return CLIB_RBTREE_KEY_DUPLICATE;\r
+        }\r
+        z = y;\r
+        if ( c < 0 )\r
+            y = y->left;\r
+        else\r
+            y = y->right;\r
+    }    \r
+    x->parent = z;\r
+    if (z) {\r
+        int c = 0;\r
+        void *cur_key;\r
+               void* new_key;\r
+        get_raw_clib_object ( z->key, &cur_key );\r
+        get_raw_clib_object ( x->key, &new_key );\r
+\r
+        c = pTree->compare_fn( new_key, cur_key);\r
+        free ( cur_key );\r
+        free ( new_key );\r
+        if (c < 0) {\r
+            z->left = x;\r
+        } else {\r
+            z->right = x;\r
+        }\r
+    }\r
+    else\r
+        pTree->root = x;\r
+\r
+    pvt_rb_insert_fixup (pTree, x);\r
+\r
+    debug_verify_properties ( pTree);\r
+    return rc;\r
+}\r
+static void\r
+pvt_rb_remove_fixup( struct clib_rb *pTree, struct clib_rb_node *x ) {\r
+    while (x != pTree->root && x->color == clib_black) {\r
+        if (x == x->parent->left) {\r
+            struct clib_rb_node *w = x->parent->right;\r
+            if (w->color == clib_red) {\r
+                w->color         = clib_black;\r
+                x->parent->color = clib_red;\r
+                pvt_left_rotate (pTree, x->parent);\r
+                w = x->parent->right;\r
+            }\r
+            if (w->left->color == clib_black && w->right->color == clib_black) {\r
+                w->color = clib_red;\r
+                x = x->parent;\r
+            } else {\r
+                if (w->right->color == clib_black)  {\r
+                    w->left->color = clib_black;\r
+                    w->color       = clib_red;\r
+                    pvt_right_rotate (pTree, w);\r
+                    w = x->parent->right;\r
+                }\r
+                w->color = x->parent->color;\r
+                x->parent->color = clib_black;\r
+                w->right->color = clib_black;\r
+                pvt_left_rotate (pTree, x->parent);\r
+                x = pTree->root;\r
+            }\r
+        } else {\r
+            struct clib_rb_node *w = x->parent->left;\r
+            if (w->color == clib_red) {\r
+                w->color = clib_black;\r
+                x->parent->color = clib_red;\r
+                pvt_right_rotate (pTree, x->parent);\r
+                w = x->parent->left;\r
+            }\r
+            if (w->right->color == clib_black && w->left->color == clib_black) {\r
+                w->color = clib_red;\r
+                x = x->parent;\r
+            } else {\r
+                if (w->left->color == clib_black) {\r
+                    w->right->color = clib_black;\r
+                    w->color = clib_red;\r
+                    pvt_left_rotate (pTree, w);\r
+                    w = x->parent->left;\r
+                }\r
+                w->color = x->parent->color;\r
+                x->parent->color = clib_black;\r
+                w->left->color = clib_black;\r
+                pvt_right_rotate (pTree, x->parent);\r
+                x = pTree->root;\r
+            }\r
+        }\r
+    }\r
+    x->color = clib_black;\r
+}\r
+\r
+static struct clib_rb_node*  \r
+pvt_remove_clib_rb(struct clib_rb *pTree, struct clib_rb_node *z ) {\r
+    struct clib_rb_node *x = (struct clib_rb_node*)0 ;\r
+    struct clib_rb_node *y = (struct clib_rb_node*)0 ;\r
+\r
+    if (z->left == rb_sentinel || z->right == rb_sentinel)\r
+        y = z;\r
+    else {\r
+        y = z->right;\r
+        while (y->left != rb_sentinel)\r
+            y = y->left;\r
+    }\r
+    if (y->left != rb_sentinel)\r
+        x = y->left;\r
+    else\r
+        x = y->right;\r
+\r
+    x->parent = y->parent;\r
+    if (y->parent)\r
+    {\r
+        if (y == y->parent->left)\r
+            y->parent->left = x;\r
+        else\r
+            y->parent->right = x;\r
+    }\r
+    else\r
+        pTree->root = x;\r
+    if (y != z) {\r
+        struct clib_object* tmp;\r
+        tmp    = z->key;\r
+        z->key = y->key;\r
+        y->key = tmp;\r
+\r
+        tmp      = z->value;\r
+        z->value = y->value;\r
+        y->value = tmp;\r
+    }\r
+    if (y->color == clib_black)\r
+        pvt_rb_remove_fixup (pTree, x);\r
+\r
+    debug_verify_properties ( pTree);\r
+    return y;\r
+}\r
+\r
+struct clib_rb_node*\r
+remove_clib_rb (struct clib_rb *pTree, void *key) {\r
+    struct clib_rb_node *z = (struct clib_rb_node*)0 ;\r
+\r
+    z = pTree->root;\r
+    while (z != rb_sentinel) {\r
+        int c = 0;\r
+        void *cur_key;\r
+        get_raw_clib_object ( z->key, &cur_key );\r
+        c = pTree->compare_fn (key, cur_key);\r
+        free ( cur_key );\r
+        if ( c == 0) {\r
+            break;\r
+        }\r
+        else {\r
+            z = ( c < 0) ? z->left : z->right;\r
+        }\r
+    }\r
+    if (z == rb_sentinel)\r
+        return (struct clib_rb_node*)0 ;\r
+    return pvt_remove_clib_rb(pTree, z );\r
+}\r
+static void\r
+pvt_delete_clib_rb_node (struct clib_rb *pTree, struct clib_rb_node *x ) {\r
+\r
+    void *key;\r
+       void *value;\r
+\r
+    if ( pTree->destruct_k_fn ) {\r
+        get_raw_clib_object ( x->key, &key );\r
+        pTree->destruct_k_fn ( key );\r
+    }\r
+    delete_clib_object( x->key );\r
+\r
+    if ( x->value ) {\r
+        if ( pTree->destruct_v_fn ) {\r
+            get_raw_clib_object ( x->value, &value);\r
+            pTree->destruct_v_fn ( value );\r
+        }\r
+        delete_clib_object( x->value );\r
+    }\r
+}\r
+\r
+clib_error  \r
+delete_clib_rb(struct clib_rb *pTree) {\r
+\r
+    clib_error rc = CLIB_ERROR_SUCCESS;\r
+    struct clib_rb_node *z = pTree->root;\r
+\r
+    while (z != rb_sentinel) {\r
+        if (z->left != rb_sentinel)\r
+            z = z->left;\r
+        else if (z->right != rb_sentinel)\r
+            z = z->right;\r
+        else {\r
+            pvt_delete_clib_rb_node ( pTree, z );\r
+            if (z->parent) {\r
+                z = z->parent;\r
+                if (z->left != rb_sentinel){\r
+                    free ( z->left );\r
+                    z->left = rb_sentinel;\r
+                }else if (z->right != rb_sentinel){\r
+                    free ( z->right );\r
+                    z->right = rb_sentinel;\r
+                }\r
+            } else {\r
+                free ( z );\r
+                z = rb_sentinel;\r
+            }\r
+        }\r
+    }\r
+    free ( pTree );\r
+    return rc;\r
+}\r
+struct clib_rb_node *\r
+minimum_clib_rb( struct clib_rb *pTree, struct clib_rb_node *x ) {\r
+       while ( x->left != rb_sentinel)\r
+               x = x->left;\r
+       return x;\r
+}\r
+\r
+struct clib_rb_node *\r
+maximum_clib_rb( struct clib_rb *pTree, struct clib_rb_node *x ) {\r
+       while ( x->right != rb_sentinel)\r
+               x = x->right;\r
+       return x;\r
+}\r
+\r
+\r
+clib_bool \r
+empty_clib_rb(struct clib_rb *pTree) {\r
+    if ( pTree->root != rb_sentinel )\r
+        return clib_true;\r
+    return clib_false;\r
+}\r
+struct clib_rb_node*\r
+tree_successor(struct clib_rb *pTree, struct clib_rb_node *x) {\r
+       struct clib_rb_node *y = (struct clib_rb_node*)0;\r
+       if ( x->right != rb_sentinel)\r
+               return minimum_clib_rb( pTree, x->right);\r
+       \r
+       if ( x  == maximum_clib_rb(pTree,pTree->root)) \r
+               return (struct clib_rb_node*)0;\r
+\r
+       y = x->parent;\r
+       while ( y != rb_sentinel && x == y->right ){\r
+               x = y;\r
+               y = y->parent;\r
+       }\r
+       return y;\r
+}\r
+\r
+\r
+void debug_verify_properties(struct clib_rb* t) {\r
+    debug_verify_property_1(t,t->root);\r
+    debug_verify_property_2(t,t->root);\r
+    debug_verify_property_4(t,t->root);\r
+    debug_verify_property_5(t,t->root);\r
+}\r
+\r
+void debug_verify_property_1(struct clib_rb *pTree,struct clib_rb_node* n) {\r
+    assert(debug_node_color(pTree,n) == clib_red || debug_node_color(pTree,n) == clib_black);\r
+    if (n == rb_sentinel) return;\r
+    debug_verify_property_1(pTree,n->left);\r
+    debug_verify_property_1(pTree,n->right);\r
+}\r
+\r
+void debug_verify_property_2(struct clib_rb *pTree,struct clib_rb_node* root) {\r
+    assert(debug_node_color(pTree,root) == clib_black);\r
+}\r
+\r
+int debug_node_color(struct clib_rb *pTree,struct clib_rb_node* n) {\r
+    return n == rb_sentinel ? clib_black : n->color;\r
+}\r
+\r
+void debug_verify_property_4(struct clib_rb *pTree,struct clib_rb_node* n) {\r
+    if (debug_node_color(pTree,n) == clib_red) {\r
+        assert (debug_node_color(pTree,n->left)   == clib_black);\r
+        assert (debug_node_color(pTree,n->right)  == clib_black);\r
+        assert (debug_node_color(pTree,n->parent) == clib_black);\r
+    }\r
+    if (n == rb_sentinel) return;\r
+    debug_verify_property_4(pTree,n->left);\r
+    debug_verify_property_4(pTree,n->right);\r
+}\r
+\r
+void debug_verify_property_5(struct clib_rb *pTree,struct clib_rb_node* root) {\r
+    int black_count_path = -1;\r
+    debug_verify_property_5_helper(pTree,root, 0, &black_count_path);\r
+}\r
+\r
+void debug_verify_property_5_helper(struct clib_rb *pTree,struct clib_rb_node* n, int black_count, int* path_black_count) {\r
+    if (debug_node_color(pTree,n) == clib_black) {\r
+        black_count++;\r
+    }\r
+    if (n == rb_sentinel) {\r
+        if (*path_black_count == -1) {\r
+            *path_black_count = black_count;\r
+        } else {\r
+            assert (black_count == *path_black_count);\r
+        }\r
+        return;\r
+    }\r
+    debug_verify_property_5_helper(pTree,n->left,  black_count, path_black_count);\r
+    debug_verify_property_5_helper(pTree,n->right, black_count, path_black_count);\r
+}\r
+\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/src/c_set.c b/junkcode/dongre.avinash@gmail.com-clibutils/src/c_set.c
new file mode 100644 (file)
index 0000000..068ed31
--- /dev/null
@@ -0,0 +1,106 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+\r
+#include <stdio.h>\r
+\r
+struct clib_set* \r
+new_clib_set ( clib_compare fn_c, clib_destroy fn_d) {\r
+\r
+    struct clib_set *pSet  =  (struct clib_set*)malloc(sizeof(struct clib_set));\r
+    if (pSet == (struct clib_set*)0 )\r
+        return (struct clib_set*)0 ;\r
+\r
+    pSet->root  = new_clib_rb (fn_c, fn_d, (void*)0);\r
+    if (pSet->root == (struct clib_rb*)0)\r
+        return (struct clib_set*)0 ;\r
+\r
+    return pSet;\r
+}\r
+clib_error   \r
+insert_clib_set (struct clib_set *pSet, void *key, size_t key_size) {\r
+    if (pSet == (struct clib_set*)0 )\r
+        return CLIB_SET_NOT_INITIALIZED;\r
+\r
+    return insert_clib_rb ( pSet->root, key, key_size, (void*)0, 0);\r
+}\r
+clib_bool    \r
+exists_clib_set ( struct clib_set *pSet, void *key) {\r
+    clib_bool found = clib_false;\r
+    struct clib_rb_node* node;\r
+\r
+    if (pSet == (struct clib_set*)0 )\r
+        return clib_false;\r
+    \r
+    node = find_clib_rb ( pSet->root, key);\r
+    if ( node != (struct clib_rb_node*)0  ) {\r
+        return clib_true;\r
+    }\r
+    return found;    \r
+}\r
+clib_error   \r
+remove_clib_set ( struct clib_set *pSet, void *key) {\r
+    clib_error rc = CLIB_ERROR_SUCCESS;\r
+    struct clib_rb_node* node;\r
+    if (pSet == (struct clib_set*)0 )\r
+        return CLIB_SET_NOT_INITIALIZED;\r
+\r
+    node = remove_clib_rb ( pSet->root, key );\r
+    if ( node != (struct clib_rb_node*)0  ) {\r
+        /*free ( node->raw_data.key);\r
+        free ( node );*/\r
+    }\r
+    return rc;\r
+}\r
+clib_bool    \r
+find_clib_set ( struct clib_set *pSet, void *key, void* outKey) {\r
+    struct clib_rb_node* node;\r
+\r
+    if (pSet == (struct clib_set*)0 )\r
+        return clib_false;\r
+\r
+    node = find_clib_rb ( pSet->root, key);\r
+    if ( node == (struct clib_rb_node*)0  ) \r
+        return clib_false;\r
+\r
+    get_raw_clib_object ( node->key, outKey );\r
+\r
+    return clib_true;\r
+\r
+}\r
+\r
+clib_error    \r
+delete_clib_set ( struct clib_set* x) {\r
+    clib_error rc = CLIB_ERROR_SUCCESS;\r
+    if ( x != (struct clib_set*)0  ){\r
+        rc = delete_clib_rb ( x->root );\r
+        free ( x );\r
+    }\r
+    return rc;\r
+}\r
+static struct clib_rb_node *\r
+minimum_clib_set( struct clib_set *x ) {\r
+       return minimum_clib_rb( x->root, x->root->root);\r
+}\r
+\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/src/c_slist.c b/junkcode/dongre.avinash@gmail.com-clibutils/src/c_slist.c
new file mode 100644 (file)
index 0000000..fc8dfce
--- /dev/null
@@ -0,0 +1,173 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+\r
+struct clib_slist* \r
+new_clib_slist(clib_destroy fn_d, clib_compare fn_c){\r
+    struct clib_slist *pSlist  = (struct clib_slist*)malloc(sizeof(struct clib_slist));\r
+    pSlist->head           = (struct clib_slist_node*)0;\r
+    pSlist->destruct_fn    = fn_d;\r
+    pSlist->compare_fn = fn_c;\r
+    pSlist->size           = 0;\r
+    return pSlist;\r
+}\r
+void           \r
+delete_clib_slist( struct clib_slist *pSlist){\r
+    while(pSlist->size != 0) {\r
+        remove_clib_slist ( pSlist, 0 );\r
+    }\r
+    free ( pSlist );\r
+}\r
+\r
+clib_error           \r
+push_back_clib_slist( struct clib_slist *pSlist, void *elem, size_t elem_size){\r
+\r
+    struct clib_slist_node* current  = (struct clib_slist_node*)0;\r
+    struct clib_slist_node* new_node = (struct clib_slist_node*)0;\r
+\r
+    new_node = (struct clib_slist_node*)malloc(sizeof(struct clib_slist_node));\r
+\r
+    new_node->elem = new_clib_object ( elem, elem_size );\r
+    if ( ! new_node->elem )\r
+        return CLIB_SLIST_INSERT_FAILED;\r
+    new_node->next = (struct clib_slist_node*)0;\r
+\r
+    if ( pSlist->head == (struct clib_slist_node*)0 ) {\r
+        pSlist->head = new_node;\r
+        pSlist->size++;\r
+        return CLIB_ERROR_SUCCESS;\r
+    }\r
+    current = pSlist->head;\r
+    while ( current->next != (struct clib_slist_node*)0 )\r
+        current  = current->next;    \r
+    current->next = new_node;\r
+    pSlist->size++;\r
+\r
+    return CLIB_ERROR_SUCCESS;\r
+}\r
+static void \r
+pvt_remove_clib_list ( struct clib_slist *pSlist, struct clib_slist_node* pSlistNode ) {\r
+    void *elem;\r
+    get_raw_clib_object(pSlistNode->elem, &elem);\r
+    if ( pSlist->destruct_fn) {             \r
+        (pSlist->destruct_fn)(elem);\r
+        delete_clib_object ( pSlistNode->elem );\r
+    }else {\r
+        free ( elem );\r
+        delete_clib_object ( pSlistNode->elem );\r
+    }        \r
+    free ( pSlistNode);\r
+}\r
+void           \r
+remove_clib_slist( struct clib_slist *pSlist, int pos ) {\r
+    int i = 0;\r
+\r
+    struct clib_slist_node* current = pSlist->head;\r
+    struct clib_slist_node* temp    = (struct clib_slist_node*)0;\r
+\r
+    if ( pos > pSlist->size ) return;\r
+\r
+    if ( pos == 0 ) {                \r
+        pSlist->head = current->next;    \r
+        pvt_remove_clib_list(pSlist, current);    \r
+        pSlist->size--;\r
+        return;\r
+    }\r
+    for ( i = 1; i < pos - 1; i++)\r
+        current = current->next;\r
+\r
+    temp          = current->next;\r
+    current->next = current->next->next;\r
+    pvt_remove_clib_list ( pSlist, temp );\r
+\r
+    pSlist->size--;\r
+}\r
+clib_error           \r
+insert_clib_slist(struct clib_slist *pSlist, int pos, void *elem, size_t elem_size) {\r
+    int i = 0;\r
+    struct clib_slist_node* current  = pSlist->head;\r
+    struct clib_slist_node* new_node = (struct clib_slist_node*)0;\r
+   \r
+    if ( pos == 1 ) {\r
+        new_node       = (struct clib_slist_node*)malloc(sizeof(struct clib_slist_node));\r
+        new_node->elem = new_clib_object ( elem, elem_size );\r
+        if ( ! new_node->elem ) {\r
+            free ( new_node );\r
+            return CLIB_SLIST_INSERT_FAILED;\r
+        }\r
+        new_node->next = pSlist->head;\r
+        pSlist->head       = new_node;\r
+        pSlist->size++;\r
+        return CLIB_ERROR_SUCCESS;\r
+    }\r
+\r
+    if ( pos >= pSlist->size + 1 ) {\r
+        return push_back_clib_slist ( pSlist, elem, elem_size );\r
+    }\r
+\r
+    for ( i = 1; i < pos - 1; i++) {\r
+        current = current->next;\r
+    }\r
+    new_node       = (struct clib_slist_node*)malloc(sizeof(struct clib_slist_node));\r
+    new_node->elem = new_clib_object ( elem, elem_size );\r
+    if ( ! new_node->elem ) {\r
+        free ( new_node );\r
+        return CLIB_SLIST_INSERT_FAILED;\r
+    }\r
+\r
+    new_node->next = current->next;\r
+    current->next  = new_node;\r
+    pSlist->size++;\r
+\r
+    return CLIB_ERROR_SUCCESS;\r
+}\r
+void           \r
+for_each_clib_slist (struct clib_slist *pSlist, void (*fn)(void* )) {\r
+    void *elem;\r
+    struct clib_slist_node* current  = pSlist->head;\r
+    while ( current != (struct clib_slist_node*)0 ) {\r
+        get_raw_clib_object(current->elem, &elem);\r
+        (fn)(elem);\r
+        free ( elem );\r
+        current = current->next;\r
+    }    \r
+}\r
+clib_bool\r
+find_clib_slist (struct clib_slist *pSlist, void* find_value, void**out_value) {\r
+    struct clib_slist_node* current  = pSlist->head;  \r
+    while ( current != (struct clib_slist_node*)0 ) {        \r
+        get_raw_clib_object(current->elem, out_value);\r
+        if ((pSlist->compare_fn)(find_value,*out_value) != 0){\r
+            break;\r
+        }\r
+        free ( *out_value );\r
+        current = current->next;\r
+    }\r
+    if ( current ) {\r
+        return clib_true;\r
+    }\r
+    return clib_false;\r
+}\r
+\r
+\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/src/c_stack.c b/junkcode/dongre.avinash@gmail.com-clibutils/src/c_stack.c
new file mode 100644 (file)
index 0000000..f5614cc
--- /dev/null
@@ -0,0 +1,50 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+#include "c_lib.h"\r
+\r
+struct clib_stack *\r
+new_clib_stack( int default_size, clib_destroy fn_d) {\r
+       struct clib_stack *pStack = ( struct clib_stack*)malloc(sizeof ( struct clib_stack));\r
+       pStack->pStackArr = new_clib_array ( default_size, NULL, fn_d);\r
+       return pStack;\r
+}\r
+void \r
+delete_clib_stack(struct clib_stack *pStack){\r
+       if ( pStack ){\r
+               delete_clib_array ( pStack->pStackArr );\r
+       }\r
+       free ( pStack );\r
+}\r
+void \r
+push_clib_stack(struct clib_stack *pStack, void *elem, size_t elem_size) {\r
+       push_back_clib_array( pStack->pStackArr, elem, elem_size);\r
+}\r
+void \r
+pop_clib_stack(struct clib_stack *pStack, void **elem) {\r
+       back_clib_array( pStack->pStackArr, elem );\r
+       remove_clib_array( pStack->pStackArr, size_clib_array( pStack->pStackArr) - 1);\r
+}\r
+clib_bool \r
+empty_clib_stack ( struct clib_stack *pStack) {\r
+       return empty_clib_array( pStack->pStackArr);\r
+}\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/src/c_util.c b/junkcode/dongre.avinash@gmail.com-clibutils/src/c_util.c
new file mode 100644 (file)
index 0000000..3219b39
--- /dev/null
@@ -0,0 +1,84 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+#include <string.h>\r
+#include <stdlib.h>\r
+\r
+void \r
+clib_copy( void *destination, void *source, size_t size ) {\r
+    memcpy ( (char*)destination, source, size);\r
+}\r
+void\r
+clib_get ( void *destination, void *source, size_t size) {\r
+    memcpy ( destination, (char*)source, size);\r
+}\r
+\r
+struct clib_object*\r
+new_clib_object(void *inObject, size_t obj_size) {\r
+    struct clib_object* tmp = (struct clib_object*)malloc(sizeof(struct clib_object));   \r
+    if ( ! tmp )\r
+        return (struct clib_object*)0;\r
+    tmp->size        = obj_size;\r
+    tmp->raw_data    = (void*)malloc(obj_size);\r
+    if ( !tmp->raw_data ) {\r
+        free ( tmp );\r
+        return (struct clib_object*)0;\r
+    }\r
+    memcpy ( tmp->raw_data, inObject, obj_size);\r
+    return tmp;\r
+}\r
+\r
+clib_error\r
+get_raw_clib_object ( struct clib_object *inObject, void**elem) {\r
+    *elem = (void*)malloc(inObject->size);\r
+    if ( ! *elem )\r
+        return CLIB_ELEMENT_RETURN_ERROR;\r
+    memcpy ( *elem, inObject->raw_data, inObject->size );\r
+\r
+    return CLIB_ERROR_SUCCESS;\r
+}\r
+void \r
+replace_raw_clib_object(struct clib_object *current_object,void *elem, size_t elem_size) {\r
+       free (current_object->raw_data);\r
+       current_object->raw_data = (void*)malloc(elem_size);\r
+       memcpy ( current_object->raw_data, elem, elem_size);\r
+}\r
+\r
+\r
+void \r
+delete_clib_object ( struct clib_object *inObject ) {\r
+    if (inObject) {\r
+        free (inObject->raw_data);\r
+        free (inObject);\r
+    }\r
+}\r
+\r
+char*\r
+clib_strdup ( char *ptr ) {\r
+    #ifdef WIN32\r
+        return _strdup (ptr);\r
+    #else\r
+        return strdup (ptr);\r
+    #endif\r
+}\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/Makefile b/junkcode/dongre.avinash@gmail.com-clibutils/test/Makefile
new file mode 100644 (file)
index 0000000..d2e5cd4
--- /dev/null
@@ -0,0 +1,22 @@
+P_NAME          :=  tstclibutils
+P_C_SRCS        :=  $(wildcard *.c)
+P_C_OBJS        :=  ${P_C_SRCS:.c=.o}
+P_INCLUDE_DIRS  :=  ../inc
+P_LIBRARY_DIRS  :=  ../src
+P_LIBRARIES     :=  clibutils
+CPPFLAGS        +=  $(foreach includedir,$(P_INCLUDE_DIRS),-I$(includedir))
+LDFLAGS         +=  $(foreach librarydir,$(P_LIBRARY_DIRS),-L$(librarydir))
+LDFLAGS         +=  $(foreach library,$(P_LIBRARIES),-l$(library))
+CC              :=  gcc -Wall -g
+CCFLAGS         :=  -Wall -g 
+
+.PHONY:         all clean
+all:            $(P_NAME)
+$(P_NAME):      $(P_C_OBJS)
+               $(CC) $(CCFLAGS) $(P_C_OBJS) -o $(P_NAME) $(LDFLAGS)
+clean:
+               @- $(RM) $(P_NAME)
+               @- $(RM) $(P_C_OBJS)
+               @- $(RM) core*
+               @- $(RM) tags
+
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_array.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_array.c
new file mode 100644 (file)
index 0000000..c2f1942
--- /dev/null
@@ -0,0 +1,305 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include <assert.h>\r
+\r
+static int \r
+compare_e ( void *left, void *right ) {\r
+    int *l = (int*) left;\r
+    int *r = (int*) right;\r
+    return *l == *r ;\r
+}\r
+static void \r
+free_e ( void *ptr ) {\r
+    if ( ptr )\r
+        free ( ptr);\r
+}\r
+static void\r
+print_e ( void *ptr ){\r
+    if ( ptr ) \r
+        printf ( "%d\n", *(int*)ptr);\r
+}\r
+static void \r
+test_with_int() {\r
+    int size = 10;\r
+    int i = 0;\r
+    int rc ;\r
+    void* p_rv = (void* )0;\r
+    int rv = 0;\r
+    struct clib_array* myArray  = new_clib_array (8,compare_e,NULL);\r
+    assert ( clib_true == empty_clib_array( myArray ));\r
+\r
+    for ( i = 0; i <= size; i++) {\r
+        push_back_clib_array ( myArray, &i ,sizeof(int));\r
+    }\r
+    assert ( clib_false == empty_clib_array( myArray ));\r
+    assert ( size + 1  == size_clib_array( myArray ));\r
+       for ( i = 0; i <= size; i++) {      \r
+        rc = element_at_clib_array ( myArray, i , &p_rv );\r
+        rv = *(int*)p_rv;\r
+           assert ( rv == i );\r
+        free ( p_rv );\r
+    }  \r
+    rc = front_clib_array ( myArray, &p_rv );\r
+    rv = *(int*)p_rv;\r
+    assert ( rv == 0 );\r
+    free ( p_rv );\r
+\r
+    rc = back_clib_array( myArray, &p_rv );\r
+    rv = *(int*)p_rv;\r
+    assert ( rv == size );\r
+    free ( p_rv );\r
+\r
+    remove_clib_array( myArray, 0 );\r
+    assert ( size  == size_clib_array( myArray ));\r
+    rc = element_at_clib_array ( myArray, 0 , &p_rv );\r
+    rv = *(int*)p_rv;\r
+    assert ( rv == 1 );\r
+    free ( p_rv );\r
+\r
+    size = size_clib_array( myArray );\r
+    remove_clib_array( myArray, size/2 );\r
+    assert ( size - 1  == size_clib_array( myArray ));\r
+    rc = element_at_clib_array ( myArray, size/2 , &p_rv );\r
+    rv = *(int*)p_rv;\r
+    assert ( rv == size/2 + 2 );\r
+    free ( p_rv );\r
+\r
+    size = size_clib_array( myArray );\r
+    remove_clib_array( myArray, size - 1);\r
+    assert ( size - 1  == size_clib_array( myArray ));\r
+    size = size_clib_array( myArray );\r
+    rc = element_at_clib_array ( myArray, size - 1, &p_rv );\r
+    rv = *(int*)p_rv;\r
+    assert ( rv == 9 );\r
+    free ( p_rv );\r
+\r
+    i = 900;\r
+    insert_at_clib_array ( myArray, 5, &i, sizeof(int));\r
+    rc = element_at_clib_array ( myArray, 5 , &p_rv );\r
+    rv = *(int*)p_rv;\r
+    assert ( rv == i );\r
+    free ( p_rv );\r
+\r
+    rc = element_at_clib_array ( myArray, 6 , &p_rv );\r
+    rv = *(int*)p_rv;\r
+    assert ( rv == 7 );\r
+    free ( p_rv );   \r
+\r
+    for ( i = 0; i < size_clib_array(myArray ); i++){\r
+        rc = element_at_clib_array ( myArray, i , &p_rv );\r
+        print_e ( p_rv);\r
+        free ( p_rv );\r
+        \r
+    }  \r
+    delete_clib_array ( myArray );\r
+}\r
+\r
+static void \r
+test_with_pointers() {\r
+    int size = 10;\r
+    int i = 0;\r
+    int *rv, rc ;\r
+    void* p_rv = (void* )0;\r
+    struct clib_array* myArray  = new_clib_array (8,compare_e,free_e);\r
+    assert ( clib_true == empty_clib_array( myArray ));\r
+\r
+    for ( i = 0; i < size; i++) {\r
+        int *v = ( int*) malloc ( sizeof(int));\r
+        memcpy ( v, &i, sizeof(int));\r
+        push_back_clib_array ( myArray, v ,sizeof(int*));\r
+        free ( v );\r
+    }\r
+    assert ( clib_false == empty_clib_array( myArray ));\r
+    assert ( size  == size_clib_array( myArray ));\r
+       for ( i = 0; i < size; i++) {       \r
+        rc = element_at_clib_array ( myArray, i , &p_rv );\r
+        rv = (int*) p_rv;\r
+           assert ( *rv == i );\r
+        free ( p_rv);\r
+    }  \r
+    rc = front_clib_array ( myArray, &p_rv );\r
+    rv = (int*) p_rv;\r
+    assert ( *rv == 0 );\r
+    free ( p_rv);\r
+\r
+    rc = back_clib_array( myArray, &p_rv );\r
+    rv = (int*) p_rv;\r
+    assert ( *rv == size - 1);\r
+    free ( p_rv);\r
+\r
+    remove_clib_array( myArray, 0 );\r
+    assert ( size - 1  == size_clib_array( myArray ));\r
+\r
+    rc = element_at_clib_array ( myArray, 0 , &p_rv );\r
+    rv = (int*) p_rv;\r
+    assert ( *rv == 1 );\r
+    free ( p_rv);\r
+\r
+    size = size_clib_array( myArray );\r
+    remove_clib_array( myArray, size/2 );\r
+    assert ( size - 1  == size_clib_array( myArray ));\r
+    rc = element_at_clib_array ( myArray, size/2 , &p_rv );\r
+    rv = (int*) p_rv;\r
+    assert ( *rv == size/2 + 2 );\r
+    free ( p_rv);\r
+\r
+    size = size_clib_array( myArray );\r
+    remove_clib_array( myArray, size - 1);\r
+    assert ( size - 1  == size_clib_array( myArray ));\r
+\r
+    size = size_clib_array( myArray );\r
+\r
+    rc = element_at_clib_array ( myArray, size - 1, &p_rv );\r
+    rv = (int*) p_rv;\r
+    assert ( *rv == 8 );\r
+    free ( p_rv);\r
+   \r
+    delete_clib_array ( myArray );\r
+}\r
+\r
+static void \r
+test_with_strings() {\r
+    int size = 10;\r
+    char *input_array[11];\r
+    int i = 0;\r
+    char *rv, rc ;\r
+    void* p_rv = (void* )0;\r
+    struct clib_array* myArray  = new_clib_array (8,compare_e,free_e);\r
+    assert ( clib_true == empty_clib_array( myArray ));\r
+\r
+    input_array[0] = "STRING_0";\r
+    input_array[1] = "STRING_1";\r
+    input_array[2] = "STRING_2";\r
+    input_array[3] = "STRING_3";\r
+    input_array[4] = "STRING_4";\r
+    input_array[5] = "STRING_5";\r
+    input_array[6] = "STRING_6";\r
+    input_array[7] = "STRING_7";\r
+    input_array[8] = "STRING_8";\r
+    input_array[9] = "STRING_9";\r
+    input_array[10] = "STRING_10";\r
+\r
+\r
+    for ( i = 0; i < size; i++) {\r
+        char *v  = clib_strdup ( input_array[i]);\r
+        push_back_clib_array ( myArray ,v, strlen(v) + 1 );\r
+        free ( v );\r
+    }\r
+    assert ( clib_false == empty_clib_array( myArray ));\r
+    assert ( size == size_clib_array( myArray ));\r
+       for ( i = 0; i < size; i++) {     \r
+        rc = element_at_clib_array ( myArray, i , &p_rv );\r
+        rv = (char*)p_rv;\r
+           assert ( strcmp( rv, input_array[i]) == 0);\r
+        free ( p_rv );\r
+    }  \r
+    rc = front_clib_array ( myArray, &p_rv );\r
+    rv = (char*)p_rv;\r
+    assert ( strcmp( rv, input_array[0]) == 0);\r
+    free ( p_rv );\r
+\r
+    rc = back_clib_array( myArray, &p_rv );\r
+    rv = (char*)p_rv;\r
+    assert ( strcmp( rv, input_array[size - 1]) == 0);\r
+    free ( p_rv );\r
+\r
+    remove_clib_array( myArray, 0 );\r
+    assert ( size - 1  == size_clib_array( myArray ));\r
+\r
+    rc = element_at_clib_array ( myArray, 0 , &p_rv );\r
+    rv = (char*)p_rv;\r
+    assert ( strcmp( rv, input_array[1]) == 0);\r
+    free ( p_rv );\r
+\r
+    size = size_clib_array( myArray );\r
+    remove_clib_array( myArray, size/2 );\r
+\r
+    rc = element_at_clib_array ( myArray, size/2 , &p_rv );\r
+    rv = (char*)p_rv;\r
+    assert ( strcmp( rv, input_array[size/2 + 2]) == 0);\r
+    free ( p_rv );\r
+\r
+    size = size_clib_array( myArray );\r
+    remove_clib_array( myArray, size - 1);\r
+    assert ( size - 1  == size_clib_array( myArray ));\r
+    size = size_clib_array( myArray );\r
+\r
+    rc = element_at_clib_array ( myArray, size - 1, &p_rv );\r
+    rv = (char*)p_rv;    \r
+    assert ( strcmp( rv, input_array[8]) == 0);\r
+    free ( p_rv );\r
+\r
+    delete_clib_array ( myArray );\r
+}\r
+static struct clib_array*\r
+create_array() {\r
+    int size = 10;\r
+    int i = 0;\r
+    int rc ;\r
+    void* p_rv = (void* )0;\r
+    int rv = 0;\r
+\r
+    struct clib_array* myArray  = new_clib_array (8,compare_e,NULL);\r
+    assert ( clib_true == empty_clib_array( myArray ));\r
+\r
+    for ( i = 0; i < size; i++) {\r
+        push_back_clib_array ( myArray, &i ,sizeof(int));\r
+    }\r
+    assert ( clib_false == empty_clib_array( myArray ));\r
+    assert ( size  == size_clib_array( myArray ));\r
+       for ( i = 0; i < size; i++) {       \r
+        rc = element_at_clib_array ( myArray, i , &p_rv );\r
+        rv = *(int*)p_rv;\r
+           assert ( rv == i );\r
+        free ( p_rv );\r
+    }  \r
+       return myArray;\r
+}\r
+static void\r
+test_for_each_array(){\r
+       struct clib_array* pArray = create_array();\r
+       struct clib_object *temp;\r
+       for_each_clib_array( pArray, print_e);\r
+\r
+       temp = pArray->pElements[5];\r
+       pArray->pElements[5] = pArray->pElements[8];\r
+       pArray->pElements[8] = temp;\r
+\r
+       for_each_clib_array( pArray, print_e);\r
+       delete_clib_array ( pArray );\r
+\r
+}\r
+void \r
+test_clib_array(){\r
+    test_with_int();\r
+    test_with_pointers();\r
+    test_with_strings();\r
+       printf ( "---------------------------------\n");\r
+       test_for_each_array();\r
+}\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_deque.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_deque.c
new file mode 100644 (file)
index 0000000..4a27d0c
--- /dev/null
@@ -0,0 +1,90 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <assert.h>\r
+\r
+static int \r
+compare_e ( void *left, void *right ) {\r
+    int *l = (int*) left;\r
+    int *r = (int*) right;\r
+    return *l == *r ;\r
+}\r
+static void \r
+free_e ( void *ptr ) {\r
+    if ( ptr )\r
+    free ( ptr);\r
+}\r
+void \r
+test_clib_deque() {\r
+    int flip = 1;\r
+    int i = 0;\r
+    int limit = 20;\r
+    void*  element;\r
+    int j = 0;\r
+\r
+    struct clib_deque* myDeq = new_clib_deque ( 10, compare_e, NULL);\r
+    assert ( (struct clib_deque*)0 != myDeq );\r
+\r
+    for ( i = 0; i <= limit; i++ ) { \r
+        if ( flip ) {\r
+            push_back_clib_deque ( myDeq, &i , sizeof(int));\r
+            flip = 0;\r
+        } else {\r
+            push_front_clib_deque ( myDeq, &i, sizeof(int) );\r
+            flip = 1;\r
+        }\r
+    }\r
+    front_clib_deque ( myDeq, &element );\r
+    assert ( *(int*)element == limit - 1 );\r
+    free ( element );\r
+\r
+    back_clib_deque ( myDeq, &element );\r
+    assert ( *(int*)element == limit);\r
+    free ( element );\r
+\r
+    while ( empty_clib_deque(myDeq) != clib_true ) {\r
+        pop_front_clib_deque ( myDeq);\r
+    }\r
+    delete_clib_deque(myDeq);\r
+\r
+    myDeq = new_clib_deque ( 10, compare_e, free_e); \r
+    for ( i = 0; i <= limit; i ++ ) { \r
+        int *v = (int*)malloc(sizeof(int ));\r
+        memcpy ( v, &i, sizeof ( int ));\r
+        push_back_clib_deque ( myDeq, v , sizeof(int*));\r
+        free ( v );\r
+    }   \r
+    for ( i = myDeq->head + 1; i < myDeq->tail; i++ ){\r
+        void *elem;\r
+        if ( element_at_clib_deque( myDeq, i, &elem ) == CLIB_ERROR_SUCCESS ) {\r
+                assert ( *(int*)elem == j++ );\r
+                free ( elem );\r
+        }\r
+    }\r
+    delete_clib_deque(myDeq);\r
+}\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_heap.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_heap.c
new file mode 100644 (file)
index 0000000..d15a839
--- /dev/null
@@ -0,0 +1,95 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+#include <stdio.h>\r
+\r
+static int \r
+compare_int ( void *left, void *right ) {\r
+    int *l = (int*)left;\r
+    int *r = (int*)right;\r
+\r
+    if ( *l < *r ) \r
+        return -1;\r
+    else if ( *l > *r ) \r
+        return 1;\r
+    return 0;\r
+}\r
+static void\r
+print_element ( void *ptr ) {\r
+       printf ( "%d\n", *(int*)ptr);\r
+}\r
+void \r
+test_clib_heap_max() {\r
+       int test[] = {4,1,3,2,16,9,10,14,8,7};\r
+       int index  = 0;\r
+       int size   = sizeof (test) /sizeof(test[0]);\r
+       void *maxElem;\r
+       struct clib_heap* pHeap = new_clib_heap ( 8, compare_int, NULL);\r
+\r
+       for ( index = 0; index < size; index++ ) {\r
+               int v = test[index];\r
+               insert_clib_heap ( pHeap, &v, sizeof(int));                     \r
+       }\r
+       build_max_clib_heap( pHeap);\r
+       printf ( "---------------------------------\n");\r
+       for_each_clib_heap ( pHeap, print_element);\r
+       printf ( "---------------------------------\n");\r
+       while ( empty_clib_heap(pHeap) != clib_true ) {\r
+               maxElem  = extract_max_clib_heap ( pHeap );\r
+               printf ( "MAX ELEMENT = %d\n", *(int*)maxElem);\r
+               free ( maxElem );\r
+       }\r
+       delete_clib_heap ( pHeap );\r
+}\r
+\r
+void\r
+test_clib_heap_min() {\r
+       int test[] = {4,1,3,2,16,9,10,14,8,7};\r
+       int index  = 0;\r
+       int size   = sizeof (test) /sizeof(test[0]);\r
+       void *maxElem;\r
+       struct clib_heap* pHeap = new_clib_heap ( 8, compare_int, NULL);\r
+\r
+       for ( index = 0; index < size; index++ ) {\r
+               int v = test[index];\r
+               insert_clib_heap ( pHeap, &v, sizeof(int));                     \r
+       }\r
+       build_min_clib_heap( pHeap);\r
+       printf ( "---------------------------------\n");\r
+       for_each_clib_heap ( pHeap, print_element);\r
+       printf ( "---------------------------------\n");\r
+       while ( empty_clib_heap(pHeap) != clib_true ) {\r
+               maxElem  = extract_min_clib_heap ( pHeap );\r
+               printf ( "MIN ELEMENT = %d\n", *(int*)maxElem);\r
+               free ( maxElem );\r
+       }\r
+       delete_clib_heap ( pHeap );\r
+\r
+}\r
+\r
+void \r
+test_clib_heap() {\r
+       test_clib_heap_max();\r
+       test_clib_heap_min();\r
+}
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_map.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_map.c
new file mode 100644 (file)
index 0000000..5305b45
--- /dev/null
@@ -0,0 +1,113 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+#include <string.h>\r
+#include <assert.h>\r
+#include <stdio.h>\r
+\r
+static int\r
+compare_e ( void *left, void *right ) {\r
+    return strcmp ( (const char *)left, (const char *) right );\r
+}\r
+char *char_value[] = {  "A","B","C","D","E","F","G","H","I","J","K","L","M",\r
+                        "N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};\r
+int int_value[] = { 1,2,3,4,5,6,7,8,9,10,\r
+                      11,12,13,14,15,16,17,18,19,20,\r
+                      21,22,23,24,25,26};\r
+\r
+static void \r
+insert_all ( struct clib_map* myMap) {\r
+    int size = sizeof(char_value)/sizeof(char_value[0]);\r
+    int i = 0;\r
+    for ( i = 0; i < size; i++ ) {\r
+        char *key = clib_strdup( char_value[i]);\r
+        int key_length = (int)strlen ( key ) + 1;\r
+        int value = int_value[i];\r
+               printf ( "Inserting [%s -> %d]\n", key, value );\r
+        insert_clib_map ( myMap, key, key_length, &value, sizeof(int)); \r
+        free ( key );\r
+    }\r
+}\r
+static void \r
+check_exists_all( struct clib_map* myMap) {\r
+    int size = sizeof(char_value)/sizeof(char_value[0]);\r
+    int i = 0;\r
+    for ( i = 0; i < size; i++ ) {\r
+        void *value ;\r
+        assert ( clib_true == exists_clib_map ( myMap, char_value[i]));\r
+        assert ( clib_true == find_clib_map( myMap, char_value[i], &value));\r
+               printf ( "-----> [%s == %d]\n", char_value[i], *(int*)value);\r
+        assert ( *(int*)value == int_value[i]);\r
+        free ( value );\r
+    }\r
+}\r
+\r
+static void \r
+remove_some_exist(struct clib_map* myMap) {\r
+    assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "A"));\r
+    assert ( clib_false == exists_clib_map ( myMap, "A"));\r
+\r
+    assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "X"));\r
+    assert ( clib_false == exists_clib_map ( myMap, "X"));\r
+\r
+    assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "Z"));\r
+    assert ( clib_false == exists_clib_map ( myMap, "Z"));\r
+\r
+    assert ( CLIB_ERROR_SUCCESS == remove_clib_map ( myMap, "H"));\r
+    assert ( clib_false == exists_clib_map ( myMap, "H"));\r
+}\r
+static void\r
+add_removed_check_all(struct clib_map* myMap) {\r
+\r
+    char *key       = clib_strdup ("A");\r
+    int  key_length = (int)strlen ( key ) + 1;\r
+    insert_clib_map ( myMap, key, key_length , &int_value[0], sizeof(int)); \r
+    free ( key );\r
+\r
+    key        = clib_strdup ("X");\r
+    key_length = (int)strlen ( key ) + 1;\r
+    insert_clib_map ( myMap, key, key_length, &int_value[23], sizeof(int)); \r
+    free ( key );\r
+\r
+    key        = clib_strdup ("Z");\r
+    key_length = (int)strlen ( key ) + 1;\r
+    insert_clib_map ( myMap, key, key_length, &int_value[25], sizeof(int)); \r
+    free ( key );\r
+\r
+    key        = clib_strdup ("H");\r
+    key_length = (int)strlen ( key ) + 1;\r
+    insert_clib_map ( myMap, key, key_length, &int_value[7 ], sizeof(int)); \r
+    free ( key );\r
+\r
+    check_exists_all(myMap);\r
+}\r
+void \r
+test_clib_map() {\r
+    struct clib_map* myMap = new_clib_map ( compare_e, NULL, NULL);\r
+    insert_all(myMap);\r
+    check_exists_all(myMap);   \r
+    remove_some_exist(myMap);\r
+    add_removed_check_all(myMap);\r
+    delete_clib_map(myMap);\r
+}\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_rb.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_rb.c
new file mode 100644 (file)
index 0000000..1a318ac
--- /dev/null
@@ -0,0 +1,255 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+\r
+/*#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <assert.h>\r
+\r
+#define BLACK 0\r
+#define RED   1\r
+\r
+#define rb_sentinel &tree->sentinel \r
+\r
+static void*\r
+    get_key ( struct clib_rb* tree, struct clib_rb_node* node) {\r
+        if ( node ) \r
+            return node->raw_data.key;\r
+        return (void*)0;\r
+    }\r
+\r
+static struct clib_rb_node*\r
+    get_left (struct clib_rb* tree, struct clib_rb_node* node ) {\r
+        if ( node->left != rb_sentinel && node->left != (struct clib_rb_node*)0 )\r
+            return node->left;\r
+        return (struct clib_rb_node*)0 ;\r
+    }\r
+static struct clib_rb_node*\r
+    get_right (struct clib_rb* tree, struct clib_rb_node* node ){\r
+        if ( node->right != rb_sentinel && node->right != (struct clib_rb_node*)0 )\r
+            return node->right;\r
+        return (struct clib_rb_node*)0 ;\r
+    }\r
+static struct clib_rb_node*\r
+    get_parent ( struct clib_rb* tree,struct clib_rb_node* node ) {\r
+        if ( node->parent != rb_sentinel && node->parent != (struct clib_rb_node*)0 )\r
+            return node->parent;\r
+        return (struct clib_rb_node*)0 ;\r
+    }\r
+\r
+int \r
+compare_rb_e ( void*  l, void* r ) {\r
+\r
+    int left =  0;\r
+    int right = 0;\r
+\r
+    if ( l ) left  = *(int*)l;\r
+    if ( r ) right = *(int*)r;\r
+\r
+    if ( left < right ) return -1;\r
+    if ( left == right ) return 0;\r
+\r
+    return 1;\r
+}\r
+\r
+void \r
+free_rb_e ( void* p ) {\r
+    if ( p ) {\r
+        free ( p );\r
+    }\r
+}\r
+\r
+typedef struct test_data_tree {\r
+    int element;\r
+    int left;\r
+    int right;\r
+    int parent;\r
+    int color;\r
+} TS;\r
+\r
+\r
+static struct clib_rb_node*\r
+pvt_find_clib_rb ( struct clib_rb* tree, clib_compare fn_c, void *key ) {\r
+    struct clib_rb_node* node = tree->root;\r
+    void* current_key = (void*)0;\r
+    int compare_result = 0;\r
+\r
+    current_key = (void*)malloc ( tree->size_of_key);\r
+    memcpy ( current_key, key, tree->size_of_key);\r
+\r
+    compare_result = (fn_c)(current_key, node->raw_data.key);\r
+    while ((node != rb_sentinel) && (compare_result = (fn_c)(current_key, node->raw_data.key)) != 0 ){\r
+        if ( compare_result < 0 ) {\r
+            node = node->left;\r
+        } else {\r
+            node = node->right;\r
+        }\r
+    } \r
+    free ( current_key );\r
+    return node;\r
+}\r
+struct clib_rb_node*\r
+find(struct clib_rb* tree, void *key ) {\r
+    return pvt_find_clib_rb ( tree, tree->compare_fn, key );\r
+}\r
+\r
+static void update_values ( void* v, int *l, int *r, int *p , int *e, struct clib_rb* tree ) {\r
+    struct clib_rb_node *x;\r
+    if ( get_key(tree,v)) \r
+        *e = *(int*)get_key (tree,v);\r
+    x = get_left(tree,v);\r
+    if ( x )\r
+        *l = *(int*)get_key(tree,x);\r
+    x = get_right(tree,v);\r
+    if (x) \r
+        *r = *(int*)get_key(tree,x);\r
+    x = get_parent ( tree, v );\r
+    if (x)             \r
+        *p = *(int*)get_key(tree,x);\r
+}\r
+\r
+static void \r
+test_each_elements(int l,int r, int p, int e,void* v, TS ts[], int i, \r
+        struct clib_rb* tree) {\r
+    assert ( ts[i].element == e);\r
+    if (ts[i].left != 0 ) \r
+        assert ( ts[i].left == l);\r
+    else\r
+        assert ((void* )0 == (void* )get_key(tree,get_left(tree,v)));\r
+    if ( ts[i].right != 0 ) \r
+        assert (ts[i].right == r);\r
+    else\r
+        assert ((void* )0 == (void* )get_key(tree,get_right(tree,v)));\r
+    if (ts[i].parent != 0 ) \r
+        assert (ts[i].parent == p);\r
+    else\r
+        assert ((void* )0 == (void* )get_key(tree,get_parent(tree,v)));\r
+}\r
+\r
+static void\r
+test_all_elements(struct clib_rb* tree, TS ts[], int size) {\r
+    int i = 0;\r
+    for ( i = 0; i < size; i++) {\r
+        void* v = (void*)0;\r
+        int l,r,p,e;\r
+        v = find ( tree, &ts[i].element);\r
+        update_values( v, &l,&r,&p,&e, tree);\r
+        test_each_elements(l,r,p,e,v, ts, i, tree);\r
+    }\r
+}\r
+\r
+static struct clib_rb* \r
+create_tree(TS ts[], int size) {\r
+    int i = 0;\r
+    struct clib_rb* tree = new_clib_rb( compare_rb_e,free_rb_e, (void*)0, sizeof(int),0);\r
+    for ( i = 0; i < size; i++) {\r
+        insert_clib_rb( tree, &(ts[i].element) ,(void*)0);\r
+    }\r
+    return tree;\r
+}\r
+\r
+\r
+void \r
+test_clib_rb() {\r
+    int size;\r
+    int size_after_delete;\r
+    int i = 0;\r
+    struct clib_rb* tree;\r
+    struct clib_rb_node* node;\r
+\r
+    TS ts[] = {\r
+        {15,6,18,0,BLACK},{6,3,9,15,RED},{18,17,20,15,BLACK},\r
+        {3,2,4,6,BLACK},{7,0,0,9,RED},{17,0,0,18,RED},\r
+        {20,0,0,18,RED},{2,0,0,3,RED},{4,0,0,3,RED},{13,0,0,9,RED},    \r
+        {9,7,13,6,BLACK}\r
+    };\r
+    TS ts_delete_leaf_13[] = {\r
+        {15,6,18,0,BLACK},{6,3,9,15,RED},{18,17,20,15,BLACK},\r
+        {3,2,4,6,BLACK},{7,0,0,9,RED},{17,0,0,18,RED},\r
+        {20,0,0,18,RED},{2,0,0,3,RED},{4,0,0,3,RED},\r
+        {9,7,0,6,BLACK}\r
+    }; \r
+    TS ts_delete_9[] = {\r
+        {15,6,18,0,BLACK},{6,3,7,15,RED},{18,17,20,15,BLACK},\r
+        {3,2,4,6,RED},{7,0,0,6,RED},{17,0,0,18,RED},\r
+        {20,0,0,18,RED},{2,0,0,3,RED},{4,0,0,3,RED}\r
+    }; \r
+    TS ts_delete_15[] = {\r
+        {6,3,7,17,RED},{18,0,20,17,BLACK},\r
+        {3,2,4,6,RED},{7,0,0,6,RED},{17,6,18,0,RED},\r
+        {20,0,0,18,RED},{2,0,0,3,RED},{4,0,0,3,RED}\r
+    };                 \r
+    TS ts_insert_1[] = {\r
+        {6,3,17,0,BLACK},{18,0,20,17,BLACK},\r
+        {3,2,4,6,RED},{7,0,0,17,RED},{17,7,18,6,RED},\r
+        {20,0,0,18,RED},{2,1,0,3,BLACK},{4,0,0,3,BLACK},\r
+        {1,0,0,2,RED}\r
+    };                 \r
+\r
+\r
+    size = (sizeof(ts)/sizeof(TS));\r
+    tree = create_tree(ts,size);\r
+    test_all_elements(tree, ts, size); \r
+    {   \r
+        i = 13;        \r
+        size = (sizeof(ts)/sizeof(TS));\r
+        size_after_delete = (sizeof(ts_delete_leaf_13)/sizeof(TS));\r
+        node = remove_clib_rb( tree, &i);\r
+        if ( node != (struct clib_rb_node*)0  ) {\r
+            free ( node->raw_data.key);\r
+            free ( node);\r
+        }\r
+        test_all_elements(tree, ts_delete_leaf_13, size_after_delete);\r
+    }\r
+    {\r
+        i = 9; \r
+        size_after_delete = (sizeof(ts_delete_9)/sizeof(TS));\r
+        node = remove_clib_rb( tree, &i);\r
+        if ( node != (struct clib_rb_node*)0  ) {\r
+            free ( node->raw_data.key);\r
+            free ( node);\r
+        }\r
+        test_all_elements(tree, ts_delete_9, size_after_delete);\r
+    }\r
+    {\r
+        i = 15;        \r
+        size_after_delete = (sizeof(ts_delete_15)/sizeof(TS));\r
+        node = remove_clib_rb( tree, &i);\r
+        if ( node != (struct clib_rb_node*)0  ) {\r
+            free ( node->raw_data.key);\r
+            free ( node);\r
+        }\r
+        test_all_elements(tree, ts_delete_15, size_after_delete);\r
+    }\r
+    {\r
+        int i = 1;\r
+        insert_clib_rb( tree, &i, (void*)0);\r
+        size_after_delete = (sizeof(ts_insert_1)/sizeof(TS));\r
+        test_all_elements(tree, ts_insert_1, size_after_delete);\r
+    }\r
+    {\r
+      delete_clib_rb(tree);\r
+    }\r
+}*/\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_set.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_set.c
new file mode 100644 (file)
index 0000000..3efea3e
--- /dev/null
@@ -0,0 +1,111 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include <assert.h>\r
+\r
+static void \r
+delete_e ( void *ptr ) {\r
+    if ( ptr ) \r
+       free ( ptr );\r
+}\r
+static int\r
+compare_e ( void *left, void *right ) {\r
+    char *l = (char*)left;\r
+    char *r = (char*)right;\r
+    return strcmp ( (const char *)l, (const char *) r );\r
+}\r
+static int \r
+compare_int ( void *left, void *right ) {\r
+    int *l = (int*)left;\r
+    int *r = (int*)right;\r
+\r
+    if ( *l < *r ) \r
+        return -1;\r
+    else if ( *l > *r ) \r
+        return 1;\r
+    return 0;\r
+}\r
+void \r
+test_clib_set(){\r
+    {\r
+        int test[] = { 0,1,2,3,4,5,6,7,8,9 };\r
+        int index  = 0;\r
+        int size   = sizeof (test) /sizeof(test[0]);\r
+        void* outKey;\r
+\r
+        struct clib_set *pSet = new_clib_set ( compare_int, NULL);\r
+\r
+        for ( index = 0; index < size; index++ ) {\r
+            int v = test[index];\r
+            insert_clib_set ( pSet, &v, sizeof(int));\r
+        }\r
+        for ( index = 0; index < size; index++ ) {\r
+            int v = test[index];\r
+            assert ( clib_true == exists_clib_set ( pSet, &v));\r
+        }\r
+\r
+        index = 9;\r
+        find_clib_set ( pSet, &index, &outKey);\r
+        assert ( 9 == *(int*)outKey);\r
+        free ( outKey );\r
+        delete_clib_set(pSet);\r
+    }\r
+    {\r
+        typedef struct test {\r
+            char *string;\r
+        } TEST_INPUT;\r
+\r
+        int index = 0;\r
+        int size = 0;\r
+        char *v;\r
+\r
+        TEST_INPUT ti[] ={\r
+            {"A for APPLE"},{"B for BALL"},{"C for CAT"}, {"D for DOG"},\r
+            {"E for ELEPHANT"},{"F for FISH"},{"G for GOAT"},\r
+            {"H for HORSE"},{"I for ICECREAM"},{"J for JOKER"},\r
+            {"K for KITE"},{"L for LAMB"},{"M for MONKEY"},\r
+            {"N for NEST"},{"O for ORANGE"},{"P for POT"},\r
+            {"Q for QUEEN"},{"R for RAT"},{"S for SHEEP"},\r
+            {"T for TABLE"},{"U for UMBRELLA"},{"V for VIOLIN"},{"W for WAX"},\r
+            {"X for XEROX"},{"Y for YUMMY"},{"Z for ZEBRA"}\r
+        };\r
+        struct clib_set *pSet = new_clib_set ( compare_e, delete_e);\r
+        size = sizeof ( ti ) / sizeof ( ti[0]);\r
+        \r
+        for ( index = 0; index < size; index++ ){\r
+            char *temp = clib_strdup ( ti[index].string );\r
+            insert_clib_set ( pSet, temp, strlen(temp) + 1 );\r
+            free ( temp );\r
+        }\r
+        for ( index = 0; index < size; index++ ){\r
+            v = ti[index].string;\r
+            assert ( clib_true == exists_clib_set ( pSet, v));\r
+        }\r
+        delete_clib_set(pSet);\r
+    }\r
+}\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_slist.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_slist.c
new file mode 100644 (file)
index 0000000..7c8337c
--- /dev/null
@@ -0,0 +1,121 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include "c_lib.h"\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include <assert.h>\r
+\r
+static void \r
+free_element ( void *ptr ) {\r
+    if ( ptr )\r
+        free ( ptr);\r
+}\r
+\r
+void\r
+add_elements_to_list( struct clib_slist* ll, int x, int y ) {\r
+    int i = 0;\r
+    for ( i = x; i <= y; i++ ) { \r
+        int *v = ( int *) malloc ( sizeof ( int ));\r
+        memcpy ( v, &i, sizeof ( int ));\r
+        push_back_clib_slist ( ll, v , sizeof(v));\r
+        free ( v );\r
+    }\r
+}\r
+void\r
+print_e ( void *ptr ) {\r
+    if ( ptr )\r
+        printf ( "%d\n", *(int*)ptr);\r
+}\r
+\r
+static int \r
+compare_element ( void *left, void *right ) {\r
+    int *l = (int*) left;\r
+    int *r = (int*) right;\r
+    return *l == *r ;\r
+}\r
+\r
+\r
+void\r
+test_clib_slist() {\r
+    int i = 0;\r
+    int *v;\r
+    void* outValue;\r
+    struct clib_slist* list = new_clib_slist(free_element,compare_element);\r
+\r
+    add_elements_to_list(list,1, 10 );\r
+    for_each_clib_slist(list, print_e);\r
+\r
+    i = 55;\r
+    v = ( int *) malloc ( sizeof ( int ));\r
+    memcpy ( v, &i, sizeof ( int ));\r
+    insert_clib_slist(list,5, v,sizeof(v));\r
+    free ( v );\r
+    for_each_clib_slist(list, print_e);\r
+\r
+    remove_clib_slist(list,5);\r
+    for_each_clib_slist(list, print_e);\r
+\r
+    remove_clib_slist(list,0);\r
+    for_each_clib_slist(list, print_e);\r
+\r
+    remove_clib_slist(list,100);\r
+    for_each_clib_slist(list, print_e);\r
+\r
+    i = 1;\r
+    v = ( int *) malloc ( sizeof ( int ));\r
+    memcpy ( v, &i, sizeof ( int ));\r
+    insert_clib_slist(list,1,v,sizeof(v));\r
+    free ( v );\r
+    for_each_clib_slist(list, print_e);\r
+\r
+    i = 11;\r
+    v = ( int *) malloc ( sizeof ( int ));\r
+    memcpy ( v, &i, sizeof ( int ));\r
+    insert_clib_slist(list,11,v,sizeof(v));\r
+    free ( v );\r
+    for_each_clib_slist(list, print_e);\r
+\r
+    i = 12;\r
+    v = ( int *) malloc ( sizeof ( int ));\r
+    memcpy ( v, &i, sizeof ( int ));\r
+    insert_clib_slist(list,200,v,sizeof(v));\r
+    free ( v );\r
+    for_each_clib_slist(list, print_e);\r
+\r
+    remove_clib_slist(list,list->size);\r
+    for_each_clib_slist(list, print_e);\r
+\r
+    i = 10;\r
+    if ( clib_true == find_clib_slist ( list, &i, &outValue)) {\r
+        assert ( i == *(int*)outValue );\r
+        free ( outValue );\r
+    }\r
+    i = 100;\r
+    assert ( clib_false == find_clib_slist ( list, &i, &outValue));\r
+\r
+    delete_clib_slist ( list );\r
+\r
+}\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_stack.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_c_stack.c
new file mode 100644 (file)
index 0000000..177999d
--- /dev/null
@@ -0,0 +1,42 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+#include "c_lib.h"\r
+#include <assert.h>\r
+\r
+void \r
+test_clib_stack() {\r
+       struct clib_stack *pStack = new_clib_stack( 10, NULL );\r
+       int i = 0;\r
+       int size = 10;\r
+       for ( i = 0; i < size; i++) {\r
+               push_clib_stack ( pStack, &i, sizeof(i));\r
+       }\r
+       size = size - 1;\r
+       while ( ! empty_clib_stack(pStack)) {\r
+               void *elem;\r
+               pop_clib_stack( pStack, &elem);\r
+               assert ( size-- == *(int*)elem);\r
+               free ( elem );\r
+       }\r
+       delete_clib_stack ( pStack );\r
+}
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/test/t_clibutils.c b/junkcode/dongre.avinash@gmail.com-clibutils/test/t_clibutils.c
new file mode 100644 (file)
index 0000000..54161a5
--- /dev/null
@@ -0,0 +1,54 @@
+/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **\r
+ *  This file is part of clib library\r
+ *  Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )\r
+ *\r
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ *  of this software and associated documentation files (the "Software"), to deal\r
+ *  in the Software without restriction, including without limitation the rights\r
+ *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ *  copies of the Software, and to permit persons to whom the Software is\r
+ *  furnished to do so, subject to the following conditions:\r
+ * \r
+ *  The above copyright notice and this permission notice shall be included in\r
+ *  all copies or substantial portions of the Software.\r
+ * \r
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ *  THE SOFTWARE.\r
+ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/\r
+\r
+#include <stdio.h>\r
+extern void test_clib_array();\r
+extern void test_clib_deque();\r
+extern void test_clib_tree();\r
+extern void test_clib_rb();\r
+extern void test_clib_set();\r
+extern void test_clib_map();\r
+extern void test_clib_slist();\r
+extern void test_clib_map();\r
+extern void test_clib_stack();\r
+extern void test_clib_heap();\r
+\r
+int main( int argc, char**argv ) {     \r
+    printf ( "Performing test for dynamic array\n");\r
+    test_clib_array();\r
+    printf ( "Performing test for deque\n");\r
+    test_clib_deque();\r
+    printf ( "Performing test for sets\n");\r
+    test_clib_set();\r
+    printf ( "Performing test for map\n");\r
+    test_clib_map();\r
+    printf ( "Performing test for slist\n");\r
+    test_clib_slist();\r
+    printf ( "Performing test for stackn");\r
+    test_clib_stack();\r
+    printf ( "Performing test for heap\n");\r
+    test_clib_heap();\r
+\r
+\r
+    return 0;\r
+}\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.ncb b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.ncb
new file mode 100644 (file)
index 0000000..ab2b3f5
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.ncb differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.sln b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.sln
new file mode 100644 (file)
index 0000000..ee03ed0
--- /dev/null
@@ -0,0 +1,29 @@
+\r
+Microsoft Visual Studio Solution File, Format Version 9.00\r
+# Visual Studio 2005\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clibutils", "clibutils.vcproj", "{B0D5C92E-C0FD-48EB-A472-FF5DC031ECB9}"\r
+EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tclibutils", "tclibutils.vcproj", "{7DB3F94C-1BA0-4BFF-B8FF-5BD95CF0A9F9}"\r
+       ProjectSection(ProjectDependencies) = postProject\r
+               {B0D5C92E-C0FD-48EB-A472-FF5DC031ECB9} = {B0D5C92E-C0FD-48EB-A472-FF5DC031ECB9}\r
+       EndProjectSection\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|Win32 = Debug|Win32\r
+               Release|Win32 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {B0D5C92E-C0FD-48EB-A472-FF5DC031ECB9}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {B0D5C92E-C0FD-48EB-A472-FF5DC031ECB9}.Debug|Win32.Build.0 = Debug|Win32\r
+               {B0D5C92E-C0FD-48EB-A472-FF5DC031ECB9}.Release|Win32.ActiveCfg = Release|Win32\r
+               {B0D5C92E-C0FD-48EB-A472-FF5DC031ECB9}.Release|Win32.Build.0 = Release|Win32\r
+               {7DB3F94C-1BA0-4BFF-B8FF-5BD95CF0A9F9}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {7DB3F94C-1BA0-4BFF-B8FF-5BD95CF0A9F9}.Debug|Win32.Build.0 = Debug|Win32\r
+               {7DB3F94C-1BA0-4BFF-B8FF-5BD95CF0A9F9}.Release|Win32.ActiveCfg = Release|Win32\r
+               {7DB3F94C-1BA0-4BFF-B8FF-5BD95CF0A9F9}.Release|Win32.Build.0 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.suo b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.suo
new file mode 100644 (file)
index 0000000..88389c6
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.suo differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.vcproj b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.vcproj
new file mode 100644 (file)
index 0000000..8625fd2
--- /dev/null
@@ -0,0 +1,259 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       Name="clibutils"\r
+       ProjectGUID="{B0D5C92E-C0FD-48EB-A472-FF5DC031ECB9}"\r
+       RootNamespace="clibutils"\r
+       Keyword="Win32Proj"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="$(SolutionDir)clibutils_$(ConfigurationName)"\r
+                       IntermediateDirectory="clibutils_$(ConfigurationName)"\r
+                       ConfigurationType="4"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="..\inc"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               ProgramDataBaseFileName="$(IntDir)\clibutils.pdb"\r
+                               WarningLevel="3"\r
+                               WarnAsError="false"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="4"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLibrarianTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
+                               RuntimeLibrary="2"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\src\c_array.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\src\c_deque.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\src\c_heap.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\src\c_map.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\src\c_rb.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\src\c_set.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\src\c_slist.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\src\c_stack.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\src\c_util.c"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\inc\c_array.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\inc\c_deque.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\inc\c_errors.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\inc\c_heap.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\inc\c_lib.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\inc\c_map.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\inc\c_rb.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\inc\c_set.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\inc\c_slist.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\inc\c_stack.h"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"\r
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
+                       >\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.vcproj.ADPROD.avdongre.user b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils.vcproj.ADPROD.avdongre.user
new file mode 100644 (file)
index 0000000..f463124
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioUserFile\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       ShowAllFiles="false"\r
+       >\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       >\r
+                       <DebugSettings\r
+                               Command=""\r
+                               WorkingDirectory=""\r
+                               CommandArguments=""\r
+                               Attach="false"\r
+                               DebuggerType="3"\r
+                               Remote="1"\r
+                               RemoteMachine="iBMC-7DX85BS"\r
+                               RemoteCommand=""\r
+                               HttpUrl=""\r
+                               PDBPath=""\r
+                               SQLDebugging=""\r
+                               Environment=""\r
+                               EnvironmentMerge="true"\r
+                               DebuggerFlavor=""\r
+                               MPIRunCommand=""\r
+                               MPIRunArguments=""\r
+                               MPIRunWorkingDirectory=""\r
+                               ApplicationCommand=""\r
+                               ApplicationArguments=""\r
+                               ShimCommand=""\r
+                               MPIAcceptMode=""\r
+                               MPIAcceptFilter=""\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       >\r
+                       <DebugSettings\r
+                               Command="$(TargetPath)"\r
+                               WorkingDirectory=""\r
+                               CommandArguments=""\r
+                               Attach="false"\r
+                               DebuggerType="3"\r
+                               Remote="1"\r
+                               RemoteMachine="iBMC-7DX85BS"\r
+                               RemoteCommand=""\r
+                               HttpUrl=""\r
+                               PDBPath=""\r
+                               SQLDebugging=""\r
+                               Environment=""\r
+                               EnvironmentMerge="true"\r
+                               DebuggerFlavor=""\r
+                               MPIRunCommand=""\r
+                               MPIRunArguments=""\r
+                               MPIRunWorkingDirectory=""\r
+                               ApplicationCommand=""\r
+                               ApplicationArguments=""\r
+                               ShimCommand=""\r
+                               MPIAcceptMode=""\r
+                               MPIAcceptFilter=""\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+</VisualStudioUserFile>\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/BuildLog.htm b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/BuildLog.htm
new file mode 100644 (file)
index 0000000..e6b7544
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/BuildLog.htm differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_array.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_array.obj
new file mode 100644 (file)
index 0000000..a726ff2
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_array.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_deque.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_deque.obj
new file mode 100644 (file)
index 0000000..77f5903
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_deque.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_heap.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_heap.obj
new file mode 100644 (file)
index 0000000..e730341
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_heap.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_map.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_map.obj
new file mode 100644 (file)
index 0000000..c8d325b
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_map.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_rb.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_rb.obj
new file mode 100644 (file)
index 0000000..3d0887b
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_rb.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_set.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_set.obj
new file mode 100644 (file)
index 0000000..02fca7a
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_set.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_slist.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_slist.obj
new file mode 100644 (file)
index 0000000..68d9bbd
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_slist.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_stack.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_stack.obj
new file mode 100644 (file)
index 0000000..ee62613
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_stack.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_util.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_util.obj
new file mode 100644 (file)
index 0000000..55cfd5d
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/c_util.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.idb b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.idb
new file mode 100644 (file)
index 0000000..32b486a
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.idb differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.lib b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.lib
new file mode 100644 (file)
index 0000000..9c64004
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.lib differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.pdb b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.pdb
new file mode 100644 (file)
index 0000000..4d88902
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/clibutils_Debug/clibutils.pdb differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils.vcproj b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils.vcproj
new file mode 100644 (file)
index 0000000..04fce08
--- /dev/null
@@ -0,0 +1,233 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       Name="tclibutils"\r
+       ProjectGUID="{7DB3F94C-1BA0-4BFF-B8FF-5BD95CF0A9F9}"\r
+       RootNamespace="tclibutils"\r
+       Keyword="Win32Proj"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="$(SolutionDir)tclibutils_$(ConfigurationName)"\r
+                       IntermediateDirectory="tclibutils_$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="..\inc"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               ProgramDataBaseFileName="$(IntDir)\tclibutils.pdb"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="4"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalDependencies="clibutils.lib"\r
+                               LinkIncremental="2"\r
+                               AdditionalLibraryDirectories="clibutils_Debug"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
+                               RuntimeLibrary="2"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\test\t_c_array.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\test\t_c_deque.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\test\t_c_heap.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\test\t_c_map.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\test\t_c_rb.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\test\t_c_set.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\test\t_c_slist.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\test\t_c_stack.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\test\t_clibutils.c"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"\r
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
+                       >\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils.vcproj.ADPROD.avdongre.user b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils.vcproj.ADPROD.avdongre.user
new file mode 100644 (file)
index 0000000..7694bdd
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioUserFile\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       ShowAllFiles="false"\r
+       >\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       >\r
+                       <DebugSettings\r
+                               Command="$(TargetPath)"\r
+                               WorkingDirectory=""\r
+                               CommandArguments=""\r
+                               Attach="false"\r
+                               DebuggerType="3"\r
+                               Remote="1"\r
+                               RemoteMachine="iBMC-7DX85BS"\r
+                               RemoteCommand=""\r
+                               HttpUrl=""\r
+                               PDBPath=""\r
+                               SQLDebugging=""\r
+                               Environment=""\r
+                               EnvironmentMerge="true"\r
+                               DebuggerFlavor=""\r
+                               MPIRunCommand=""\r
+                               MPIRunArguments=""\r
+                               MPIRunWorkingDirectory=""\r
+                               ApplicationCommand=""\r
+                               ApplicationArguments=""\r
+                               ShimCommand=""\r
+                               MPIAcceptMode=""\r
+                               MPIAcceptFilter=""\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       >\r
+                       <DebugSettings\r
+                               Command="$(TargetPath)"\r
+                               WorkingDirectory=""\r
+                               CommandArguments=""\r
+                               Attach="false"\r
+                               DebuggerType="3"\r
+                               Remote="1"\r
+                               RemoteMachine="iBMC-7DX85BS"\r
+                               RemoteCommand=""\r
+                               HttpUrl=""\r
+                               PDBPath=""\r
+                               SQLDebugging=""\r
+                               Environment=""\r
+                               EnvironmentMerge="true"\r
+                               DebuggerFlavor=""\r
+                               MPIRunCommand=""\r
+                               MPIRunArguments=""\r
+                               MPIRunWorkingDirectory=""\r
+                               ApplicationCommand=""\r
+                               ApplicationArguments=""\r
+                               ShimCommand=""\r
+                               MPIAcceptMode=""\r
+                               MPIAcceptFilter=""\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+</VisualStudioUserFile>\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/BuildLog.htm b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/BuildLog.htm
new file mode 100644 (file)
index 0000000..1d1d040
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/BuildLog.htm differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/mt.dep b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/mt.dep
new file mode 100644 (file)
index 0000000..a44d723
--- /dev/null
@@ -0,0 +1 @@
+Manifest resource last updated at 12:03:46.09 on Mon 04/18/2011 \r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_array.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_array.obj
new file mode 100644 (file)
index 0000000..5a9eb2a
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_array.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_deque.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_deque.obj
new file mode 100644 (file)
index 0000000..d27d19c
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_deque.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_heap.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_heap.obj
new file mode 100644 (file)
index 0000000..ff2548e
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_heap.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_map.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_map.obj
new file mode 100644 (file)
index 0000000..cfe55fa
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_map.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_rb.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_rb.obj
new file mode 100644 (file)
index 0000000..e46dc68
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_rb.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_set.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_set.obj
new file mode 100644 (file)
index 0000000..4400a26
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_set.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_slist.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_slist.obj
new file mode 100644 (file)
index 0000000..adfe3d1
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_slist.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_stack.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_stack.obj
new file mode 100644 (file)
index 0000000..39c7721
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_c_stack.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_clibutils.obj b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_clibutils.obj
new file mode 100644 (file)
index 0000000..251db70
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/t_clibutils.obj differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe
new file mode 100644 (file)
index 0000000..d3a2466
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe.embed.manifest b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe.embed.manifest
new file mode 100644 (file)
index 0000000..81a9cec
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">\r
+  <dependency>\r
+    <dependentAssembly>\r
+      <assemblyIdentity type="win32" name="Microsoft.VC80.DebugCRT" version="8.0.50727.762" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>\r
+    </dependentAssembly>\r
+  </dependency>\r
+</assembly>
\ No newline at end of file
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe.embed.manifest.res b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe.embed.manifest.res
new file mode 100644 (file)
index 0000000..84deeec
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe.embed.manifest.res differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe.intermediate.manifest b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.exe.intermediate.manifest
new file mode 100644 (file)
index 0000000..af0ac02
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\r
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>\r
+  <dependency>\r
+    <dependentAssembly>\r
+      <assemblyIdentity type='win32' name='Microsoft.VC80.DebugCRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />\r
+    </dependentAssembly>\r
+  </dependency>\r
+</assembly>\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.idb b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.idb
new file mode 100644 (file)
index 0000000..10c48ef
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.idb differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.ilk b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.ilk
new file mode 100644 (file)
index 0000000..01c3c5d
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.ilk differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.pdb b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.pdb
new file mode 100644 (file)
index 0000000..39d9284
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils.pdb differ
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils_pure.ini b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils_pure.ini
new file mode 100644 (file)
index 0000000..e8a74a8
--- /dev/null
@@ -0,0 +1,2 @@
+[Purify]\r
+\r
diff --git a/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils_pure.log b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils_pure.log
new file mode 100644 (file)
index 0000000..cb52279
Binary files /dev/null and b/junkcode/dongre.avinash@gmail.com-clibutils/win/tclibutils_Debug/tclibutils_pure.log differ