Blame include/complib/cl_ptr_vector.h

Packit 13e616
/*
Packit 13e616
 * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
Packit 13e616
 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
Packit 13e616
 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
Packit 13e616
 *
Packit 13e616
 * This software is available to you under a choice of one of two
Packit 13e616
 * licenses.  You may choose to be licensed under the terms of the GNU
Packit 13e616
 * General Public License (GPL) Version 2, available from the file
Packit 13e616
 * COPYING in the main directory of this source tree, or the
Packit 13e616
 * OpenIB.org BSD license below:
Packit 13e616
 *
Packit 13e616
 *     Redistribution and use in source and binary forms, with or
Packit 13e616
 *     without modification, are permitted provided that the following
Packit 13e616
 *     conditions are met:
Packit 13e616
 *
Packit 13e616
 *      - Redistributions of source code must retain the above
Packit 13e616
 *        copyright notice, this list of conditions and the following
Packit 13e616
 *        disclaimer.
Packit 13e616
 *
Packit 13e616
 *      - Redistributions in binary form must reproduce the above
Packit 13e616
 *        copyright notice, this list of conditions and the following
Packit 13e616
 *        disclaimer in the documentation and/or other materials
Packit 13e616
 *        provided with the distribution.
Packit 13e616
 *
Packit 13e616
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 13e616
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 13e616
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 13e616
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit 13e616
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit 13e616
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit 13e616
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit 13e616
 * SOFTWARE.
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Abstract:
Packit 13e616
 *	This file contains pointer vector definitions.  Pointer Vector provides
Packit 13e616
 *  dynmically resizable array functionality.
Packit 13e616
 */
