当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 0

刻BITTER/ioxx
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ioxx_data_basic.hpp 3.29 KB
一键复制 编辑 原始数据 按行查看 历史
刻BITTER 提交于 2024-04-21 02:47 . changed some
// 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"
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/etberzin/ioxx.git
git@gitee.com:etberzin/ioxx.git
etberzin
ioxx
ioxx
main

搜索帮助