libcmutils 0.6.5
Multi-platform C99 utility library
Loading...
Searching...
No Matches
Arrays, maps, lists and their iterator.

Data Structures

struct  CMUTIL_Iterator
 Iterator of collection members. More...
 
struct  CMUTIL_Array
 Dynamic array of any type element. More...
 
struct  CMUTIL_MapPair
 Key-value pair for CMUTIL_Map. More...
 
struct  CMUTIL_Map
 Hashmap type with item order preserved. More...
 
struct  CMUTIL_List
 A doubly linked list type. More...
 

Macros

#define CMUTIL_ARRAY_DEFAULT   10
 
#define CMUTIL_ArrayCreate()    CMUTIL_ArrayCreateEx(CMUTIL_ARRAY_DEFAULT, NULL, NULL)
 Creates an unsorted dynamic array.
 
#define CMUTIL_MAP_DEFAULT   256
 
#define CMUTIL_MapCreate()
 
#define CMUTIL_ListCreate()   CMUTIL_ListCreateEx(NULL)
 Create a new list with default settings.
 

Functions

CMUTIL_ArrayCMUTIL_ArrayCreateEx (size_t initcapacity, CMCompareCB comparator, CMFreeCB freecb)
 Creates a dynamic array with capacity and optional comparator and free callback.
 
CMUTIL_MapCMUTIL_MapCreateEx (uint32_t bucketsize, CMBool isucase, CMFreeCB freecb, float load_factor)
 Create a new map with custom settings.
 
CMUTIL_ListCMUTIL_ListCreateEx (CMFreeCB freecb)
 Create a new list with a custom free callback.
 

Detailed Description

Macro Definition Documentation

◆ CMUTIL_ARRAY_DEFAULT

#define CMUTIL_ARRAY_DEFAULT   10

Default initial capacity of a dynamic array.

◆ CMUTIL_ArrayCreate

#define CMUTIL_ArrayCreate ( )     CMUTIL_ArrayCreateEx(CMUTIL_ARRAY_DEFAULT, NULL, NULL)

Creates an unsorted dynamic array.

Returns
A new dynamic array.

◆ CMUTIL_MAP_DEFAULT

#define CMUTIL_MAP_DEFAULT   256

The default initial bucket size for the map.

◆ CMUTIL_MapCreate

#define CMUTIL_MapCreate ( )
Value:
CMUTIL_MAP_DEFAULT, CMFalse, NULL, 0.75f)
#define CMUTIL_MAP_DEFAULT
Definition libcmutils.h:2561
CMUTIL_Map * CMUTIL_MapCreateEx(uint32_t bucketsize, CMBool isucase, CMFreeCB freecb, float load_factor)
Create a new map with custom settings.
@ CMFalse
Definition libcmutils.h:236

Create a new map with default settings.

◆ CMUTIL_ListCreate

#define CMUTIL_ListCreate ( )    CMUTIL_ListCreateEx(NULL)

Create a new list with default settings.

This macro creates a new CMUTIL_List object without a custom free callback.

Returns
A pointer to the newly created list, or NULL on failure.

Function Documentation

◆ CMUTIL_ArrayCreateEx()

CMUTIL_Array * CMUTIL_ArrayCreateEx ( size_t  initcapacity,
CMCompareCB  comparator,
CMFreeCB  freecb 
)

Creates a dynamic array with capacity and optional comparator and free callback.

Parameters
initcapacityInitial capacity of this array.
comparatorComparator callback for a sorted array. You must provide this callback if you want to create a sorted array.
freecbFree callback for each item in this array, if this parameter is supplied, this array will take the ownership of its items.
Returns
A new dynamic array.

◆ CMUTIL_MapCreateEx()

CMUTIL_Map * CMUTIL_MapCreateEx ( uint32_t  bucketsize,
CMBool  isucase,
CMFreeCB  freecb,
float  load_factor 
)

Create a new map with custom settings.

Parameters
bucketsizeThe initial number of buckets for the map.
isucaseWhether the key of the map should be case-insensitive.
freecbA callback function to free values when the map is destroyed.
load_factorThe load factor for the map, 0.75 may appropriate for most use cases.
Returns
A pointer to the newly created map, or NULL on failure.

◆ CMUTIL_ListCreateEx()

CMUTIL_List * CMUTIL_ListCreateEx ( CMFreeCB  freecb)

Create a new list with a custom free callback.

This function creates a new CMUTIL_List object with a specified callback function to free items when the list is destroyed.

Parameters
freecbA callback function to free items when the list is destroyed. If NULL, items will not be freed.
Returns
A pointer to the newly created list, or NULL on failure.