diff --git a/slides/cours_14.md b/slides/cours_14.md index 231421ff4113c8ee92b86b3c68769b3d8fc1744d..a76ee404bf977a6b28d16a4e18a988440609c545 100644 --- a/slides/cours_14.md +++ b/slides/cours_14.md @@ -107,3 +107,67 @@ bool search(table, key, value) { } ``` +# Écrivons le code! + +* Mais avant: + * Quelles sont les structures de données dont nous avons besoin? + * Y a-t-il des fonctions auxiliaires à écrire? + * Écrire les signatures des fonctions. + +. . . + +## Structures de données + +. . . + +```C +typedef enum {empty, deleted, occupied}; +typedef ... key_t; +typedef ... value_t; +typedef struct _cell_t { + key_t key; + value_t value; + state_t state; +} cell_t; +typedef struct _hm { + cell_t *table; + int capacity; + int size; +} hm; +``` + +# Écrivons le code! + +## Fonctions auxiliaires + +. . . + +```C +static int hash(key_t key); +static int rehash(int index, key_t key); +static int find_index(hm h, key_t key); +``` + +## Signature de l'API + +```C +void hm_init(hm *h, int capacity); +void hm_destroy(hm *h); +bool hm_set(hm *h, key_t key, value_t *value); +bool hm_get(hm h, key_t key, value_t *value); +bool hm_remove(hm *h, key_t key, value_t *value); +bool hm_search(hm h, key_t key); +void hm_print(hm h); +``` + +# Live code session! + +0. Offered to you by ProtonVPN! + +. . . + +1. Like the video. +2. Subscribe to the channel. +3. Use our one time voucher for ProtonVPN: `PAULISAWESOME`. +4. Consider donating on our patreon. +