Skip to content

Commit 849cb1e

Browse files
committed
Directory adjust & Format
1 parent ad15320 commit 849cb1e

32 files changed

+449
-487
lines changed

.clang-format

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
BasedOnStyle: LLVM
2+
PointerAlignment: Right
3+
IndentWidth: 4
4+
MaxEmptyLinesToKeep: 1
5+
ObjCSpaceAfterProperty: true
6+
ObjCBlockIndentWidth: 4
7+
AllowShortFunctionsOnASingleLine: true
8+
AllowShortIfStatementsOnASingleLine: true
9+
AlignTrailingComments: true
10+
SpacesInSquareBrackets: true
11+
SpacesInParentheses : true
12+
AlignConsecutiveDeclarations: true
13+
AlignConsecutiveAssignments: true
14+
SpaceBeforeAssignmentOperators: true
15+
SpacesInContainerLiterals: true
16+
IndentWrappedFunctionNames: true
17+
KeepEmptyLinesAtTheStartOfBlocks: true
18+
BreakConstructorInitializersBeforeComma: true
19+
AllowAllParametersOfDeclarationOnNextLine: true
20+
SpaceAfterCStyleCast: true
21+
TabWidth: 4
22+
UseTab: Never

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,6 @@ paket-files/
309309
# Python Tools for Visual Studio (PTVS)
310310
__pycache__/
311311
*.pyc
312+
313+
# local build test
314+
*make

compile_flags.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Iinclude/

eight_numbers_c.psess

-73
This file was deleted.

include/algorithm_module.h

+7-131
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,13 @@
1-
#pragma once
1+
//注意:本文件所有定义类型/函数以AM_做前缀
22

3-
#include <cmath>
4-
#include <cstdlib>
5-
#include <algorithm>
6-
#include <functional>
7-
#include <unordered_map>
8-
#include <list>
9-
#include <utility>
3+
#include "begin.h"
104

11-
#include "c_algorithm_module.h"
12-
13-
#ifdef WIN32
14-
#define PUBLIC __declspec(dllexport) //dll输出函数,至于为什么要叫public.......
15-
#else
16-
#define PUBLIC
5+
#ifdef __cplusplus
6+
extern "C" {
177
#endif
188

19-
namespace Algorithm {
20-
21-
/**不存在的编号,长度..*/
22-
const int NIL = -1;
23-
24-
namespace Graph {
25-
26-
//适配器类型声明
27-
28-
/**
29-
* @param idx_v:节点编号
30-
* @return:节点idx_v相连的第一条边的编号,无边时返回NIL
31-
*/
32-
typedef std::function<int(int idx_v)> FirstEdgeAdapter;
33-
34-
/**
35-
* @param: idx_v:节点编号
36-
* @param: idx_e:当前扫描到的边
37-
* @return:返回下一条边的id,无边时返回NIL
38-
*/
39-
typedef std::function<int(int idx_v, int idx_e)> NextEdgeAdapter;
40-
41-
/**
42-
* @param: idx_v:节点编号
43-
* @param: idx_e:当前扫描到的边
44-
* @return:返回指向节点的id,无边时返回NIL
45-
*/
46-
typedef std::function<int(int idx_v, int idx_e)> EdgeToAdapter;
47-
48-
/**
49-
* @param idx_v:表示此边与v相连
50-
* @param idx_e:表示此边编号
51-
* @return:节点idx_v的编号为idx_e的边的长度
52-
*/
53-
typedef std::function<double(int idx_v, int idx_e)> EdgeLengthAdapter;
54-
55-
/**
56-
* @param idx_v:表示节点idx_v
57-
* @param idx_e:表示与idx_v相连的编号为idx_e的边
58-
* @return:节点idx_v的编号为idx_e的边的容量
59-
*/
60-
typedef std::function <double(int idx_v, int idx_e)> EdgeContainAdapter;
9+
#include "graph.h"
6110

62-
/**
63-
* 如果无路径,则点的序列为空
64-
* @param first:表示点的序列
65-
* @param second:表示边的序列
66-
*/
67-
typedef std::pair<std::list<int>, std::list<int>> PathType;
68-
69-
/**空路径*/
70-
const static PathType NIL_PATH = std::make_pair(std::list<int>(), std::list<int>());
71-
72-
struct GraphAdapter {
73-
FirstEdgeAdapter firstOf;
74-
NextEdgeAdapter nextOf;
75-
EdgeToAdapter destOf;
76-
EdgeLengthAdapter lengthOf;
77-
EdgeContainAdapter containOf;
78-
};
79-
80-
/**
81-
* @param idx_start_v:最初的节点编号
82-
* @param idx_dest_v:目标节点编号
83-
* @param firstOf,nextOf,edgeTo:图的属性
84-
* @return: 返回所走的路径
85-
*/
86-
PUBLIC PathType
87-
bfs(
88-
int idx_start_v, int idx_dest_v,
89-
const FirstEdgeAdapter & firstOf, const NextEdgeAdapter & nextOf,
90-
const EdgeToAdapter & destOf);
91-
92-
/**
93-
* 使用bfs算法求最少步骤的路径
94-
* @param idx_start_v:最初的节点编号
95-
* @param idx_dest_v:目标节点编号
96-
* @param graph:图的属性
97-
* @return: 返回所走的路径
98-
*/
99-
inline PathType
100-
bfs(
101-
int idx_start_v, int idx_dest_v,
102-
const GraphAdapter& graph) {
103-
return bfs(idx_start_v, idx_dest_v,
104-
graph.firstOf, graph.nextOf, graph.destOf);
105-
}
106-
107-
/**
108-
* @param idx_start_v:最初的节点编号
109-
* @param idx_dest_v:目标节点编号
110-
* @param firstOf,nextOf,edgeTo:图的属性
111-
* @return: 返回所需的步数
112-
*/
113-
inline int
114-
bfsStep(
115-
int idx_start_v, int idx_dest_v,
116-
const FirstEdgeAdapter & firstOf, const NextEdgeAdapter & nextOf,
117-
const EdgeToAdapter & destOf) {
118-
119-
PathType tmp = bfs(idx_start_v, idx_dest_v, firstOf, nextOf, destOf);
120-
return tmp.first.size() - 1;
121-
};
122-
123-
/**
124-
* @param idx_start_v:最初的节点编号
125-
* @param idx_dest_v:目标节点编号
126-
* @param graph:图的属性
127-
* @return: 返回所需的步数
128-
*/
129-
inline int
130-
bfsStep(
131-
int idx_start_v, int idx_dest_v,
132-
const GraphAdapter & graph) {
133-
return bfsStep(idx_start_v, idx_dest_v,
134-
graph.firstOf, graph.nextOf, graph.destOf);
135-
}
136-
}
11+
#ifdef __cplusplus
13712
}
13+
#endif

include/algorithm_module.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include "algorithm_module.h"
4+
5+
#ifdef WIN32
6+
#define PUBLIC \
7+
__declspec( dllexport ) // dll输出函数,至于为什么要叫public.......
8+
#else
9+
#define PUBLIC
10+
#endif
11+
12+
#include "graph.hpp"
13+
14+
namespace Algorithm {
15+
16+
/**不存在的编号,长度..*/
17+
constexpr int NIL = -1;
18+
19+
} // namespace Algorithm

include/begin.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
#include <stdlib.h>
3+
4+
#ifdef WIN32
5+
#define PUBLIC __declspec( dllexport )
6+
#else
7+
#define PUBLIC
8+
#endif
9+

include/c_algorithm_module.h

-96
This file was deleted.

0 commit comments

Comments
 (0)