LCOV - code coverage report
Current view: top level - runtime/c/c_base/inc - vector.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 5 100.0 %
Date: 2026-08-27 13:24:42 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3             :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4             :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5             :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6             :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7             :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8             :  * See LICENSE in the root of the software repository for the full text of the License.
       9             :  */
      10             : #ifndef C_BASE_VECTOR_H
      11             : #define C_BASE_VECTOR_H
      12             : #include "c_base.h"
      13             : #ifdef __cplusplus
      14             : extern "C" {
      15             : #endif
      16             : typedef struct {
      17             :     size_t itemSize;
      18             :     size_t size;
      19             :     size_t capacity;
      20             :     uint8_t *data;
      21             :     FnDestroy pfnDestroyItem;
      22             : } Vector;
      23             : 
      24             : #define NewVector(objType) CreateVector(sizeof(objType))
      25             : 
      26             : // itemSize 不能为0,请调用者保证
      27             : void InitVector(Vector *vector, size_t itemSize);
      28           1 : static inline void SetVectorDestroyItem(Vector *vector, FnDestroy pfnDestroyItem)
      29             : {
      30           1 :     vector->pfnDestroyItem = pfnDestroyItem;
      31           1 : };
      32             : void DeInitVector(Vector *vector);
      33             : 
      34             : // itemSize 不能为0,请调用者保证
      35             : Vector *CreateVector(size_t itemSize);
      36             : void DestroyVector(Vector *vector);
      37             : void ClearVector(Vector *vector);
      38           2 : static inline size_t VectorSize(const Vector *vector)
      39             : {
      40           2 :     return vector->size;
      41             : };
      42             : size_t ReSizeVector(Vector *vector, size_t size);
      43             : size_t CapacityVector(Vector *vector, size_t capacity);
      44             : void *EmplaceVector(Vector *vector, size_t index, void *data);
      45             : void *EmplaceBackVector(Vector *vector, void *data);
      46             : void *EmplaceHeadVector(Vector *vector, void *data);
      47             : void RemoveVector(Vector *vector, size_t index);
      48             : void MoveVector(Vector *src, Vector *desc);
      49             : void *VectorAt(Vector *vector, size_t index);
      50             : const void *ConstVectorAt(const Vector *vector, size_t index);
      51             : #ifdef __cplusplus
      52             : }
      53             : #endif
      54             : #endif // C_BASE_VECTOR_H

Generated by: LCOV version 1.14