Ja0ck5


  • Home

  • Archives

  • Search

InnoDB表的限制

Posted on 2017-02-02 | In Mysql
InnoDB表的限制 对InnoDB表的限制在本节中的以下主题下进行描述:

最大值和最小值

一个表最多可以包含1017列。虚拟生成的列包含在此限制中。

一个表最多可以包含64个辅助索引。

索引键前缀长度限制是使用DYNAMIC或COMPRESSED行格式的InnoDB表的3072字节。

索引键前缀长度限制是使用REDUNDANT或COMPACT行格式的InnoDB表的767字节。例如,在TEXT或VARCHAR列上,如果假设utf8mb4字符集和每个字符最多4个字节,则列前缀索引可能超过191个字符,从而达到此限制。

Read more »

对象的内存布局

Posted on 2017-01-12 | In JVM

对象的内存布局

对象在内存中存储的布局可以分为3块区域: 对象头(Header)、实例数据(Instance Data) 和对齐填充(Padding)

HotSpot 虚拟机的对象头包括两部分信息

  1. 用于存储对象自身的运行时数据

    如 哈希码(HashCode)、GC 分代年龄、锁状态标志、线程持有的锁、偏向线程ID、偏向时间戳等。

    这部分数据的长度在 32位和64位虚拟机(未开启压缩指针) 中分别为 32bit 和 64bit,官方称之为 “Mark Word“.

    对象需要存储的运行时数据很多,其实已经超出了 32位、64位 Bitmap 结构所能记录的限度,但是对象头信息是与对象自身定义的 数据无关的额外存储成本, 考虑到虚拟机空间效率, Mark Word 被设计成一个非固定的数据结构以便在极小的空间存储尽量多的信息,它会根据对象的状态复用自己的存储空间。

    例如: 在 32 位的 HotSpot 虚拟机中,如果对象处于未被锁定的状态下,那么 Mark Word 的32bit 空间中的 25bit 用于存储对象哈希码,4 bit 用于 存储对象分代年龄,2bit 用于存储锁标志位,1bit固定为0,而在其他状态(轻量级锁,重量锁,GC标记,偏向锁)下的存储内容:

    Read more »

HotSpot 虚拟机中的对象

Posted on 2017-01-10 | In JVM

HotSpot 虚拟机中的对象

HotSpot 虚拟机在 Java 堆中对象分配、布局和访问的过程。

虚拟机遇到一条 new 指令时:

1. 检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并检查这个符号引用代表的类是否已被加载、解析和初始化过。 
2. 没有 则执行相应的类加载过程。 
3. 类加载检查通过后,虚拟机将为新生对象分配内存。 

分配内存空间

对象所需内存的大小在类加载完成后便可以确定,为对象分配空间的任务等同于把一块确定大小的内存从 Java 堆中划分出来。

Read more »

Java 内存区域

Posted on 2017-01-08 | In JVM

Java 内存区域

内存结构图

1. 程序计数器(Program Counter Register)

程序计数器是一块较小的内存空间,可以看做是当前线程所执行的字节码的行号指示器。

在虚拟机的概念模型里(仅是概念模型,各种虚拟机可能会通过一些更高效的方式去实现)。

字节码解释器 工作时就是通过改变这个计数器的值来选取下一条需要执行的字节码指令,分支、循环、跳转、异常处理、线程恢复等基础功能都需要依赖这个计数器来完成。

Java 虚拟机的**多线程是通过线程轮流切换**,并**分配处理器执行时间**的方式来实现的,**在任何一个确定的时刻,一个处理器(对于多核处理器来说是一个内核)都只会执行一条线程中的指令**。      

因此,为了线程切换后能恢复到正确的执行位置,每条线程都需要有一个独立的程序计数器,各条线程之间的计数器互不影响,独立存储,是 “线程私有“的内存。

Read more »

类与类加载器

Posted on 2017-01-06 | In JVM

类与类加载器

1
2
    虚拟机设计团队把类加载阶段中的 "通过一个类的全限定名来获取描述此类的二进制字节流" 这个动作放到 Java 虚拟机外部去实现,以便让应用程序自己决定如何
去获取需要的类。 实现这个动作的 代码模块 称为 "类加载器"。

