cn_map / new_cn_map

Syntax

CN_MAP new_cn_map(size_t key_size, size_t value_size, CNC_COMP (*func)(void *, void *))

Description

Initialises the CN_Map and returns a pointer to it. This instance is created via malloc and must be freed by using cn_map_free.

The CN_Map works on sizeof()'s of datatypes (key_size and value_size to allow for generic typing. You must also specify a comparison function func that the CN_Map will use to determine how to sort keys. The sorting function should return -1 or lower if a value is "less than" another, 0 if equal, and 1 or greater if the item is "greater than" another. For compatibility, we recommend you use the CNC_COMP (int) datatype when making custom comparison functions.

Return Value

Will return a pointer to a CN_MAP on success. Returns NULL otherwise.

Examples

Basic Usage

#include <stdio.h>
#include <stdlib.h>

#include "cn_cmp.h"
#include "cn_map.h"

main() {
	//Create a new cn_map
	CN_MAP map = new_cn_map(sizeof(int), sizeof(int), cn_cmp_int);

	//Free the CN_Map
	cn_map_free(map);
}