当前位置: 首页 >> 科技 >
Map接口采用键值的含义是什么?循环冗余校验码是什么意思?
来源:创视网     时间:2023-01-30 11:27:47

Map接口采用键值对具有映射关系的形式存储数据,可以存储null,添加元素key存在时会覆盖value,所有key不能重复,但是value可以重复

1.HashMap(部分源码)

//默认初始容量

static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16

//最大容量

static final int MAXIMUM_CAPACITY = 1 << 30;

//默认的负载因子

static final float DEFAULT_LOAD_FACTOR = 0.75f;

//当桶节点数量大于8就会转为红黑树(JDK1.8引入的红黑树)

static final int TREEIFY_THRESHOLD = 8;

//当桶节点数量小于6就会转为链表,前提条件是当前桶是红黑树结构

static final int UNTREEIFY_THRESHOLD = 6;

//当HashMap中的所有元素数量大于64,也会转为红黑树

static final int MIN_TREEIFY_CAPACITY = 64;

//节点内部类,将一个键值对对象化

static class Node implements Map.Entry {

final inthash;//哈希值

final K key;

V value;

Node next;

Node(int hash, K key, V value, Node next) {

this.hash = hash;

this.key = key;

this.value = value;

this.next = next;

}

public final int hashCode() {

return Objects.hashCode(key) ^ Objects.hashCode(value);

}

}

//哈希桶,存放键值对元素的数组

transient Node[] table;

//存放具体元素的集

transient Set> entrySet;

//阈值,元素数量超过阈值发生扩容

int threshold;

//哈希表的加载因子

final float loadFactor;

//红黑树

static final class TreeNode extends LinkedHashMap.Entry {

TreeNode parent;

TreeNode left;

TreeNode right;

TreeNode prev;

boolean red;

.......

}

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

上面是HashMap的一些基本属性,可以看出底层是一个数组,数组里面存放是一个单向链表。

循环冗余校验码(CRC),简称循环码,是一种常用的、具有检错、纠错能力的校验码,在早期的通信中运用广泛。循环冗余校验码常用于外存储器和计算机同步通信的数据校验。奇偶校验码和海明校验码都是采用奇偶检测为手段检错和纠错的(奇偶校验码不具有纠错能力),而循环冗余校验则是通过某种数学运算来建立数据位和校验位的约定关系的。

推荐新闻 +
猜您喜欢 +