类加载器 虽然只用于实现类的加载动作,但它在Java 程序中起到的作用却远远不限于类加载阶段。

对于任意一个类,都需要 由 加载它的类加载器 和 这个类本身一同确立其在 Java 虚拟机中的唯一性,每一个类加载器,都拥有一个独立的类名称空间。 两个类来自同一个 Class 文件,被同一个虚拟机加载,只要加载它们的类加载器不同,则这两个类必定不相等。

Read more »

二分法三种模型

Posted on 2017-01-05 | In Algorithms

二分法三种模型

时间复杂度

T(n) = T(n/2) + O(1) = O(logn)

T(n) = T(n/2) + O(n) = O(n)

left <= right

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  /**
* left <= right
* @param nums
* @param target
* @return
*/
public int binarySearch(int[] nums, int target) {
int left = 0, right = nums.length - 1; // [left,right]
while (left <= right) { // left == right
int mid = (right - left) / 2 + left;
if (nums[mid] < target) {
left = mid + 1; // [mid + 1,right]
} else if (nums[mid] > target) {
right = mid - 1; // [left ,mid - 1]
} else {
return mid;
}
}
return -1;
}
Read more »

784. Letter Case Permutation

Posted on 2017-01-04 | In LeetCode

Letter Case Permutation

1
2
3
4
5
6
7
8
9
10
11
12
13
Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string.  Return a list of all possible strings we could create.

Examples:Input: S = "a1b2"
Output: ["a1b2", "a1B2", "A1b2", "A1B2"]

Input: S = "3z4"
Output: ["3z4", "3Z4"]

Input: S = "12345"
Output: ["12345"]
Note:
S will be a string with length between 1 and 12.
S will consist only of letters or digits.

图解

Read more »

300. Longest Increasing Subsequence

Posted on 2016-12-30 | In LeetCode

Longest Increasing Subsequence

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Given an unsorted array of integers, find the length of longest increasing subsequence.
Example:

Input: [10,9,2,5,3,7,101,18]
Output: 4
Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
Note:
*
There may be more than one LIS combination, it is only necessary for you to return the length.
*
Your algorithm should run in O(n2) complexity.


Follow up: Could you improve it to O(n log n) time complexity?

递归图解LIS

Read more »

126 Word Ladder II

Posted on 2016-12-10 | In LeetCode

Word Ladder II

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
Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:
1.
Only one letter can be changed at a time
2.
Each transformed word must exist in the word list. Note that beginWord is not a transformed word.


Note:
*
Return an empty list if there is no such transformation sequence.
*
All words have the same length.
*
All words contain only lowercase alphabetic characters.
*
You may assume no duplicates in the word list.
*
You may assume beginWord and endWord are non-empty and are not the same.


Example 1:

Input:
beginWord = "hit",
endWord = "cog",
wordList = ["hot","dot","dog","lot","log","cog"]

Output:
[
["hit","hot","dot","dog","cog"],
["hit","hot","lot","log","cog"]
]
Example 2:
Input:
beginWord = "hit"
endWord = "cog"
wordList = ["hot","dot","dog","lot","log"]

Output: []

Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
Read more »

127. Word Ladder

Posted on 2016-12-08 | In LeetCode

Word Ladder

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
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:
1.
Only one letter can be changed at a time.
2.
Each transformed word must exist in the word list. Note that beginWord is not a transformed word.


Note:
*
Return 0 if there is no such transformation sequence.
*
All words have the same length.
*
All words contain only lowercase alphabetic characters.
*
You may assume no duplicates in the word list.
*
You may assume beginWord and endWord are non-empty and are not the same.


Example 1:

Input:
beginWord = "hit",
endWord = "cog",
wordList = ["hot","dot","dog","lot","log","cog"]

Output: 5

Explanation: As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog",
return its length 5.
Example 2:
Input:
beginWord = "hit"
endWord = "cog"
wordList = ["hot","dot","dog","lot","log"]

Output: 0

Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.

Word Ladder 单向宽度优先搜索 与 双向宽度优先搜索的时间复杂度比较:

Read more »
12

Ja0ck5

11 posts
4 categories
5 tags
© 2019 Ja0ck5
Powered by Hexo
|
Theme — NexT.Muse v5.1.4