DAWorkbench 0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
DA::da_hash_table< T, row_index_type, col_index_type, hasher > 模板类 参考

基于 std::unordered_map 的稀疏表格数据结构 更多...

#include <da_hash_table.hpp>

Public 类型

using key_type = std::pair< row_index_type, col_index_type >
 
using value_type = std::pair< const key_type, T >
 
using table_index_type = key_type
 
using iterator = typename std::unordered_map< key_type, T, hasher >::iterator
 
using const_iterator = typename std::unordered_map< key_type, T, hasher >::const_iterator
 
using size_type = typename std::unordered_map< key_type, T, hasher >::size_type
 

Public 成员函数

 da_hash_table (const da_hash_table &other)=default
 
 da_hash_table (da_hash_table &&other) noexcept=default
 
 da_hash_table (std::initializer_list< value_type > init)
 初始化列表构造函数
 
da_hash_tableoperator= (const da_hash_table &other)=default
 
da_hash_tableoperator= (da_hash_table &&other) noexcept=default
 
T & at (row_index_type r, col_index_type c)
 带边界检查的元素访问
 
const T & at (row_index_type r, col_index_type c) const
 带边界检查的常量元素访问
 
T & at (key_type k)
 
const T & at (key_type k) const
 
T & operator() (row_index_type r, col_index_type c)
 函数调用运算符访问元素
 
const T operator() (row_index_type r, col_index_type c) const
 函数调用运算符访问元素(常量版本)
 
T & operator() (key_type k)
 
const T operator() (key_type k) const
 
value (row_index_type r, col_index_type c) const
 安全的元素访问,返回默认值如果不存在
 
value (row_index_type r, col_index_type c, const T &defaultValue) const
 安全的元素访问,返回指定默认值如果不存在
 
T & operator[] (key_type k)
 
bool empty () const noexcept
 检查表格是否为空
 
size_type size () const noexcept
 返回元素数量
 
size_type max_size () const noexcept
 返回最大可能元素数量
 
void clear () noexcept
 清空表格
 
std::pair< iterator, bool > insert (const value_type &value)
 插入元素
 
template<class P >
std::pair< iterator, bool > insert (P &&value)
 
template<class InputIt >
void insert (InputIt first, InputIt last)
 插入元素范围
 
void insert (std::initializer_list< value_type > ilist)
 插入初始化列表
 
template<class... Args>
std::pair< iterator, bool > emplace (Args &&... args)
 
iterator erase (const_iterator pos)
 删除指定位置元素
 
iterator erase (const_iterator first, const_iterator last)
 删除元素范围
 
size_type erase (row_index_type r, col_index_type c)
 删除指定行列元素
 
iterator find (key_type k)
 查找元素
 
const_iterator find (key_type k) const
 查找元素
 
iterator find (row_index_type r, col_index_type c)
 查找元素
 
const_iterator find (row_index_type r, col_index_type c) const
 查找元素(常量版本)
 
size_type count (row_index_type r, col_index_type c) const
 统计元素出现次数
 
iterator begin () noexcept
 返回指向起始的迭代器
 
const_iterator begin () const noexcept
 返回指向起始的常量迭代器
 
const_iterator cbegin () const noexcept
 返回指向起始的常量迭代器
 
iterator end () noexcept
 返回指向末尾的迭代器
 
const_iterator end () const noexcept
 返回指向末尾的常量迭代器
 
const_iterator cend () const noexcept
 返回指向末尾的常量迭代器
 
float load_factor () const noexcept
 返回当前负载因子
 
float max_load_factor () const noexcept
 返回最大负载因子
 
void max_load_factor (float ml)
 设置最大负载因子
 
void rehash (size_type count)
 设置桶数并重新哈希
 
void reserve (size_type count)
 预留空间
 
size_type bucket_count () const noexcept
 返回桶数
 
size_type max_bucket_count () const noexcept
 返回最大桶数
 
table_index_type shape () const
 计算表格的形状(最大行索引和最大列索引加1)
 
std::vector< row_index_type > row_indices () const
 获取实际使用的行索引列表
 
std::vector< col_index_type > column_indices () const
 获取实际使用的列索引列表
 
std::vector< std::pair< col_index_type, T > > row (row_index_type r) const
 获取指定行的所有元素
 
