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