mirror of https://gitee.com/bigwinds/arangodb
156 lines
6.3 KiB
C++
156 lines
6.3 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
/// DISCLAIMER
|
|
///
|
|
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
|
|
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
|
///
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
/// you may not use this file except in compliance with the License.
|
|
/// You may obtain a copy of the License at
|
|
///
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
///
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
/// See the License for the specific language governing permissions and
|
|
/// limitations under the License.
|
|
///
|
|
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
|
///
|
|
/// @author Dr. Frank Celler
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef ARANGODB_BASICS_VECTOR_H
|
|
#define ARANGODB_BASICS_VECTOR_H 1
|
|
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
|
|
#include "Basics/Common.h"
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief pod vector
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
struct TRI_vector_t {
|
|
char* _buffer;
|
|
uint32_t _lengthX; // private. do not access from outside!
|
|
uint32_t _capacityX; // private. do not access from outside!
|
|
uint32_t _elementSizeX; // private. do not access from outside!
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief initializes a vector
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void TRI_InitVector(TRI_vector_t*, size_t);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief initializes a vector, with user-definable settings
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
int TRI_InitVector2(TRI_vector_t*, size_t, size_t);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief destroys a vector, but does not free the pointer
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void TRI_DestroyVector(TRI_vector_t*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns length of vector
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
static inline size_t TRI_LengthVector(TRI_vector_t const* vector) {
|
|
return static_cast<size_t>(vector->_lengthX);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns capacity of vector
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
static inline size_t TRI_CapacityVector(TRI_vector_t const* vector) {
|
|
return static_cast<size_t>(vector->_capacityX);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief ensures a vector has space for extraCapacity more items
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
int TRI_ReserveVector(TRI_vector_t*, size_t);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief adjusts the length of the vector
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void TRI_SetLengthVector(TRI_vector_t*, size_t);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief resizes the vector
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
int TRI_ResizeVector(TRI_vector_t*, size_t);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief adds and element at the end
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
int TRI_PushBackVector(TRI_vector_t*, void const*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief removes an element
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void TRI_RemoveVector(TRI_vector_t*, size_t);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns an element to the vector after borrowing it via
|
|
/// TRI_NextVector. This will also decrease the vector length by one.
|
|
/// The caller must ensure that the element has been fetched from the vector
|
|
/// before.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void TRI_ReturnVector(TRI_vector_t*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief increases vector length by one and returns the address of the
|
|
/// (uninitialized) element at the new position
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void* TRI_NextVector(TRI_vector_t*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns the element at a given position, no bounds checking
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
static inline void* TRI_AddressVector(TRI_vector_t const* vector, size_t pos) {
|
|
return static_cast<void*>(vector->_buffer + pos * static_cast<size_t>(vector->_elementSizeX));
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns the element at a given position
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void* TRI_AtVector(TRI_vector_t const*, size_t);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief inserts an element at a given position
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
int TRI_InsertVector(TRI_vector_t*, void const*, size_t);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief sets an element at a given position
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void TRI_SetVector(TRI_vector_t*, size_t, void const*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns the beginning
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void* TRI_BeginVector(TRI_vector_t const*);
|
|
|
|
#endif
|