Add Dart codes to the documents. (#529)

This commit is contained in:
Yudong Jin
2023-06-02 02:40:26 +08:00
committed by GitHub
parent 041a989d33
commit 025051c81b
38 changed files with 849 additions and 96 deletions

View File

@@ -223,6 +223,12 @@
```
=== "Dart"
```dart title="hash_map.dart"
```
遍历哈希表有三种方式,即 **遍历键值对、遍历键、遍历值**。
=== "Java"
@@ -381,6 +387,12 @@
```
=== "Dart"
```dart title="hash_map.dart"
```
## 哈希函数
哈希表的底层实现为数组,同时可能包含链表、二叉树(红黑树)等数据结构,以提高查询性能(将在下节讨论)。
@@ -484,6 +496,14 @@ $$
[class]{ArrayHashMap}-[func]{}
```
=== "Dart"
```dart title="array_hash_map.dart"
[class]{Entry}-[func]{}
[class]{ArrayHashMap}-[func]{}
```
## 哈希冲突
细心的你可能已经注意到,**在某些情况下,哈希函数 $f(x) = x \bmod 100$ 可能无法正常工作**。具体来说,当输入的 key 后两位相同时,哈希函数的计算结果也会相同,从而指向同一个 value 。例如,查询学号为 $12836$ 和 $20336$ 的两个学生时,我们得到: