Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
TinySTL
提交
7784f65e
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 搜索 >>
提交
7784f65e
编写于
12月 30, 2014
作者:
邹
邹晓航
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add suffix_array
上级
c82d8008
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
95 addition
and
0 deletion
+95
-0
TinySTL/SuffixArray.h
TinySTL/SuffixArray.h
+55
-0
TinySTL/TinySTL.vcxproj
TinySTL/TinySTL.vcxproj
+10
-0
TinySTL/TinySTL.vcxproj.filters
TinySTL/TinySTL.vcxproj.filters
+30
-0
未找到文件。
TinySTL/SuffixArray.h
0 → 100644
浏览文件 @
7784f65e
#ifndef _SUFFIX_ARRAY_H_
#define _SUFFIX_ARRAY_H_
#include <vector>
#include <memory>
namespace
TinySTL
{
class
suffix_array
{
private:
//typedef std::unique_ptr<std::vector<int>> vecPtr;
private:
std
::
vector
<
int
>
_array
;
public:
template
<
class
InputIterator
>
//arr - 源数组
//len - 源数组长度
//max_len - max_len代表字符串中字符的取值范围,是基数排序的一个参数,
// 如果原序列都是字母可以直接取128,如果原序列本身都是整数的话,则m可以取比最大的整数大1的值。
suffix_array
(
InputIterator
arr
,
int
len
,
int
max_len
=
128
){
//采用了罗穗骞论文中实现的倍增算法
_array
.
resize
(
len
);
int
wa
[
1024
],
wb
[
1024
],
wv
[
1024
],
ws
[
1024
];
int
i
,
j
,
p
,
*
x
=
wa
,
*
y
=
wb
,
*
t
;
for
(
i
=
0
;
i
<
max_len
;
i
++
)
ws
[
i
]
=
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
ws
[
x
[
i
]
=
arr
[
i
]]
++
;
for
(
i
=
1
;
i
<
max_len
;
i
++
)
ws
[
i
]
+=
ws
[
i
-
1
];
for
(
i
=
len
-
1
;
i
>=
0
;
i
--
)
_array
[
--
ws
[
x
[
i
]]]
=
i
;
for
(
j
=
1
,
p
=
1
;
p
<
len
;
j
*=
2
,
max_len
=
p
)
{
for
(
p
=
0
,
i
=
len
-
j
;
i
<
len
;
i
++
)
y
[
p
++
]
=
i
;
for
(
i
=
0
;
i
<
len
;
i
++
)
if
(
_array
[
i
]
>=
j
)
y
[
p
++
]
=
_array
[
i
]
-
j
;
for
(
i
=
0
;
i
<
len
;
i
++
)
wv
[
i
]
=
x
[
y
[
i
]];
for
(
i
=
0
;
i
<
max_len
;
i
++
)
ws
[
i
]
=
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
ws
[
wv
[
i
]]
++
;
for
(
i
=
1
;
i
<
max_len
;
i
++
)
ws
[
i
]
+=
ws
[
i
-
1
];
for
(
i
=
len
-
1
;
i
>=
0
;
i
--
)
_array
[
--
ws
[
wv
[
i
]]]
=
y
[
i
];
for
(
t
=
x
,
x
=
y
,
y
=
t
,
p
=
1
,
x
[
_array
[
0
]]
=
0
,
i
=
1
;
i
<
len
;
i
++
)
x
[
_array
[
i
]]
=
cmp
(
y
,
_array
[
i
-
1
],
_array
[
i
],
j
)
?
p
-
1
:
p
++
;
}
return
;
}
const
std
::
vector
<
int
>
suffixArray
()
const
{
return
_array
;
}
private:
bool
cmp
(
int
*
arr
,
int
a
,
int
b
,
int
l
){
return
arr
[
a
]
==
arr
[
b
]
&&
arr
[
a
+
l
]
==
arr
[
b
+
l
];
}
};
}
#endif
\ No newline at end of file
TinySTL/TinySTL.vcxproj
浏览文件 @
7784f65e
...
...
@@ -83,6 +83,10 @@
<ClCompile
Include=
"Profiler\Profiler.cpp"
/>
<ClCompile
Include=
"Test\AlgorithmTest.cpp"
/>
<ClCompile
Include=
"Test\PairTest.cpp"
/>
<ClCompile
Include=
"Test\PriorityQueueTest.cpp"
/>
<ClCompile
Include=
"Test\StringTest.cpp"
/>
<ClCompile
Include=
"Test\SuffixArrayTest.cpp"
/>
<ClCompile
Include=
"Test\VectorTest.cpp"
/>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"Algorithm.h"
/>
...
...
@@ -102,8 +106,14 @@
<ClInclude
Include=
"ReverseIterator.h"
/>
<ClInclude
Include=
"Stack.h"
/>
<ClInclude
Include=
"String.h"
/>
<ClInclude
Include=
"SuffixArray.h"
/>
<ClInclude
Include=
"Test\AlgorithmTest.h"
/>
<ClInclude
Include=
"Test\PairTest.h"
/>
<ClInclude
Include=
"Test\PriorityQueueTest.h"
/>
<ClInclude
Include=
"Test\StringTest.h"
/>
<ClInclude
Include=
"Test\SuffixArrayTest.h"
/>
<ClInclude
Include=
"Test\TestUtil.h"
/>
<ClInclude
Include=
"Test\VectorTest.h"
/>
<ClInclude
Include=
"TypeTraits.h"
/>
<ClInclude
Include=
"UninitializedFunctions.h"
/>
<ClInclude
Include=
"Utility.h"
/>
...
...
TinySTL/TinySTL.vcxproj.filters
浏览文件 @
7784f65e
...
...
@@ -33,6 +33,18 @@
<ClCompile
Include=
"Test\AlgorithmTest.cpp"
>
<Filter>
Test
</Filter>
</ClCompile>
<ClCompile
Include=
"Test\VectorTest.cpp"
>
<Filter>
Test
</Filter>
</ClCompile>
<ClCompile
Include=
"Test\StringTest.cpp"
>
<Filter>
Test
</Filter>
</ClCompile>
<ClCompile
Include=
"Test\PriorityQueueTest.cpp"
>
<Filter>
Test
</Filter>
</ClCompile>
<ClCompile
Include=
"Test\SuffixArrayTest.cpp"
>
<Filter>
Test
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"TypeTraits.h"
>
...
...
@@ -104,6 +116,24 @@
<ClInclude
Include=
"Test\PairTest.h"
>
<Filter>
Test
</Filter>
</ClInclude>
<ClInclude
Include=
"Test\AlgorithmTest.h"
>
<Filter>
Test
</Filter>
</ClInclude>
<ClInclude
Include=
"Test\VectorTest.h"
>
<Filter>
Test
</Filter>
</ClInclude>
<ClInclude
Include=
"Test\StringTest.h"
>
<Filter>
Test
</Filter>
</ClInclude>
<ClInclude
Include=
"Test\PriorityQueueTest.h"
>
<Filter>
Test
</Filter>
</ClInclude>
<ClInclude
Include=
"SuffixArray.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
<ClInclude
Include=
"Test\SuffixArrayTest.h"
>
<Filter>
Test
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None
Include=
"..\README.md"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录