tonglin0325的个人主页

JavaScript排序算法——希尔排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>希尔排序</title>
<!--<link rel="stylesheet" type="text/css" href="../style/fdt.css" />-->
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../js/jquery.easydrag.handler.beta2.js"></script>
<script type="text/javascript">

$(document).ready(
function() {

var array_1 = [9,8,7,6,5,4,3,2,1];
alert(array_1);
/*shellSort*/
alert(shellSort(array_1));

}
);



</script>

<style type="text/css">

* { padding:0; margin:0; }

body {
padding: 100px;
font-size: 15px;
}




</style>


<script type="text/javascript">
function shellSort(array){
var stepArr = [1031612713, 217378076, 45806244, 9651787, 2034035, 428481, 90358, 19001, 4025, 1750, 836, 701, 301, 132, 57, 23, 10, 4, 1]; // reverse() 在维基上看到这个最优的步长 较小数组
var i = 0;
var stepArrLength = stepArr.length;
var len = array.length;
var len2 = parseInt(len/2);

for(;i < stepArrLength; i++){
if(stepArr[i] > len2){
continue;
}
stepSort(stepArr[i]);
}
// 排序一个步长
function stepSort(step){

//console.log(step) 使用的步长统计

var i = 0, j = 0, f, tem, key;


for(;i < step; i++){// 依次循环列
for(j=1; step * j + i < len; j++){//依次循环每列的每行
tem = f = step * j + i;
key = array[f];
while((tem-=step) >= 0){// 依次向上查找 <-
// <----
// <-------

if(array[tem] > key){
array[tem+step] = array[tem];
}else{
break;
}
}
array[tem + step ] = key;
}
}

}

return array;

}


</script>


</head>




<body>
希尔排序
</body>
</html>

全文 >>

JavaScript排序算法——归并排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>归并排序</title>
<!--<link rel="stylesheet" type="text/css" href="../style/fdt.css" />-->
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../js/jquery.easydrag.handler.beta2.js"></script>
<script type="text/javascript">

$(document).ready(
function() {

var array_1 = [9,8,7,6,5,4,3,2,1];
alert(array_1);
/*mergeSort*/
//迭代实现
alert(mergeSort(array_1));

}
);



</script>

<style type="text/css">

* { padding:0; margin:0; }

body {
padding: 100px;
font-size: 15px;
}




</style>


<script type="text/javascript">
function merge(left,right){
var result=[];
while(left.length>0 &amp;&amp; right.length>0){
if(left[0]<right[0]){
result.push(left.shift());
}else{
result.push(right.shift());
}
}
alert(" left="+left+" right"+right+" result="+result);
alert(result.concat(left).concat(right));
return result.concat(left).concat(right);
}

function mergeSort(items){
if(items.length == 1){
return items;
}
var middle=Math.floor(items.length/2),
left=items.slice(0,middle),
right=items.slice(middle);
alert(" middle="+middle+" items.length="+items.length+" left="+left+" right"+right+" items"+items);
return merge(mergeSort(left),mergeSort(right));
}



</script>


</head>




<body>
归并排序
</body>
</html>

全文 >>

JavaScript排序算法——插入排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>插入</title>
<!--<link rel="stylesheet" type="text/css" href="../style/fdt.css" />-->
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../js/jquery.easydrag.handler.beta2.js"></script>
<script type="text/javascript">

$(document).ready(
function() {

var array_1 = [9,8,7,6,5,4,3,2,1];
alert(array_1);
/*insertSort*/
alert(insertSort(array_1));
}
);

</script>


<script type="text/javascript">
function insertSort(array){
var i = 1,j, step, key, len = array.length;

for (; i < len; i++) {

step = j = i;
key = array[j];

while (--j > -1) {
if (array[j] > key) {
array[j + 1] = array[j];
}
else {
break;
}
}
array[j + 1] = key;
}
return array;
}

</script>



<style type="text/css">

* { padding:0; margin:0; }

body {
padding: 100px;
font-size: 15px;
}




</style>

</head>




<body>
快速排序
</body>
</html>

全文 >>

JavaScript排序算法——快速排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>快速排序</title>
<!--<link rel="stylesheet" type="text/css" href="../style/fdt.css" />-->
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../js/jquery.easydrag.handler.beta2.js"></script>
<script type="text/javascript">

$(document).ready(
function() {

var array_1 = [4,5,3,1,2];
alert(array_1);
/*quickSort*/
alert(quickSort(array_1));

}
);



</script>

<style type="text/css">

* { padding:0; margin:0; }

body {
padding: 100px;
font-size: 15px;
}




</style>


<script type="text/javascript">
function quickSort(array){
//var array = [8,4,6,2,7,9,3,5,74,5];
//var array = [0,1,2,44,4,324,5,65,6,6,34,4,5,6,2,43,5,6,62,43,5,1,4,51,56,76,7,7,2,1,45,4,6,7];
var i = 0;
var j = array.length - 1;
var Sort = function(i, j){

// 结束条件
if(i == j ){ return };

var key = array[i];
var stepi = i; // 记录开始位置
var stepj = j; // 记录结束位置

while(j > i){
alert(array);
// j <<-------------- 向前查找
if(array[j] >= key){
j--;
}else{
array[i] = array[j]
//i++ ------------>>向后查找
while(j > ++i){
if(array[i] > key){
array[j] = array[i];
break;
}
}
}
}

alert(array);
alert("i="+i+",j="+j+",stepi="+stepi+",stepj="+stepj);

// 如果第一个取出的 key 是最小的数
if(stepi == i){
Sort(++i, stepj);
return ;
}

// 最后一个空位留给 key
array[i] = key;

// 递归
Sort(stepi, i);
Sort(j, stepj);
}

Sort(i, j);

return array;
}


