当前位置: 首页 > wzjs >正文

网站栏目架构福州医疗网站建设

网站栏目架构,福州医疗网站建设,全球十大软件公司,我想做地推怎么找渠道一、源码 代码实现了Rust的类型级二进制数的左移运算(<<)&#xff0c;使用类型系统在编译期进行计算。 use super::basic::{Z0, P1, N1, B0, B1, NonZero, NonOne, Unsigned}; use super::sub1::Sub1; use core::ops::Shl;// 左移运算&#xff08;<<&#xff09…

一、源码

代码实现了Rust的类型级二进制数的左移运算(<<),使用类型系统在编译期进行计算。

use super::basic::{Z0, P1, N1, B0, B1, NonZero, NonOne, Unsigned};
use super::sub1::Sub1;
use core::ops::Shl;// ==================== 左移运算(<<) ====================
// Z0 << U
impl<R: Unsigned> Shl<R> for Z0 {type Output = Z0;fn shl(self, _: R) -> Self::Output {Z0  // 0 << n = 0}
}// P1 << U
impl Shl<Z0> for P1 {// P1 << Z0type Output = Self;fn shl(self, _: Z0) -> Self::Output {self}
}impl Shl<P1> for P1 {// P1 << P1type Output = B0<P1>;fn shl(self, _: P1) -> Self::Output {B0::new()}
}impl<R: Unsigned + NonZero + NonOne + Sub1> Shl<R> for P1
whereP1: Shl<<R as Sub1>::Output>
{// P1 << 超过1的数type Output = B0<<P1 as Shl<R::Output>>::Output>;fn shl(self, _: R) -> Self::Output {B0::new()}
}// N1 << U
impl Shl<Z0> for N1 {// N1 << Z0type Output = Self;fn shl(self, _: Z0) -> Self::Output {self}
}impl Shl<P1> for N1 {// N1 << P1type Output = B0<N1>;fn shl(self, _: P1) -> Self::Output {B0::new()}
}impl<R: Unsigned + NonZero + NonOne + Sub1> Shl<R> for N1
whereN1: Shl<<R as Sub1>::Output>
{// P1 << 超过1的数type Output = B0<<N1 as Shl<R::Output>>::Output>;fn shl(self, _: R) -> Self::Output {B0::new()}
}// B0 << U
impl<H: NonZero> Shl<Z0> for B0<H> {// B0 << Z0type Output = Self;fn shl(self, _: Z0) -> Self::Output {self}
}impl<H: NonZero> Shl<P1> for B0<H> {// B0 << P1type Output = B0<B0<H>>;fn shl(self, _: P1) -> Self::Output {B0::new()}
}impl<H: NonZero, R: Unsigned + NonZero + NonOne + Sub1> Shl<R> for B0<H>
whereB0<H>: Shl<<R as Sub1>::Output>
{// B0 << 超过1的数type Output = B0<<B0<H> as Shl<R::Output>>::Output>;fn shl(self, _: R) -> Self::Output {B0::new()}
}// B1 << U
impl<H: NonZero> Shl<Z0> for B1<H> {// B1 << Z0type Output = Self;fn shl(self, _: Z0) -> Self::Output {self}
}impl<H: NonZero> Shl<P1> for B1<H> {// B1 << P1type Output = B0<B1<H>>;fn shl(self, _: P1) -> Self::Output {B0::new()}
}impl<H: NonZero, R: Unsigned + NonZero + NonOne + Sub1> Shl<R> for B1<H>
whereB1<H>: Shl<<R as Sub1>::Output>
{// B1 << 超过1的数type Output = B0<<B1<H> as Shl<R::Output>>::Output>;fn shl(self, _: R) -> Self::Output {B0::new()}
}

二、类型和trait引入

use super::basic::{Z0, P1, N1, B0, B1, NonZero, NonOne, Unsigned};
use super::sub1::Sub1;
use core::ops::Shl;
  • 从父模块引入基础类型:

    • Z0: 表示0

    • P1: 表示+1

    • N1: 表示-1

    • B0, B1: 二进制位(0和1)

    • 标记trait: NonZero, NonOne, Unsigned

  • Sub1: 减1操作

  • Shl: Rust的左移运算符trait

三、零的左移实现

impl<R: Unsigned> Shl<R> for Z0 {type Output = Z0;fn shl(self, _: R) -> Self::Output {Z0  // 0 << n = 0}
}
  • 任何数左移0还是0

