Egrome
 
载入中...
搜索中...
未找到
Table< std::tuple< Args... > > 模板类 参考abstract

本地数据库类,支持千万级数据量的本地数据库 更多...

#include <Database.hpp>

Public 成员函数

bool loadDatabase (const std::string_view &database_path)
 从文件加载数据库到内存
 
bool saveDatabase (const std::string_view &database_path)
 将内存中的数据保存至文件
 
void append (const _LINE_type &line)
 向数据库中添加一行数据
 
void append (_LINE_type &&line)
 向数据库中移动一行数据
 
void revoke (std::size_t index)
 将数据库中指定位置的数据设置为删除状态
 
_LINE_type & getline (std::size_t index)
 获取数据库中指定位置的数据
 
template<std::size_t N, class Func >
std::vector< std::pair< const _LINE_type *, std::size_t > > find_index_if (Func condition)
 查找并返回所有满足condition的行
 
template<std::size_t N, class Func >
std::vector< const _LINE_type * > find_if (Func condition)
 查找并返回所有满足condition的行
 
template<std::size_t N, class Func >
std::size_t count_if (Func condition)
 查找所有满足condition的行的数量
 
template<std::size_t N, class Func >
std::size_t revoke_if (Func condition)
 查找所有满足condition的行并标记为删除状态
 
void print () const
 打印数据库中的前100条数据
 
void clear ()
 清空内存中的数据库数据
 
std::size_t size () const
 获取当前数据库中数据总数量
 
std::size_t count () const
 获取当前数据库中有效数据数量
 

Protected 成员函数

virtual void readLine (const void *input, _LINE_type &data)=0
 读取数据的格式化函数
 
virtual void writeLine (void *output, const _LINE_type &data)=0
 写入数据的格式化函数
 
virtual void printLine (const _LINE_type &data) const =0
 打印一行数据的格式化函数
 

Protected 属性

std::size_t lenth = (sizeof(Args) + ... + 0ULL)
 行数据的长度,默认为对Args中所有类型的sizeof求和
 

详细描述

template<typename... Args>
class Table< std::tuple< Args... > >

本地数据库类,支持千万级数据量的本地数据库

数据库的存储格式为:

  1. 32字节的头部信息:
    • 8字节:文件长度信息
    • 8字节:一行数据长度
    • 8字节:表的数据量
    • 8字节:保留字节
  2. 若干行数据,每行数据长度为lenth字节,数据格式为用户自定义读写函数确定
    模板参数
    ...Args指定表的字段类型
    注解
    此功能需要C++17或更高版本

成员函数说明

◆ append() [1/2]

template<typename... Args>
void Table< std::tuple< Args... > >::append ( _LINE_type && line)
inline

向数据库中移动一行数据

参数
line要移动的数据

时间复杂度:O(1)

◆ append() [2/2]

template<typename... Args>
void Table< std::tuple< Args... > >::append ( const _LINE_type & line)
inline

向数据库中添加一行数据

参数
line要添加的数据

时间复杂度:O(1)

◆ count()

template<typename... Args>
std::size_t Table< std::tuple< Args... > >::count ( ) const
inline

获取当前数据库中有效数据数量

返回
数据库中有效数据数量

时间复杂度:O(1)

◆ count_if()

template<typename... Args>
template<std::size_t N, class Func >
std::size_t Table< std::tuple< Args... > >::count_if ( Func condition)
inline

查找所有满足condition的行的数量

模板参数
N要比较的字段的索引
Func条件函数类型
参数
condition条件函数
返回
所有满足condition的行的数量

时间复杂度:O(n)

◆ find_if()

template<typename... Args>
template<std::size_t N, class Func >
std::vector< const _LINE_type * > Table< std::tuple< Args... > >::find_if ( Func condition)
inline

查找并返回所有满足condition的行

模板参数
N要比较的字段的索引
Func条件函数类型
参数
condition条件函数
返回
所有满足condition的行数据,即满足 condition(std::get<N>(line))==true

时间复杂度:O(n)

◆ find_index_if()

template<typename... Args>
template<std::size_t N, class Func >
std::vector< std::pair< const _LINE_type *, std::size_t > > Table< std::tuple< Args... > >::find_index_if ( Func condition)
inline

查找并返回所有满足condition的行

模板参数
N要比较的字段的索引
Func条件函数类型
参数
condition条件函数
返回
所有满足condition的行数据和索引,即满足 condition(std::get<N>(line))==true

时间复杂度:O(n)

◆ getline()

template<typename... Args>
_LINE_type & Table< std::tuple< Args... > >::getline ( std::size_t index)
inline

获取数据库中指定位置的数据

参数
index索引
返回
数据库中指定位置的数据

时间复杂度:O(1)

◆ loadDatabase()

template<typename... Args>
bool Table< std::tuple< Args... > >::loadDatabase ( const std::string_view & database_path)
inline

从文件加载数据库到内存

参数
database_path文件路径
返回
若加载失败,返回false;否则返回true

◆ printLine()

template<typename... Args>
virtual void Table< std::tuple< Args... > >::printLine ( const _LINE_type & data) const
protectedpure virtual

打印一行数据的格式化函数

参数
data要打印的一行数据

在子类中,必须实现此函数

◆ readLine()

template<typename... Args>
virtual void Table< std::tuple< Args... > >::readLine ( const void * input,
_LINE_type & data )
protectedpure virtual

读取数据的格式化函数

参数
input从文件中读取的一行数据
data进行类型格式化后的结果

在子类中,必须实现此函数

◆ revoke()

template<typename... Args>
void Table< std::tuple< Args... > >::revoke ( std::size_t index)
inline

将数据库中指定位置的数据设置为删除状态

参数
index索引

调用此函数后,数据库中对应位置的数据将被标记为删除状态,被标记的数据不会再被保存至文件中

时间复杂度:O(1)

◆ revoke_if()

template<typename... Args>
template<std::size_t N, class Func >
std::size_t Table< std::tuple< Args... > >::revoke_if ( Func condition)
inline

查找所有满足condition的行并标记为删除状态

模板参数
N要比较的字段的索引
Func条件函数类型
参数
condition条件函数
返回
所有满足condition的行的数量

时间复杂度:O(n)

◆ saveDatabase()

template<typename... Args>
bool Table< std::tuple< Args... > >::saveDatabase ( const std::string_view & database_path)
inline

将内存中的数据保存至文件

参数
database_path文件路径
lenth一行数据的长度(以字节计),默认为对Args中所有类型的sizeof求和
返回
若保存失败,返回false;否则返回true

◆ size()

template<typename... Args>
std::size_t Table< std::tuple< Args... > >::size ( ) const
inline

获取当前数据库中数据总数量

返回
数据库中数据总数量

时间复杂度:O(1)

◆ writeLine()

template<typename... Args>
virtual void Table< std::tuple< Args... > >::writeLine ( void * output,
const _LINE_type & data )
protectedpure virtual

写入数据的格式化函数

参数
output要写入数据库的一行数据
data将要写入数据库的具有类型的数据

在子类中,必须实现此函数

类成员变量说明

◆ lenth

template<typename... Args>
std::size_t Table< std::tuple< Args... > >::lenth = (sizeof(Args) + ... + 0ULL)
protected

行数据的长度,默认为对Args中所有类型的sizeof求和

警告
若行数据中存在复杂类型(例如std::string, T*等),则必须在子类中指定行数据的长度,否则无法正确读写数据

该类的文档由以下文件生成: