Path: blob/master/drivers/gpu/drm/amd/display/include/vector.h
26535 views
/*1* Copyright 2012-15 Advanced Micro Devices, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*21* Authors: AMD22*23*/2425#ifndef __DAL_VECTOR_H__26#define __DAL_VECTOR_H__2728struct vector {29uint8_t *container;30uint32_t struct_size;31uint32_t count;32uint32_t capacity;33struct dc_context *ctx;34};3536bool dal_vector_construct(37struct vector *vector,38struct dc_context *ctx,39uint32_t capacity,40uint32_t struct_size);4142struct vector *dal_vector_create(43struct dc_context *ctx,44uint32_t capacity,45uint32_t struct_size);4647/* 'initial_value' is optional. If initial_value not supplied,48* each "structure" in the vector will contain zeros by default. */49struct vector *dal_vector_presized_create(50struct dc_context *ctx,51uint32_t size,52void *initial_value,53uint32_t struct_size);5455void dal_vector_destruct(56struct vector *vector);5758void dal_vector_destroy(59struct vector **vector);6061uint32_t dal_vector_get_count(62const struct vector *vector);6364/* dal_vector_insert_at65* reallocate container if necessary66* then shell items at right and insert67* return if the container modified68* do not check that index belongs to container69* since the function is private and index is going to be calculated70* either with by function or as get_count+1 */71bool dal_vector_insert_at(72struct vector *vector,73const void *what,74uint32_t position);7576bool dal_vector_append(77struct vector *vector,78const void *item);7980/* operator[] */81void *dal_vector_at_index(82const struct vector *vector,83uint32_t index);8485void dal_vector_set_at_index(86const struct vector *vector,87const void *what,88uint32_t index);8990/* create a clone (copy) of a vector */91struct vector *dal_vector_clone(92const struct vector *vector_other);9394/* dal_vector_remove_at_index95* Shifts elements on the right from remove position to the left,96* removing an element at position by overwrite means*/97bool dal_vector_remove_at_index(98struct vector *vector,99uint32_t index);100101uint32_t dal_vector_capacity(const struct vector *vector);102103bool dal_vector_reserve(struct vector *vector, uint32_t capacity);104105void dal_vector_clear(struct vector *vector);106107/***************************************************************************108* Macro definitions of TYPE-SAFE versions of vector set/get functions.109***************************************************************************/110111#define DAL_VECTOR_INSERT_AT(vector_type, type_t) \112static bool vector_type##_vector_insert_at( \113struct vector *vector, \114type_t what, \115uint32_t position) \116{ \117return dal_vector_insert_at(vector, what, position); \118}119120#define DAL_VECTOR_APPEND(vector_type, type_t) \121static bool vector_type##_vector_append( \122struct vector *vector, \123type_t item) \124{ \125return dal_vector_append(vector, item); \126}127128/* Note: "type_t" is the ONLY token accepted by "checkpatch.pl" and by129* "checkcommit" as *return type*.130* For uniformity reasons "type_t" is used for all type-safe macro131* definitions here. */132#define DAL_VECTOR_AT_INDEX(vector_type, type_t) \133static type_t vector_type##_vector_at_index( \134const struct vector *vector, \135uint32_t index) \136{ \137return dal_vector_at_index(vector, index); \138}139140#define DAL_VECTOR_SET_AT_INDEX(vector_type, type_t) \141static void vector_type##_vector_set_at_index( \142const struct vector *vector, \143type_t what, \144uint32_t index) \145{ \146dal_vector_set_at_index(vector, what, index); \147}148149#endif /* __DAL_VECTOR_H__ */150151152