std::vector< std::pair< row_index_type, T > > column (col_index_type c) const
 获取指定列的所有元素
 
void swap (da_hash_table &other) noexcept
 交换两个表格的内容
 
template<class P >
std::pair< typename da_hash_table< T, row_index_type, col_index_type, hasher >::iterator, bool > insert (P &&value)
 插入元素(通用引用)
 
template<class... Args>
std::pair< typename da_hash_table< T, row_index_type, col_index_type, hasher >::iterator, bool > emplace (Args &&... args)
 原位构造元素
 

详细描述

template<typename T, typename row_index_type = std::size_t, typename col_index_type = row_index_type, typename hasher = pair_hash>
class DA::da_hash_table< T, row_index_type, col_index_type, hasher >

基于 std::unordered_map 的稀疏表格数据结构

此类提供了一个稀疏表格数据结构,使用哈希表存储非默认值, 适合存储稀疏的二维数据,其中大部分元素为默认值。

模板参数
T存储的值类型
row_index_type行索引类型,默认为 std::size_t
col_index_type列索引类型,默认为 row_index_type
hasher哈希函数类型,默认为 pair_hash

构造及析构函数说明

◆ da_hash_table()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
DA::da_hash_table< T, row_index_type, col_index_type, hasher >::da_hash_table ( std::initializer_list< value_type >  init)

初始化列表构造函数

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
init初始化列表
{{0, 0}, 1},
{{1, 1}, 2},
{{2, 2}, 3}
};
基于 std::unordered_map 的稀疏表格数据结构
Definition da_hash_table.hpp:36

成员函数说明

