Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
test_list.c File Reference
#include "gwlib/gwlib.h"

Go to the source code of this file.

Macros

#define HUGE_SIZE   20
 

Functions

static int my_sort_cmp (const void *a, const void *b)
 
int main (void)
 

Macro Definition Documentation

#define HUGE_SIZE   20

Definition at line 66 of file test_list.c.

Referenced by main().

Function Documentation

int main ( void  )

Definition at line 78 of file test_list.c.

References debug(), gwlib_init(), gwlib_shutdown(), gwlist_append(), gwlist_create, gwlist_destroy(), gwlist_get(), gwlist_len(), gwlist_sort(), HUGE_SIZE, my_sort_cmp(), octstr_create, octstr_destroy_item(), octstr_get_cstr, uuid_clear(), uuid_generate(), UUID_STR_LEN, and uuid_unparse().

79 {
80  List *list;
81  char id[UUID_STR_LEN + 1];
82  int i;
83 
84  gwlib_init();
85 
86  debug("",0,"List performance test.");
87  list = gwlist_create();
88 
89  /* generate UUIDs and populate the list */
90  debug("", 0, "Creating %d UUIDs for the list.", HUGE_SIZE);
91  for (i = 0; i < HUGE_SIZE; i++) {
92  Octstr *os;
93  uuid_t uid;
94  uuid_generate(uid);
95  uuid_unparse(uid, id);
96  os = octstr_create(id);
97  gwlist_append(list, os);
98  uuid_clear(uid);
99  }
100  debug("",0,"Objects in the list: %ld", gwlist_len(list));
101 
102  /* try to sort */
103  debug("",0,"Sorting.");
104  gwlist_sort(list, my_sort_cmp);
105  debug("",0,"Sorting done.");
106  for (i = 0; i < HUGE_SIZE; i++) {
107  Octstr *os = gwlist_get(list, i);
108  debug("",0,"After sort: %s %d", octstr_get_cstr(os), i);
109  }
110 
112 
113  gwlib_shutdown();
114  return 0;
115 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void gwlist_sort(List *list, int(*cmp)(const void *, const void *))
Definition: list.c:576
void uuid_unparse(const uuid_t uu, char *out)
Definition: gw_uuid.c:561
void uuid_generate(uuid_t out)
Definition: gw_uuid.c:392
static int my_sort_cmp(const void *a, const void *b)
Definition: test_list.c:69
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
#define octstr_create(cstr)
Definition: octstr.h:125
void octstr_destroy_item(void *os)
Definition: octstr.c:334
#define UUID_STR_LEN
Definition: gw_uuid.h:19
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
void gwlib_shutdown(void)
Definition: gwlib.c:94
#define gwlist_create()
Definition: list.h:136
unsigned char uuid_t[16]
Definition: gw_uuid.h:32
void gwlib_init(void)
Definition: gwlib.c:78
#define HUGE_SIZE
Definition: test_list.c:66
Definition: list.c:102
void uuid_clear(uuid_t uu)
Definition: gw_uuid.c:105
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
static int my_sort_cmp ( const void *  a,
const void *  b 
)
static

Definition at line 69 of file test_list.c.

References octstr_compare().

Referenced by main().

70 {
71  const Octstr *fa = a;
72  const Octstr *fb = b;
73 
74  return octstr_compare(fa, fb);
75 }
Definition: octstr.c:118
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.