cvector - /* * File: cvector.h * -* Defines the interface...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/** * File: cvector.h * --------------- * Defines the interface for the CVector type. * * The CVector manages a linear indexed collection of homogeneous elements. * Think of it as an upgrade from the raw C array, with convenient dynamic * memory management (grow/shrink), operations to insert/remove, and * sort and search facilities. In order to work for all types of elements, * all CVector elements must be passed and returned via (void *) pointers. * Given its extensive use of untyped pointers, the CVector is a bit tricky * to use correctly as a client. Be diligent! * * CS107 Spring 2010 jzelenski */ #ifndef _cvector_h #define _cvector_h #include <stdbool.h> // this header defines the C99 bool type /** * Type: CVectorCmpElemFn * ---------------------- * CVectorCmpElemFn is the typename for a pointer to a client-supplied * comparator function passed to CVector to sort or search for elements. * The comparator takes two const void * pointers (these point to elements) * and returns an int. That int should indicate the ordering of the two elements * using the same convention as the strcmp library function: * * If element at elemAddr1 < element at elemAddr2, return a negative number * If element at elemAddr1 > element at elemAddr2, return a positive number * If element at elemAddr1 = element at elemAddr2, return zero */ typedef int (*CVectorCmpElemFn)(const void *elemAddr1, const void *elemAddr2); /** * Type: CVectorFreeElemFn * ----------------------- * CVectorFreeElemFn is the typename for a pointer to a client-supplied function * passed to CVector to apply to an element being removed/freed. The free function * takes one void * pointer that points to the element about to be removed/freed. */ typedef void (*CVectorFreeElemFn)(void *elemAddr); /** * Type: CVectorMapElemFn * ---------------------- * CVectorMapElemFn is the typename for a pointer to a client-supplied mapping * function passed to CVector to apply to each element. The map function takes * a void * pointer to the element and another void * for extra data pointer * passed by the client. */ typedef void (*CVectorMapElemFn)(void *elemAddr, void *auxData);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
/** * Type: CVector * ------------- * Defines the concrete representation of the CVector internals.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/24/2012 for the course CS 107 taught by Professor Cain,g during the Spring '08 term at Stanford.

Page1 / 5

cvector - /* * File: cvector.h * -* Defines the interface...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online