◆ at() [1/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
T & DA::da_hash_table< T, row_index_type, col_index_type, hasher >::at ( row_index_type  r,
col_index_type  c 
)

带边界检查的元素访问

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
c列索引
返回
元素的引用
异常
std::out_of_range如果元素不存在
table.insert({{0, 0}, 42});
try {
int& value = table.at(0, 0); // 返回42
int& invalid = table.at(1, 1); // 抛出std::out_of_range
} catch (const std::out_of_range& e) {
// 处理异常
}
std::pair< iterator, bool > insert(const value_type &value)
插入元素
Definition da_hash_table.hpp:455
T & at(row_index_type r, col_index_type c)
带边界检查的元素访问
Definition da_hash_table.hpp:198

◆ at() [2/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
const T & DA::da_hash_table< T, row_index_type, col_index_type, hasher >::at ( row_index_type  r,
col_index_type  c 
) const

带边界检查的常量元素访问

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
c列索引
返回
元素的常量引用
异常
std::out_of_range如果元素不存在
const DA::da_hash_table<int> table = {{{0, 0}, 42}};
try {
const int& value = table.at(0, 0); // 返回42
const int& invalid = table.at(1, 1); // 抛出std::out_of_range
} catch (const std::out_of_range& e) {
// 处理异常
}
T value(row_index_type r, col_index_type c) const
安全的元素访问,返回默认值如果不存在
Definition da_hash_table.hpp:322

◆ begin() [1/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::const_iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::begin ( ) const
noexcept

返回指向起始的常量迭代器

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
指向表格起始的常量迭代器
const DA::da_hash_table<int> table = {{{0, 0}, 42}, {{1, 1}, 43}};
for (auto it = table.begin(); it != table.end(); ++it) {
std::cout << "(" << it->first.first << ", " << it->first.second
<< ") = " << it->second << std::endl;
}
iterator begin() noexcept
返回指向起始的迭代器
Definition da_hash_table.hpp:762
iterator end() noexcept
返回指向末尾的迭代器
Definition da_hash_table.hpp:833

◆ begin() [2/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::begin ( )
noexcept

返回指向起始的迭代器

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
指向表格起始的迭代器
DA::da_hash_table<int> table = {{{0, 0}, 42}, {{1, 1}, 43}};
for (auto it = table.begin(); it != table.end(); ++it) {
std::cout << "(" << it->first.first << ", " << it->first.second
<< ") = " << it->second << std::endl;
}

◆ bucket_count()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::size_type DA::da_hash_table< T, row_index_type, col_index_type, hasher >::bucket_count ( ) const
noexcept

返回桶数

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
当前桶数
size_t bc = table.bucket_count();
std::cout << "当前桶数: " << bc << std::endl;
size_type bucket_count() const noexcept
返回桶数
Definition da_hash_table.hpp:999

◆ cbegin()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::const_iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::cbegin ( ) const
noexcept

返回指向起始的常量迭代器

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
指向表格起始的常量迭代器
const DA::da_hash_table<int> table = {{{0, 0}, 42}, {{1, 1}, 43}};
for (auto it = table.cbegin(); it != table.cend(); ++it) {
std::cout << "(" << it->first.first << ", " << it->first.second
<< ") = " << it->second << std::endl;
}
const_iterator cend() const noexcept
返回指向末尾的常量迭代器
Definition da_hash_table.hpp:881
const_iterator cbegin() const noexcept
返回指向起始的常量迭代器
Definition da_hash_table.hpp:812

◆ cend()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::const_iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::cend ( ) const
noexcept

返回指向末尾的常量迭代器

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
指向表格末尾的常量迭代器
const DA::da_hash_table<int> table = {{{0, 0}, 42}, {{1, 1}, 43}};
for (auto it = table.cbegin(); it != table.cend(); ++it) {
// 处理元素
}

◆ clear()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
void DA::da_hash_table< T, row_index_type, col_index_type, hasher >::clear ( )
noexcept

清空表格

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
DA::da_hash_table<int> table = {{{0, 0}, 42}};
table.clear(); // 清空表格
// 现在表格为空
void clear() noexcept
清空表格
Definition da_hash_table.hpp:428

◆ column()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
std::vector< std::pair< row_index_type, T > > DA::da_hash_table< T, row_index_type, col_index_type, hasher >::column ( col_index_type  c) const

获取指定列的所有元素

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
c列索引
返回
包含指定列所有元素的向量,每个元素是(行索引, 值)的pair
{{0, 0}, 42},
{{2, 0}, 43},
{{1, 1}, 44}
};
auto col0 = table.column(0); // 返回[(0, 42), (2, 43)]
std::vector< std::pair< row_index_type, T > > column(col_index_type c) const
获取指定列的所有元素
Definition da_hash_table.hpp:1190

◆ column_indices()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
std::vector< col_index_type > DA::da_hash_table< T, row_index_type, col_index_type, hasher >::column_indices ( ) const

获取实际使用的列索引列表

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
包含所有实际使用的列索引的向量
{{0, 0}, 42},
{{2, 1}, 43},
{{0, 2}, 44}
};
auto cols = table.column_indices(); // 返回[0, 1, 2]
std::vector< col_index_type > column_indices() const
获取实际使用的列索引列表
Definition da_hash_table.hpp:1122

◆ count()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::size_type DA::da_hash_table< T, row_index_type, col_index_type, hasher >::count ( row_index_type  r,
col_index_type  c 
) const

统计元素出现次数

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
c列索引
返回
元素出现次数(0或1)
DA::da_hash_table<int> table = {{{0, 0}, 42}};
size_t count = table.count(0, 0); // 返回1
count = table.count(1, 1); // 返回0
size_type count(row_index_type r, col_index_type c) const
统计元素出现次数
Definition da_hash_table.hpp:738

◆ emplace()

template<typename T , typename row_index_type = std::size_t, typename col_index_type = row_index_type, typename hasher = pair_hash>
template<class... Args>
std::pair< typename da_hash_table< T, row_index_type, col_index_type, hasher >::iterator, bool > DA::da_hash_table< T, row_index_type, col_index_type, hasher >::emplace ( Args &&...  args)

原位构造元素

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
Args参数类型
参数
args构造参数
返回
包含迭代器和布尔值的pair,指示插入是否成功
auto result = table.emplace(std::make_pair(0, 0), 42);
if (result.second) {
std::cout << "插入成功" << std::endl;
}

◆ empty()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
bool DA::da_hash_table< T, row_index_type, col_index_type, hasher >::empty ( ) const
noexcept

检查表格是否为空

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
如果表格为空返回true,否则返回false
if (table.empty()) {
std::cout << "表格为空" << std::endl;
}
bool empty() const noexcept
检查表格是否为空
Definition da_hash_table.hpp:368

◆ end() [1/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::const_iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::end ( ) const
noexcept

返回指向末尾的常量迭代器

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
指向表格末尾的常量迭代器
const DA::da_hash_table<int> table = {{{0, 0}, 42}, {{1, 1}, 43}};
for (auto it = table.begin(); it != table.end(); ++it) {
// 处理元素
}

◆ end() [2/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::end ( )
noexcept

返回指向末尾的迭代器

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
指向表格末尾的迭代器
DA::da_hash_table<int> table = {{{0, 0}, 42}, {{1, 1}, 43}};
for (auto it = table.begin(); it != table.end(); ++it) {
// 处理元素
}

◆ erase() [1/3]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::erase ( const_iterator  first,
const_iterator  last 
)

删除元素范围

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
first范围起始迭代器
last范围结束迭代器
返回
指向被删除元素之后位置的迭代器
{{0, 0}, 42},
{{1, 1}, 43},
{{2, 2}, 44}
};
auto first = table.find(0, 0);
auto last = table.find(2, 2);
if (first != table.end() && last != table.end()) {
table.erase(first, last); // 删除范围[first, last)内的元素
}
iterator erase(const_iterator pos)
删除指定位置元素
Definition da_hash_table.hpp:584
iterator find(key_type k)
查找元素
Definition da_hash_table.hpp:651

◆ erase() [2/3]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::erase ( const_iterator  pos)

删除指定位置元素

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
pos要删除的元素位置
返回
指向被删除元素之后位置的迭代器
DA::da_hash_table<int> table = {{{0, 0}, 42}};
auto it = table.find(0, 0);
if (it != table.end()) {
table.erase(it); // 删除元素
}

◆ erase() [3/3]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::size_type DA::da_hash_table< T, row_index_type, col_index_type, hasher >::erase ( row_index_type  r,
col_index_type  c 
)

删除指定行列元素

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
c列索引
返回
被删除的元素数量(0或1)
DA::da_hash_table<int> table = {{{0, 0}, 42}};
size_t count = table.erase(0, 0); // 返回1
count = table.erase(1, 1); // 返回0

◆ find() [1/4]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::find ( key_type  k)

查找元素

参数
k键值
返回
指向元素的迭代器,如果未找到则返回end()

◆ find() [2/4]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::const_iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::find ( key_type  k) const

查找元素

参数
k键值
返回
指向元素的迭代器,如果未找到则返回end()

◆ find() [3/4]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::find ( row_index_type  r,
col_index_type  c 
)

查找元素

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
c列索引
返回
指向元素的迭代器,如果未找到则返回end()
DA::da_hash_table<int> table = {{{0, 0}, 42}};
auto it = table.find(0, 0);
if (it != table.end()) {
std::cout << "找到元素: " << it->second << std::endl;
}

◆ find() [4/4]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::const_iterator DA::da_hash_table< T, row_index_type, col_index_type, hasher >::find ( row_index_type  r,
col_index_type  c 
) const

查找元素(常量版本)

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
c列索引
返回
指向元素的常量迭代器,如果未找到则返回end()
const DA::da_hash_table<int> table = {{{0, 0}, 42}};
auto it = table.find(0, 0);
if (it != table.end()) {
std::cout << "找到元素: " << it->second << std::endl;
}

◆ insert() [1/4]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
std::pair< typename da_hash_table< T, row_index_type, col_index_type, hasher >::iterator, bool > DA::da_hash_table< T, row_index_type, col_index_type, hasher >::insert ( const value_type &  value)

插入元素

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
value要插入的元素
返回
包含迭代器和布尔值的pair,指示插入是否成功
auto result = table.insert({{0, 0}, 42});
if (result.second) {
std::cout << "插入成功" << std::endl;
}

◆ insert() [2/4]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
template<class InputIt >
void DA::da_hash_table< T, row_index_type, col_index_type, hasher >::insert ( InputIt  first,
InputIt  last 
)

插入元素范围

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
InputIt输入迭代器类型
参数
first范围起始迭代器
last范围结束迭代器
std::vector<std::pair<std::pair<int, int>, int>> values = {
{{0, 0}, 42},
{{1, 1}, 43}
};
table.insert(values.begin(), values.end());

◆ insert() [3/4]

template<typename T , typename row_index_type = std::size_t, typename col_index_type = row_index_type, typename hasher = pair_hash>
template<class P >
std::pair< typename da_hash_table< T, row_index_type, col_index_type, hasher >::iterator, bool > DA::da_hash_table< T, row_index_type, col_index_type, hasher >::insert ( P &&  value)

插入元素(通用引用)

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
P元素类型
参数
value要插入的元素
返回
包含迭代器和布尔值的pair,指示插入是否成功
auto result = table.insert(std::make_pair(std::make_pair(0, 0), 42));
if (result.second) {
std::cout << "插入成功" << std::endl;
}

◆ insert() [4/4]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
void DA::da_hash_table< T, row_index_type, col_index_type, hasher >::insert ( std::initializer_list< value_type >  ilist)

插入初始化列表

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
ilist初始化列表
table.insert({
{{0, 0}, 42},
{{1, 1}, 43}
});

◆ load_factor()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
float DA::da_hash_table< T, row_index_type, col_index_type, hasher >::load_factor ( ) const
noexcept

返回当前负载因子

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
当前负载因子
float lf = table.load_factor();
std::cout << "当前负载因子: " << lf << std::endl;
float load_factor() const noexcept
返回当前负载因子
Definition da_hash_table.hpp:901

◆ max_bucket_count()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::size_type DA::da_hash_table< T, row_index_type, col_index_type, hasher >::max_bucket_count ( ) const
noexcept

返回最大桶数

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
最大桶数
size_t mbc = table.max_bucket_count();
std::cout << "最大桶数: " << mbc << std::endl;
size_type max_bucket_count() const noexcept
返回最大桶数
Definition da_hash_table.hpp:1020

◆ max_load_factor() [1/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
float DA::da_hash_table< T, row_index_type, col_index_type, hasher >::max_load_factor ( ) const
noexcept

返回最大负载因子

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
最大负载因子
float mlf = table.max_load_factor();
std::cout << "最大负载因子: " << mlf << std::endl;
float max_load_factor() const noexcept
返回最大负载因子
Definition da_hash_table.hpp:921

◆ max_load_factor() [2/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
void DA::da_hash_table< T, row_index_type, col_index_type, hasher >::max_load_factor ( float  ml)

设置最大负载因子

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
ml新的最大负载因子
table.max_load_factor(0.75f); // 设置最大负载因子为0.75

◆ max_size()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::size_type DA::da_hash_table< T, row_index_type, col_index_type, hasher >::max_size ( ) const
noexcept

返回最大可能元素数量

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
表格可容纳的最大元素数量
std::cout << "表格最大可容纳 " << table.max_size() << " 个元素" << std::endl;
size_type max_size() const noexcept
返回最大可能元素数量
Definition da_hash_table.hpp:408

◆ operator()() [1/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
T & DA::da_hash_table< T, row_index_type, col_index_type, hasher >::operator() ( row_index_type  r,
col_index_type  c 
)

函数调用运算符访问元素

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
c列索引
返回
元素的引用
table(0, 0) = 42; // 插入或修改元素
int value = table(0, 0); // 获取元素值
int missing = table(1, 1); // 返回默认构造的值(0)

◆ operator()() [2/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
const T DA::da_hash_table< T, row_index_type, col_index_type, hasher >::operator() ( row_index_type  r,
col_index_type  c 
) const

函数调用运算符访问元素(常量版本)

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
c列索引
返回
元素的值或默认值
const DA::da_hash_table<int> table = {{{0, 0}, 42}};
int value = table(0, 0); // 返回42
int missing = table(1, 1); // 返回默认构造的值(0)

◆ rehash()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
void DA::da_hash_table< T, row_index_type, col_index_type, hasher >::rehash ( size_type  count)

设置桶数并重新哈希

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
count新的桶数
table.rehash(100); // 设置桶数为100并重新哈希
void rehash(size_type count)
设置桶数并重新哈希
Definition da_hash_table.hpp:959

◆ reserve()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
void DA::da_hash_table< T, row_index_type, col_index_type, hasher >::reserve ( size_type  count)

预留空间

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
count要预留的元素数量
table.reserve(100); // 预留100个元素的空间
void reserve(size_type count)
预留空间
Definition da_hash_table.hpp:978

◆ row()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
std::vector< std::pair< col_index_type, T > > DA::da_hash_table< T, row_index_type, col_index_type, hasher >::row ( row_index_type  r) const

获取指定行的所有元素

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
返回
包含指定行所有元素的向量,每个元素是(列索引, 值)的pair
{{0, 0}, 42},
{{0, 2}, 43},
{{1, 1}, 44}
};
auto row0 = table.row(0); // 返回[(0, 42), (2, 43)]
std::vector< std::pair< col_index_type, T > > row(row_index_type r) const
获取指定行的所有元素
Definition da_hash_table.hpp:1155

◆ row_indices()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
std::vector< row_index_type > DA::da_hash_table< T, row_index_type, col_index_type, hasher >::row_indices ( ) const

获取实际使用的行索引列表

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
包含所有实际使用的行索引的向量
{{0, 0}, 42},
{{2, 1}, 43},
{{0, 2}, 44}
};
auto rows = table.row_indices(); // 返回[0, 2]
std::vector< row_index_type > row_indices() const
获取实际使用的行索引列表
Definition da_hash_table.hpp:1090

◆ shape()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::table_index_type DA::da_hash_table< T, row_index_type, col_index_type, hasher >::shape ( ) const

计算表格的形状(最大行索引和最大列索引加1)

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
包含最大行索引+1和最大列索引+1的pair
{{0, 0}, 42},
{{2, 3}, 43},
{{1, 5}, 44}
};
auto shape = table.shape(); // 返回(3, 6)
std::cout << "表格形状: " << shape.first << " x " << shape.second << std::endl;
// 输出: 表格形状: 3 x 6
table_index_type shape() const
计算表格的形状(最大行索引和最大列索引加1)
Definition da_hash_table.hpp:1048

◆ size()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
da_hash_table< T, row_index_type, col_index_type, hasher >::size_type DA::da_hash_table< T, row_index_type, col_index_type, hasher >::size ( ) const
noexcept

返回元素数量

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
返回
表格中的元素数量
DA::da_hash_table<int> table = {{{0, 0}, 42}, {{1, 1}, 43}};
std::cout << "表格有 " << table.size() << " 个元素" << std::endl;
// 输出: 表格有 2 个元素
size_type size() const noexcept
返回元素数量
Definition da_hash_table.hpp:388

◆ swap()

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
void DA::da_hash_table< T, row_index_type, col_index_type, hasher >::swap ( da_hash_table< T, row_index_type, col_index_type, hasher > &  other)
noexcept

交换两个表格的内容

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
other要交换的另一个表格
DA::da_hash_table<int> table1 = {{{0, 0}, 42}};
DA::da_hash_table<int> table2 = {{{1, 1}, 43}};
table1.swap(table2);
// 现在table1包含{{1, 1}, 43},table2包含{{0, 0}, 42}
void swap(da_hash_table &other) noexcept
交换两个表格的内容
Definition da_hash_table.hpp:1223

◆ value() [1/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
T DA::da_hash_table< T, row_index_type, col_index_type, hasher >::value ( row_index_type  r,
col_index_type  c 
) const

安全的元素访问,返回默认值如果不存在

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
c列索引
返回
元素的值或默认构造的值
DA::da_hash_table<int> table = {{{0, 0}, 42}};
int value = table.value(0, 0); // 返回42
int missing = table.value(1, 1); // 返回0(默认构造的int)

◆ value() [2/2]

template<typename T , typename row_index_type , typename col_index_type , typename hasher >
T DA::da_hash_table< T, row_index_type, col_index_type, hasher >::value ( row_index_type  r,
col_index_type  c,
const T &  defaultValue 
) const

安全的元素访问,返回指定默认值如果不存在

模板参数
T存储的值类型
row_index_type行索引类型
col_index_type列索引类型
hasher哈希函数类型
参数
r行索引
c列索引
defaultValue指定的默认值
返回
元素的值或指定的默认值
DA::da_hash_table<int> table = {{{0, 0}, 42}};
int value = table.value(0, 0, -1); // 返回42
int missing = table.value(1, 1, -1); // 返回-1

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