-
Notifications
You must be signed in to change notification settings - Fork 0
How do I?
Jack edited this page Mar 26, 2017
·
3 revisions
For release build (optimised, no debug symbols, just library archive file):
make
For development build (unoptimised, debug symbols, unit tests, ASan):
make debug
For ease of use while writing code,
./tools/build.sh # from project root
Firstly, initialise the list (both single and double are equivalent):
SList my_list;
slist_init(&my_list);
/* my_list is now initialised */
To add stuff to it:
/* my stuff */
int my_int = 1;
float my_float = 3.1415;
const char* my_str = "starman";
/* append to list */
slist_append((void*)my_int, &my_list);
slist_append((void*)my_float, &my_list);
slist_append((void*)my_str, &my_list);
To test for list membership:
bool found = false;
slist_in(&found, (void*)1, &my_list);
/* on success, found == true */
Finding something in a list:
unsigned int loc = 0;
slist_find(&loc, (void*)my_str, &my_list);
/* on success, loc == 3 */
To remove stuff you don't want:
slist_remove(1, &my_list); /* removes my_float from my_list */
When you're done, don't forget to free:
slist_free(NULL, &my_list);
If you've got more complicated data in your list (like pointers to your own structures that might point to allocated memory themselves), tell JCRL how to free your data:
void free_my_stuff(void* data)
{
free((my_struct*)data->big_mem_block);
}
slist_free(&free_my_stuff, &my_complicated_list);
Once again, both single and double are equivalent:
bool cmp(void* a, void* b) /* JCRL needs a comparison function */
{
if((int)a < (int)b)
{
return true;
}
return false;
}
bubblesort_slist(&cmp, &my_list); /* bubblesort */
isort_slist(&cmp, &my_list); /* insertion sort */
/* ... */