Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tianyazhichiC
algorithm-visualizer
提交
88191691
A
algorithm-visualizer
项目概览
tianyazhichiC
/
algorithm-visualizer
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
algorithm-visualizer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
88191691
编写于
4月 28, 2018
作者:
J
Jason Park
提交者:
Jason
4月 30, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add randomize module
上级
9871d1c7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
57 addition
and
4 deletion
+57
-4
src/frontend/core/Randomize.js
src/frontend/core/Randomize.js
+47
-0
src/frontend/core/datas/Array2DData.js
src/frontend/core/datas/Array2DData.js
+1
-1
src/frontend/core/datas/GraphData.js
src/frontend/core/datas/GraphData.js
+2
-2
src/frontend/core/index.js
src/frontend/core/index.js
+1
-0
src/frontend/core/tracerManager.jsx
src/frontend/core/tracerManager.jsx
+2
-1
src/frontend/core/tracers/Tracer.js
src/frontend/core/tracers/Tracer.js
+4
-0
未找到文件。
src/frontend/core/Randomize.js
0 → 100644
浏览文件 @
88191691
const
integer
=
(
min
=
1
,
max
=
9
)
=>
{
return
(
Math
.
random
()
*
(
max
-
min
+
1
)
|
0
)
+
min
;
};
const
array1D
=
(
N
,
options
)
=>
{
return
array2D
(
1
,
N
,
options
)[
0
];
};
const
array2D
=
(
N
=
10
,
M
=
10
,
options
=
{})
=>
{
const
{
sorted
=
false
,
min
,
max
}
=
options
;
const
D
=
[];
for
(
let
i
=
0
;
i
<
N
;
i
++
)
{
D
.
push
([]);
for
(
let
j
=
0
;
j
<
M
;
j
++
)
{
D
[
i
].
push
(
integer
(
min
,
max
));
}
if
(
sorted
)
D
[
i
].
sort
((
a
,
b
)
=>
a
-
b
);
}
return
D
;
};
const
graph
=
(
N
=
5
,
options
=
{})
=>
{
const
{
directed
=
true
,
weighted
=
false
,
ratio
=
.
3
,
min
,
max
}
=
options
;
const
G
=
new
Array
(
N
);
for
(
let
i
=
0
;
i
<
N
;
i
++
)
G
[
i
]
=
new
Array
(
N
);
for
(
let
i
=
0
;
i
<
N
;
i
++
)
{
G
[
i
][
i
]
=
0
;
if
(
directed
)
{
for
(
let
j
=
0
;
j
<
N
;
j
++
)
{
if
(
i
===
j
)
continue
;
G
[
i
][
j
]
=
Math
.
random
()
<
ratio
?
weighted
?
integer
(
min
,
max
)
:
1
:
0
;
}
}
else
{
for
(
let
j
=
0
;
j
<
i
;
j
++
)
{
G
[
i
][
j
]
=
G
[
j
][
i
]
=
Math
.
random
()
<
ratio
?
weighted
?
integer
(
min
,
max
)
:
1
:
0
;
}
}
}
return
G
;
};
export
default
{
integer
,
array1D
,
array2D
,
graph
,
};
\ No newline at end of file
src/frontend/core/datas/Array2DData.js
浏览文件 @
88191691
...
...
@@ -18,7 +18,7 @@ class Array2DData extends Data {
super
.
set
();
}
notify
(
x
,
y
,
v
)
{
notify
(
x
,
y
,
v
=
this
.
data
[
x
][
y
].
value
)
{
this
.
data
[
x
][
y
].
value
=
v
;
this
.
data
[
x
][
y
].
notified
=
true
;
this
.
render
();
...
...
src/frontend/core/datas/GraphData.js
浏览文件 @
88191691
...
...
@@ -108,12 +108,12 @@ class Graph {
}
addNode
(
id
,
weight
,
visited
,
x
=
0
,
y
=
0
)
{
if
(
this
.
findNode
(
id
))
throw
new
Error
(
`Node '
${
id
}
' is already added.`
)
;
if
(
this
.
findNode
(
id
))
return
;
this
.
nodes
.
push
({
id
,
weight
,
visited
,
x
,
y
});
}
addEdge
(
source
,
target
,
weight
,
visited
)
{
if
(
this
.
findEdge
(
source
,
target
))
throw
new
Error
(
`Edge from '
${
source
}
' to '
${
target
}
' is already added.`
)
;
if
(
this
.
findEdge
(
source
,
target
))
return
;
this
.
edges
.
push
({
source
,
target
,
weight
,
visited
});
}
...
...
src/frontend/core/index.js
浏览文件 @
88191691
export
{
default
as
Randomize
}
from
'
./Randomize
'
;
export
{
default
as
Seed
}
from
'
./Seed
'
;
export
{
default
as
tracerManager
}
from
'
./tracerManager
'
;
\ No newline at end of file
src/frontend/core/tracerManager.jsx
浏览文件 @
88191691
import
React
from
'
react
'
;
import
{
Seed
}
from
'
/core
'
;
import
{
Randomize
,
Seed
}
from
'
/core
'
;
import
*
as
Tracers
from
'
/core/tracers
'
;
import
{
Tracer
}
from
'
/core/tracers
'
;
import
*
as
Datas
from
'
/core/datas
'
;
...
...
@@ -8,6 +8,7 @@ import { Array1DRenderer, Array2DRenderer, ChartRenderer, GraphRenderer, LogRend
Object
.
assign
(
window
,
Tracers
);
Object
.
assign
(
window
,
Datas
);
Object
.
assign
(
window
,
{
Randomize
});
class
TracerManager
{
constructor
()
{
...
...
src/frontend/core/tracers/Tracer.js
浏览文件 @
88191691
class
Tracer
{
constructor
(
title
=
this
.
constructor
.
name
,
options
=
{})
{
if
(
typeof
title
===
'
object
'
)
{
options
=
title
;
title
=
this
.
constructor
.
name
;
}
this
.
key
=
Tracer
.
seed
.
addTracer
(
this
.
constructor
.
name
,
title
,
options
);
this
.
register
(
'
reset
'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录