当前位置:网站首页>d包含区间
d包含区间
2022-08-11 11:27:00 【fqbqrr】
alias ir = inclusiveRange;
auto inclusiveRange(T = int)(T f = T(0), T l = T(0), T s = T(1)) {
if(!l) {
l = f;
f = 0;
}
return InclusiveRange!T(f, l, s);
}
struct InclusiveRange(T) {
T front, last, step, term;
this(T front, T last, T step) {
this.front = front;
this.last = last;
this.step = step;
this.term = last;
if(this.diff % step)
{
const t = cast(int)(this.diff / step);
this.term = cast(T)(t * step + this.front);
}
}
auto save() {
return this; }
auto opSlice() {
return this; }
auto opDollar() {
return this.length; }
auto opSlice(T a, T b) in (b<=this.length)
{
return InclusiveRange!T(
cast(T)(front + a * step),
cast(T)(front + (b - 1) * step), step);
}
bool opBinaryRight(string op:"in")(T lhs)
{
foreach(r; this)
{
if(isClose(lhs, r, 1e-6))
{
return true;
}
}
return false;
}
T sum()
{
const residueCheck = front ? 2 * front + diff
: diff;
return cast(T)(length * residueCheck / 2);
}
auto diff() {
return term - front; }
auto length() {
return cast(int)(diff / step + 1); }
bool empty() {
return front > last; }
T back() {
return last; }
void popBack() {
if(!empty) last -= step; }
void popFront() {
if(!empty) front += step; }
}
边栏推荐
猜你喜欢

AWS、Splunk和Symantec牵头成立OCSF开放网络安全架构框架

The old saying: The interview must ask "Three handshakes, four waves", so you can't forget it

HyperLynx(五)反射仿真

1. 类与对象——什么是对象
![C# Call AutoNavi Map API to obtain latitude, longitude and positioning [Detailed 4D explanation with complete code]](/img/39/75a32a787c4e85026a768fd5781f25.png)
C# Call AutoNavi Map API to obtain latitude, longitude and positioning [Detailed 4D explanation with complete code]

低延时实时音视频在5G远程操控场景的应用实践

如何用100元制作一块全志V853的AI 开发板

CCF大会腾源会专场即将召开,聚焦基础软件与开发语言未来发展

如何批量下载hugging face模型和数据集文件

数据库导出的csv文件纯数字被转为科学计数法
随机推荐
Flexmonster 数据透视表和图表组件
【学习笔记】线性规划对偶定理
学习笔记【nlp中的sample和beam_search】
【毕业设计】老人心率脉搏血压体征监测手表 - stm32 单片机 嵌入式 物联网
[Study Notes] Maximum matching of general graphs
【项目篇- 项目团队部分怎么写、如何作图?(两千字图文总结建议)】创新创业竞赛项目计划书、新苗国创(大创)申报书、挑战杯创业计划竞赛
a-upload上传图片去掉预览icon
App Clip 苹果小程序开发须知
HM升压IC芯片代理商
Flutter 教程之 Kotlin 多平台与 Flutter,为您的应用选择哪一个
反射获取DLL中的字段、属性、方法、泛型方法(C#)
Five minutes to teach you intranet penetration
『独家』互联网 BAT 大厂 Android高级工程师面试题:174道题目让你做到面试无忧
黑马瑞吉外卖之公共字段自动填充
Common operations in Typora tables
Small target stunt | Complete the small target detection upgrade of Yolov5 in the easiest way!
Ince-Gaussian mode
Web3 创业者指南:如何为你的产品构建一个去中心化社区?
【2022】【Thesis Notes】Ultra-thin THz deflection based on laser direct writing graphene oxide paper——
论文笔记:《Time Series Generative Adversrial Networks》(TimeGAN,时间序列GAN)