2 * Copyright 2012-15 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #ifndef __DAL_VECTOR_H__
27 #define __DAL_VECTOR_H__
34 struct dc_context
*ctx
;
37 bool dal_vector_construct(
38 struct vector
*vector
,
39 struct dc_context
*ctx
,
41 uint32_t struct_size
);
43 struct vector
*dal_vector_create(
44 struct dc_context
*ctx
,
46 uint32_t struct_size
);
48 /* 'initial_value' is optional. If initial_value not supplied,
49 * each "structure" in the vector will contain zeros by default. */
50 struct vector
*dal_vector_presized_create(
51 struct dc_context
*ctx
,
54 uint32_t struct_size
);
56 void dal_vector_destruct(
57 struct vector
*vector
);
59 void dal_vector_destroy(
60 struct vector
**vector
);
62 uint32_t dal_vector_get_count(
63 const struct vector
*vector
);
65 /* dal_vector_insert_at
66 * reallocate container if necessary
67 * then shell items at right and insert
68 * return if the container modified
69 * do not check that index belongs to container
70 * since the function is private and index is going to be calculated
71 * either with by function or as get_count+1 */
72 bool dal_vector_insert_at(
73 struct vector
*vector
,
77 bool dal_vector_append(
78 struct vector
*vector
,
82 void *dal_vector_at_index(
83 const struct vector
*vector
,
86 void dal_vector_set_at_index(
87 const struct vector
*vector
,
91 /* create a clone (copy) of a vector */
92 struct vector
*dal_vector_clone(
93 const struct vector
*vector_other
);
95 /* dal_vector_remove_at_index
96 * Shifts elements on the right from remove position to the left,
97 * removing an element at position by overwrite means*/
98 bool dal_vector_remove_at_index(
99 struct vector
*vector
,
102 uint32_t dal_vector_capacity(const struct vector
*vector
);
104 bool dal_vector_reserve(struct vector
*vector
, uint32_t capacity
);
106 void dal_vector_clear(struct vector
*vector
);
108 /***************************************************************************
109 * Macro definitions of TYPE-SAFE versions of vector set/get functions.
110 ***************************************************************************/
112 #define DAL_VECTOR_INSERT_AT(vector_type, type_t) \
113 static bool vector_type##_vector_insert_at( \
114 struct vector *vector, \
118 return dal_vector_insert_at(vector, what, position); \
121 #define DAL_VECTOR_APPEND(vector_type, type_t) \
122 static bool vector_type##_vector_append( \
123 struct vector *vector, \
126 return dal_vector_append(vector, item); \
129 /* Note: "type_t" is the ONLY token accepted by "checkpatch.pl" and by
130 * "checkcommit" as *return type*.
131 * For uniformity reasons "type_t" is used for all type-safe macro
132 * definitions here. */
133 #define DAL_VECTOR_AT_INDEX(vector_type, type_t) \
134 static type_t vector_type##_vector_at_index( \
135 const struct vector *vector, \
138 return dal_vector_at_index(vector, index); \
141 #define DAL_VECTOR_SET_AT_INDEX(vector_type, type_t) \
142 static void vector_type##_vector_set_at_index( \
143 const struct vector *vector, \
147 dal_vector_set_at_index(vector, what, index); \
150 #endif /* __DAL_VECTOR_H__ */