Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2dedcc8a
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,发现更多精彩内容 >>
提交
2dedcc8a
编写于
11月 06, 2011
作者:
D
David Rajchenbach-Teller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[stdlib optim] rope::node improved balancing strategy
上级
81a93eff
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
59 addition
and
8 deletion
+59
-8
src/lib/rope.rs
src/lib/rope.rs
+59
-8
未找到文件。
src/lib/rope.rs
浏览文件 @
2dedcc8a
...
...
@@ -95,6 +95,7 @@ fn of_str(str: @str) -> rope {
*/
fn
of_substr
(
str
:
@
str
,
byte_offset
:
uint
,
byte_len
:
uint
)
->
rope
{
if
byte_len
==
0u
{
ret
node
::
empty
;
}
if
byte_offset
+
byte_len
>
str
::
byte_len
(
*
str
)
{
fail
;
}
ret
node
::
content
(
node
::
of_substr
(
str
,
byte_offset
,
byte_len
));
}
...
...
@@ -702,18 +703,50 @@ fn of_str(str: @str) -> @node {
}
/*
Function: of_substr
Adopt a slice of a string as a node.
If the slice is longer than `max_leaf_char_len`, it is logically split
between as many leaves as necessary. Regardless, the string itself
is not copied.
@param byte_start The byte offset where the slice of `str` starts.
@param byte_len The number of bytes from `str` to use.
Parameters:
byte_start - The byte offset where the slice of `str` starts.
byte_len - The number of bytes from `str` to use.
Safety note:
- Behavior is undefined if `byte_start` or `byte_len` do not represent
valid positions in `str`
*/
fn
of_substr
(
str
:
@
str
,
byte_start
:
uint
,
byte_len
:
uint
)
->
@
node
{
assert
(
byte_len
>
0u
);
let
char_len
=
str
::
char_len_range
(
*
str
,
byte_start
,
byte_len
);
ret
of_substr_unsafer
(
str
,
byte_start
,
byte_len
,
str
::
char_len_range
(
*
str
,
byte_start
,
byte_len
));
}
/*
Function: of_substr_unsafer
Adopt a slice of a string as a node.
If the slice is longer than `max_leaf_char_len`, it is logically split
between as many leaves as necessary. Regardless, the string itself
is not copied.
byte_start - The byte offset where the slice of `str` starts.
byte_len - The number of bytes from `str` to use.
char_len - The number of chars in `str` in the interval
[byte_start, byte_start+byte_len(
Safety note:
- Behavior is undefined if `byte_start` or `byte_len` do not represent
valid positions in `str`
- Behavior is undefined if `char_len` does not accurately represent the
number of chars between byte_start and byte_start+byte_len
*/
fn
of_substr_unsafer
(
str
:
@
str
,
byte_start
:
uint
,
byte_len
:
uint
,
char_len
:
uint
)
->
@
node
{
assert
(
byte_start
+
byte_len
<=
str
::
byte_len
(
*
str
));
let
candidate
=
@
leaf
({
byte_offset
:
byte_start
,
byte_len
:
byte_len
,
...
...
@@ -784,6 +817,15 @@ fn of_substr(str: @str, byte_start: uint, byte_len: uint) -> @node {
}
/*
Function: tree_from_forest_destructive
Concatenate a forest of nodes into one tree.
Parameters:
forest - The forest. This vector is progressively rewritten during
execution and should be discarded as meaningless afterwards.
*/
fn
tree_from_forest_destructive
(
forest
:
[
mutable
@
node
])
->
@
node
{
let
i
=
0u
;
let
len
=
vec
::
len
(
forest
);
...
...
@@ -796,17 +838,26 @@ fn tree_from_forest_destructive(forest: [mutable @node]) -> @node {
let
right_len
=
char_len
(
right
);
let
left_height
=
height
(
left
);
let
right_height
=
height
(
right
);
if
left_len
+
right_len
>
hint_max_leaf_char_len
//TODO: Improve strategy
||
left_height
>=
hint_max_node_height
||
right_height
>=
hint_max_node_height
{
if
left_len
+
right_len
>
hint_max_leaf_char_len
{
if
left_len
<=
hint_max_leaf_char_len
{
left
=
flatten
(
left
);
left_height
=
height
(
left
);
}
if
right_len
<=
hint_max_leaf_char_len
{
right
=
flatten
(
right
);
right_height
=
height
(
right
);
}
}
if
left_height
>=
hint_max_node_height
{
left
=
of_substr_unsafer
(
@
serialize_node
(
left
),
0u
,
byte_len
(
left
),
left_len
);
}
if
right_height
>=
hint_max_node_height
{
right
=
of_substr_unsafer
(
@
serialize_node
(
right
),
0u
,
byte_len
(
right
),
right_len
);
}
forest
[
i
/
2u
]
=
concat2
(
left
,
right
);
i
+=
2u
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录