diff --git a/.idea/misc.xml b/.idea/misc.xml index 686ec174e6a2dc91a95520d1e09690655cb0a852..322d2e73294b4452359be47f0a6828c0acb40e75 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> - <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (notebook4)" project-jdk-type="Python SDK" /> + <component name="Black"> + <option name="sdkName" value="Python 3.13 (tp2-hachage)" /> + </component> + <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (tp2-hachage)" project-jdk-type="Python SDK" /> </project> \ No newline at end of file diff --git a/.idea/tp2-hachage.iml b/.idea/tp2-hachage.iml index 8b8c395472a5a6b3598af42086e590417ace9933..5656cb133c573f76704e6be7f5a608802ad39f31 100644 --- a/.idea/tp2-hachage.iml +++ b/.idea/tp2-hachage.iml @@ -1,8 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <module type="PYTHON_MODULE" version="4"> <component name="NewModuleRootManager"> - <content url="file://$MODULE_DIR$" /> - <orderEntry type="inheritedJdk" /> + <content url="file://$MODULE_DIR$"> + <excludeFolder url="file://$MODULE_DIR$/.venv" /> + <excludeFolder url="file://$MODULE_DIR$/.venv1" /> + </content> + <orderEntry type="jdk" jdkName="Python 3.13 (tp2-hachage)" jdkType="Python SDK" /> <orderEntry type="sourceFolder" forTests="false" /> </component> <component name="PyDocumentationSettings"> diff --git a/__pycache__/tp_2_miso_mphf.cpython-313.pyc b/__pycache__/tp_2_miso_mphf.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9438a2394075cb8aa612bdc7164587a53032ae42 Binary files /dev/null and b/__pycache__/tp_2_miso_mphf.cpython-313.pyc differ diff --git a/tp_2_miso_mphf.py b/tp_2_miso_mphf.py index 1d8802c0cd4efa811ebf325a18d3e6756ed9e7e2..aeb4f93c7eb02d0d64b56ed79a6b5918e734d45a 100644 --- a/tp_2_miso_mphf.py +++ b/tp_2_miso_mphf.py @@ -141,11 +141,29 @@ def create_hash_table(set_kmer, n): >>> all(kmer in tableau for kmer in set_kmer) True """ - pass # TODO modifier + # créer la mphf pour les kmers + def MPH(kmer): # On peut pas hacher un set directement + return hash(kmer) % n # une fonction MPH qui calcule un index pour chaque kmer + + # initialiser un tableau de taille n (une liste) - # écrire les kmers aux adresses du tableau données par la mphf - # retourner le tableau et la mphf + tableau = [None] * n + for kmer in set_kmer: + index = MPH(kmer) + initial_index = index #Sauvegarde de l'index initial pour eviter une boucle infinie + + #Recherche d'une case libre avec linear probing (résolution des collisions) + while tableau[index] is not None: # écrire les kmers aux adresses du tableau données par la mphf + index = (index + 1) % n # on boucle à zero si on atteint la fin + if index == initial_index: + raise RuntimeError("La table de achage est pleine. Essayez avec une taille plus grande.") + tableau[index] = kmer #Insérer le k-mer + + return tableau, MPH # retourner le tableau et la mphf + + +