Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
TinySTL
提交
d56e93e2
T
TinySTL
项目概览
OpenDocCN
/
TinySTL
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TinySTL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d56e93e2
编写于
2月 06, 2015
作者:
邹
邹晓航
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成generate和distance
上级
200bb788
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
62 addition
and
3 deletion
+62
-3
README.md
README.md
+2
-0
TinySTL/Algorithm.h
TinySTL/Algorithm.h
+31
-1
TinySTL/Test/AlgorithmTest.cpp
TinySTL/Test/AlgorithmTest.cpp
+25
-2
TinySTL/Test/AlgorithmTest.h
TinySTL/Test/AlgorithmTest.h
+3
-0
TinySTL/TinySTL.vcxproj
TinySTL/TinySTL.vcxproj
+1
-0
未找到文件。
README.md
浏览文件 @
d56e93e2
...
...
@@ -70,6 +70,8 @@ TinySTL
*
search:100%
*
advance:100%
*
sort:100%
*
generate:100%
*
distance:100%
*
其他组件:
*
circular_buffer:100%
*
bitmap:100%
...
...
TinySTL/Algorithm.h
浏览文件 @
d56e93e2
...
...
@@ -531,7 +531,37 @@ namespace TinySTL{
sort
(
first
,
p1
,
pred
);
sort
(
p1
+
1
,
last
,
pred
);
}
//********** [generate] ******************************
//********* [Algorithm Complexity: O(N)] ****************
template
<
class
InputIterator
,
class
Function
>
void
generate
(
InputIterator
first
,
InputIterator
last
,
Function
func
){
for
(;
first
!=
last
;
++
first
){
*
first
=
func
();
}
}
//********** [distance] ******************************
//********* [Algorithm Complexity: O(N)] ****************
template
<
class
InputIterator
>
typename
iterator_traits
<
InputIterator
>::
difference_type
_distance
(
InputIterator
first
,
InputIterator
last
,
input_iterator_tag
){
typename
iterator_traits
<
InputIterator
>::
difference_type
dist
=
0
;
while
(
first
++
!=
last
){
++
dist
;
}
return
dist
;
}
template
<
class
RandomIterator
>
typename
iterator_traits
<
RandomIterator
>::
difference_type
_distance
(
RandomIterator
first
,
RandomIterator
last
,
random_access_iterator_tag
){
auto
dist
=
last
-
first
;
return
dist
;
}
template
<
class
Iterator
>
typename
iterator_traits
<
Iterator
>::
difference_type
distance
(
Iterator
first
,
Iterator
last
){
typedef
typename
iterator_traits
<
Iterator
>::
iterator_category
iterator_category
;
return
_distance
(
first
,
last
,
iterator_category
());
}
}
...
...
TinySTL/Test/AlgorithmTest.cpp
浏览文件 @
d56e93e2
...
...
@@ -202,9 +202,9 @@ namespace TinySTL{
TinySTL
::
sort
(
std
::
begin
(
arr3
),
std
::
end
(
arr3
));
assert
(
std
::
is_sorted
(
std
::
begin
(
arr3
),
std
::
end
(
arr3
)));
int
arr4
[
100
00
];
int
arr4
[
100
];
std
::
random_device
rd
;
for
(
auto
i
=
0
;
i
!=
10
0
;
++
i
){
for
(
auto
i
=
0
;
i
!=
10
;
++
i
){
for
(
auto
&
n
:
arr4
){
n
=
rd
()
%
65536
;
}
...
...
@@ -212,7 +212,28 @@ namespace TinySTL{
assert
(
std
::
is_sorted
(
std
::
begin
(
arr4
),
std
::
end
(
arr4
)));
}
}
void
testGenerate
(){
int
arr1
[
100
],
arr2
[
100
];
auto
f
=
[](
int
i
){
return
i
;
};
for
(
auto
i
=
0
;
i
!=
100
;
++
i
){
auto
func
=
std
::
bind
(
f
,
i
);
TinySTL
::
generate
(
std
::
begin
(
arr1
),
std
::
end
(
arr1
),
func
);
std
::
generate
(
std
::
begin
(
arr2
),
std
::
end
(
arr2
),
func
);
}
assert
(
TinySTL
::
Test
::
container_equal
(
arr1
,
arr2
));
}
void
testDistance
(){
TinySTL
::
list
<
int
>
l
(
10
,
0
);
TinySTL
::
vector
<
int
>
v
(
10
,
0
);
auto
lit
=
l
.
begin
();
TinySTL
::
advance
(
lit
,
5
);
auto
vit
=
v
.
begin
();
TinySTL
::
advance
(
vit
,
5
);
assert
(
TinySTL
::
distance
(
l
.
begin
(),
lit
)
==
5
);
assert
(
TinySTL
::
distance
(
v
.
begin
(),
vit
)
==
5
);
}
void
testAllCases
(){
testFill
();
...
...
@@ -235,6 +256,8 @@ namespace TinySTL{
testSearch
();
testAdvance
();
testSort
();
testGenerate
();
testDistance
();
}
}
}
\ No newline at end of file
TinySTL/Test/AlgorithmTest.h
浏览文件 @
d56e93e2
...
...
@@ -10,6 +10,7 @@
#include <cctype>
#include <cstring>
#include <cassert>
#include <functional>
#include <list>
#include <random>
#include <vector>
...
...
@@ -41,6 +42,8 @@ namespace TinySTL{
void
testSearch
();
void
testAdvance
();
void
testSort
();
void
testGenerate
();
void
testDistance
();
void
testAllCases
();
}
...
...
TinySTL/TinySTL.vcxproj
浏览文件 @
d56e93e2
...
...
@@ -76,6 +76,7 @@
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
<StackReserveSize>
0x10000000
</StackReserveSize>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录