google / google/gson

LinkedTreeMap效率怎么样,和HashMap相比呢?

Open
#1,596 4 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

JsonObject的底层用的是LinkedTreeMap,Google自己写了一套。应该是有序的红黑树Map。 插入时间复杂度为O(lgn) + 左旋/右旋等等。查找时间复杂度为O(lgn) + 左旋/右旋等等。

而自带的HashMap,插入基本为O1, 查找基本为O1。就算有冲突,大于8,也会默认转为红黑树,优化的非常好。

那为什么Google要专门写一套呢?有人对比过效率么?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.