├── .mvn
└── wrapper
│ ├── MavenWrapperDownloader.java
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── algorithm
│ │ └── xlb
│ │ └── algorithm
│ │ ├── AlgorithmApplication.java
│ │ ├── bitset
│ │ └── BitSetTest.java
│ │ ├── cbo
│ │ ├── DFSGreedy.java
│ │ ├── Greedy.java
│ │ ├── README.md
│ │ └── VolcanoPlaner.java
│ │ ├── dag
│ │ ├── DAG.java
│ │ ├── LinkedHashSetMultimap.java
│ │ └── README.md
│ │ ├── graph
│ │ ├── ASearch.java
│ │ ├── Dijkstra.java
│ │ ├── Kruskal.java
│ │ └── Prim.java
│ │ └── leetcode
│ │ └── regex
│ │ └── RegexSolution.java
└── resources
│ └── application.properties
└── test
└── java
└── com
└── algorithm
└── xlb
└── algorithm
├── AlgorithmApplicationTests.java
├── DAGChainTest.java
├── DAGExecTest.java
└── DAGTest.java
/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | https://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | import java.io.File;
21 | import java.io.FileInputStream;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.net.URL;
25 | import java.nio.channels.Channels;
26 | import java.nio.channels.ReadableByteChannel;
27 | import java.util.Properties;
28 |
29 | public class MavenWrapperDownloader {
30 |
31 | /**
32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
33 | */
34 | private static final String DEFAULT_DOWNLOAD_URL =
35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
36 |
37 | /**
38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
39 | * use instead of the default one.
40 | */
41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
42 | ".mvn/wrapper/maven-wrapper.properties";
43 |
44 | /**
45 | * Path where the maven-wrapper.jar will be saved to.
46 | */
47 | private static final String MAVEN_WRAPPER_JAR_PATH =
48 | ".mvn/wrapper/maven-wrapper.jar";
49 |
50 | /**
51 | * Name of the property which should be used to override the default download url for the wrapper.
52 | */
53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
54 |
55 | public static void main(String args[]) {
56 | System.out.println("- Downloader started");
57 | File baseDirectory = new File(args[0]);
58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
59 |
60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
61 | // wrapperUrl parameter.
62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
63 | String url = DEFAULT_DOWNLOAD_URL;
64 | if(mavenWrapperPropertyFile.exists()) {
65 | FileInputStream mavenWrapperPropertyFileInputStream = null;
66 | try {
67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
68 | Properties mavenWrapperProperties = new Properties();
69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
71 | } catch (IOException e) {
72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
73 | } finally {
74 | try {
75 | if(mavenWrapperPropertyFileInputStream != null) {
76 | mavenWrapperPropertyFileInputStream.close();
77 | }
78 | } catch (IOException e) {
79 | // Ignore ...
80 | }
81 | }
82 | }
83 | System.out.println("- Downloading from: : " + url);
84 |
85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
86 | if(!outputFile.getParentFile().exists()) {
87 | if(!outputFile.getParentFile().mkdirs()) {
88 | System.out.println(
89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
90 | }
91 | }
92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
93 | try {
94 | downloadFileFromURL(url, outputFile);
95 | System.out.println("Done");
96 | System.exit(0);
97 | } catch (Throwable e) {
98 | System.out.println("- Error downloading");
99 | e.printStackTrace();
100 | System.exit(1);
101 | }
102 | }
103 |
104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
105 | URL website = new URL(urlString);
106 | ReadableByteChannel rbc;
107 | rbc = Channels.newChannel(website.openStream());
108 | FileOutputStream fos = new FileOutputStream(destination);
109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
110 | fos.close();
111 | rbc.close();
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smartxing/algorithm/a44d4b809f76b0c2046bc8e88ad4212707ba60b7/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### [Task 任务调度算法 DAG 实现](https://github.com/smartxing/algorithm/blob/master/src/main/java/com/algorithm/xlb/algorithm/dag/README.md)
2 | ```text
3 | stage的划分,以及算子的优化
4 | ```
5 |
6 | ### [贪心算法](https://github.com/smartxing/algorithm/blob/master/src/main/java/com/algorithm/xlb/algorithm/cbo/README.md)
7 | ```text
8 | calcite cbo其实就是贪心的,配合一些剪枝的技巧 ,并不是全局最优解
9 | 注意:calcite的代价优化都是需要自己实现过的,
10 | 1 实现统计 比如表的count
11 | 2 实现算子的代价,默认是按行数实现的
12 | ```
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.7.RELEASE
9 |
10 |
11 | com.algorithm.xlb
12 | algorithm
13 | 0.0.1-SNAPSHOT
14 | algorithm
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 |
35 | com.google.guava
36 | guava
37 | 28.1-jre
38 |
39 |
40 |
41 | commons-io
42 | commons-io
43 | 2.6
44 |
45 |
46 |
47 | org.apache.commons
48 | commons-lang3
49 | 3.9
50 |
51 |
52 |
53 |
54 | org.apache.commons
55 | commons-collections4
56 | 4.4
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | org.springframework.boot
65 | spring-boot-maven-plugin
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/src/main/java/com/algorithm/xlb/algorithm/AlgorithmApplication.java:
--------------------------------------------------------------------------------
1 | package com.algorithm.xlb.algorithm;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class AlgorithmApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(AlgorithmApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/algorithm/xlb/algorithm/bitset/BitSetTest.java:
--------------------------------------------------------------------------------
1 | package com.algorithm.xlb.algorithm.bitset;
2 |
3 | import com.google.common.collect.Maps;
4 |
5 | import java.util.Arrays;
6 | import java.util.BitSet;
7 | import java.util.HashMap;
8 |
9 | /**
10 | *
11 | * @author xingliangbo
12 | * @version $Id: v 0.1 2019-09-10 11:13 xingliangbo Exp $
13 | */
14 | public class BitSetTest {
15 |
16 | public static void main(String[] args) {
17 |
18 | BitSet bitSet = new BitSet(6);
19 | // bitSet.set(1, false);
20 | bitSet.set(2, true);
21 | bitSet.set(3, true);
22 |
23 | System.out.println(bitSet.cardinality());
24 | BitSet bitSet2 = new BitSet(6);
25 | bitSet2.set(1, true);
26 | bitSet2.set(2, true);
27 | // bitSet.and(bitSet2);
28 | // System.out.println("xx:" + bitSet);
29 |
30 | // bitSet.or(bitSet2);
31 | // System.out.println("xx:" + bitSet);
32 | //同值取0 异值取1
33 | // bitSet.xor(bitSet2);
34 | // System.out.println("xx:" + bitSet);
35 | //相同的取0
36 | bitSet.andNot(bitSet2);
37 | System.out.println("xx:" + bitSet);
38 |
39 | System.out.println(Integer.toBinaryString(-1));
40 | int x = 0x7FFFFFFF;
41 | System.out.println(Integer.toBinaryString(x));
42 |
43 |
44 | System.out.println(-1 & x);
45 | System.out.println(Integer.MAX_VALUE);
46 | System.out.println(Integer.MIN_VALUE);
47 | System.out.println(Integer.toBinaryString(-2147483648));
48 | System.out.println("1111111111111111111111111111111".length());
49 | HashMap