Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
88bd646b
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
88bd646b
编写于
9月 05, 2014
作者:
B
Brendan Zabarauskas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make integer bit count methods return uints
Fixes rust-lang/rfcs#224
上级
5248b118
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
17 addition
and
17 deletion
+17
-17
src/libcore/num/mod.rs
src/libcore/num/mod.rs
+10
-10
src/libcoretest/num/int_macros.rs
src/libcoretest/num/int_macros.rs
+3
-3
src/libcoretest/num/uint_macros.rs
src/libcoretest/num/uint_macros.rs
+3
-3
src/libnum/bigint.rs
src/libnum/bigint.rs
+1
-1
未找到文件。
src/libcore/num/mod.rs
浏览文件 @
88bd646b
...
...
@@ -406,7 +406,7 @@ pub trait Int: Primitive
///
/// assert_eq!(n.count_ones(), 3);
/// ```
fn
count_ones
(
self
)
->
Self
;
fn
count_ones
(
self
)
->
uint
;
/// Returns the number of zeros in the binary representation of the integer.
///
...
...
@@ -418,7 +418,7 @@ pub trait Int: Primitive
/// assert_eq!(n.count_zeros(), 5);
/// ```
#[inline]
fn
count_zeros
(
self
)
->
Self
{
fn
count_zeros
(
self
)
->
uint
{
(
!
self
)
.count_ones
()
}
...
...
@@ -432,7 +432,7 @@ fn count_zeros(self) -> Self {
///
/// assert_eq!(n.leading_zeros(), 10);
/// ```
fn
leading_zeros
(
self
)
->
Self
;
fn
leading_zeros
(
self
)
->
uint
;
/// Returns the number of trailing zeros in the binary representation
/// of the integer.
...
...
@@ -444,7 +444,7 @@ fn count_zeros(self) -> Self {
///
/// assert_eq!(n.trailing_zeros(), 3);
/// ```
fn
trailing_zeros
(
self
)
->
Self
;
fn
trailing_zeros
(
self
)
->
uint
;
/// Shifts the bits to the left by a specified amount amount, `n`, wrapping
/// the truncated bits to the end of the resulting integer.
...
...
@@ -569,13 +569,13 @@ fn to_le(self) -> Self {
(
$T:ty
,
$BITS:expr
,
$ctpop:path
,
$ctlz:path
,
$cttz:path
,
$bswap:path
)
=>
{
impl
Int
for
$T
{
#[inline]
fn
count_ones
(
self
)
->
$T
{
unsafe
{
$ctpop
(
self
)
}
}
fn
count_ones
(
self
)
->
uint
{
unsafe
{
$ctpop
(
self
)
as
uint
}
}
#[inline]
fn
leading_zeros
(
self
)
->
$T
{
unsafe
{
$ctlz
(
self
)
}
}
fn
leading_zeros
(
self
)
->
uint
{
unsafe
{
$ctlz
(
self
)
as
uint
}
}
#[inline]
fn
trailing_zeros
(
self
)
->
$T
{
unsafe
{
$cttz
(
self
)
}
}
fn
trailing_zeros
(
self
)
->
uint
{
unsafe
{
$cttz
(
self
)
as
uint
}
}
#[inline]
fn
rotate_left
(
self
,
n
:
uint
)
->
$T
{
...
...
@@ -629,13 +629,13 @@ unsafe fn bswap8(x: u8) -> u8 { x }
(
$T:ty
,
$U:ty
)
=>
{
impl
Int
for
$T
{
#[inline]
fn
count_ones
(
self
)
->
$T
{
(
self
as
$U
)
.count_ones
()
as
$T
}
fn
count_ones
(
self
)
->
uint
{
(
self
as
$U
)
.count_ones
()
}
#[inline]
fn
leading_zeros
(
self
)
->
$T
{
(
self
as
$U
)
.leading_zeros
()
as
$T
}
fn
leading_zeros
(
self
)
->
uint
{
(
self
as
$U
)
.leading_zeros
()
}
#[inline]
fn
trailing_zeros
(
self
)
->
$T
{
(
self
as
$U
)
.trailing_zeros
()
as
$T
}
fn
trailing_zeros
(
self
)
->
uint
{
(
self
as
$U
)
.trailing_zeros
()
}
#[inline]
fn
rotate_left
(
self
,
n
:
uint
)
->
$T
{
(
self
as
$U
)
.rotate_left
(
n
)
as
$T
}
...
...
src/libcoretest/num/int_macros.rs
浏览文件 @
88bd646b
...
...
@@ -95,9 +95,9 @@ fn test_count_ones() {
#[test]
fn
test_count_zeros
()
{
assert!
(
A
.count_zeros
()
==
BITS
as
$T
-
3
);
assert!
(
B
.count_zeros
()
==
BITS
as
$T
-
2
);
assert!
(
C
.count_zeros
()
==
BITS
as
$T
-
5
);
assert!
(
A
.count_zeros
()
==
BITS
-
3
);
assert!
(
B
.count_zeros
()
==
BITS
-
2
);
assert!
(
C
.count_zeros
()
==
BITS
-
5
);
}
#[test]
...
...
src/libcoretest/num/uint_macros.rs
浏览文件 @
88bd646b
...
...
@@ -55,9 +55,9 @@ fn test_count_ones() {
#[test]
fn
test_count_zeros
()
{
assert!
(
A
.count_zeros
()
==
BITS
as
$T
-
3
);
assert!
(
B
.count_zeros
()
==
BITS
as
$T
-
2
);
assert!
(
C
.count_zeros
()
==
BITS
as
$T
-
5
);
assert!
(
A
.count_zeros
()
==
BITS
-
3
);
assert!
(
B
.count_zeros
()
==
BITS
-
2
);
assert!
(
C
.count_zeros
()
==
BITS
-
5
);
}
#[test]
...
...
src/libnum/bigint.rs
浏览文件 @
88bd646b
...
...
@@ -807,7 +807,7 @@ fn shr_bits(&self, n_bits: uint) -> BigUint {
pub
fn
bits
(
&
self
)
->
uint
{
if
self
.is_zero
()
{
return
0
;
}
let
zeros
=
self
.data
.last
()
.unwrap
()
.leading_zeros
();
return
self
.data
.len
()
*
BigDigit
::
bits
-
(
zeros
as
uint
)
;
return
self
.data
.len
()
*
BigDigit
::
bits
-
zeros
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录