  • 适用于所有无符号类型R

四、正一(P1)的左移

impl Shl<Z0> for P1 { // P1 << 0 = P1type Output = Self;fn shl(self, _: Z0) -> Self::Output { self }
}impl Shl<P1> for P1 { // P1 << 1 = B0<P1> (即10,二进制表示)type Output = B0<P1>;fn shl(self, _: P1) -> Self::Output { B0::new() }
}impl<R: Unsigned + NonZero + NonOne + Sub1> Shl<R> for P1
where P1: Shl<<R as Sub1>::Output> {type Output = B0<<P1 as Shl<R::Output>>::Output>;fn shl(self, _: R) -> Self::Output { B0::new() }
}
  • 分三种情况处理:

    • 移0位:保持不变

    • 移1位:变成B0(二进制10)

    • 移多位:递归处理

五、负一(N1)的左移

impl Shl<Z0> for N1 { ... }  // 同P1
impl Shl<P1> for N1 { ... }  // 同P1
impl<R: Unsigned + NonZero + NonOne + Sub1> Shl<R> for N1 { ... }  // 同P1
  • 处理逻辑与P1完全相同

六、B0(二进制0)的左移

impl<H: NonZero> Shl<Z0> for B0<H> { ... }  // 移0位
impl<H: NonZero> Shl<P1> for B0<H> { ... }  // 移1位
impl<H: NonZero, R: Unsigned + NonZero + NonOne + Sub1> Shl<R> for B0<H> { ... }  // 移多位
  • 在二进制数前补0:

    • B0 << 1 = B0<B0>

    • 递归处理多位移动

七、B1(二进制1)的左移

impl<H: NonZero> Shl<Z0> for B1<H> { ... }  // 移0位
impl<H: NonZero> Shl<P1> for B1<H> { ... }  // 移1位
impl<H: NonZero, R: Unsigned + NonZero + NonOne + Sub1> Shl<R> for B1<H> { ... }  // 移多位
  • 类似B0,但在二进制数低位补0

八、关键点总结

  1. 递归处理:多位移动通过递归减1实现

  2. 类型级计算:所有操作在编译期确定

  3. 二进制表示:

  • B0表示在二进制数H低位加0

  • B1表示在二进制数H低位加1

  1. 特殊值处理:
  • P1表示+1(二进制1)

  • N1表示-1

  • Z0表示0

这种实现方式常用于需要编译期计算的场景,如物理单位系统、矩阵运算等,可以完全消除运行时开销。

http://www.dtcms.com/wzjs/784545.html

相关文章:

  • 做公司网站首页网站转化微信小程序
  • 做公益筹集项目的网站如何制作自己的二维码
  • 毕业设计代做网站php济宁市兖州区建设局网站
  • 网站色调搭配wordpress多地址
  • 做外贸哪个网站看外汇百度号码认证
  • 网站空间不支持php5.4国家重点学科建设网站
  • 济宁网站建设软件开发网站兼容哪些浏览器
  • 彩票网站开发 违法保定知名网站建设公司
  • 长沙学做网站建设邯郸网站设计公司排名
  • 做淘客需要网站广州seo网站排名
  • 网站开发客户提供素材360建筑网官网下载
  • 网站快照诊断个人可以做哪些有意思的网站
  • 校园网站推广方案怎么做简单网站html模板下载地址
  • 太原做网站公司哪家好网站制作类软件推荐
  • 中小企业网站建设论文山东省济南市莱芜区
  • 给赌场做网站设计公司上市企业
  • 中山视角做网站的公司dw如何在网站做弹窗
  • 淘宝美工与网站开发网站建设 阿里巴巴旗下
  • 企业对比网站做网站需要写配置文件吗
  • 建设银行签名通在网站哪里下载wordpress 用户权限
  • 中国城乡建设部官方网站app 设计网站建设
  • 设计规范网站东莞东城招聘网最新招聘
  • 有做游戏广告的网站制作wordpress文章模板
  • 网站建设包括哪些内容退役厅网站建设中标公告
  • server 2012 iis 添加网站微商城登录
  • 长沙网站搭建gate网站合约怎么做空
  • 泉州市住房与城乡建设局网站贴吧aso优化贴吧
  • 计算机网站的开发流程工作汇报总结怎么写
  • 网站 网站 建设做网站被骗首付款怎么报案
  • 服务器在国外怎样做网站镜像阿里 网站建设