Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
XmchxUp committed May 24, 2024
1 parent dad2ee0 commit 706cb19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 2024/05/cpp_hashmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Code](https://github.com/cs-learning-every-day/CS106L/tree/main/cs106L-assignment2)

主要是const和template的使用结合。

const函数都去直接掉用非const函数

```sh
template <typename K, typename M, typename H>
typename HashMap<K, M, H>::const_iterator HashMap<K, M, H>::begin() const {
// This is called the static_cast/const_cast trick, which allows us to reuse
// the non-const version of find to implement the const version.
// The idea is to cast this so it's pointing to a non-const HashMap, which
// calls the overload above (and prevent infinite recursion).
// Also note that we are calling the conversion operator in the iterator
// class!
return static_cast<const_iterator>(
const_cast<HashMap<K, M, H>*>(this)->begin());
}
```
底层就是一个bucket array(hash索引), bucket是一个链表存储索引冲突的节点。
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The best thing to do is have fun.
- [Hobby Projects](/hobby_projects.md)
- [Kata](/kata.md)
- **2024-05**
- [怎么实现一个HashMap STL-compliant, industrial strength, robust, and blazingly fast data structure](/2024/05/cpp_hashmap.md)
- [RC-EaseProbe 一个优雅的状态检测工具,支持多种协议和通知平台](/2024/05/rc_easeprobe.md)
- [从一个Wiki地址如何一步一步的到另一个Wiki地址](/2024/05/wiki_start_to_wiki_end.md)
- [如何手搓一个 CPU?](/2024/05/cs61cpu.md)
Expand Down

0 comments on commit 706cb19

Please sign in to comment.