</script>


</head>




<body>
快速排序
</body>
</html>

全文 >>

JavaScript排序算法——选择排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>选择排序</title>
<!--<link rel="stylesheet" type="text/css" href="../style/fdt.css" />-->
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../js/jquery.easydrag.handler.beta2.js"></script>
<script type="text/javascript">

$(document).ready(
function() {

var array_1 = [9,8,7,6,5,4,3,2,1];
alert(array_1);
/*selectionSort*/
alert(selectionSort(array_1));

}
);



</script>

<style type="text/css">

* { padding:0; margin:0; }

body {
padding: 100px;
font-size: 15px;
}




</style>


<script type="text/javascript">
function selectionSort(array){
var len = array.length;
var index = 0;
var k;
var item;
var c;
for(var i=0; i<len; i++){

//最小的数
item = array[i];
//最小的数的位置编号
index = i;
//寻找最小的数位置
for(j=i+1; j<len;j++){
if(array[j] < item){
index = j;
item = array[j];
}
}
if(index != i){
c = array[i];
array[i] = array[index];
array[index] = c;
}
}
return array;
}


</script>


</head>




<body>
选择排序
</body>
</html>

全文 >>

Ubuntu16.04安装opentsdb2.4.1

官方文档

1
2
https://github.com/OpenTSDB/opentsdb/wiki/Installation-on-Cloudera-Virtual-Machine

opentsdb的安装依赖Hbase,本文中使用的是CDH5.16.2中的Hbase 1.2.0+cdh5.16.2

1.git clone

1
2
git clone https://github.com/OpenTSDB/opentsdb.git

2.安装

1
2
3
4
cd opentsdb
./build.sh
env COMPRESSION=none HBASE_HOME=/opt/cloudera/parcels/CDH/lib/hbase ./src/create_table.sh

如果Hbase启用了kerberos,则需要先认证

1
2
kinit -kt ~/下载/hbase.keytab hbase/master@HADOOP.COM

上面的脚本会在hbase中初始化4张table

1
2
3
4
5
6
7
8
9
10
hbase(main):004:0> list
TABLE
tsdb
tsdb-meta
tsdb-tree
tsdb-uid
4 row(s) in 0.0370 seconds

=> ["tsdb", "tsdb-meta", "tsdb-tree", "tsdb-uid"]

如果遇到

1
2
3
4
5
create 'tsdb',
{NAME => 't', VERSIONS => 1, COMPRESSION => 'NONE', BLOOMFILTER => 'ROW', DATA_BLOCK_ENCODING => 'DIFF', TTL => 'FOREVER'}

ERROR: For input string: "FOREVER"

请修改 create_table.sh 脚本

1
2
lintong@master:~/software/opentsdb/src$ vim create_table.sh

将 TSDB_TTL=${TSDB_TTL-‘FOREVER’} 修改成 TSDB_TTL=${TSDB_TTL-‘2147483647’}

如果你的hbase开启了kerberos,则需要

1
2
mv ./src/opentsdb.conf ./build/

然后编译opentsdb.conf配置文件,添加KERBEROS相关配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 --------- NETWORK ----------
# The TCP port TSD should use for communications
# *** REQUIRED ***
tsd.network.port = 10015

# ----------- HTTP -----------
# The location of static files for the HTTP GUI interface.
# *** REQUIRED ***
tsd.http.staticroot = ./staticroot
# Where TSD should write it's cache files to
# *** REQUIRED ***
tsd.http.cachedir = /tmp/tsd

# --------- CORE ----------
# Whether or not to automatically create UIDs for new metric types, default
# is False
tsd.core.auto_create_metrics = true
# Name of the HBase table where data points are stored, default is "tsdb"
tsd.storage.hbase.data_table = tsdb
# Path under which the znode for the -ROOT- region is located, default is "/hbase"
tsd.storage.hbase.zk_basedir = /hbase
# A comma separated list of Zookeeper hosts to connect to, with or without
# port specifiers, default is "localhost"
tsd.storage.hbase.zk_quorum = master

#-------- KERBEROS -----
hbase.security.auth.enable=true
hbase.security.authentication=kerberos
hbase.sasl.clientconfig=Client
hbase.kerberos.regionserver.principal=hbase/_HOST@HADOOP.COM

同时添加jass文件

1
2
3
4
5
6
7
8
9
10
11
lintong@master:~/software/opentsdb/build/jaas$ ls
jaas.conf
lintong@master:~/software/opentsdb/build/jaas$ cat jaas.conf
Client {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
useTicketCache=false
keyTab="/home/lintong/下载/hbase.keytab"
principal="hbase/master@HADOOP.COM";
};

参考:OpenTSDB搭建过程(CDH环境,kerberos认证)

HBase 1.1.2.2.6.0.3-8 TTL设置过之后,无法显示重置为FOREVER

3.创建缓存目录

1
2
mkdir /tmp/tsd

4.启动opentsdb

1
2
lintong@master:~/software/opentsdb/build$ JVMARGS="-Djava.security.auth.login.config=/home/lintong/software/opentsdb/build/jaas/jaas.conf -Dzookeeper.sasl.client=false" ./tsdb tsd

也可以添加到./tsdb启动脚本中

5.访问,我的是10015端口

全文 >>

jQuery学习笔记——弹出对话框

引用jQuery库文件的