Comments (2)
Yes, it's clear. I understand, thank you very much!
from sc.
Internally, map uses an array (struct sc_map_item_str *mem
above). struct sc_map_item_xx
is like:
struct sc_map_item_##name {
K key;
V value;
uint32_t hash;
};
This array contains some key value pairs, some of them are used some of them are not.
If the key of an array item is zero (key == 0), it means that item/slot is empty. So, we can place the new item there.
What if user wants to store key=0, (say key = 0, value = 15). How are we going to distinguish between "empty indicator" key=0 and this valid item?
Hashmap does a trick, if user wants to put key=0, hashmap stores it as the first item:
Line 232 in f0bb6d9
So, how do you know if that special slot is empty or not? Hashmap uses used
boolean for that. If user puts key=0 to the map, it will be stored as the first item and used
value will be true. So, when user calls get(key=0), we'll know if there is a real value in that special slot.
For pointer types (like str, void*), special key is NULL btw.
Let me know if this is clear. Cheers!
from sc.
Related Issues (15)
- question: why pass by reference in `sc_str_substring((char** str, uint32_t start, uint32_t end)`? HOT 6
- test
- Using this lib over FetchContent HOT 5
- Compile errors on Release HOT 7
- sc_str_append_fmt is trimming whitespaces at the end of the formated strings HOT 3
- Add shrink option to sc_buf
- [error]“afunix.h”: No such file or directory sc_socket_test HOT 2
- What does this function? HOT 17
- EPOLLET in non-blocking sc_sock HOT 10
- Any plans on implementing AVL tree? HOT 5
- sc_array.h: error: implicit declaration of function 'memmove' HOT 3
- #if defined(_WIN32) || defined(_WIN64) is not enough to check for MSVC HOT 7
- sc_sock: WSAPoll is broken HOT 2
- sc_sock thread-safety HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sc.