C++树状数组模板库——“BITree.hpp”
更新日志
2022年3月29日更新
- 为了迎合标准库的命名规范,发布了"TypeName.hpp"类型名作出规范,并基于该库修改本库所有函数名、参数名、变量名使其符合规范;
- 新增了
BITree(forward_iter_t, size_t)
构造函数并基于此新增了BITree(initializer_list_t<T>)
构造函数;
- 修改了
plus_t
和multiply_t
及其逆运算的实现方式,以此简化代码、增加代码可读性;
2022年3月15日更新
- 基本完成了模板库并发布到CSDN博客;
2022年3月11日更新
- 完成了部分内容;
2022年3月8日更新
- 完成了部分内容;
模板库源码(C++14标准)
#ifndef BITREE_HPP
#define BITREE_HPP
#include <vector>
#include <initializer_list>
#include "TypeName.hpp"
namespace ds
{
template <typename S, typename T = S, typename res_t = S>
struct plus_t
{
struct inverse_t
{
inline res_t operator()(const S &a, const T &b)
{
return (a - b);
}
inline static res_t calc(const S &a, const T &b)
{
return (a - b);
}
};
static constexpr res_t initial()
{
return res_t();
}
inline res_t operator()(const S &a, const T &b)
{
return (a + b);
}
inline static res_t calc(const S &a, const T &b)
{
return (a + b);
}
};
template <typename S, typename T = S, typename res_t = S>
struct multiply_t
{
struct inverse_t
{
inline res_t operator()(const S &a, const T &b)
{
return (a / b);
}
inline static res_t calc(const S &a, const T &b)
{
return (a / b);
}
};
static constexpr res_t initial()
{
return 1;
}
inline res_t operator()(const S &a, const T &b)
{
return (a * b);
}
inline static res_t calc(const S &a, const T &b