C++树状数组模板库——“BITree.hpp“

C++树状数组模板库——“BITree.hpp”

更新日志

2022年3月29日更新
  1. 为了迎合标准库的命名规范,发布了"TypeName.hpp"类型名作出规范,并基于该库修改本库所有函数名、参数名、变量名使其符合规范;
  2. 新增了BITree(forward_iter_t, size_t)构造函数并基于此新增了BITree(initializer_list_t<T>)构造函数;
  3. 修改了plus_tmultiply_t及其逆运算的实现方式,以此简化代码、增加代码可读性;
2022年3月15日更新
  1. 基本完成了模板库并发布到CSDN博客;
2022年3月11日更新
  1. 完成了部分内容;
2022年3月8日更新
  1. 完成了部分内容;

模板库源码(C++14标准)

#ifndef BITREE_HPP
#define BITREE_HPP

#include <vector>
#include <initializer_list>
#include "TypeName.hpp"

namespace ds // Data structure
{
   
    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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值