Ali's new retail database design and actual combat (upgraded version)

download: Alibaba's new retail database design and actual combat (upgraded version)

The course is based on the "Suning Cloud Business" business of "Alibaba Department of New Retail", and takes you to complete the database design from zero to one, taking into account the "basic and high": the foundation covers CRUD, indexing, affairs; the high includes clusters, Lucene full-text search Word segmentation with Chinese helps you master the design and actual combat capabilities of the database. Sort out the core pain points, give enterprise-level solutions, and project interviews can also be easy.
Suitable for the crowd
1. Quickly accumulate practical work experience in database, students with big factory pursuits
2. Engineers with 1-2 years of work experience, such as: RD, QA, DBA
3. People who are interested in the new business form-new retail,
such as: PM, data analysis direction operation, etc.

Technical reserve requires
basic knowledge of MySQL to
master at least one programming language
import java.util.Scanner;
public class Calculate {
private static Scanner in;//Create an input object
public static void main(String[] args) {
// TODO Auto- generated method stub
Calculate i =new Calculate();
int Max = 0;
int Max1 = 0;
in = new Scanner(System.in);
System.out.print("Please enter the length of the array:");
int j= in.nextInt();//Input the length of the array
System.out.print("Please input the array one by one:");
int Arr[]=new int[j];//Input the array
for(int a = 0;a <j; a++){
Arr[a]=in.nextInt();
}
int Arr1[]=new int [j];
for(int a = 0; a <j; a++) {
for(int b = 0; b <j; b++){
Arr1[b]=Arr[(b + a)%(j)];
}
Max=i.findMaxArr(Arr1);
if(Max > Max1) {
Max1 = Max;
}
}
System.out.print("最大的子數組和爲"+Max1);
}
public int findMaxArr(int[] arr) {
int Arr = 0;
int MaxArr = 0;
int c = arr.length;
int Location2=0;
int a;
for ( a = 0; a < c; a++) {
Arr += arr[a];
if (Arr < 0) {
Arr = 0;
}
if (Arr > MaxArr) {
MaxArr = Arr;
}
}
for(a = Location2; a >= 0; a--) {
if(MaxArr-arr[a]==0) {
break;
}
}
if (MaxArr == 0) {
for ( a = 0; a < c; a++) {
if (a == 0) {
MaxArr = arr[a];
}
if (arr[a]> MaxArr) {
MaxArr = arr[a];
}
}
}
return MaxArr;
}
}
2. Stop the unit test code as follows:

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class CalculateTest {
private Calculate mcalculate;
int[] Calculate = {1,4,5,-5,-1};br/>@Before
public void setUp() throws Exception {
mcalculate =new Calculate();
br/>}
@Test
public void testMain() throws Exception {
br/>}
@Test
public void testFindMaxArr() throws Exception {
assertEquals(10, mcalculate.findMaxArr(Calculate), 0);
}
}
二、代码作風阐明
1,分行定義變量

        int Arr = 0;
        int MaxArr = 0;
        int c = arr.length;
        int Location2=0;
        int a;            

2. Indentation style (indent)

Among the issues related to code style, the most conspicuous one can be said to be the indentation of the code (Indent). The so-called indentation is to leave a partial length at the left end of each line of code, which more clearly shows the hierarchical structure of the program in appearance.

Third, the unit test verifies the correctness of the program and the screenshot of the operation result
1. Using the unit testing tool JUnit that comes with Eclipse, first click on the file, create new, select Junit Text Case, and then select the class and method to be tested ,Figure 1,

![]()

Figure 1 Operation process diagram

The creation of victory is shown in Figure 2,

![]()

Figure 2 Create victory interface diagram

2. The operation result is shown in Figure 3:

![]()

Figure 3 Operation results

3. Test results

(1) The largest sub-array is partial, the test case [1,4,5,-5,-1], the largest sub-array and 10 (Figure 4)

![]()

Figure 4 Test result victory

(2) The largest sub-array is partial, the test case [1,3,-1], the largest sub-array and 4 (Figure 5)

![]()

Figure 5 Test result victory

3. The array is all zeros, the test case [0,0,0], the largest sub-array and 0 (Figure 6)

![]()

Figure 6 Test result victory

4. The array is all negative, the test case [-1, -3, -1], the largest sub-array and -1 (Figure 7)

![]()

Figure 7 Test result victory

5. The largest sub-array is the true subset, test case [2, 3, 4], the largest sub-array and 9 (Figure 8)

![]()

Figure 8 Test result victory

6. The largest sub-array is a single number, test cases [1, -2, 5, -1, -1], the largest sub-array and 9 (Figure 9)

![]()

Figure 9 Test result victory

4. Performance analysis results and improvement
1, to minimize the repeated calculation of variables

For example: to understand a concept and call a method, even if there is only one sentence in the method, it is costly, including creating a stack frame, maintaining the scene when the method is invoked, and restoring the scene when the method is called. So for example the following operation:

        int c = arr.length;
        for ( a = 0; a < c; a++) {
            Arr += arr[a];
            if (Arr < 0) {
                Arr = 0;
            }
            if (Arr > MaxArr) {
                MaxArr = Arr;
              }
        }            

Instead of using:

for (a = 0; a <arr.length; a++) {
Arr += arr[a];
if (Arr <0) {
Arr = 0;
}
if (Arr> MaxArr) {
MaxArr = Arr;
}
}
2, Try to prevent random use of static variables

3. Don't create some unused objects, don't import some unused classes

This is meaningless. If "The value of the local variable i is not used" and "The import java.util is never used" appear in the code, then please delete these useless content.

4. Please know that there is no difference between if (i == 1) and if (1 == i) in java, but in terms of reading habits, it is recommended to use the former

People usually ask whether there is a difference between "if (i == 1)" and "if (1== i)", which should start with C/C++.

In C/C++, the judgment condition of "if (i == 1)" is established. It is based on 0 and non-zero. 0 means false and non-zero means true. Although Java's "if (i == 1)" There is no difference in semantics from "if (1 == i)". In terms of reading habits, it is better to suggest using the former.

For example (code in bold):

for(a = Location2; a >= 0; a--) {
if(MaxArr-arr[a]==0) {
break;
}
}
if (MaxArr == 0) {
for ( a = 0; a < c; a++) {
if (a == 0) {
MaxArr = arr[a];
}
if (arr[a] > MaxArr) {
MaxArr = arr[a];
}
}
}

Guess you like

Origin blog.51cto.com/15134648/2663685