cn_map / cn_map_end

Syntax

void cn_map_end(CN_MAP map, CNM_ITERATOR * iterator)

Description

Sets iterator to point at the node past the last (highest value) in the CN_Map map.

Return Value

N/A

Examples

Basic Usage

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

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

main() {
	CN_MAP map = cn_map_init(char, int, cn_cmp_char);

	char key;
	int  value;

	//Put in a-z with 0-25 in as key/value pairs.
	for (key = 'a', value = 0; key <= 'z'; key++, value++) {
		cn_map_insert(map, &key, &value);
	}

	//Make 2 iterators: current (beginning) and end
	CNM_ITERATOR cur, end;
	
	//Set accordingly
	cn_map_begin(map, &cur);
	cn_map_end  (map, &end);

	//Traverse by comparing pointers directly
	for (; cur.node != end.node; cn_map_next(map, &cur)) {
		printf(
			"%c -> %d\n",
			cn_map_iterator_key  (&cur, char),
			cn_map_iterator_value(&cur, int)
		);
	}

	cn_map_free(map);
}