当前位置:网站首页>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; }
}
边栏推荐
猜你喜欢
【项目篇- 项目团队部分怎么写、如何作图?(两千字图文总结建议)】创新创业竞赛项目计划书、新苗国创(大创)申报书、挑战杯创业计划竞赛
darknet 结构体汇总
文献阅读(185)Co-design
What areas of the deep neural network are related to the human brain neural network?
巧用自定义函数,文本控件秒变高速缓存
老生常谈:面试必问“三次握手,四次挥手”这么讲,保证你忘不了
centos linux 下安装mysql 8.0
98转出0转入,985高校土木工程沦为“天坑”引热议
五分钟教你内网穿透
fiddler双向认证
随机推荐
我用这个操作,代码可读性提升一个档次
Flutter经验整理
a-upload上传图片去掉预览icon
网络安全——nmap
锂电池充电芯片IC
2. 类与对象——封装
Notes and Recommendations for Using Logs
兴盛优选:时序数据如何高效处理?
How long does it take to train a neural network, neural network training takes too long
Analyzes how Flink task than YARN container memory limit
如何批量下载hugging face模型和数据集文件
form-making notes on climbing pits (jeecg project replaces form designer)
C# Call AutoNavi Map API to obtain latitude, longitude and positioning [Detailed 4D explanation with complete code]
独家采访 | 智能源于自发产生而非计划:进化论拥趸,前OpenAI研究经理、UBC大学副教授Jeff Clune
I got the P8 "top" distributed architecture manual that went viral on Ali's intranet
开发者时薪高达1200美元?一文带你走近Move语言的编程魅力!
EXCLUSIVE INTERVIEW | INTELLIGENCE IS SPONTANED, NOT PLANNED: Evolution Fan, Former OpenAI Research Manager and UBC Associate Professor Jeff Clune
智能恒等于推荐系统
那些不用写代码也能做游戏的工具
centos linux 下安装mysql 8.0