Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e68333a6
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,发现更多精彩内容 >>
提交
e68333a6
编写于
7月 20, 2014
作者:
J
Jonas Hietala
提交者:
Alex Crichton
7月 21, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish bitv docs.
上级
71afdc43
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
56 deletion
+65
-56
src/libcollections/bitv.rs
src/libcollections/bitv.rs
+44
-39
src/libcollections/lib.rs
src/libcollections/lib.rs
+21
-17
未找到文件。
src/libcollections/bitv.rs
浏览文件 @
e68333a6
...
...
@@ -25,6 +25,8 @@
//!
//! // Store the primes as a BitvSet
//! let primes = {
//! // Assume all numbers are prime to begin, and then we
//! // cross off non-primes progressively
//! let mut bv = Bitv::with_capacity(max_prime, true);
//!
//! // Neither 0 nor 1 are prime
...
...
@@ -33,8 +35,8 @@
//!
//! for i in range(2, max_prime) {
//! // if i is a prime
//! if bv
.get(i)
{
//! //
m
ark all multiples of i as non-prime (any multiples below i * i
//! if bv
[i]
{
//! //
M
ark all multiples of i as non-prime (any multiples below i * i
//! // will have been marked as non-prime previously)
//! for j in iter::range_step(i * i, max_prime, i) { bv.set(j, false) }
//! }
...
...
@@ -252,6 +254,9 @@ pub fn with_capacity(nbits: uint, init: bool) -> Bitv {
/// let bv: Bitv = [false, true].iter().map(|n| *n).collect();
/// assert_eq!(bv.get(0), false);
/// assert_eq!(bv.get(1), true);
///
/// // Can also use array indexing
/// assert_eq!(bv[1], true);
/// ```
#[inline]
pub
fn
get
(
&
self
,
i
:
uint
)
->
bool
{
...
...
@@ -275,7 +280,7 @@ pub fn get(&self, i: uint) -> bool {
///
/// let mut bv = Bitv::with_capacity(5, false);
/// bv.set(3, true);
/// assert_eq!(bv
.get(3)
, true);
/// assert_eq!(bv
[3]
, true);
/// ```
#[inline]
pub
fn
set
(
&
mut
self
,
i
:
uint
,
x
:
bool
)
{
...
...
@@ -478,7 +483,7 @@ pub fn any(&self) -> bool {
/// Organise the bits into bytes, such that the first bit in the
/// `Bitv` becomes the high-order bit of the first byte. If the
/// size of the `Bitv` is not a multiple of 8 then trailing bits
/// will be filled-in with
false/0
.
/// will be filled-in with
`false`
.
///
/// # Example
///
...
...
@@ -716,9 +721,9 @@ pub fn push(&mut self, elem: bool) {
/// # Example
///
/// ```
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// let bv = from_bytes([0b10100000, 0b00010010]);
/// let bv =
bitv::
from_bytes([0b10100000, 0b00010010]);
/// assert!(bv.eq_vec([true, false, true, false,
/// false, false, false, false,
/// false, false, false, true,
...
...
@@ -898,7 +903,7 @@ fn idx(&mut self, index: uint) -> Option<bool> {
///
/// ```
/// use std::collections::{BitvSet, Bitv};
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// // It's a regular set
/// let mut s = BitvSet::new();
...
...
@@ -913,7 +918,7 @@ fn idx(&mut self, index: uint) -> Option<bool> {
/// }
///
/// // Can initialize from a `Bitv`
/// let other = BitvSet::from_bitv(from_bytes([0b11010000]));
/// let other = BitvSet::from_bitv(
bitv::
from_bytes([0b11010000]));
///
/// s.union_with(&other);
///
...
...
@@ -1048,7 +1053,7 @@ pub fn unwrap(self) -> Bitv {
/// s.insert(0);
///
/// let bv = s.get_ref();
/// assert_eq!(bv
.get(0)
, true);
/// assert_eq!(bv
[0]
, true);
/// ```
#[inline]
pub
fn
get_ref
<
'a
>
(
&
'a
self
)
->
&
'a
Bitv
{
...
...
@@ -1131,9 +1136,9 @@ pub fn shrink_to_fit(&mut self) {
///
/// ```
/// use std::collections::BitvSet;
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// let s = BitvSet::from_bitv(from_bytes([0b01001010]));
/// let s = BitvSet::from_bitv(
bitv::
from_bytes([0b01001010]));
///
/// // Print 1, 4, 6 in arbitrary order
/// for x in s.iter() {
...
...
@@ -1152,10 +1157,10 @@ pub fn iter<'a>(&'a self) -> BitPositions<'a> {
///
/// ```
/// use std::collections::BitvSet;
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
/// let a = BitvSet::from_bitv(
bitv::
from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(
bitv::
from_bytes([0b10100000]));
///
/// // Print 0, 1, 2, 4 in arbitrary order
/// for x in a.union(&b) {
...
...
@@ -1180,10 +1185,10 @@ pub fn union<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
///
/// ```
/// use std::collections::BitvSet;
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
/// let a = BitvSet::from_bitv(
bitv::
from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(
bitv::
from_bytes([0b10100000]));
///
/// // Print 2
/// for x in a.intersection(&b) {
...
...
@@ -1209,10 +1214,10 @@ pub fn intersection<'a>(&'a self, other: &'a BitvSet) -> Take<TwoBitPositions<'a
///
/// ```
/// use std::collections::BitvSet;
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
/// let a = BitvSet::from_bitv(
bitv::
from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(
bitv::
from_bytes([0b10100000]));
///
/// // Print 2, 4 in arbitrary order
/// for x in a.difference(&b) {
...
...
@@ -1245,10 +1250,10 @@ pub fn difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions<'a> {
///
/// ```
/// use std::collections::BitvSet;
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// let a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
/// let a = BitvSet::from_bitv(
bitv::
from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(
bitv::
from_bytes([0b10100000]));
///
/// // Print 0, 1, 4 in arbitrary order
/// for x in a.symmetric_difference(&b) {
...
...
@@ -1272,13 +1277,13 @@ pub fn symmetric_difference<'a>(&'a self, other: &'a BitvSet) -> TwoBitPositions
///
/// ```
/// use std::collections::BitvSet;
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// let mut a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
/// let mut a = BitvSet::from_bitv(
bitv::
from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(
bitv::
from_bytes([0b10100000]));
///
/// a.union_with(&b);
/// assert_eq!(a.unwrap(), from_bytes([0b11101000]));
/// assert_eq!(a.unwrap(),
bitv::
from_bytes([0b11101000]));
/// ```
#[inline]
pub
fn
union_with
(
&
mut
self
,
other
:
&
BitvSet
)
{
...
...
@@ -1291,13 +1296,13 @@ pub fn union_with(&mut self, other: &BitvSet) {
///
/// ```
/// use std::collections::BitvSet;
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// let mut a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
/// let mut a = BitvSet::from_bitv(
bitv::
from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(
bitv::
from_bytes([0b10100000]));
///
/// a.intersect_with(&b);
/// assert_eq!(a.unwrap(), from_bytes([0b00100000]));
/// assert_eq!(a.unwrap(),
bitv::
from_bytes([0b00100000]));
/// ```
#[inline]
pub
fn
intersect_with
(
&
mut
self
,
other
:
&
BitvSet
)
{
...
...
@@ -1310,13 +1315,13 @@ pub fn intersect_with(&mut self, other: &BitvSet) {
///
/// ```
/// use std::collections::BitvSet;
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// let mut a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
/// let mut a = BitvSet::from_bitv(
bitv::
from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(
bitv::
from_bytes([0b10100000]));
///
/// a.difference_with(&b);
/// assert_eq!(a.unwrap(), from_bytes([0b01001000]));
/// assert_eq!(a.unwrap(),
bitv::
from_bytes([0b01001000]));
/// ```
#[inline]
pub
fn
difference_with
(
&
mut
self
,
other
:
&
BitvSet
)
{
...
...
@@ -1329,13 +1334,13 @@ pub fn difference_with(&mut self, other: &BitvSet) {
///
/// ```
/// use std::collections::BitvSet;
/// use std::collections::bitv
::from_bytes
;
/// use std::collections::bitv;
///
/// let mut a = BitvSet::from_bitv(from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(from_bytes([0b10100000]));
/// let mut a = BitvSet::from_bitv(
bitv::
from_bytes([0b01101000]));
/// let b = BitvSet::from_bitv(
bitv::
from_bytes([0b10100000]));
///
/// a.symmetric_difference_with(&b);
/// assert_eq!(a.unwrap(), from_bytes([0b11001000]));
/// assert_eq!(a.unwrap(),
bitv::
from_bytes([0b11001000]));
/// ```
#[inline]
pub
fn
symmetric_difference_with
(
&
mut
self
,
other
:
&
BitvSet
)
{
...
...
src/libcollections/lib.rs
浏览文件 @
e68333a6
...
...
@@ -330,36 +330,36 @@ pub trait MutableSet<T>: Set<T> + Mutable {
///
/// # Example
///
/// With a `Deque` we can simulate a
stack
:
/// With a `Deque` we can simulate a
queue efficiently
:
///
/// ```
/// use std::collections::{RingBuf, Deque};
///
/// let mut
stack
= RingBuf::new();
///
stack.push_front
(1i);
///
stack.push_front
(2i);
///
stack.push_front
(3i);
/// let mut
queue
= RingBuf::new();
///
queue.push_back
(1i);
///
queue.push_back
(2i);
///
queue.push_back
(3i);
///
/// // Will print
3, 2, 1
/// while !
stack
.is_empty() {
/// let x =
stack
.pop_front().unwrap();
/// // Will print
1, 2, 3
/// while !
queue
.is_empty() {
/// let x =
queue
.pop_front().unwrap();
/// println!("{}", x);
/// }
/// ```
///
/// We can
simulate a queue
:
/// We can
also simulate a stack
:
///
/// ```
/// use std::collections::{RingBuf, Deque};
///
/// let mut
queue
= RingBuf::new();
///
queue.push_back
(1i);
///
queue.push_back
(2i);
///
queue.push_back
(3i);
/// let mut
stack
= RingBuf::new();
///
stack.push_front
(1i);
///
stack.push_front
(2i);
///
stack.push_front
(3i);
///
/// // Will print
1, 2, 3
/// while !
queue
.is_empty() {
/// let x =
queue
.pop_front().unwrap();
/// // Will print
3, 2, 1
/// while !
stack
.is_empty() {
/// let x =
stack
.pop_front().unwrap();
/// println!("{}", x);
/// }
/// ```
...
...
@@ -385,7 +385,7 @@ pub trait MutableSet<T>: Set<T> + Mutable {
/// }
/// ```
pub
trait
Deque
<
T
>
:
Mutable
{
/// Provide a reference to the front element, or `None` if the sequence is
.
/// Provide a reference to the front element, or `None` if the sequence is
/// empty.
///
/// # Example
...
...
@@ -472,6 +472,7 @@ pub trait Deque<T> : Mutable {
/// d.push_front(1i);
/// d.push_front(2i);
/// assert_eq!(d.front(), Some(&2i));
/// ```
fn
push_front
(
&
mut
self
,
elt
:
T
);
/// Insert an element last in the sequence.
...
...
@@ -485,6 +486,7 @@ pub trait Deque<T> : Mutable {
/// d.push_back(1i);
/// d.push_back(2i);
/// assert_eq!(d.front(), Some(&1i));
/// ```
fn
push_back
(
&
mut
self
,
elt
:
T
);
/// Remove the last element and return it, or `None` if the sequence is empty.
...
...
@@ -501,6 +503,7 @@ pub trait Deque<T> : Mutable {
/// assert_eq!(d.pop_back(), Some(2i));
/// assert_eq!(d.pop_back(), Some(1i));
/// assert_eq!(d.pop_back(), None);
/// ```
fn
pop_back
(
&
mut
self
)
->
Option
<
T
>
;
/// Remove the first element and return it, or `None` if the sequence is empty.
...
...
@@ -517,6 +520,7 @@ pub trait Deque<T> : Mutable {
/// assert_eq!(d.pop_front(), Some(1i));
/// assert_eq!(d.pop_front(), Some(2i));
/// assert_eq!(d.pop_front(), None);
/// ```
fn
pop_front
(
&
mut
self
)
->
Option
<
T
>
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录