initial hashmap code
This commit is contained in:
@@ -51,7 +51,7 @@ It is similar to `poll()` but more efficient when dealing with lots of fds. The
|
||||
int epoll_create1(int flags);
|
||||
```
|
||||
|
||||
Just pass 0 for the `flags`, it is an improved version of the `epoll_create()`. It creates a new epoll instance nad returns the fd of that instance.
|
||||
Just pass 0 for the `flags`, it is an improved version of the `epoll_create()`. It creates a new epoll instance and returns the fd of that instance.
|
||||
|
||||
```c
|
||||
#include <sys/epoll.h>
|
||||
|
||||
19
notes/hash-table.md
Normal file
19
notes/hash-table.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Hash Table
|
||||
Well, the moment has come. I never made a Hash Map algorithm, but in this scenario I have to save both fd and sockaddr (I could make a simply linked list, but it's a way to learn new things).
|
||||
|
||||
Let's start with a little bit of theory.
|
||||
|
||||
A *Hash Table* is a data structure also called **dictionary** or **map**. It maps *keys* to *values* thanks to a **hash function** that computes and *index* (**hash code**) into an array of **buckets**.
|
||||
|
||||
One problem could be the *hash collision* where the hash function computes the same index for different values. A fix could be the **chaining** method, where for the same hash code you can make a linked list and append the index. Then the lookup function will go through the list and find the key.
|
||||
|
||||
In a Hash Map you can insert, delete and lookup (simply search).
|
||||
|
||||
### Hash function
|
||||
The easiest way... don't judge me.
|
||||
|
||||
- Integer keys:
|
||||
$$ hash(\text{key}) = \text{key} \mod \text{table\_dim} $$
|
||||
|
||||
- String keys:
|
||||
$$ hash(key) = \sum_{i=0}^{len(key) - 1} ascii\_value(key[i]) * prime\_number$$
|
||||
11
notes/http-request.md
Normal file
11
notes/http-request.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# HTTP Request
|
||||
This is an example of a basic HTTP request made from the browser:
|
||||
|
||||
```bash
|
||||
GET / HTTP/1.1
|
||||
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
|
||||
Host: www.tutorialspoint.com
|
||||
Accept-Language: en-us
|
||||
Accept-Encoding: gzip, deflate
|
||||
Connection: Keep-Alive
|
||||
```
|
||||
Reference in New Issue
Block a user