1 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
\r
2 * This file is part of clib library
\r
3 * Copyright (C) 2011 Avinash Dongre ( dongre.avinash@gmail.com )
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 * of this software and associated documentation files (the "Software"), to deal
\r
7 * in the Software without restriction, including without limitation the rights
\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 * copies of the Software, and to permit persons to whom the Software is
\r
10 * furnished to do so, subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
22 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
\r
32 free_element ( void *ptr ) {
\r
38 add_elements_to_list( struct clib_slist* ll, int x, int y ) {
\r
40 for ( i = x; i <= y; i++ ) {
\r
41 int *v = ( int *) malloc ( sizeof ( int ));
\r
42 memcpy ( v, &i, sizeof ( int ));
\r
43 push_back_clib_slist ( ll, v , sizeof(v));
\r
48 print_e ( void *ptr ) {
\r
50 printf ( "%d\n", *(int*)ptr);
\r
54 compare_element ( void *left, void *right ) {
\r
55 int *l = (int*) left;
\r
56 int *r = (int*) right;
\r
66 struct clib_slist* list = new_clib_slist(free_element,compare_element);
\r
68 add_elements_to_list(list,1, 10 );
\r
69 for_each_clib_slist(list, print_e);
\r
72 v = ( int *) malloc ( sizeof ( int ));
\r
73 memcpy ( v, &i, sizeof ( int ));
\r
74 insert_clib_slist(list,5, v,sizeof(v));
\r
76 for_each_clib_slist(list, print_e);
\r
78 remove_clib_slist(list,5);
\r
79 for_each_clib_slist(list, print_e);
\r
81 remove_clib_slist(list,0);
\r
82 for_each_clib_slist(list, print_e);
\r
84 remove_clib_slist(list,100);
\r
85 for_each_clib_slist(list, print_e);
\r
88 v = ( int *) malloc ( sizeof ( int ));
\r
89 memcpy ( v, &i, sizeof ( int ));
\r
90 insert_clib_slist(list,1,v,sizeof(v));
\r
92 for_each_clib_slist(list, print_e);
\r
95 v = ( int *) malloc ( sizeof ( int ));
\r
96 memcpy ( v, &i, sizeof ( int ));
\r
97 insert_clib_slist(list,11,v,sizeof(v));
\r
99 for_each_clib_slist(list, print_e);
\r
102 v = ( int *) malloc ( sizeof ( int ));
\r
103 memcpy ( v, &i, sizeof ( int ));
\r
104 insert_clib_slist(list,200,v,sizeof(v));
\r
106 for_each_clib_slist(list, print_e);
\r
108 remove_clib_slist(list,list->size);
\r
109 for_each_clib_slist(list, print_e);
\r
112 if ( clib_true == find_clib_slist ( list, &i, &outValue)) {
\r
113 assert ( i == *(int*)outValue );
\r
117 assert ( clib_false == find_clib_slist ( list, &i, &outValue));
\r
119 delete_clib_slist ( list );
\r