diff --git a/__pycache__/tp_2_miso_mphf.cpython-311.pyc b/__pycache__/tp_2_miso_mphf.cpython-311.pyc index 097e73219b3bbdca831893468f81055151c9d3ed..f3f6b2e8d946f32d1cb56e5bed2623aa23462d75 100644 Binary files a/__pycache__/tp_2_miso_mphf.cpython-311.pyc and b/__pycache__/tp_2_miso_mphf.cpython-311.pyc differ diff --git a/tp_2_miso_mphf.py b/tp_2_miso_mphf.py index ac9b827c45ccf72c836ac7ec1b3e4c039d7419bd..9cdf618460ebaf0e6f35e0af267a3258af78bbdd 100644 --- a/tp_2_miso_mphf.py +++ b/tp_2_miso_mphf.py @@ -82,8 +82,6 @@ def construction_mphf(set_kmer, n, gamma=2, nb_niveaux=3): rangs = [] # On initialise le rang maximal par 0 max_rang = 0 - # - i = 0 # On parcours tous les kmers dans set_kmer for kmer in set_kmer: # hacher le kmer @@ -94,9 +92,9 @@ def construction_mphf(set_kmer, n, gamma=2, nb_niveaux=3): index = grand_tableau.index(h2) # récupérer son rang (utiliser la fonction count()) c = grand_tableau[0:index].count(-1) - rangs = index - c + rang = index - c # ajouter à la mphf [h, rang] - mphf.append((h2, rangs)) + mphf.append((h2, rang)) # mettre à jour max_rang max_rang += 1 @@ -124,16 +122,21 @@ def get_hash_mphf(mphf, kmer): int: Hash du k-mer. Examples: - #>>> set_kmer = {str(i) for i in range(10)} - #>>> n = 10 - #>>> mphf = construction_mphf(set_kmer, n) - #>>> kmer = "5" - #>>> hash_mphf = get_hash_mphf(mphf, kmer) - #>>> 0 <= hash_mphf < n - #True + >>> set_kmer = {str(i) for i in range(10)} + >>> n = 10 + >>> mphf = construction_mphf(set_kmer, n) + >>> kmer = "5" + >>> hash_mphf = get_hash_mphf(mphf, kmer) + >>> 0 <= hash_mphf < n + True """ - pass # TODO modifier + h = abs(hash(kmer)) + for h_kmer, rang in mphf: + if h == h_kmer: + return rang + return -1 + def create_hash_table(set_kmer, n): """ for _ in range(len(index)): c = grand_tableau.count(-1)chage. @@ -199,4 +202,14 @@ def compare_taille(n_max, fichier_sortie): #compare_taille(10000,"mphf.png") import doctest -doctest.testmod() \ No newline at end of file +doctest.testmod() + +if __name__ == '__main__': + set_kmer = {str(i) for i in range(10)} + mphf = construction_mphf(set_kmer, 10) + print(mphf) + + kmer = '5' + print(abs(hash(kmer))) + h= get_hash_mphf(mphf, kmer) + print(h) \ No newline at end of file