From a475111de298c548241e8bb5bf5c56c8d6320370 Mon Sep 17 00:00:00 2001 From: Orestis <orestis.malaspinas@pm.me> Date: Fri, 14 Jan 2022 18:08:24 +0100 Subject: [PATCH] updated the slides --- slides/cours_14.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/slides/cours_14.md b/slides/cours_14.md index 231421f..a76ee40 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. + -- GitLab