代码拉取完成,页面将自动刷新
// Copyright (c) 2023 刻BITTER
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <cstdint>
#include <cstdlib>
#include <initializer_list>
namespace data_basic {
namespace _hide {
template <bool fit_in_8, bool fit_in_16, bool fit_in_32>
struct _enough_index_type {
};
template <>
struct _enough_index_type<true, true, true> {
using type = uint8_t;
};
template <>
struct _enough_index_type<false, true, true> {
using type = uint16_t;
};
template <>
struct _enough_index_type<false, false, true> {
using type = uint32_t;
};
template <>
struct _enough_index_type<false, false, false> {
using type = uint64_t;
};
} // namespace _hide
/**
* @breif 根据所需的bit flag 数量,选择最小能容纳的整数类型
*
* 若所需数量为8,则可用uint8_t,若数量为10,则可用uint16_t,依此类推。
*
*/
template <size_t Count>
struct enough_bit_flag_type {
using type = typename _hide::_enough_index_type<Count <= 8, Count <= 16, Count <= 32>::type;
};
template <size_t Count>
using enough_bit_flag_type_t = typename enough_bit_flag_type<Count>::type;
/**
* @breif 根据所需索引的元素数量,选择最小能容纳的整数类型
*
* 若列表最多元素数量为100,则可用uint8_t 索引其中每个元素;若元素数量为1000,则需要用uint16_t。
*
*/
template <size_t Count>
struct enough_index_type {
using type = typename _hide::_enough_index_type<Count <= UINT8_MAX, Count <= UINT16_MAX, Count <= UINT64_MAX>::type;
};
template <size_t Count>
using enough_index_type_t = typename enough_index_type<Count>::type;
template <typename T>
struct to_signed {
};
template <>
struct to_signed<uint8_t> {
using type = int8_t;
};
template <>
struct to_signed<uint16_t> {
using type = int16_t;
};
template <>
struct to_signed<uint32_t> {
using type = int32_t;
};
template <>
struct to_signed<uint64_t> {
using type = int64_t;
};
template <typename T>
using to_signed_t = typename to_signed<T>::type;
template <typename V,
typename IndexType,
size_t SegmentSize,
size_t SegmentCount,
typename InSegmentIndexType = IndexType,
typename SegmentIndexType = enough_index_type_t<SegmentCount>>
class StaticSegmentMappingList {
private:
IndexType _segment_start_index_list[SegmentCount] = {0}; // 各个分段的起始索引,必须按从小到大排列
V _segment_list[SegmentCount][SegmentSize] = {0};
StaticSegmentMappingList(std::initializer_list<IndexType> segment_start_index_list) :
_segment_start_index_list(segment_start_index_list) {}
// TODO:
};
} // namespace data_basic
#include "data_basic/ring_buffer.hpp"
#include "data_basic/simple_linked_list.hpp"
#include "data_basic/pointer_list.hpp"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。