Packit 13e616
Packit 13e616
#ifndef _CL_PTR_VECTOR_H_
Packit 13e616
#define _CL_PTR_VECTOR_H_
Packit 13e616
Packit 13e616
#include <complib/cl_types.h>
Packit 13e616
Packit 13e616
#ifdef __cplusplus
Packit 13e616
#  define BEGIN_C_DECLS extern "C" {
Packit 13e616
#  define END_C_DECLS   }
Packit 13e616
#else				/* !__cplusplus */
Packit 13e616
#  define BEGIN_C_DECLS
Packit 13e616
#  define END_C_DECLS
Packit 13e616
#endif				/* __cplusplus */
Packit 13e616
Packit 13e616
BEGIN_C_DECLS
Packit 13e616
/****h* Component Library/Pointer Vector
Packit 13e616
* NAME
Packit 13e616
*	Pointer Vector
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The Pointer Vector is a self-sizing array of pointers. Like a traditonal
Packit 13e616
*	array, a pointer vector allows efficient constant time access to elements
Packit 13e616
*	with a specified index.  A pointer vector grows transparently as the
Packit 13e616
*	user adds elements to the array.
Packit 13e616
*
Packit 13e616
*	The cl_pointer vector_t structure should be treated as opaque and should be
Packit 13e616
*	manipulated only through the provided functions.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Structures:
Packit 13e616
*		cl_ptr_vector_t
Packit 13e616
*
Packit 13e616
*	Callbacks:
Packit 13e616
*		cl_pfn_ptr_vec_apply_t, cl_pfn_ptr_vec_find_t
Packit 13e616
*
Packit 13e616
*	Item Manipulation:
Packit 13e616
*		cl_ptr_vector_set, cl_ptr_vector_obj
Packit 13e616
*
Packit 13e616
*	Initialization:
Packit 13e616
*		cl_ptr_vector_construct, cl_ptr_vector_init, cl_ptr_vector_destroy
Packit 13e616
*
Packit 13e616
*	Manipulation:
Packit 13e616
*		cl_ptr_vector_get_capacity, cl_ptr_vector_set_capacity,
Packit 13e616
*		cl_ptr_vector_get_size, cl_ptr_vector_set_size, cl_ptr_vector_set_min_size
Packit 13e616
*		cl_ptr_vector_get_ptr, cl_ptr_vector_get, cl_ptr_vector_at, cl_ptr_vector_set
Packit 13e616
*
Packit 13e616
*	Search:
Packit 13e616
*		cl_ptr_vector_find_from_start, cl_ptr_vector_find_from_end
Packit 13e616
*		cl_ptr_vector_apply_func
Packit 13e616
*********/
Packit 13e616
/****d* Component Library: Pointer Vector/cl_pfn_ptr_vec_apply_t
Packit 13e616
* NAME
Packit 13e616
*	cl_pfn_ptr_vec_apply_t
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_pfn_ptr_vec_apply_t function type defines the prototype for
Packit 13e616
*	functions used to iterate elements in a pointer vector.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
typedef void
Packit 13e616
 (*cl_pfn_ptr_vec_apply_t) (IN const size_t index,
Packit 13e616
			    IN void *const element, IN void *context);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	index
Packit 13e616
*		[in] Index of the element.
Packit 13e616
*
Packit 13e616
*	p_element
Packit 13e616
*		[in] Pointer to an element at the specified index in the pointer vector.
Packit 13e616
*
Packit 13e616
*	context
Packit 13e616
*		[in] Context provided in a call to cl_ptr_vector_apply_func.
Packit 13e616
*
Packit 13e616
* RETURN VALUE
Packit 13e616
*	This function does not return a value.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	This function type is provided as function prototype reference for
Packit 13e616
*	the function passed by users as a parameter to the cl_ptr_vector_apply_func
Packit 13e616
*	function.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_apply_func
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****d* Component Library: Pointer Vector/cl_pfn_ptr_vec_find_t
Packit 13e616
* NAME
Packit 13e616
*	cl_pfn_ptr_vec_find_t
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_pfn_ptr_vec_find_t function type defines the prototype for
Packit 13e616
*	functions used to find elements in a pointer vector.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
typedef cl_status_t
Packit 13e616
    (*cl_pfn_ptr_vec_find_t) (IN const size_t index,
Packit 13e616
			      IN const void *const element, IN void *context);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	index
Packit 13e616
*		[in] Index of the element.
Packit 13e616
*
Packit 13e616
*	p_element
Packit 13e616
*		[in] Pointer to an element at the specified index in the
Packit 13e616
*		pointer vector.
Packit 13e616
*
Packit 13e616
*	context
Packit 13e616
*		[in] Context provided in a call to cl_ptr_vector_find_from_start or
Packit 13e616
*		cl_ptr_vector_find_from_end.
Packit 13e616
*
Packit 13e616
* RETURN VALUES
Packit 13e616
*	Return CL_SUCCESS if the element was found. This stops pointer vector
Packit 13e616
*	iteration.
Packit 13e616
*
Packit 13e616
*	CL_NOT_FOUND to continue the pointer vector iteration.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	This function type is provided as function prototype reference for the
Packit 13e616
*	function provided by users as a parameter to the
Packit 13e616
*	cl_ptr_vector_find_from_start and cl_ptr_vector_find_from_end functions.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_find_from_start, cl_ptr_vector_find_from_end
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****s* Component Library: Pointer Vector/cl_ptr_vector_t
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_t
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	Pointer Vector structure.
Packit 13e616
*
Packit 13e616
*	The cl_ptr_vector_t structure should be treated as opaque and should be
Packit 13e616
*	manipulated only through the provided functions.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
typedef struct _cl_ptr_vector {
Packit 13e616
	size_t size;
Packit 13e616
	size_t grow_size;
Packit 13e616
	size_t capacity;
Packit 13e616
	const void **p_ptr_array;
Packit 13e616
	cl_state_t state;
Packit 13e616
} cl_ptr_vector_t;
Packit 13e616
/*
Packit 13e616
* FIELDS
Packit 13e616
*	size
Packit 13e616
*		 Number of elements successfully initialized in the pointer vector.
Packit 13e616
*
Packit 13e616
*	grow_size
Packit 13e616
*		 Number of elements to allocate when growing.
Packit 13e616
*
Packit 13e616
*	capacity
Packit 13e616
*		 total # of elements allocated.
Packit 13e616
*
Packit 13e616
*	alloc_list
Packit 13e616
*		 List of allocations.
Packit 13e616
*
Packit 13e616
*	p_ptr_array
Packit 13e616
*		 Internal array of pointers to elements.
Packit 13e616
*
Packit 13e616
*	state
Packit 13e616
*		State of the pointer vector.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_construct
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_construct
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_construct function constructs a pointer vector.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
void cl_ptr_vector_construct(IN cl_ptr_vector_t * const p_vector);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure to construct.
Packit 13e616
*
Packit 13e616
* RETURN VALUE
Packit 13e616
*	This function does not return a value.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	Allows calling cl_ptr_vector_destroy without first calling
Packit 13e616
*	cl_ptr_vector_init.
Packit 13e616
*
Packit 13e616
*	Calling cl_ptr_vector_construct is a prerequisite to calling any other
Packit 13e616
*	pointer vector function except cl_ptr_vector_init.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_init, cl_ptr_vector_destroy
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_init
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_init
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_init function initializes a pointer vector for use.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
cl_status_t
Packit 13e616
cl_ptr_vector_init(IN cl_ptr_vector_t * const p_vector,
Packit 13e616
		   IN const size_t min_size, IN const size_t grow_size);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure to inititalize.
Packit 13e616
*
Packit 13e616
*	min_size
Packit 13e616
*		[in] Initial number of elements.
Packit 13e616
*
Packit 13e616
*	grow_size
Packit 13e616
*		[in] Number of elements to allocate when incrementally growing
Packit 13e616
*		the pointer vector.  A value of zero disables automatic growth.
Packit 13e616
*
Packit 13e616
* RETURN VALUES
Packit 13e616
*	CL_SUCCESS if the pointer vector was initialized successfully.
Packit 13e616
*
Packit 13e616
*	CL_INSUFFICIENT_MEMORY if the initialization failed.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_construct, cl_ptr_vector_destroy,
Packit 13e616
*	cl_ptr_vector_set, cl_ptr_vector_get, cl_ptr_vector_at
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_destroy
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_destroy
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_destroy function destroys a pointer vector.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
void cl_ptr_vector_destroy(IN cl_ptr_vector_t * const p_vector);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure to destroy.
Packit 13e616
*
Packit 13e616
* RETURN VALUE
Packit 13e616
*	This function does not return a value.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_destroy frees all memory allocated for the pointer vector.
Packit 13e616
*
Packit 13e616
*	This function should only be called after a call to cl_ptr_vector_construct
Packit 13e616
*	or cl_ptr_vector_init.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_construct, cl_ptr_vector_init
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_get_capacity
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_get_capacity
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_get_capacity function returns the capacity of
Packit 13e616
*	a pointer vector.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
static inline size_t
Packit 13e616
cl_ptr_vector_get_capacity(IN const cl_ptr_vector_t * const p_vector)
Packit 13e616
{
Packit 13e616
	CL_ASSERT(p_vector);
Packit 13e616
	CL_ASSERT(p_vector->state == CL_INITIALIZED);
Packit 13e616
Packit 13e616
	return (p_vector->capacity);
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure whose capacity to return.
Packit 13e616
*
Packit 13e616
* RETURN VALUE
Packit 13e616
*	Capacity, in elements, of the pointer vector.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	The capacity is the number of elements that the pointer vector can store,
Packit 13e616
*	and can be greater than the number of elements stored. To get the number
Packit 13e616
*	of elements stored in the pointer vector, use cl_ptr_vector_get_size.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_set_capacity, cl_ptr_vector_get_size
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_get_size
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_get_size
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_get_size function returns the size of a pointer vector.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
static inline uint32_t
Packit 13e616
cl_ptr_vector_get_size(IN const cl_ptr_vector_t * const p_vector)
Packit 13e616
{
Packit 13e616
	CL_ASSERT(p_vector);
Packit 13e616
	CL_ASSERT(p_vector->state == CL_INITIALIZED);
Packit 13e616
	return ((uint32_t) p_vector->size);
Packit 13e616
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure whose size to return.
Packit 13e616
*
Packit 13e616
* RETURN VALUE
Packit 13e616
*	Size, in elements, of the pointer vector.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_set_size, cl_ptr_vector_get_capacity
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_get
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_get
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_get function returns the pointer stored in a
Packit 13e616
*	pointer vector at a specified index.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
static inline void *cl_ptr_vector_get(IN const cl_ptr_vector_t * const p_vector,
Packit 13e616
				      IN const size_t index)
Packit 13e616
{
Packit 13e616
	CL_ASSERT(p_vector);
Packit 13e616
	CL_ASSERT(p_vector->state == CL_INITIALIZED);
Packit 13e616
	CL_ASSERT(p_vector->size > index);
Packit 13e616
Packit 13e616
	return ((void *)p_vector->p_ptr_array[index]);
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure from which to get an
Packit 13e616
*		element.
Packit 13e616
*
Packit 13e616
*	index
Packit 13e616
*		[in] Index of the element.
Packit 13e616
*
Packit 13e616
* RETURN VALUE
Packit 13e616
*	Value of the pointer stored at the specified index.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_get provides constant access times regardless of the index.
Packit 13e616
*
Packit 13e616
*	cl_ptr_vector_get does not perform boundary checking. Callers are
Packit 13e616
*	responsible for providing an index that is within the range of the pointer
Packit 13e616
*	vector.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_at, cl_ptr_vector_set, cl_ptr_vector_get_size
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_at
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_at
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_at function copies an element stored in a pointer
Packit 13e616
*	vector at a specified index, performing boundary checks.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
cl_status_t
Packit 13e616
cl_ptr_vector_at(IN const cl_ptr_vector_t * const p_vector,
Packit 13e616
		 IN const size_t index, OUT void **const p_element);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure from which to get a copy of
Packit 13e616
*		an element.
Packit 13e616
*
Packit 13e616
*	index
Packit 13e616
*		[in] Index of the element.
Packit 13e616
*
Packit 13e616
*	p_element
Packit 13e616
*		[out] Pointer to storage for the pointer element. Contains a copy of
Packit 13e616
*		the desired pointer upon successful completion of the call.
Packit 13e616
*
Packit 13e616
* RETURN VALUES
Packit 13e616
*	CL_SUCCESS if an element was found at the specified index.
Packit 13e616
*
Packit 13e616
*	CL_INVALID_SETTING if the index was out of range.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_at provides constant time access regardless of
Packit 13e616
*	the index, and performs boundary checking on the pointer vector.
Packit 13e616
*
Packit 13e616
*	Upon success, the p_element parameter contains a copy of the
Packit 13e616
*	desired element.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_get
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_set
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_set
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_set function sets the element at the specified index.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
cl_status_t
Packit 13e616
cl_ptr_vector_set(IN cl_ptr_vector_t * const p_vector,
Packit 13e616
		  IN const size_t index, IN const void *const element);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure into which to store
Packit 13e616
*		an element.
Packit 13e616
*
Packit 13e616
*	index
Packit 13e616
*		[in] Index of the element.
Packit 13e616
*
Packit 13e616
*	element
Packit 13e616
*		[in] Pointer to store in the pointer vector.
Packit 13e616
*
Packit 13e616
* RETURN VALUES
Packit 13e616
*	CL_SUCCESS if the element was successfully set.
Packit 13e616
*
Packit 13e616
*	CL_INSUFFICIENT_MEMORY if the pointer vector could not be resized to
Packit 13e616
*	accommodate the new element.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_set grows the pointer vector as needed to accommodate
Packit 13e616
*	the new element, unless the grow_size parameter passed into the
Packit 13e616
*	cl_ptr_vector_init function was zero.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_get
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_insert
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_insert
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_insert function inserts an element into a pointer vector.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
static inline cl_status_t
Packit 13e616
cl_ptr_vector_insert(IN cl_ptr_vector_t * const p_vector,
Packit 13e616
		     IN const void *const element,
Packit 13e616
		     OUT size_t * const p_index OPTIONAL)
Packit 13e616
{
Packit 13e616
	cl_status_t status;
Packit 13e616
Packit 13e616
	CL_ASSERT(p_vector);
Packit 13e616
	CL_ASSERT(p_vector->state == CL_INITIALIZED);
Packit 13e616
Packit 13e616
	status = cl_ptr_vector_set(p_vector, p_vector->size, element);
Packit 13e616
	if (status == CL_SUCCESS && p_index)
Packit 13e616
		*p_index = p_vector->size - 1;
Packit 13e616
Packit 13e616
	return (status);
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure into which to store
Packit 13e616
*		an element.
Packit 13e616
*
Packit 13e616
*	element
Packit 13e616
*		[in] Pointer to store in the pointer vector.
Packit 13e616
*
Packit 13e616
*	p_index
Packit 13e616
*		[out] Pointer to the index of the element.  Valid only if
Packit 13e616
*		insertion was successful.
Packit 13e616
*
Packit 13e616
* RETURN VALUES
Packit 13e616
*	CL_SUCCESS if the element was successfully inserted.
Packit 13e616
*
Packit 13e616
*	CL_INSUFFICIENT_MEMORY if the pointer vector could not be resized to
Packit 13e616
*	accommodate the new element.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_insert places the new element at the end of
Packit 13e616
*	the pointer vector.
Packit 13e616
*
Packit 13e616
*	cl_ptr_vector_insert grows the pointer vector as needed to accommodate
Packit 13e616
*	the new element, unless the grow_size parameter passed into the
Packit 13e616
*	cl_ptr_vector_init function was zero.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_remove, cl_ptr_vector_set
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_remove
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_remove
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_remove function removes and returns the pointer stored
Packit 13e616
*	in a pointer vector at a specified index.  Items beyond the removed item
Packit 13e616
*	are shifted down and the size of the pointer vector is decremented.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
void *cl_ptr_vector_remove(IN cl_ptr_vector_t * const p_vector,
Packit 13e616
			   IN const size_t index);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure from which to get an
Packit 13e616
*		element.
Packit 13e616
*
Packit 13e616
*	index
Packit 13e616
*		[in] Index of the element.
Packit 13e616
*
Packit 13e616
* RETURN VALUE
Packit 13e616
*	Value of the pointer stored at the specified index.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_remove does not perform boundary checking. Callers are
Packit 13e616
*	responsible for providing an index that is within the range of the pointer
Packit 13e616
*	vector.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_insert, cl_ptr_vector_get_size
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_set_capacity
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_set_capacity
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_set_capacity function reserves memory in a
Packit 13e616
*	pointer vector for a specified number of pointers.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
cl_status_t
Packit 13e616
cl_ptr_vector_set_capacity(IN cl_ptr_vector_t * const p_vector,
Packit 13e616
			   IN const size_t new_capacity);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure whose capacity to set.
Packit 13e616
*
Packit 13e616
*	new_capacity
Packit 13e616
*		[in] Total number of elements for which the pointer vector should
Packit 13e616
*		allocate memory.
Packit 13e616
*
Packit 13e616
* RETURN VALUES
Packit 13e616
*	CL_SUCCESS if the capacity was successfully set.
Packit 13e616
*
Packit 13e616
*	CL_INSUFFICIENT_MEMORY if there was not enough memory to satisfy the
Packit 13e616
*	operation. The pointer vector is left unchanged.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_set_capacity increases the capacity of the pointer vector.
Packit 13e616
*	It does not change the size of the pointer vector. If the requested
Packit 13e616
*	capacity is less than the current capacity, the pointer vector is left
Packit 13e616
*	unchanged.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_get_capacity, cl_ptr_vector_set_size,
Packit 13e616
*	cl_ptr_vector_set_min_size
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_set_size
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_set_size
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_set_size function resizes a pointer vector, either
Packit 13e616
*	increasing or decreasing its size.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
cl_status_t
Packit 13e616
cl_ptr_vector_set_size(IN cl_ptr_vector_t * const p_vector,
Packit 13e616
		       IN const size_t size);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure whose size to set.
Packit 13e616
*
Packit 13e616
*	size
Packit 13e616
*		[in] Number of elements desired in the pointer vector.
Packit 13e616
*
Packit 13e616
* RETURN VALUES
Packit 13e616
*	CL_SUCCESS if the size of the pointer vector was set successfully.
Packit 13e616
*
Packit 13e616
*	CL_INSUFFICIENT_MEMORY if there was not enough memory to complete the
Packit 13e616
*	operation. The pointer vector is left unchanged.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_set_size sets the pointer vector to the specified size.
Packit 13e616
*	If size is smaller than the current size of the pointer vector, the size
Packit 13e616
*	is reduced.
Packit 13e616
*
Packit 13e616
*	This function can only fail if size is larger than the current capacity.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_get_size, cl_ptr_vector_set_min_size,
Packit 13e616
*	cl_ptr_vector_set_capacity
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_set_min_size
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_set_min_size
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_set_min_size function resizes a pointer vector to a
Packit 13e616
*	specified size if the pointer vector is smaller than the specified size.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
cl_status_t
Packit 13e616
cl_ptr_vector_set_min_size(IN cl_ptr_vector_t * const p_vector,
Packit 13e616
			   IN const size_t min_size);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure whose minimum size to set.
Packit 13e616
*
Packit 13e616
*	min_size
Packit 13e616
*		[in] Minimum number of elements that the pointer vector should contain.
Packit 13e616
*
Packit 13e616
* RETURN VALUES
Packit 13e616
*	CL_SUCCESS if the pointer vector size is greater than or equal to min_size.
Packit 13e616
*	This could indicate that the pointer vector's capacity was increased to
Packit 13e616
*	min_size or that the pointer vector was already of sufficient size.
Packit 13e616
*
Packit 13e616
*	CL_INSUFFICIENT_MEMORY if there was not enough memory to resize the
Packit 13e616
*	pointer vector.  The pointer vector is left unchanged.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	If min_size is smaller than the current size of the pointer vector,
Packit 13e616
*	the pointer vector is unchanged. The pointer vector is unchanged if the
Packit 13e616
*	size could not be changed due to insufficient memory being available to
Packit 13e616
*	perform the operation.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_get_size, cl_ptr_vector_set_size,
Packit 13e616
*	cl_ptr_vector_set_capacity
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_apply_func
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_apply_func
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_apply_func function invokes a specified function for
Packit 13e616
*	every element in a pointer vector.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
void
Packit 13e616
cl_ptr_vector_apply_func(IN const cl_ptr_vector_t * const p_vector,
Packit 13e616
			 IN cl_pfn_ptr_vec_apply_t pfn_callback,
Packit 13e616
			 IN const void *const context);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure whose elements to iterate.
Packit 13e616
*
Packit 13e616
*	pfn_callback
Packit 13e616
*		[in] Function invoked for every element in the array.
Packit 13e616
*		See the cl_pfn_ptr_vec_apply_t function type declaration for details
Packit 13e616
*		about the callback function.
Packit 13e616
*
Packit 13e616
*	context
Packit 13e616
*		[in] Value to pass to the callback function.
Packit 13e616
*
Packit 13e616
* RETURN VALUE
Packit 13e616
*	This function does not return a value.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_apply_func invokes the specified function for every element
Packit 13e616
*	in the pointer vector, starting from the beginning of the pointer vector.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_find_from_start, cl_ptr_vector_find_from_end,
Packit 13e616
*	cl_pfn_ptr_vec_apply_t
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_find_from_start
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_find_from_start
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_find_from_start function uses a specified function to
Packit 13e616
*	search for elements in a pointer vector starting from the lowest index.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
size_t
Packit 13e616
cl_ptr_vector_find_from_start(IN const cl_ptr_vector_t * const p_vector,
Packit 13e616
			      IN cl_pfn_ptr_vec_find_t pfn_callback,
Packit 13e616
			      IN const void *const context);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure to inititalize.
Packit 13e616
*
Packit 13e616
*	pfn_callback
Packit 13e616
*		[in] Function invoked to determine if a match was found.
Packit 13e616
*		See the cl_pfn_ptr_vec_find_t function type declaration for details
Packit 13e616
*		about the callback function.
Packit 13e616
*
Packit 13e616
*	context
Packit 13e616
*		[in] Value to pass to the callback function.
Packit 13e616
*
Packit 13e616
* RETURN VALUES
Packit 13e616
*	Index of the element, if found.
Packit 13e616
*
Packit 13e616
*	Size of the pointer vector if the element was not found.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_find_from_start does not remove the found element from
Packit 13e616
*	the pointer vector. The index of the element is returned when the function
Packit 13e616
*	provided by the pfn_callback parameter returns CL_SUCCESS.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_find_from_end, cl_ptr_vector_apply_func,
Packit 13e616
*	cl_pfn_ptr_vec_find_t
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Component Library: Pointer Vector/cl_ptr_vector_find_from_end
Packit 13e616
* NAME
Packit 13e616
*	cl_ptr_vector_find_from_end
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	The cl_ptr_vector_find_from_end function uses a specified function to
Packit 13e616
*	search for elements in a pointer vector starting from the highest index.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
size_t
Packit 13e616
cl_ptr_vector_find_from_end(IN const cl_ptr_vector_t * const p_vector,
Packit 13e616
			    IN cl_pfn_ptr_vec_find_t pfn_callback,
Packit 13e616
			    IN const void *const context);
Packit 13e616
/*
Packit 13e616
* PARAMETERS
Packit 13e616
*	p_vector
Packit 13e616
*		[in] Pointer to a cl_ptr_vector_t structure to inititalize.
Packit 13e616
*
Packit 13e616
*	pfn_callback
Packit 13e616
*		[in] Function invoked to determine if a match was found.
Packit 13e616
*		See the cl_pfn_ptr_vec_find_t function type declaration for details
Packit 13e616
*		about the callback function.
Packit 13e616
*
Packit 13e616
*	context
Packit 13e616
*		[in] Value to pass to the callback function.
Packit 13e616
*
Packit 13e616
* RETURN VALUES
Packit 13e616
*	Index of the element, if found.
Packit 13e616
*
Packit 13e616
*	Size of the pointer vector if the element was not found.
Packit 13e616
*
Packit 13e616
* NOTES
Packit 13e616
*	cl_ptr_vector_find_from_end does not remove the found element from
Packit 13e616
*	the pointer vector. The index of the element is returned when the function
Packit 13e616
*	provided by the pfn_callback parameter returns CL_SUCCESS.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*	Pointer Vector, cl_ptr_vector_find_from_start, cl_ptr_vector_apply_func,
Packit 13e616
*	cl_pfn_ptr_vec_find_t
Packit 13e616
*********/
Packit 13e616
Packit 13e616
END_C_DECLS
Packit 13e616
#endif				/* _CL_PTR_VECTOR_H_ */